]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/sync.2
Changes: Ready for 5.02
[thirdparty/man-pages.git] / man2 / sync.2
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 2017-09-15 "Linux" "Linux Programmer's Manual"
37 .SH NAME
38 sync, syncfs \- commit filesystem caches to disk
39 .SH SYNOPSIS
40 .B #include <unistd.h>
41 .PP
42 .B void sync(void);
43 .PP
44 .BI "int syncfs(int " fd );
45 .PP
46 .in -4n
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
49 .in
50 .PP
51 .BR sync ():
52 .ad l
53 .RS 4
54 _XOPEN_SOURCE\ >=\ 500
55 .\" || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
56 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
57 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
58 .RE
59 .ad
60 .PP
61 .BR syncfs ():
62 .ad l
63 .RS 4
64 _GNU_SOURCE
65 .RE
66 .ad
67 .SH DESCRIPTION
68 .BR sync ()
69 causes all pending modifications to filesystem metadata and cached file
70 data to be written to the underlying filesystems.
71 .PP
72 .BR syncfs ()
73 is like
74 .BR sync (),
75 but synchronizes just the filesystem containing file
76 referred to by the open file descriptor
77 .IR fd .
78 .SH RETURN VALUE
79 .BR syncfs ()
80 returns 0 on success;
81 on error, it returns \-1 and sets
82 .I errno
83 to indicate the error.
84 .SH ERRORS
85 .BR sync ()
86 is always successful.
87 .PP
88 .BR syncfs ()
89 can fail for at least the following reason:
90 .TP
91 .B EBADF
92 .I fd
93 is not a valid file descriptor.
94 .SH VERSIONS
95 .BR syncfs ()
96 first appeared in Linux 2.6.39;
97 library support was added to glibc in version 2.14.
98 .SH CONFORMING TO
99 .BR sync ():
100 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
101 .PP
102 .BR syncfs ()
103 is Linux-specific.
104 .SH NOTES
105 Since glibc 2.2.2, the Linux prototype for
106 .BR sync ()
107 is as listed above,
108 following the various standards.
109 In glibc 2.2.1 and earlier,
110 it was "int sync(void)", and
111 .BR sync ()
112 always returned 0.
113 .PP
114 According to the standard specification (e.g., POSIX.1-2001),
115 .BR sync ()
116 schedules the writes, but may return before the actual
117 writing is done. However Linux waits for I/O completions,
118 and thus
119 .BR sync ()
120 or
121 .BR syncfs ()
122 provide the same guarantees as fsync called on every file in
123 the system or filesystem respectively.
124 .SH BUGS
125 Before version 1.3.20 Linux did not wait for I/O to complete
126 before returning.
127 .SH SEE ALSO
128 .BR sync (1),
129 .BR fdatasync (2),
130 .BR fsync (2)