'\"macro stdmacro
.if n .pH g2.fsync @(#)fsync	40.7 of 10/10/89
.\" Copyright 1989 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 \- synchronize a file's in-memory state with that on the physical
medium
.SH SYNOPSIS
\f4#include <unistd.h>\f1
.sp
\f4int fsync(int fildes);\f1
.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.
.P
\f4fsync\f1 fails 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 \f4fsync\f1 system call.
.TP 15
\f4EIO\fP
An I/O error occurred while reading from or writing to the file system.
.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)
