Synchronizing a File
fsync()
and fdatasync()
explicitly synchronize a file to
secondary storage.
The fsync()
routine guarantees that the interface is synchronized at the I/O
file integrity completion level. fdatasync()
guarantees that
the interface is synchronized at level of I/O data integrity completion. For
more information, see the
fsync(3C) man page.
Applications can synchronize each I/O operation before the operation completes. Setting the
O_DSYNC flag on the file description by using
open()
or fcntl()
ensures that all I/O
writes reach I/O data completion before the operation completes. Setting the
O_SYNC flag on the file description ensures that all I/O
writes have reached completion before the operation is indicated as completed.
Setting the O_RSYNC flag on the file description ensures that
all I/O reads read()
and aio_read()
reach the
same level of completion that is requested by the descriptor setting. The
descriptor setting can be either O_DSYNC or
O_SYNC. For more information, see the
open(2),
fcntl(2), and
read(2) man pages.