'\"macro stdmacro .if n .pH g2.fsync @(#)fsync 40.9 of 1/3/91 .\" Copyright 1991 UNIX System Laboratories, Inc. .\" Copyright 1989, 1990 AT&T .nr X .if \nX=0 .ds x} fsync 2 "" "\&" .if \nX=1 .ds x} fsync 2 "" .if \nX=2 .ds x} fsync 2 "" "\&" .if \nX=3 .ds x} fsync "" "" "\&" .TH \*(x} .SH NAME \f4fsync\f1, \f4fdatasync\f1 \- synchronize a file's in-memory state with that on the physical medium .Op c p a .SH SYNOPSIS .nf \f4#include \f1 .PP .B "int fsync(int fildes); .B "int fdatasync(int fildes); .fi .PP .Op .SH DESCRIPTION \f4fsync\f1 moves all modified data and attributes of \f2fildes\f1 to a storage device. When \f4fsync\f1 returns, all in-memory modified copies of buffers associated with \f2fildes\f1 have been written to the physical medium. \f4fsync\fP is different from \f4sync\fP, which schedules disk I/O for all files but returns before the I/O completes. .PP \f4fsync\f1 should be used by programs that require that a file be in a known state. For example, a program that contains a simple transaction facility might use \f4fsync\f1 to ensure that all changes to a file or files caused by a given transaction were recorded on a storage medium. .PP \f4fdatasync\f1 is the same as \f4fsync\f1, except that it only moves all the modified data, and not the attributes of \f2fildes\f1 to a storage device. .P \f4fsync\f1 and \f4fdatasync\f1 fail if one or more of the following are true: .TP 15 \f4EBADF\fP \f2fildes\f1 is not a valid file descriptor open for writing. .TP 15 \f4ENOLINK\fP \f2fildes\f1 is on a remote machine and the link on that machine is no longer active. .TP 15 \f4EINTR\fP A signal was caught during execution of the system call. .TP 15 \f4EIO\fP An I/O error occurred while reading from or writing to the file system. .TP15 \f4EINVAL\fp \f2fildes\f1 is not a valid descriptor Synchronized I/O. .SH DIAGNOSTICS Upon successful completion, a value of 0 is returned. Otherwise, a value of \-1 is returned and \f4errno\fP is set to indicate the error. .SH NOTES The way the data reach the physical medium depends on both implementation and hardware. \f4fsync\f1 returns when the device driver tells it that the write has taken place. .SH "SEE ALSO" \f4sync\fP(2)