1SYNC(2) Linux Programmer's Manual SYNC(2)
2
3
4
6 sync, syncfs - commit filesystem caches to disk
7
9 #include <unistd.h>
10
11 void sync(void);
12
13 int syncfs(int fd);
14
15 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17 sync():
18 _XOPEN_SOURCE >= 500
19 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
20 || /* Glibc versions <= 2.19: */ _BSD_SOURCE
21
22 syncfs():
23 _GNU_SOURCE
24
26 sync() causes all pending modifications to filesystem metadata and
27 cached file data to be written to the underlying filesystems.
28
29 syncfs() is like sync(), but synchronizes just the filesystem containā
30 ing file referred to by the open file descriptor fd.
31
33 syncfs() returns 0 on success; on error, it returns -1 and sets errno
34 to indicate the error.
35
37 sync() is always successful.
38
39 syncfs() can fail for at least the following reason:
40
41 EBADF fd is not a valid file descriptor.
42
44 syncfs() first appeared in Linux 2.6.39; library support was added to
45 glibc in version 2.14.
46
48 sync(): POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
49
50 syncfs() is Linux-specific.
51
53 Since glibc 2.2.2, the Linux prototype for sync() is as listed above,
54 following the various standards. In glibc 2.2.1 and earlier, it was
55 "int sync(void)", and sync() always returned 0.
56
57 According to the standard specification (e.g., POSIX.1-2001), sync()
58 schedules the writes, but may return before the actual writing is done.
59 However Linux waits for I/O completions, and thus sync() or syncfs()
60 provide the same guarantees as fsync called on every file in the system
61 or filesystem respectively.
62
64 Before version 1.3.20 Linux did not wait for I/O to complete before
65 returning.
66
68 sync(1), fdatasync(2), fsync(2)
69
71 This page is part of release 4.15 of the Linux man-pages project. A
72 description of the project, information about reporting bugs, and the
73 latest version of this page, can be found at
74 https://www.kernel.org/doc/man-pages/.
75
76
77
78Linux 2017-09-15 SYNC(2)