OSDN Git Service

(split) LDP: Update original to v3.37.
[linuxjm/LDP_man-pages.git] / original / man2 / sync.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\" and Copyright (c) 2011 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
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 2012-02-12 "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 file systems.
69
70 .BR syncfs ()
71 is like
72 .BR sync (),
73 but synchronizes just the file system 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 .SH "CONFORMING TO"
96 .BR sync ():
97 SVr4, 4.3BSD, POSIX.1-2001.
98
99 .BR syncfs ()
100 is Linux-specific.
101 .SH NOTES
102 Since glibc 2.2.2 the Linux prototype for
103 .BR sync ()
104 is as listed above,
105 following the various standards.
106 In libc4, libc5, and glibc up to 2.2.1
107 it was "int sync(void)", and
108 .BR sync ()
109 always returned 0.
110 .SH BUGS
111 According to the standard specification (e.g., POSIX.1-2001),
112 .BR sync ()
113 schedules the writes, but may return before the actual
114 writing is done.
115 However, since version 1.3.20 Linux does actually wait.
116 (This still does not guarantee data integrity: modern disks have
117 large caches.)
118 .SH "SEE ALSO"
119 .BR bdflush (2),
120 .BR fdatasync (2),
121 .BR fsync (2),
122 .BR sync (8),
123 .BR update (8)