Seth Woolley's Man Viewer

fsync(2) - fdatasync, fsync, fdatasync, fsync - synchronize a file's complete in-core state with that on disk - man 2 fsync

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

FSYNC(2)                   Linux Programmer's Manual                  FSYNC(2)



NAME
       fsync,  fdatasync  -  synchronize  a file(1,n)'s complete in-core state with
       that on disk

SYNOPSIS
       #include <unistd.h>

       int fsync(int fd);

       int fdatasync(int fd);

DESCRIPTION
       fsync copies all in-core parts of a file(1,n) to disk, and waits  until  the
       device  reports  that all parts are on stable storage.  It also updates
       metadata stat(1,2) information. It does  not  necessarily  ensure  that  the
       entry  in(1,8) the directory containing the file(1,n) has also reached disk.  For
       that an explicit fsync on the file(1,n) descriptor of the directory is  also
       needed.

       fdatasync  does  the  same as fsync but only flushes user data, not the
       meta data like the mtime or atime.


RETURN VALUE
       On success, zero is returned.  On error(8,n), -1 is returned, and  errno  is
       set(7,n,1 builtins) appropriately.

ERRORS
       EBADF  fd is not a valid file(1,n) descriptor open(2,3,n) for writing.

       EIO    An error(8,n) occurred during synchronization.

       EROFS, EINVAL
              fd  is  bound  to a special file(1,n) which does not support synchro-
              nization.

NOTES
       In case the hard disk has write(1,2) cache enabled, the data may not  really
       be on permanent storage when fsync/fdatasync return.

       When  an  ext2  file(1,n)  system is mounted with the sync(1,2,8) option, directory
       entries are also implicitly synced by fsync.

       On kernels before 2.4, fsync on  big  files  can  be  inefficient.   An
       alternative might be to use the O_SYNC flag to open(2,3,n)(2).

CONFORMING TO
       POSIX.1b (formerly POSIX.4)

SEE ALSO
       bdflush(2), open(2,3,n)(2), sync(1,2,8)(2) mount(2,8)(8), sync(1,2,8)(8), update(7,n)(8)



Linux 1.3.85                      2001-04-18                          FSYNC(2)

References for this manual (incoming links)