xref: /dragonfly/lib/libc/sys/fsync.2 (revision 7d3e9a5b)
1.\" Copyright (c) 1983, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\" Copyright (c) 2016 The FreeBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" Parts of this documentation were written by
7.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship
8.\" from the FreeBSD Foundation.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)fsync.2	8.1 (Berkeley) 6/4/93
35.\"
36.Dd September 14, 2021
37.Dt FSYNC 2
38.Os
39.Sh NAME
40.Nm fdatasync ,
41.Nm fsync
42.Nd "synchronise changes to a file"
43.Sh LIBRARY
44.Lb libc
45.Sh SYNOPSIS
46.In unistd.h
47.Ft int
48.Fn fdatasync "int fd"
49.Ft int
50.Fn fsync "int fd"
51.Sh DESCRIPTION
52The
53.Fn fsync
54system call
55causes all modified data and attributes of the file referenced by
56the file descriptor
57.Fa fd
58to be moved to a permanent storage device.
59This normally results in all in-core modified copies
60of buffers for the associated file to be written to a disk.
61.Pp
62The
63.Fn fdatasync
64system call causes all modified data of
65.Fa fd
66to be moved to a permanent storage device.
67Unlike
68.Fn fsync ,
69the system call does not guarantee that file attributes or
70metadata necessary to access the file are committed to the permanent storage.
71.Pp
72The
73.Fn fsync
74system call
75should be used by programs that require a file to be
76in a known state, for example, in building a simple transaction
77facility.
78If the file metadata has already been committed, using
79.Fn fdatasync
80can be more efficient than
81.Fn fsync .
82.Pp
83Both
84.Fn fdatasync
85and
86.Fn fsync
87calls are cancellation points.
88.Sh RETURN VALUES
89.Rv -std fdatasync fsync
90.Sh ERRORS
91The
92.Fn fsync
93and
94.Fn fdatasync
95calls fail if:
96.Bl -tag -width Er
97.It Bq Er EBADF
98The
99.Fa fd
100argument
101is not a valid descriptor.
102.It Bq Er EINVAL
103The
104.Fa fd
105argument
106refers to a socket, not to a file.
107.It Bq Er EIO
108An I/O error occurred while reading from or writing to the file system.
109.\".It Bq Er EINTEGRITY
110.\"Corrupted data was detected while reading from the file system.
111.El
112.Sh SEE ALSO
113.Xr fsync 1 ,
114.Xr sync 2 ,
115.Xr syncer 4 ,
116.Xr sync 8
117.Sh HISTORY
118The
119.Fn fsync
120system call appeared in
121.Bx 4.2 .
122The
123.Fn fdatasync
124system call appeared in
125.Fx 11.1
126and was ported to
127.Dx 6.1 .
128.\".Sh BUGS
129.\"The
130.\".Fn fdatasync
131.\"system call currently does not guarantee that enqueued
132.\".Xr aio 4
133.\"requests for the file referenced by
134.\".Fa fd
135.\"are completed before the syscall returns.
136