Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
FSYNC(2)		  FreeBSD System Calls Manual		      FSYNC(2)

NAME
     fsync, fdatasync -- synchronize a file's in-core state with that on disk

SYNOPSIS
     #include <unistd.h>

     int
     fsync(int fd);

     int
     fdatasync(int fd);

DESCRIPTION
     The fsync() function causes all modified data and attributes of fd	to be
     moved to a	permanent storage device.  This	normally results in all	in-
     core modified copies of buffers for the associated	file to	be written to
     a disk.

     The fdatasync() function is similar to fsync() except that	it only	guar-
     antees modified data (and metadata	necessary to read that data) is	com-
     mitted to storage.	 Other file modifications may be left unsynchronized.

     fsync() and fdatasync() should be used by programs	that require a file to
     be	in a known state, for example, in building a simple transaction	facil-
     ity.

     If	fsync()	or fdatasync() fail with EIO, the state	of the on-disk data
     may have been only	partially written.  To guard against potential incon-
     sistency, future calls will continue failing until	all references to the
     file are closed.

RETURN VALUES
     The fsync() and fdatasync() functions return the value 0 if successful;
     otherwise the value -1 is returned	and the	global variable	errno is set
     to	indicate the error.

ERRORS
     The fsync() and fdatasync() functions fail	if:

     [EBADF]		fd is not a valid descriptor.

     [EINVAL]		fd does	not refer to a file which can be synchronized.

     [EIO]		An I/O error occurred while reading from or writing to
			the file system.

SEE ALSO
     sync(2), sync(8)

STANDARDS
     The fsync() and fdatasync() functions conform to IEEE Std 1003.1-2008
     ("POSIX.1").

HISTORY
     The fsync() system	call first appeared in 4.1cBSD,	and the	fdatasync()
     function has been available since OpenBSD 5.4.

BUGS
     The fdatasync() function is currently a wrapper around fsync(), so	it
     synchronizes more state than necessary.

FreeBSD	13.0			April 18, 2019			  FreeBSD 13.0

NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ERRORS | SEE ALSO | STANDARDS | HISTORY | BUGS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=fsync&sektion=2&manpath=OpenBSD+6.9>

home | help