Debian Codegraph @

upstream/debian-trixie/man2/sync.2

raw
1 .\" Copyright (c) 1992 Drew Eckhardt ([email protected]), March 28, 1992
2 .\" and Copyright (c) 2011 Michael Kerrisk <[email protected]>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .\" Modified by Michael Haardt <[email protected]>
7 .\" Modified Sat Jul 24 12:02:47 1993 by Rik Faith <[email protected]>
8 .\" Modified 15 Apr 1995 by Michael Chastain <[email protected]>:
9 .\" Added reference to `bdflush(2)'.
10 .\" Modified 960414 by Andries Brouwer <[email protected]>:
11 .\" Added the fact that since 1.3.20 sync actually waits.
12 .\" Modified Tue Oct 22 22:27:07 1996 by Eric S. Raymond <[email protected]>
13 .\" Modified 2001-10-10 by aeb, following Michael Kerrisk.
14 .\" 2011-09-07, mtk, Added syncfs() documentation,
15 .\"
16 .TH sync 2 2024-05-02 "Linux man-pages 6.9.1"
17 .SH NAME
18 sync, syncfs \- commit filesystem caches to disk
19 .SH LIBRARY
20 Standard C library
21 .RI ( libc ", " \-lc )
22 .SH SYNOPSIS
23 .nf
24 .B #include <unistd.h>
25 .P
26 .B void sync(void);
27 .P
28 .BI "int syncfs(int " fd );
29 .fi
30 .P
31 .RS -4
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
34 .RE
35 .P
36 .BR sync ():
37 .nf
38 _XOPEN_SOURCE >= 500
39 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
40 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
41 || /* glibc <= 2.19: */ _BSD_SOURCE
42 .fi
43 .P
44 .BR syncfs ():
45 .nf
46 _GNU_SOURCE
47 .fi
48 .SH DESCRIPTION
49 .BR sync ()
50 causes all pending modifications to filesystem metadata and cached file
51 data to be written to the underlying filesystems.
52 .P
53 .BR syncfs ()
54 is like
55 .BR sync (),
56 but synchronizes just the filesystem containing file
57 referred to by the open file descriptor
58 .IR fd .
59 .SH RETURN VALUE
60 .BR syncfs ()
61 returns 0 on success;
62 on error, it returns \-1 and sets
63 .I errno
64 to indicate the error.
65 .SH ERRORS
66 .BR sync ()
67 is always successful.
68 .P
69 .BR syncfs ()
70 can fail for at least the following reasons:
71 .TP
72 .B EBADF
73 .I fd
74 is not a valid file descriptor.
75 .TP
76 .B EIO
77 An error occurred during synchronization.
78 This error may relate to data written to any file on the filesystem, or on
79 metadata related to the filesystem itself.
80 .TP
81 .B ENOSPC
82 Disk space was exhausted while synchronizing.
83 .TP
84 .B ENOSPC
85 .TQ
86 .B EDQUOT
87 Data was written to a file on NFS or another filesystem which does not
88 allocate space at the time of a
89 .BR write (2)
90 system call, and some previous write failed due to insufficient
91 storage space.
92 .SH VERSIONS
93 According to the standard specification (e.g., POSIX.1-2001),
94 .BR sync ()
95 schedules the writes, but may return before the actual
96 writing is done.
97 However Linux waits for I/O completions,
98 and thus
99 .BR sync ()
100 or
101 .BR syncfs ()
102 provide the same guarantees as
103 .BR fsync ()
104 called on every file in
105 the system or filesystem respectively.
106 .SH STANDARDS
107 .TP
108 .BR sync ()
109 POSIX.1-2008.
110 .TP
111 .BR syncfs ()
112 Linux.
113 .SH HISTORY
114 .TP
115 .BR sync ()
116 POSIX.1-2001, SVr4, 4.3BSD.
117 .TP
118 .BR syncfs ()
119 Linux 2.6.39,
120 glibc 2.14.
121 .P
122 Since glibc 2.2.2, the Linux prototype for
123 .BR sync ()
124 is as listed above,
125 following the various standards.
126 In glibc 2.2.1 and earlier,
127 it was "int sync(void)", and
128 .BR sync ()
129 always returned 0.
130 .P
131 In mainline kernel versions prior to Linux 5.8,
132 .BR syncfs ()
133 will fail only when passed a bad file descriptor
134 .RB ( EBADF ).
135 Since Linux 5.8,
136 .\" commit 735e4ae5ba28c886d249ad04d3c8cc097dad6336
137 .BR syncfs ()
138 will also report an error if one or more inodes failed
139 to be written back since the last
140 .BR syncfs ()
141 call.
142 .SH BUGS
143 Before Linux 1.3.20, Linux did not wait for I/O to complete
144 before returning.
145 .SH SEE ALSO
146 .BR sync (1),
147 .BR fdatasync (2),
148 .BR fsync (2)