xref: /freebsd-src/lib/libsys/fsync.2 (revision dab59af3bcc7cb7ba01569d3044894b3e860ad56)
18269e767SBrooks Davis.\" Copyright (c) 1983, 1993
28269e767SBrooks Davis.\"	The Regents of the University of California.  All rights reserved.
3*dab59af3SLi-Wen Hsu.\" Copyright (c) 2016 The FreeBSD Foundation
48269e767SBrooks Davis.\"
58269e767SBrooks Davis.\" Parts of this documentation were written by
68269e767SBrooks Davis.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
78269e767SBrooks Davis.\" from the FreeBSD Foundation.
88269e767SBrooks Davis.\"
98269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without
108269e767SBrooks Davis.\" modification, are permitted provided that the following conditions
118269e767SBrooks Davis.\" are met:
128269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright
138269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer.
148269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright
158269e767SBrooks Davis.\"    notice, this list of conditions and the following disclaimer in the
168269e767SBrooks Davis.\"    documentation and/or other materials provided with the distribution.
178269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors
188269e767SBrooks Davis.\"    may be used to endorse or promote products derived from this software
198269e767SBrooks Davis.\"    without specific prior written permission.
208269e767SBrooks Davis.\"
218269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
228269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248269e767SBrooks Davis.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
258269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
268269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
278269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
288269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
298269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
308269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
318269e767SBrooks Davis.\" SUCH DAMAGE.
328269e767SBrooks Davis.\"
338269e767SBrooks Davis.Dd March 30, 2020
348269e767SBrooks Davis.Dt FSYNC 2
358269e767SBrooks Davis.Os
368269e767SBrooks Davis.Sh NAME
378269e767SBrooks Davis.Nm fdatasync ,
388269e767SBrooks Davis.Nm fsync
398269e767SBrooks Davis.Nd "synchronise changes to a file"
408269e767SBrooks Davis.Sh LIBRARY
418269e767SBrooks Davis.Lb libc
428269e767SBrooks Davis.Sh SYNOPSIS
438269e767SBrooks Davis.In unistd.h
448269e767SBrooks Davis.Ft int
458269e767SBrooks Davis.Fn fdatasync "int fd"
468269e767SBrooks Davis.Ft int
478269e767SBrooks Davis.Fn fsync "int fd"
488269e767SBrooks Davis.Sh DESCRIPTION
498269e767SBrooks DavisThe
508269e767SBrooks Davis.Fn fsync
518269e767SBrooks Davissystem call
528269e767SBrooks Daviscauses all modified data and attributes of the file referenced by
538269e767SBrooks Davisthe file descriptor
548269e767SBrooks Davis.Fa fd
558269e767SBrooks Davisto be moved to a permanent storage device.
568269e767SBrooks DavisThis normally results in all in-core modified copies
578269e767SBrooks Davisof buffers for the associated file to be written to a disk.
588269e767SBrooks Davis.Pp
598269e767SBrooks DavisThe
608269e767SBrooks Davis.Fn fdatasync
618269e767SBrooks Davissystem call causes all modified data of
628269e767SBrooks Davis.Fa fd
638269e767SBrooks Davisto be moved to a permanent storage device.
648269e767SBrooks DavisUnlike
658269e767SBrooks Davis.Fn fsync ,
668269e767SBrooks Davisthe system call does not guarantee that file attributes or
678269e767SBrooks Davismetadata necessary to access the file are committed to the permanent storage.
688269e767SBrooks Davis.Pp
698269e767SBrooks DavisThe
708269e767SBrooks Davis.Fn fsync
718269e767SBrooks Davissystem call
728269e767SBrooks Davisshould be used by programs that require a file to be
738269e767SBrooks Davisin a known state, for example, in building a simple transaction
748269e767SBrooks Davisfacility.
758269e767SBrooks DavisIf the file metadata has already been committed, using
768269e767SBrooks Davis.Fn fdatasync
778269e767SBrooks Daviscan be more efficient than
788269e767SBrooks Davis.Fn fsync .
798269e767SBrooks Davis.Pp
808269e767SBrooks DavisBoth
818269e767SBrooks Davis.Fn fdatasync
828269e767SBrooks Davisand
838269e767SBrooks Davis.Fn fsync
848269e767SBrooks Daviscalls are cancellation points.
858269e767SBrooks Davis.Sh RETURN VALUES
868269e767SBrooks Davis.Rv -std fsync
878269e767SBrooks Davis.Sh ERRORS
888269e767SBrooks DavisThe
898269e767SBrooks Davis.Fn fsync
908269e767SBrooks Davisand
918269e767SBrooks Davis.Fn fdatasync
928269e767SBrooks Daviscalls fail if:
938269e767SBrooks Davis.Bl -tag -width Er
948269e767SBrooks Davis.It Bq Er EBADF
958269e767SBrooks DavisThe
968269e767SBrooks Davis.Fa fd
978269e767SBrooks Davisargument
988269e767SBrooks Davisis not a valid descriptor.
998269e767SBrooks Davis.It Bq Er EINVAL
1008269e767SBrooks DavisThe
1018269e767SBrooks Davis.Fa fd
1028269e767SBrooks Davisargument
1038269e767SBrooks Davisrefers to a socket, not to a file.
1048269e767SBrooks Davis.It Bq Er EIO
1058269e767SBrooks DavisAn I/O error occurred while reading from or writing to the file system.
1068269e767SBrooks Davis.It Bq Er EINTEGRITY
1078269e767SBrooks DavisCorrupted data was detected while reading from the file system.
1088269e767SBrooks Davis.El
1098269e767SBrooks Davis.Sh SEE ALSO
1108269e767SBrooks Davis.Xr fsync 1 ,
1118269e767SBrooks Davis.Xr sync 2 ,
1128269e767SBrooks Davis.Xr syncer 4 ,
1138269e767SBrooks Davis.Xr sync 8
1148269e767SBrooks Davis.Sh HISTORY
1158269e767SBrooks DavisThe
1168269e767SBrooks Davis.Fn fsync
1178269e767SBrooks Davissystem call appeared in
1188269e767SBrooks Davis.Bx 4.2 .
1198269e767SBrooks DavisThe
1208269e767SBrooks Davis.Fn fdatasync
1218269e767SBrooks Davissystem call appeared in
1228269e767SBrooks Davis.Fx 11.1 .
1238269e767SBrooks Davis.Sh BUGS
1248269e767SBrooks DavisThe
1258269e767SBrooks Davis.Fn fdatasync
1268269e767SBrooks Davissystem call currently does not guarantee that enqueued
1278269e767SBrooks Davis.Xr aio 4
1288269e767SBrooks Davisrequests for the file referenced by
1298269e767SBrooks Davis.Fa fd
1308269e767SBrooks Davisare completed before the syscall returns.
131