fsync or fsync_range Subroutine
Purpose
Writes changes in a file to permanent storage.
Library
Standard C Library (libc.a)
Syntax
#include <unistd.h>
int fsync ( FileDescriptor)
int FileDescriptor;
int fsync_range (FileDescriptor, how, start, length)
int FileDescriptor;
int how;
off_t start;
off_t length;
Description
The fsync subroutine causes all modified data in the open file specified by the FileDescriptor parameter to be saved to permanent storage. On return from the fsync subroutine, all updates have been saved on permanent storage.
The fsync_range subroutine causes all modified data in the specified range of the open file specified by the FileDescriptor parameter to be saved to permanent storage. On return from the fsync_range subroutine, all updates in the specified range have been saved on permanent storage.
This paragraph refers to deprecated function available only in the JFS file system. Data written to a file that a process has opened for deferred update (with the O_DEFER flag) is not written to permanent storage until another process issues an fsync_range or fsync call against this file or runs a synchronous write subroutine (with the O_SYNC flag) on this file. See the fcntl.h file and the open subroutine for descriptions of the O_DEFER and O_SYNC flags respectively.
Parameters
Item | Description |
---|---|
FileDescriptor | A valid, open file descriptor. |
how | Specify the handling characteristics of the operation.
|
start | Starting file offset. |
length | Length, or zero for all cache data. |
Return Values
Upon successful completion, the fsync subroutine returns a value of 0. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error.
Upon successful completion, the fsync_range subroutine returns a value of 0. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error.
Error Codes
The fsync or fsync_range subroutine is unsuccessful if one or more of the following are true:
Item | Description |
---|---|
EIO | An I/O error occurred while reading from or writing to the file system. |
EBADF | The FileDescriptor parameter is not a valid file descriptor open for writing. |
EINVAL | The file is not a regular file. |
EINTR | The subroutine was interrupted by a signal. |