| 1 |
.\" Copyright 1992, Drew Eckhardt <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH sync 2 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
sync, syncfs \- commit filesystem caches to disk |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <unistd.h> |
| 15 |
.P |
| 16 |
.B void sync(void); |
| 17 |
.P |
| 18 |
.BI "int syncfs(int " fd ); |
| 19 |
.fi |
| 20 |
.P |
| 21 |
.RS -4 |
| 22 |
Feature Test Macro Requirements for glibc (see |
| 23 |
.BR feature_test_macros (7)): |
| 24 |
.RE |
| 25 |
.P |
| 26 |
.BR sync (): |
| 27 |
.nf |
| 28 |
_XOPEN_SOURCE >= 500 |
| 29 |
.\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED |
| 30 |
|| /* Since glibc 2.19: */ _DEFAULT_SOURCE |
| 31 |
|| /* glibc <= 2.19: */ _BSD_SOURCE |
| 32 |
.fi |
| 33 |
.P |
| 34 |
.BR syncfs (): |
| 35 |
.nf |
| 36 |
_GNU_SOURCE |
| 37 |
.fi |
| 38 |
.SH DESCRIPTION |
| 39 |
.BR sync () |
| 40 |
causes all pending modifications to filesystem metadata and cached file |
| 41 |
data to be written to the underlying filesystems. |
| 42 |
.P |
| 43 |
.BR syncfs () |
| 44 |
is like |
| 45 |
.BR sync (), |
| 46 |
but synchronizes just the filesystem containing file |
| 47 |
referred to by the open file descriptor |
| 48 |
.IR fd . |
| 49 |
.SH RETURN VALUE |
| 50 |
.BR syncfs () |
| 51 |
returns 0 on success; |
| 52 |
on error, it returns \-1 and sets |
| 53 |
.I errno |
| 54 |
to indicate the error. |
| 55 |
.SH ERRORS |
| 56 |
.BR sync () |
| 57 |
is always successful. |
| 58 |
.P |
| 59 |
.BR syncfs () |
| 60 |
can fail for at least the following reasons: |
| 61 |
.TP |
| 62 |
.B EBADF |
| 63 |
.I fd |
| 64 |
is not a valid file descriptor. |
| 65 |
.TP |
| 66 |
.B EIO |
| 67 |
An error occurred during synchronization. |
| 68 |
This error may relate to data written to any file on the filesystem, or on |
| 69 |
metadata related to the filesystem itself. |
| 70 |
.TP |
| 71 |
.B ENOSPC |
| 72 |
Disk space was exhausted while synchronizing. |
| 73 |
.TP |
| 74 |
.B ENOSPC |
| 75 |
.TQ |
| 76 |
.B EDQUOT |
| 77 |
Data was written to a file on NFS or another filesystem which does not |
| 78 |
allocate space at the time of a |
| 79 |
.BR write (2) |
| 80 |
system call, and some previous write failed due to insufficient |
| 81 |
storage space. |
| 82 |
.SH VERSIONS |
| 83 |
According to the standard specification (i.e., POSIX.1), |
| 84 |
.BR sync () |
| 85 |
schedules the writes, but may return before the actual |
| 86 |
writing is done. |
| 87 |
However Linux waits for I/O completions, |
| 88 |
and thus |
| 89 |
.BR sync () |
| 90 |
or |
| 91 |
.BR syncfs () |
| 92 |
provide the same guarantees as |
| 93 |
.BR fsync () |
| 94 |
called on every file in |
| 95 |
the system or filesystem respectively. |
| 96 |
.SH STANDARDS |
| 97 |
.TP |
| 98 |
.BR sync () |
| 99 |
POSIX.1-2024. |
| 100 |
.TP |
| 101 |
.BR syncfs () |
| 102 |
Linux. |
| 103 |
.SH HISTORY |
| 104 |
.TP |
| 105 |
.BR sync () |
| 106 |
POSIX.1-2001, SVr4, 4.3BSD. |
| 107 |
.TP |
| 108 |
.BR syncfs () |
| 109 |
Linux 2.6.39, |
| 110 |
glibc 2.14. |
| 111 |
.P |
| 112 |
Since glibc 2.2.2, the Linux prototype for |
| 113 |
.BR sync () |
| 114 |
is as listed above, |
| 115 |
following the various standards. |
| 116 |
In glibc 2.2.1 and earlier, |
| 117 |
it was "int sync(void)", and |
| 118 |
.BR sync () |
| 119 |
always returned 0. |
| 120 |
.P |
| 121 |
In mainline kernel versions prior to Linux 5.8, |
| 122 |
.BR syncfs () |
| 123 |
will fail only when passed a bad file descriptor |
| 124 |
.RB ( EBADF ). |
| 125 |
Since Linux 5.8, |
| 126 |
.\" commit 735e4ae5ba28c886d249ad04d3c8cc097dad6336 |
| 127 |
.BR syncfs () |
| 128 |
will also report an error if one or more inodes failed |
| 129 |
to be written back since the last |
| 130 |
.BR syncfs () |
| 131 |
call. |
| 132 |
.SH BUGS |
| 133 |
Before Linux 1.3.20, Linux did not wait for I/O to complete |
| 134 |
before returning. |
| 135 |
.SH SEE ALSO |
| 136 |
.BR sync (1), |
| 137 |
.BR fdatasync (2), |
| 138 |
.BR fsync (2) |