'\" te
.\" Copyright (c) 2008 Sun Microsystems, Inc.  All Rights Reserved.
.\" Copyright 1989 AT&T
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH FSYNC 3C "Feb 5, 2008"
.SH NAME
fsync \- synchronize changes to a file
.SH SYNOPSIS
.LP
.nf
#include <unistd.h>

\fBint\fR \fBfsync\fR(\fBint\fR \fIfildes\fR);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBfsync()\fR function moves all modified data and attributes of the file
descriptor \fIfildes\fR to a storage device. When \fBfsync()\fR returns, all
in-memory modified copies of buffers associated with \fIfildes\fR have been
written to the physical medium. The \fBfsync()\fR function is different from
\fBsync()\fR, which schedules disk I/O for all files  but returns before the
I/O completes. The \fBfsync()\fR function forces all outstanding data
operations to synchronized file integrity completion (see \fBfcntl.h\fR(3HEAD)
definition of \fBO_SYNC\fR.)
.sp
.LP
The \fBfsync()\fR function forces all currently queued I/O operations
associated with the file indicated by the file descriptor \fIfildes\fR to the
synchronized I/O completion state. All I/O operations are completed as defined
for synchronized I/O file integrity completion.
.SH RETURN VALUES
.sp
.LP
Upon successful completion, \fB0\fR is returned. Otherwise, \fB\(mi1\fR is
returned and \fBerrno\fR is set to indicate the error. If the \fBfsync()\fR
function fails, outstanding I/O operations are not guaranteed to have been
completed.
.SH ERRORS
.sp
.LP
The \fBfsync()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 13n
The \fIfildes\fR argument is not a valid file descriptor.
.RE

.sp
.ne 2
.na
\fB\fBEINTR\fR\fR
.ad
.RS 13n
A signal was caught during execution of the \fBfsync()\fR function.
.RE

.sp
.ne 2
.na
\fB\fBEIO\fR\fR
.ad
.RS 13n
An I/O error occurred while reading from or writing to the file system.
.RE

.sp
.ne 2
.na
\fB\fBENOSPC\fR\fR
.ad
.RS 13n
There was no free space remaining on the device containing the file.
.RE

.sp
.ne 2
.na
\fB\fBETIMEDOUT\fR\fR
.ad
.RS 13n
Remote connection timed out. This occurs when the file is on an  \fBNFS\fR file
system mounted with the  \fIsoft\fR option. See  \fBmount_nfs\fR(1M).
.RE

.sp
.LP
In the event that any of the queued I/O operations fail, \fBfsync()\fR returns
the error conditions defined for \fBread\fR(2) and \fBwrite\fR(2).
.SH USAGE
.sp
.LP
The \fBfsync()\fR function should be used by applications that require that a
file be in a known state. For example, an application that contains a simple
transaction facility might use  \fBfsync()\fR to ensure that all changes to a
file or files caused by a given transaction were recorded on a storage medium.
.sp
.LP
The manner in which the data reach the physical medium depends on both
implementation and hardware.  The \fBfsync()\fR function returns when notified
by the device driver that the write has taken place.
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
_
MT-Level	Async-Signal-Safe
_
Standard	See \fBstandards\fR(5).
.TE

.SH SEE ALSO
.sp
.LP
\fBmount_nfs\fR(1M), \fBread\fR(2), \fBsync\fR(2), \fBwrite\fR(2),
\fBfcntl.h\fR(3HEAD), \fBfdatasync\fR(3C), \fBattributes\fR(5),
\fBstandards\fR(5)