]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/fsync.2
MFC 359465: Document EINTEGRITY errors for many system calls.
[FreeBSD/FreeBSD.git] / lib / libc / sys / fsync.2
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 .\" $FreeBSD$
36 .\"
37 .Dd March 30, 2020
38 .Dt FSYNC 2
39 .Os
40 .Sh NAME
41 .Nm fdatasync ,
42 .Nm fsync
43 .Nd "synchronise changes to a file"
44 .Sh LIBRARY
45 .Lb libc
46 .Sh SYNOPSIS
47 .In unistd.h
48 .Ft int
49 .Fn fdatasync "int fd"
50 .Ft int
51 .Fn fsync "int fd"
52 .Sh DESCRIPTION
53 The
54 .Fn fsync
55 system call
56 causes all modified data and attributes of the file referenced by
57 the file descriptor
58 .Fa fd
59 to be moved to a permanent storage device.
60 This normally results in all in-core modified copies
61 of buffers for the associated file to be written to a disk.
62 .Pp
63 The
64 .Fn fdatasync
65 system call causes all modified data of
66 .Fa fd
67 to be moved to a permanent storage device.
68 Unlike
69 .Fn fsync ,
70 the system call does not guarantee that file attributes or
71 metadata necessary to access the file are committed to the permanent storage.
72 .Pp
73 The
74 .Fn fsync
75 system call
76 should be used by programs that require a file to be
77 in a known state, for example, in building a simple transaction
78 facility.
79 If the file metadata has already been committed, using
80 .Fn fdatasync
81 can be more efficient than
82 .Fn fsync .
83 .Pp
84 Both
85 .Fn fdatasync
86 and
87 .Fn fsync
88 calls are cancellation points.
89 .Sh RETURN VALUES
90 .Rv -std fsync
91 .Sh ERRORS
92 The
93 .Fn fsync
94 and
95 .Fn fdatasync
96 calls fail if:
97 .Bl -tag -width Er
98 .It Bq Er EBADF
99 The
100 .Fa fd
101 argument
102 is not a valid descriptor.
103 .It Bq Er EINVAL
104 The
105 .Fa fd
106 argument
107 refers to a socket, not to a file.
108 .It Bq Er EIO
109 An I/O error occurred while reading from or writing to the file system.
110 .It Bq Er EINTEGRITY
111 Corrupted data was detected while reading from the file system.
112 .El
113 .Sh SEE ALSO
114 .Xr fsync 1 ,
115 .Xr sync 2 ,
116 .Xr syncer 4 ,
117 .Xr sync 8
118 .Sh HISTORY
119 The
120 .Fn fsync
121 system call appeared in
122 .Bx 4.2 .
123 The
124 .Fn fdatasync
125 system call appeared in
126 .Fx 11.1 .
127 .Sh BUGS
128 The
129 .Fn fdatasync
130 system call currently does not guarantee that enqueued
131 .Xr aio 4
132 requests for the file referenced by
133 .Fa fd
134 are completed before the syscall returns.