1 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
2 .\" and Copyright (c) 2011 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
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,
36 .TH SYNC 2 2021-03-22 "Linux" "Linux Programmer's Manual"
38 sync, syncfs \- commit filesystem caches to disk
41 .B #include <unistd.h>
45 .BI "int syncfs(int " fd );
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
56 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
57 || /* Since glibc 2.19: */ _DEFAULT_SOURCE
58 || /* Glibc <= 2.19: */ _BSD_SOURCE
67 causes all pending modifications to filesystem metadata and cached file
68 data to be written to the underlying filesystems.
73 but synchronizes just the filesystem containing file
74 referred to by the open file descriptor
79 on error, it returns \-1 and sets
81 to indicate the error.
87 can fail for at least the following reasons:
91 is not a valid file descriptor.
94 An error occurred during synchronization.
95 This error may relate to data written to any file on the filesystem, or on
96 metadata related to the filesystem itself.
99 Disk space was exhausted while synchronizing.
101 .BR ENOSPC ", " EDQUOT
102 Data was written to a files on NFS or another filesystem which does not
103 allocate space at the time of a
105 system call, and some previous write failed due to insufficient
109 first appeared in Linux 2.6.39;
110 library support was added to glibc in version 2.14.
113 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
118 Since glibc 2.2.2, the Linux prototype for
121 following the various standards.
122 In glibc 2.2.1 and earlier,
123 it was "int sync(void)", and
127 According to the standard specification (e.g., POSIX.1-2001),
129 schedules the writes, but may return before the actual
131 However Linux waits for I/O completions,
136 provide the same guarantees as
138 called on every file in
139 the system or filesystem respectively.
141 In mainline kernel versions prior to 5.8,
143 will fail only when passed a bad file descriptor
146 .\" commit 735e4ae5ba28c886d249ad04d3c8cc097dad6336
148 will also report an error if one or more inodes failed
149 to be written back since the last
153 Before version 1.3.20 Linux did not wait for I/O to complete