fsync(2) fsync(2)
NAME
fsync - synchronize file status
SYNOPSIS
#include <unistd.h>
int fsync(int fildes);
DESCRIPTION
fsync() moves all modified data and attributes of fildes to a storage
device. When fsync() returns, all in-memory modified copies of buffers
associated with fildes have been written to the physical medium.
fsync() is different from sync, which schedules disk I/O for all files
but returns before the I/O completes.
fsync() should be used by programs that require modifications to a
file to be completed before continuing. For example, a program that
contains a simple transaction facility might use fsync() to ensure
that all changes to a file or files caused by a given transaction were
recorded on a storage medium.
fsync() fails if one or more of the following apply:
EBADF fildes is not a valid file descriptor open for writing.
ENOLINK fildes is on a remote machine and the link to that machine is
no longer active.
EINTR A signal was caught during execution of the fsync() system
call.
EIO An I/O error occurred while reading from or writing to the
file system.
RESULT
Upon successful completion, a value of 0 is returned. Otherwise, a
value of -1 is returned and errno is set to indicate the error.
NOTES
The way the data reach the physical medium depends on both implementa-
tion and hardware. fsync() returns when the device driver tells it
that the write has taken place.
SEE ALSO
sync(2).
Page 1 Reliant UNIX 5.44 Printed 11/98