1sync(2)                       System Calls Manual                      sync(2)
2
3
4

NAME

6       sync, syncfs - commit filesystem caches to disk
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <unistd.h>
13
14       void sync(void);
15
16       int syncfs(int fd);
17
18   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20       sync():
21           _XOPEN_SOURCE >= 500
22               || /* Since glibc 2.19: */ _DEFAULT_SOURCE
23               || /* glibc <= 2.19: */ _BSD_SOURCE
24
25       syncfs():
26           _GNU_SOURCE
27

DESCRIPTION

29       sync()  causes  all  pending  modifications  to filesystem metadata and
30       cached file data to be written to the underlying filesystems.
31
32       syncfs() is like sync(), but synchronizes just the filesystem  contain‐
33       ing file referred to by the open file descriptor fd.
34

RETURN VALUE

36       syncfs()  returns  0 on success; on error, it returns -1 and sets errno
37       to indicate the error.
38

ERRORS

40       sync() is always successful.
41
42       syncfs() can fail for at least the following reasons:
43
44       EBADF  fd is not a valid file descriptor.
45
46       EIO    An error occurred during synchronization.  This error may relate
47              to  data  written  to any file on the filesystem, or on metadata
48              related to the filesystem itself.
49
50       ENOSPC Disk space was exhausted while synchronizing.
51
52       ENOSPC, EDQUOT
53              Data was written to a file on NFS or  another  filesystem  which
54              does  not  allocate space at the time of a write(2) system call,
55              and some previous  write  failed  due  to  insufficient  storage
56              space.
57

VERSIONS

59       According  to  the  standard specification (e.g., POSIX.1-2001), sync()
60       schedules the writes, but may return before the actual writing is done.
61       However  Linux  waits  for I/O completions, and thus sync() or syncfs()
62       provide the same guarantees as fsync() called on every file in the sys‐
63       tem or filesystem respectively.
64

STANDARDS

66       sync() POSIX.1-2008.
67
68       syncfs()
69              Linux.
70

HISTORY

72       sync() POSIX.1-2001, SVr4, 4.3BSD.
73
74       syncfs()
75              Linux 2.6.39, glibc 2.14.
76
77       Since  glibc  2.2.2, the Linux prototype for sync() is as listed above,
78       following the various standards.  In glibc 2.2.1 and  earlier,  it  was
79       "int sync(void)", and sync() always returned 0.
80
81       In mainline kernel versions prior to Linux 5.8, syncfs() will fail only
82       when passed a bad file descriptor (EBADF).  Since Linux  5.8,  syncfs()
83       will  also  report  an error if one or more inodes failed to be written
84       back since the last syncfs() call.
85

BUGS

87       Before Linux 1.3.20, Linux did not wait for I/O to complete before  re‐
88       turning.
89

SEE ALSO

91       sync(1), fdatasync(2), fsync(2)
92
93
94
95Linux man-pages 6.05              2023-03-30                           sync(2)
Impressum