SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
Macros | Functions
sion_file.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "sion.h"
#include "sion_debug.h"
#include "sion_error_handler.h"
#include "sion_internal.h"
#include "sion_file.h"
Include dependency graph for sion_file.c:

Go to the source code of this file.

Macros

#define _XOPEN_SOURCE   700
 
#define DFUNCTION   "_sion_file_close"
 
#define STR_PRT(X)   case X: return # X
 

Functions

_sion_fileptr_sion_file_open (const char *fname, unsigned int flags, unsigned int addflags)
 Create and open a new file for writing. More...
 
int _sion_file_close (_sion_fileptr *sion_fileptr)
 Close file and destroys fileptr structure. More...
 
sion_int64 _sion_file_write (const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
 Write data to file. More...
 
sion_int64 _sion_file_read (void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
 Read data from file. More...
 
long _sion_file_get_opt_blksize (_sion_fileptr *sion_fileptr)
 Get optional file system block size for a file. More...
 
int _sion_file_stat_file (const char *fname)
 Check if file exists (LARGE_FILE support on BlueGene) More...
 
int _sion_file_stat_file2 (const char *fname, unsigned int apiflag)
 Check if file exists with appropriate low-level API. More...
 
sion_int64 _sion_file_set_position (_sion_fileptr *sion_fileptr, sion_int64 startpointer)
 Set new position in file. More...
 
sion_int64 _sion_file_get_position (_sion_fileptr *sion_fileptr)
 Get new position in file. More...
 
int _sion_file_flush (_sion_fileptr *sion_fileptr)
 Flush data to file. More...
 
int _sion_file_purge (_sion_fileptr *sion_fileptr)
 Purge data to file. More...
 
int _sion_file_set_buffer (_sion_fileptr *sion_fileptr, char *buffer, sion_int32 buffer_size)
 Set buffer of fp. More...
 
int _sion_file_set_second_fileptr (_sion_fileptr *sion_fileptr, FILE *fileptr)
 Set second fileptr for file if opened with ANSI. More...
 
int _sion_file_unset_second_fileptr (_sion_fileptr *sion_fileptr)
 Unset second fileptr for file if opened with ANSI. More...
 
int _sion_file_get_fd (_sion_fileptr *sion_fileptr)
 Utility function: Get POSIX fp. More...
 
FILE * _sion_file_open_ansi_write_create (const char *fname, unsigned int addflags)
 ANSI: Create and open a new file for writing. More...
 
FILE * _sion_file_open_ansi_write_existing (const char *fname, unsigned int addflags)
 ANSI: Open a new file for writing. More...
 
FILE * _sion_file_open_ansi_read (const char *fname, unsigned int addflags)
 ANSI: Open a file for reading. More...
 
int _sion_file_close_ansi (FILE *fileptr)
 ANSI: Close a file. More...
 
long _sion_file_get_opt_blksize_ansi (FILE *fileptr)
 ANSI: Get optional file system block size for a file. More...
 
sion_int64 _sion_file_set_position_ansi (FILE *fileptr, sion_int64 startpointer)
 ANSI: Set the start position for the current task. More...
 
sion_int64 _sion_file_get_position_ansi (FILE *fileptr)
 ANSI: Get the current position in file. More...
 
int _sion_file_flush_ansi (FILE *fileptr)
 ANSI: Flush the data to the disk. More...
 
int _sion_file_purge_ansi (FILE *fileptr)
 ANSI: Purge the data to the disk. More...
 
int _sion_file_set_buffer_ansi (FILE *fileptr, char *buffer, sion_int32 buffer_size)
 ANSI: set buffer of fp. More...
 
sion_int64 _sion_file_write_ansi (const void *data, sion_int64 bytes, FILE *fileptr)
 ANSI: Write data to file. More...
 
sion_int64 _sion_file_read_ansi (void *data, sion_int64 bytes, FILE *fileptr)
 ANSI: Read data from file. More...
 
int _sion_file_open_posix_write_create (const char *fname, unsigned int addflags)
 POSIX: Create and open a new file for writing. More...
 
int _sion_file_open_posix_write_existing (const char *fname, unsigned int addflags)
 POSIX: Open a new file for writing. More...
 
int _sion_file_open_posix_read (const char *fname, unsigned int addflags)
 POSIX: Open a file for reading. More...
 
int _sion_file_close_posix (int fd)
 POSIX: Close a file. More...
 
long _sion_file_get_opt_blksize_posix (int fd)
 POSIX: Get optional file system block size for a file. More...
 
sion_int64 _sion_file_set_position_posix (int fd, sion_int64 startpointer)
 POSIX: Set the start position for the current task. More...
 
sion_int64 _sion_file_get_position_posix (int fd)
 POSIX: Get the current position in file. More...
 
int _sion_file_flush_posix (int fd)
 POSIX: Flush the data to the disk. More...
 
int _sion_file_purge_posix (int fd)
 POSIX: Purge the data to the disk. More...
 
int _sion_file_set_buffer_posix (int fd, char *buffer, sion_int32 buffer_size)
 POSIX: set buffer of fd. More...
 
sion_int64 _sion_file_write_posix (const void *data, sion_int64 bytes, int fd)
 POSIX: Write data to file. More...
 
sion_int64 _sion_file_read_posix (void *data, sion_int64 bytes, int fd)
 POSIX: Read data from file. More...
 
_sion_fileptr_sion_file_alloc_and_init_sion_fileptr (void)
 Create and return _sion_fileptr. More...
 
char * _sion_fileptrflags_to_str (unsigned int flag)
 
char * _sion_get_fileptr_desc (_sion_fileptr *sion_fileptr)
 

Function Documentation

◆ _sion_file_alloc_and_init_sion_fileptr()

_sion_fileptr* _sion_file_alloc_and_init_sion_fileptr ( void  )

Create and return _sion_fileptr.

Returns
_sion_fileptr

Definition at line 1526 of file sion_file.c.

Referenced by _sion_file_open().

◆ _sion_file_close()

int _sion_file_close ( _sion_fileptr sion_fileptr)

Close file and destroys fileptr structure.

Parameters
[in,out]sion_fileptrfile handle
Returns
SION_SUCCESS if success

Definition at line 178 of file sion_file.c.

◆ _sion_file_close_ansi()

int _sion_file_close_ansi ( FILE *  fileptr)

ANSI: Close a file.

Parameters
*fileptrANSI file pointer
Returns
SION_SUCCESS or SION_NOT_SUCCESS

Definition at line 671 of file sion_file.c.

◆ _sion_file_close_posix()

int _sion_file_close_posix ( int  fd)

POSIX: Close a file.

Parameters
fdPOSIX file pointer
Returns
SION_SUCCESS or SION_NOT_SUCCESS

Definition at line 950 of file sion_file.c.

◆ _sion_file_flush()

int _sion_file_flush ( _sion_fileptr sion_fileptr)

Flush data to file.

Parameters
sion_fileptrfileptr
Returns
SION_SUCCESS if ok

Definition at line 434 of file sion_file.c.

◆ _sion_file_flush_ansi()

int _sion_file_flush_ansi ( FILE *  fileptr)

ANSI: Flush the data to the disk.

Parameters
*fileptrfile handle
Return values
<tt>SION_SUCCESS</tt>if OK

Definition at line 805 of file sion_file.c.

Referenced by _sion_file_purge_ansi().

◆ _sion_file_flush_posix()

int _sion_file_flush_posix ( int  fd)

POSIX: Flush the data to the disk.

Parameters
fdfile descriptor
Return values
<tt>SION_SUCCESS</tt>if OK

Definition at line 1053 of file sion_file.c.

◆ _sion_file_get_fd()

int _sion_file_get_fd ( _sion_fileptr sion_fileptr)

Utility function: Get POSIX fp.

Parameters
sion_fileptrfile handle
Returns
a POSIX file descriptor or SION_ID_UNDEF on failure

Definition at line 573 of file sion_file.c.

Referenced by fsion_get_fileno_c().

◆ _sion_file_get_opt_blksize()

long _sion_file_get_opt_blksize ( _sion_fileptr sion_fileptr)

Get optional file system block size for a file.

Parameters
sion_fileptrfileptr
Returns
blocksize or -1 if not defined

Definition at line 289 of file sion_file.c.

◆ _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.

Parameters
fileptrfileptr
Returns
blocksize or -1 if not defined

Definition at line 686 of file sion_file.c.

◆ _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.

Parameters
fdfile descriptor
Returns
blocksize or -1 if not defined

Definition at line 965 of file sion_file.c.

◆ _sion_file_get_position()

sion_int64 _sion_file_get_position ( _sion_fileptr sion_fileptr)

Get new position in file.

Parameters
sion_fileptrfileptr
Returns
position in file or -1 on failure

Definition at line 401 of file sion_file.c.

◆ _sion_file_get_position_ansi()

sion_int64 _sion_file_get_position_ansi ( FILE *  fileptr)

ANSI: Get the current position in file.

Parameters
*fileptrfile handle
Return values
positionin file, -1 on failure

Definition at line 762 of file sion_file.c.

◆ _sion_file_get_position_posix()

sion_int64 _sion_file_get_position_posix ( int  fd)

POSIX: Get the current position in file.

Parameters
fdfile handle
Return values
positionin file or -1 on failure

Definition at line 1025 of file sion_file.c.

◆ _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.

Parameters
fnamefilename to use
flagsflags
addflagsoptional additional flags
Returns
file handle, or NULL on error

Definition at line 53 of file sion_file.c.

References _sion_file_alloc_and_init_sion_fileptr(), _sion_file_open_ansi_read(), _sion_file_open_ansi_write_create(), _sion_file_open_ansi_write_existing(), SION_FILE_FLAG_ANSI, SION_FILE_FLAG_CREATE, SION_FILE_FLAG_READ, and SION_FILE_FLAG_WRITE.

◆ _sion_file_open_ansi_read()

FILE* _sion_file_open_ansi_read ( const char *  fname,
unsigned int  addflags 
)

ANSI: Open a file for reading.

Parameters
*fnamefilename to use
addflagsoptional additional flags
Returns
file handle or NULL

Definition at line 653 of file sion_file.c.

Referenced by _sion_file_open().

◆ _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.

Parameters
*fnamefilename to use
addflagsoptional additional flags
Returns
file handle or NULL

Definition at line 611 of file sion_file.c.

Referenced by _sion_file_open().

◆ _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.

Parameters
*fnamefilename to use
addflagsoptional additional flags
Returns
file handle or NULL

Definition at line 630 of file sion_file.c.

Referenced by _sion_file_open().

◆ _sion_file_open_posix_read()

int _sion_file_open_posix_read ( const char *  fname,
unsigned int  addflags 
)

POSIX: Open a file for reading.

Parameters
*fnamefilename to use
addflagsoptional additional flags
Returns
file handle or -1 on failure

Definition at line 925 of file sion_file.c.

◆ _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.

Parameters
*fnamefilename to use
addflagsoptional additional flags
Returns
file handle or -1 on failure

Definition at line 873 of file sion_file.c.

◆ _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.

Parameters
*fnamefilename to use
addflagsoptional additional flags
Returns
file handle or -1 on failure

Definition at line 899 of file sion_file.c.

◆ _sion_file_purge()

int _sion_file_purge ( _sion_fileptr sion_fileptr)

Purge data to file.

Parameters
sion_fileptrfileptr
Returns
SION_SUCCESS if ok

Definition at line 467 of file sion_file.c.

◆ _sion_file_purge_ansi()

int _sion_file_purge_ansi ( FILE *  fileptr)

ANSI: Purge the data to the disk.

Parameters
*fileptrfile handle
Return values
<tt>SION_SUCCESS</tt>if OK

Definition at line 815 of file sion_file.c.

References _sion_file_flush_ansi().

◆ _sion_file_purge_posix()

int _sion_file_purge_posix ( int  fd)

POSIX: Purge the data to the disk.

Purge is only relevant for ANSI, using fsync instead

Parameters
fdfile descriptor
Return values
<tt>SION_SUCCESS</tt>if OK

Definition at line 1076 of file sion_file.c.

◆ _sion_file_read()

sion_int64 _sion_file_read ( void *  data,
sion_int64  bytes,
_sion_fileptr sion_fileptr 
)

Read data from file.

Parameters
datapointer to data
bytesnumber of bytes to write
sion_fileptrfile handle
Returns
returns bytes if the requested amount could be read, on EOF, returns n with 0 <= n < bytes, otherwise -1

Definition at line 257 of file sion_file.c.

◆ _sion_file_read_ansi()

sion_int64 _sion_file_read_ansi ( void *  data,
sion_int64  bytes,
FILE *  fileptr 
)

ANSI: Read data from file.

Parameters
datapointer to data
bytesnumber of bytes to read
fileptrfile handle
Returns
returns bytes if the requested amount could be read, on EOF, returns n with 0 <= n < bytes, otherwise -1

Definition at line 854 of file sion_file.c.

◆ _sion_file_read_posix()

sion_int64 _sion_file_read_posix ( void *  data,
sion_int64  bytes,
int  fd 
)

POSIX: Read data from file.

Parameters
datapointer to data
bytesnumber of bytes to read
fdfile handle
Returns
returns bytes if the requested amount could be read, on EOF, returns n with 0 <= n < bytes, otherwise -1

Definition at line 1145 of file sion_file.c.

◆ _sion_file_set_buffer()

int _sion_file_set_buffer ( _sion_fileptr sion_fileptr,
char *  buffer,
sion_int32  buffer_size 
)

Set buffer of fp.

Parameters
*sion_fileptrfile handle
*bufferpointer buffer
*buffer_sizebuffer size
Return values
<tt>SION_SUCCESS</tt>if OK

Definition at line 495 of file sion_file.c.

◆ _sion_file_set_buffer_ansi()

int _sion_file_set_buffer_ansi ( FILE *  fileptr,
char *  buffer,
sion_int32  buffer_size 
)

ANSI: set buffer of fp.

Parameters
*fileptrfile handle
*bufferpointer buffer
*buffer_sizebuffer size
Return values
<tt>SION_SUCCESS</tt>if OK

Definition at line 827 of file sion_file.c.

◆ _sion_file_set_buffer_posix()

int _sion_file_set_buffer_posix ( int  fd,
char *  buffer,
sion_int32  buffer_size 
)

POSIX: set buffer of fd.

Parameters
fdfile descriptor
*bufferpointer buffer
*buffer_sizebuffer size
Return values
<tt>SION_SUCCESS</tt>if OK

Definition at line 1099 of file sion_file.c.

◆ _sion_file_set_position()

sion_int64 _sion_file_set_position ( _sion_fileptr sion_fileptr,
sion_int64  startpointer 
)

Set new position in file.

Parameters
sion_fileptrfileptr
startpointernew position
Returns
new position in file or -1 on failure

Definition at line 367 of file sion_file.c.

◆ _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.

Parameters
*fileptrfile handle
startpointerthe position for the current task
Returns
new position in file, -1 on failure

Definition at line 708 of file sion_file.c.

◆ _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.

Parameters
fdfile descriptor
startpointerthe position for the current task
Returns
new position in file, -1 on failure

Definition at line 986 of file sion_file.c.

◆ _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.

Parameters
sion_fileptrfile handle
fileptrsecond file pointer
Returns
SION_SUCCESS if success

Definition at line 529 of file sion_file.c.

◆ _sion_file_stat_file()

int _sion_file_stat_file ( const char *  fname)

Check if file exists (LARGE_FILE support on BlueGene)

Parameters
*fnamefilename to use
Returns
0 or 1

Definition at line 318 of file sion_file.c.

References _sion_file_stat_file2(), and SION_FILE_FLAG_POSIX.

◆ _sion_file_stat_file2()

int _sion_file_stat_file2 ( const char *  fname,
unsigned int  apiflag 
)

Check if file exists with appropriate low-level API.

Parameters
*fnamefilename to use
apiflagindicates the low-level API to use (POSIX, ANSI, etc.)
Returns
1 if the file exists, otherwise 0

Definition at line 329 of file sion_file.c.

References SION_FILE_FLAG_ANSI, and SION_FILE_FLAG_POSIX.

Referenced by _sion_file_stat_file().

◆ _sion_file_unset_second_fileptr()

int _sion_file_unset_second_fileptr ( _sion_fileptr sion_fileptr)

Unset second fileptr for file if opened with ANSI.

Parameters
sion_fileptrfile handle
Returns
SION_SUCCESS if success

Definition at line 551 of file sion_file.c.

◆ _sion_file_write()

sion_int64 _sion_file_write ( const void *  data,
sion_int64  bytes,
_sion_fileptr sion_fileptr 
)

Write data to file.

Parameters
datapointer to data
bytesnumber of bytes to write
sion_fileptrfile handle
Returns
returns bytes if the requested amount could be written, otherwise -1

Definition at line 221 of file sion_file.c.

◆ _sion_file_write_ansi()

sion_int64 _sion_file_write_ansi ( const void *  data,
sion_int64  bytes,
FILE *  fileptr 
)

ANSI: Write data to file.

Parameters
datapointer to data
bytesnumber of bytes to write
fileptrfile handle
Returns
returns bytes if the requested amount could be written, otherwise -1

Definition at line 840 of file sion_file.c.

◆ _sion_file_write_posix()

sion_int64 _sion_file_write_posix ( const void *  data,
sion_int64  bytes,
int  fd 
)

POSIX: Write data to file.

Parameters
datapointer to data
bytesnumber of bytes to write
fdfile handle
Returns
returns bytes if the requested amount could be written, otherwise -1

Definition at line 1112 of file sion_file.c.

◆ _sion_fileptrflags_to_str()

char* _sion_fileptrflags_to_str ( unsigned int  flag)
Returns
String representation of flag

Definition at line 1550 of file sion_file.c.

◆ _sion_get_fileptr_desc()

char* _sion_get_fileptr_desc ( _sion_fileptr sion_fileptr)
Returns
File pointer description

Definition at line 1568 of file sion_file.c.

References SION_FILE_FLAG_ANSI, SION_FILE_FLAG_CREATE, SION_FILE_FLAG_POSIX, and SION_FILE_FLAG_WRITE.