SIONlib  1.7.6
Scalable I/O library for parallel access to task-local files
sion_file.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2019 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
14 #ifndef SION_SION_FILE_H
15 #define SION_SION_FILE_H
16 
17 #include <stdio.h>
18 
19 #include "sion_const.h"
20 #include "sion_datatypes.h"
21 
22 #define SION_FILE_FLAG_ANSI 1
23 #define SION_FILE_FLAG_SCNDANSI 2
24 #define SION_FILE_FLAG_POSIX 4
25 #define SION_FILE_FLAG_CREATE 8
26 #define SION_FILE_FLAG_WRITE 16
27 #define SION_FILE_FLAG_READ 32
28 #define SION_FILE_FLAG_SIONFWD 64
30 struct _sion_fileptr_s {
31  unsigned int flags;
32  FILE *fileptr;
33  FILE *second_fileptr;
34  int fd;
35  sion_int64 position;
36 };
37 typedef struct _sion_fileptr_s _sion_fileptr;
38 
39 /* open/close */
40 _sion_fileptr *_sion_file_open(const char *fname, unsigned int flags, unsigned int addflags);
41 int _sion_file_close( _sion_fileptr *sion_fileptr );
42 
43 /* write/read */
44 sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr );
45 sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr );
46 
47 /* utility */
48 int _sion_file_set_second_fileptr( _sion_fileptr *sion_fileptr, FILE* fileptr);
51 int _sion_file_stat_file(const char *fname);
52 int _sion_file_stat_file2(const char *fname, unsigned int apiflag);
53 
54 sion_int64 _sion_file_set_position(_sion_fileptr *fileptr, sion_int64 startpointer);
55 sion_int64 _sion_file_get_position(_sion_fileptr *fileptr);
56 
57 int _sion_file_flush(_sion_fileptr *fileptr);
58 int _sion_file_purge(_sion_fileptr *fileptr);
59 
60 int _sion_file_set_buffer(_sion_fileptr *fileptr, char *buffer, sion_int32 buffer_size);
61 int _sion_file_get_fd( _sion_fileptr *sion_fileptr);
62 
63 
64 /* ********************************************************************************************** */
65 /* *** Internal INTERFACE Functions (ANSI, POSIX) */
66 /* ********************************************************************************************** */
67 FILE *_sion_file_open_ansi_write_create(const char *fname, unsigned int addflags);
68 FILE *_sion_file_open_ansi_write_existing(const char *fname, unsigned int addflags);
69 FILE *_sion_file_open_ansi_read(const char *fname, unsigned int addflags);
70 int _sion_file_close_ansi(FILE *fileptr);
71 long _sion_file_get_opt_blksize_ansi( FILE *fileptr);
72 sion_int64 _sion_file_set_position_ansi(FILE *fileptr, sion_int64 startpointer);
73 sion_int64 _sion_file_get_position_ansi(FILE *fileptr);
74 int _sion_file_flush_ansi(FILE *fileptr);
75 int _sion_file_purge_ansi(FILE *fileptr);
76 int _sion_file_set_buffer_ansi(FILE *fileptr, char *buffer, sion_int32 buffer_size);
77 sion_int64 _sion_file_write_ansi(const void *data, sion_int64 bytes, FILE *fileptr );
78 sion_int64 _sion_file_read_ansi(void *data, sion_int64 bytes, FILE *fileptr );
79 
80 int _sion_file_open_posix_write_create(const char *fname, unsigned int addflags);
81 int _sion_file_open_posix_write_existing(const char *fname, unsigned int addflags);
82 int _sion_file_open_posix_read(const char *fname, unsigned int addflags);
83 int _sion_file_close_posix(int fd);
85 sion_int64 _sion_file_set_position_posix(int fd, sion_int64 startpointer);
86 sion_int64 _sion_file_get_position_posix(int fd);
87 int _sion_file_flush_posix(int fd);
88 int _sion_file_purge_posix(int fd);
89 int _sion_file_set_buffer_posix(int fd, char *buffer, sion_int32 buffer_size);
90 sion_int64 _sion_file_write_posix(const void *data, sion_int64 bytes, int fd );
91 sion_int64 _sion_file_read_posix(void *data, sion_int64 bytes, int fd );
92 
93 #if defined(_SION_SIONFWD)
94 int _sion_file_open_sionfwd_write_create(const char *fname, unsigned int addflags);
95 int _sion_file_open_sionfwd_write_existing(const char *fname, unsigned int addflags);
96 int _sion_file_open_sionfwd_read(const char *fname, unsigned int addflags);
97 int _sion_file_close_sionfwd(int fd);
98 long _sion_file_get_opt_blksize_sionfwd(int fd);
99 int _sion_file_flush_sionfwd(int fd);
100 int _sion_file_purge_sionfwd(int fd);
101 int _sion_file_set_buffer_sionfwd(int fd, char *buffer, sion_int32 buffer_size);
102 sion_int64 _sion_file_write_sionfwd(const void *data, sion_int64 bytes, int fd, sion_int64 *position);
103 sion_int64 _sion_file_read_sionfwd(void *data, sion_int64 bytes, int fd, sion_int64 *position);
104 #endif
105 
106 /* ********************************************************************************************** */
107 /* *** Internal Utility Functions */
108 /* ********************************************************************************************** */
110 char* _sion_get_fileptr_desc(_sion_fileptr *sion_fileptr);
111 
112 
113 #endif
_sion_file_get_position_posix
sion_int64 _sion_file_get_position_posix(int fd)
POSIX: Get the current position in file.
Definition: sion_file.c:915
_sion_get_fileptr_desc
char * _sion_get_fileptr_desc(_sion_fileptr *sion_fileptr)
Definition: sion_file.c:1225
_sion_file_flush
int _sion_file_flush(_sion_fileptr *fileptr)
Flush data to file.
Definition: sion_file.c:345
_sion_file_get_opt_blksize_posix
long _sion_file_get_opt_blksize_posix(int fd)
POSIX: Get optional file system block size for a file.
Definition: sion_file.c:855
_sion_file_stat_file
int _sion_file_stat_file(const char *fname)
Check if file exists (LARGE_FILE support on BlueGene)
Definition: sion_file.c:251
_sion_file_get_fd
int _sion_file_get_fd(_sion_fileptr *sion_fileptr)
Utility function: Get POSIX fp.
Definition: sion_file.c:470
sion_datatypes.h
_sion_file_set_second_fileptr
int _sion_file_set_second_fileptr(_sion_fileptr *sion_fileptr, FILE *fileptr)
Set second fileptr for file if opened with ANSI.
Definition: sion_file.c:426
_sion_file_write_posix
sion_int64 _sion_file_write_posix(const void *data, sion_int64 bytes, int fd)
POSIX: Write data to file.
Definition: sion_file.c:1002
_sion_file_read
sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Read data from file.
Definition: sion_file.c:204
_sion_file_open
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
Definition: sion_file.c:45
_sion_file_set_buffer_ansi
int _sion_file_set_buffer_ansi(FILE *fileptr, char *buffer, sion_int32 buffer_size)
ANSI: set buffer of fp.
Definition: sion_file.c:717
_sion_file_write
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
Definition: sion_file.c:175
_sion_file_purge_ansi
int _sion_file_purge_ansi(FILE *fileptr)
ANSI: Purge the data to the disk.
Definition: sion_file.c:705
_sion_file_open_posix_read
int _sion_file_open_posix_read(const char *fname, unsigned int addflags)
POSIX: Open a file for reading.
Definition: sion_file.c:815
_sion_file_close_ansi
int _sion_file_close_ansi(FILE *fileptr)
ANSI: Close a file.
Definition: sion_file.c:561
_sion_file_read_ansi
sion_int64 _sion_file_read_ansi(void *data, sion_int64 bytes, FILE *fileptr)
ANSI: Read data from file.
Definition: sion_file.c:744
_sion_file_close_posix
int _sion_file_close_posix(int fd)
POSIX: Close a file.
Definition: sion_file.c:840
_sion_file_flush_posix
int _sion_file_flush_posix(int fd)
POSIX: Flush the data to the disk.
Definition: sion_file.c:943
_sion_file_set_position_posix
sion_int64 _sion_file_set_position_posix(int fd, sion_int64 startpointer)
POSIX: Set the start position for the current task.
Definition: sion_file.c:876
_sion_file_get_opt_blksize
long _sion_file_get_opt_blksize(_sion_fileptr *fileptr)
Get optional file system block size for a file.
Definition: sion_file.c:229
_sion_file_set_buffer
int _sion_file_set_buffer(_sion_fileptr *fileptr, char *buffer, sion_int32 buffer_size)
Set buffer of fp.
Definition: sion_file.c:399
_sion_file_open_ansi_write_create
FILE * _sion_file_open_ansi_write_create(const char *fname, unsigned int addflags)
ANSI: Create and open a new file for writing.
Definition: sion_file.c:501
_sion_file_open_ansi_write_existing
FILE * _sion_file_open_ansi_write_existing(const char *fname, unsigned int addflags)
ANSI: Open a new file for writing.
Definition: sion_file.c:520
_sion_file_set_buffer_posix
int _sion_file_set_buffer_posix(int fd, char *buffer, sion_int32 buffer_size)
POSIX: set buffer of fd.
Definition: sion_file.c:989
sion_const.h
_sion_file_unset_second_fileptr
int _sion_file_unset_second_fileptr(_sion_fileptr *sion_fileptr)
Unset second fileptr for file if opened with ANSI.
Definition: sion_file.c:448
_sion_file_read_posix
sion_int64 _sion_file_read_posix(void *data, sion_int64 bytes, int fd)
POSIX: Read data from file.
Definition: sion_file.c:1035
_sion_file_open_posix_write_existing
int _sion_file_open_posix_write_existing(const char *fname, unsigned int addflags)
POSIX: Open a new file for writing.
Definition: sion_file.c:789
_sion_file_flush_ansi
int _sion_file_flush_ansi(FILE *fileptr)
ANSI: Flush the data to the disk.
Definition: sion_file.c:695
_sion_file_write_ansi
sion_int64 _sion_file_write_ansi(const void *data, sion_int64 bytes, FILE *fileptr)
ANSI: Write data to file.
Definition: sion_file.c:730
_sion_file_open_posix_write_create
int _sion_file_open_posix_write_create(const char *fname, unsigned int addflags)
POSIX: Create and open a new file for writing.
Definition: sion_file.c:763
_sion_file_open_ansi_read
FILE * _sion_file_open_ansi_read(const char *fname, unsigned int addflags)
ANSI: Open a file for reading.
Definition: sion_file.c:543
_sion_file_stat_file2
int _sion_file_stat_file2(const char *fname, unsigned int apiflag)
Check if file exists with appropriate low-level API.
Definition: sion_file.c:262
_sion_file_close
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
Definition: sion_file.c:139
_sion_file_get_position_ansi
sion_int64 _sion_file_get_position_ansi(FILE *fileptr)
ANSI: Get the current position in file.
Definition: sion_file.c:652
_sion_file_alloc_and_init_sion_fileptr
_sion_fileptr * _sion_file_alloc_and_init_sion_fileptr(void)
Create and return _sion_fileptr.
Definition: sion_file.c:1187
_sion_file_purge
int _sion_file_purge(_sion_fileptr *fileptr)
Purge data to file.
Definition: sion_file.c:371
_sion_file_set_position
sion_int64 _sion_file_set_position(_sion_fileptr *fileptr, sion_int64 startpointer)
Set new position in file.
Definition: sion_file.c:292
_sion_file_set_position_ansi
sion_int64 _sion_file_set_position_ansi(FILE *fileptr, sion_int64 startpointer)
ANSI: Set the start position for the current task.
Definition: sion_file.c:598
_sion_fileptr_s
Definition: sion_file.h:29
_sion_file_purge_posix
int _sion_file_purge_posix(int fd)
POSIX: Purge the data to the disk.
Definition: sion_file.c:966
_sion_file_get_opt_blksize_ansi
long _sion_file_get_opt_blksize_ansi(FILE *fileptr)
ANSI: Get optional file system block size for a file.
Definition: sion_file.c:576
_sion_file_get_position
sion_int64 _sion_file_get_position(_sion_fileptr *fileptr)
Get new position in file.
Definition: sion_file.c:319