OSDN Git Service

28a12cfafdbbbcf1f85db72d84639bba5892ccb3
[linuxjm/LDP_man-pages.git] / original / 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 2014-04-06 "Linux" "Linux Programmer's Manual"
37 .SH NAME
38 sync, syncfs \- commit buffer cache to disk
39 .SH SYNOPSIS
40 .B #include <unistd.h>
41 .sp
42 .B void sync(void);
43 .sp
44 .BI "int syncfs(int " fd );
45 .sp
46 .in -4n
47 Feature Test Macro Requirements for glibc (see
48 .BR feature_test_macros (7)):
49 .in
50 .sp
51 .BR sync ():
52 .ad l
53 .RS 4
54 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
55 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
56 .RE
57 .ad
58 .sp
59 .BR syncfs ():
60 .ad l
61 .RS 4
62 _GNU_SOURCE
63 .RE
64 .ad
65 .SH DESCRIPTION
66 .BR sync ()
67 causes all buffered modifications to file metadata and data to be
68 written to the underlying filesystems.
69
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
86 .BR syncfs ()
87 can fail for at least the following reason:
88 .TP
89 .B EBADF
90 .I fd
91 is not a valid file descriptor.
92 .SH VERSIONS
93 .BR syncfs ()
94 first appeared in Linux 2.6.39;
95 library support was added to glibc in version 2.14.
96 .SH CONFORMING TO
97 .BR sync ():
98 SVr4, 4.3BSD, POSIX.1-2001.
99
100 .BR syncfs ()
101 is Linux-specific.
102 .SH NOTES
103 Since glibc 2.2.2 the Linux prototype for
104 .BR sync ()
105 is as listed above,
106 following the various standards.
107 In libc4, libc5, and glibc up to 2.2.1
108 it was "int sync(void)", and
109 .BR sync ()
110 always returned 0.
111 .SH BUGS
112 According to the standard specification (e.g., POSIX.1-2001),
113 .BR sync ()
114 schedules the writes, but may return before the actual
115 writing is done.
116 However, since version 1.3.20 Linux does actually wait.
117 (This still does not guarantee data integrity: modern disks have
118 large caches.)
119 .SH SEE ALSO
120 .BR bdflush (2),
121 .BR fdatasync (2),
122 .BR fsync (2),
123 .BR sync (8)
124 .SH COLOPHON
125 This page is part of release 3.67 of the Linux
126 .I man-pages
127 project.
128 A description of the project,
129 information about reporting bugs,
130 and the latest version of this page,
131 can be found at
132 \%http://www.kernel.org/doc/man\-pages/.