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 <= 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 reasons:
40
41 EBADF fd is not a valid file descriptor.
42
43 EIO An error occurred during synchronization. This error may relate
44 to data written to any file on the filesystem, or on metadata
45 related to the filesystem itself.
46
47 ENOSPC Disk space was exhausted while synchronizing.
48
49 ENOSPC, EDQUOT
50 Data was written to a files on NFS or another filesystem which
51 does not allocate space at the time of a write(2) system call,
52 and some previous write failed due to insufficient storage
53 space.
54
56 syncfs() first appeared in Linux 2.6.39; library support was added to
57 glibc in version 2.14.
58
60 sync(): POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
61
62 syncfs() is Linux-specific.
63
65 Since glibc 2.2.2, the Linux prototype for sync() is as listed above,
66 following the various standards. In glibc 2.2.1 and earlier, it was
67 "int sync(void)", and sync() always returned 0.
68
69 According to the standard specification (e.g., POSIX.1-2001), sync()
70 schedules the writes, but may return before the actual writing is done.
71 However Linux waits for I/O completions, and thus sync() or syncfs()
72 provide the same guarantees as fsync() called on every file in the sys‐
73 tem or filesystem respectively.
74
75 In mainline kernel versions prior to 5.8, syncfs() will fail only when
76 passed a bad file descriptor (EBADF). Since Linux 5.8, syncfs() will
77 also report an error if one or more inodes failed to be written back
78 since the last syncfs() call.
79
81 Before version 1.3.20 Linux did not wait for I/O to complete before re‐
82 turning.
83
85 sync(1), fdatasync(2), fsync(2)
86
88 This page is part of release 5.12 of the Linux man-pages project. A
89 description of the project, information about reporting bugs, and the
90 latest version of this page, can be found at
91 https://www.kernel.org/doc/man-pages/.
92
93
94
95Linux 2021-03-22 SYNC(2)