namespaces.7: ffix
[man-pages.git] / man2 / sync.2
blob0fa39ae71deb35cba6adde4422ecd71c8f3d1ac8
1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\" and Copyright (c) 2011 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Modified by Michael Haardt <michael@moria.de>
27 .\" Modified Sat Jul 24 12:02:47 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 15 Apr 1995 by Michael Chastain <mec@shell.portal.com>:
29 .\"   Added reference to `bdflush(2)'.
30 .\" Modified 960414 by Andries Brouwer <aeb@cwi.nl>:
31 .\"   Added the fact that since 1.3.20 sync actually waits.
32 .\" Modified Tue Oct 22 22:27:07 1996 by Eric S. Raymond <esr@thyrsus.com>
33 .\" Modified 2001-10-10 by aeb, following Michael Kerrisk.
34 .\" 2011-09-07, mtk, Added syncfs() documentation,
35 .\"
36 .TH SYNC 2 2021-03-22 "Linux" "Linux Programmer's Manual"
37 .SH NAME
38 sync, syncfs \- commit filesystem caches to disk
39 .SH SYNOPSIS
40 .nf
41 .B #include <unistd.h>
42 .PP
43 .B void sync(void);
44 .PP
45 .BI "int syncfs(int " fd );
46 .fi
47 .PP
48 .RS -4
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
51 .RE
52 .PP
53 .BR sync ():
54 .nf
55     _XOPEN_SOURCE >= 500
56 .\"    || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
57         || /* Since glibc 2.19: */ _DEFAULT_SOURCE
58         || /* Glibc <= 2.19: */ _BSD_SOURCE
59 .fi
60 .PP
61 .BR syncfs ():
62 .nf
63     _GNU_SOURCE
64 .fi
65 .SH DESCRIPTION
66 .BR sync ()
67 causes all pending modifications to filesystem metadata and cached file
68 data to be written to the underlying filesystems.
69 .PP
70 .BR syncfs ()
71 is like
72 .BR sync (),
73 but synchronizes just the filesystem containing file
74 referred to by the open file descriptor
75 .IR fd .
76 .SH RETURN VALUE
77 .BR syncfs ()
78 returns 0 on success;
79 on error, it returns \-1 and sets
80 .I errno
81 to indicate the error.
82 .SH ERRORS
83 .BR sync ()
84 is always successful.
85 .PP
86 .BR syncfs ()
87 can fail for at least the following reasons:
88 .TP
89 .B EBADF
90 .I fd
91 is not a valid file descriptor.
92 .TP
93 .B EIO
94 An error occurred during synchronization.
95 This error may relate to data written to any file on the filesystem, or on
96 metadata related to the filesystem itself.
97 .TP
98 .B ENOSPC
99 Disk space was exhausted while synchronizing.
101 .BR ENOSPC ", " EDQUOT
102 Data was written to a file on NFS or another filesystem which does not
103 allocate space at the time of a
104 .BR write (2)
105 system call, and some previous write failed due to insufficient
106 storage space.
107 .SH VERSIONS
108 .BR syncfs ()
109 first appeared in Linux 2.6.39;
110 library support was added to glibc in version 2.14.
111 .SH CONFORMING TO
112 .BR sync ():
113 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
115 .BR syncfs ()
116 is Linux-specific.
117 .SH NOTES
118 Since glibc 2.2.2, the Linux prototype for
119 .BR sync ()
120 is as listed above,
121 following the various standards.
122 In glibc 2.2.1 and earlier,
123 it was "int sync(void)", and
124 .BR sync ()
125 always returned 0.
127 According to the standard specification (e.g., POSIX.1-2001),
128 .BR sync ()
129 schedules the writes, but may return before the actual
130 writing is done.
131 However Linux waits for I/O completions,
132 and thus
133 .BR sync ()
135 .BR syncfs ()
136 provide the same guarantees as
137 .BR fsync ()
138 called on every file in
139 the system or filesystem respectively.
141 In mainline kernel versions prior to 5.8,
142 .BR syncfs ()
143 will fail only when passed a bad file descriptor
144 .RB ( EBADF ).
145 Since Linux 5.8,
146 .\" commit 735e4ae5ba28c886d249ad04d3c8cc097dad6336
147 .BR syncfs ()
148 will also report an error if one or more inodes failed
149 to be written back since the last
150 .BR syncfs ()
151 call.
152 .SH BUGS
153 Before version 1.3.20 Linux did not wait for I/O to complete
154 before returning.
155 .SH SEE ALSO
156 .BR sync (1),
157 .BR fdatasync (2),
158 .BR fsync (2)