fsync, fdatasync - synchronize a file's complete in-core state with that on disk
int fsync(int fd);
int fdatasync(int fd);
copies all in-core parts of a file to disk, and waits until the
device reports that all parts are on stable storage.
It also updates metadata stat information. It does not necessarily ensure
that the entry in the directory containing the file has also reached disk.
For that an explicit
on the file descriptor of the directory is also needed.
does the same as
but only flushes user data, not the meta data like the mtime or atime.
On success, zero is returned. On error, -1 is returned, and
is set appropriately.
is not a valid file descriptor open for writing.
- EROFS, EINVAL
is bound to a special file which does not support synchronization.
An error occurred during synchronization.
In case the hard disk has write cache enabled,
the data may not really be on permanent storage when
When an ext2 file system is mounted with the
option, directory entries are also implicitly synced by
On kernels before 2.4,
on big files can be inefficient.
An alternative might be to use the
POSIX.1b (formerly POSIX.4)
- RETURN VALUE
- CONFORMING TO
- SEE ALSO