1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) and
4 .\" and Copyright 2006 Michael Kerrisk <mtk.manpages@gmail.com>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified 21 Aug 1994 by Michael Chastain <mec@shell.portal.com>:
27 .\" Removed note about old libc (pre-4.5.26) translating to 'sync'.
28 .\" Modified 15 Apr 1995 by Michael Chastain <mec@shell.portal.com>:
29 .\" Added `see also' section.
30 .\" Modified 13 Apr 1996 by Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
31 .\" Added remarks about fdatasync.
32 .\" Modified 31 Jan 1997 by Eric S. Raymond <esr@thyrsus.com>
33 .\" Modified 18 Apr 2001 by Andi Kleen
34 .\" Fix description to describe what it really does; add a few caveats.
35 .\" 2006-04-28, mtk, substantial rewrite of various parts.
36 .\" 2012-02-27 Various changes by Christoph Hellwig <hch@lst.de>
38 .TH FSYNC 2 2012-02-27 "Linux" "Linux Programmer's Manual"
40 fsync, fdatasync \- synchronize a file's in-core state with storage device
42 .B #include <unistd.h>
44 .BI "int fsync(int " fd );
46 .BI "int fdatasync(int " fd );
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
54 _BSD_SOURCE || _XOPEN_SOURCE
56 || /* since glibc 2.8: */ _POSIX_C_SOURCE\ >=\ 200112L
57 .\" _POSIX_C_SOURCE\ >=\ 200112L only since glibc 2.8
60 _POSIX_C_SOURCE\ >=\ 199309L || _XOPEN_SOURCE\ >=\ 500
63 transfers ("flushes") all modified in-core data of
64 (i.e., modified buffer cache pages for) the
65 file referred to by the file descriptor
67 to the disk device (or other permanent storage device) so that all
68 changed information can be retrieved even after the system crashed or
70 This includes writing through or flushing a disk cache if present.
71 The call blocks until the device reports that the transfer has completed.
72 It also flushes metadata information associated with the file (see
78 does not necessarily ensure
79 that the entry in the directory containing the file has also reached disk.
82 on a file descriptor for the directory is also needed.
87 but does not flush modified metadata unless that metadata
88 is needed in order to allow a subsequent data retrieval to be
90 For example, changes to
94 (respectively, time of last access and
95 time of last modification; see
97 do not require flushing because they are not necessary for
98 a subsequent data read to be handled correctly.
99 On the other hand, a change to the file size
103 would require a metadata flush.
107 is to reduce disk activity for applications that do not
108 require all metadata to be synchronized with the disk.
110 On success, these system calls return zero.
111 On error, \-1 is returned, and
113 is set appropriately.
118 is not a valid open file descriptor.
121 An error occurred during synchronization.
123 .BR EROFS ", " EINVAL
125 is bound to a special file which does not support synchronization.
127 4.3BSD, POSIX.1-2001.
129 On POSIX systems on which
132 .B _POSIX_SYNCHRONIZED_IO
135 to a value greater than 0.
138 .\" POSIX.1-2001: It shall be defined to -1 or 0 or 200112L.
139 .\" -1: unavailable, 0: ask using sysconf().
140 .\" glibc defines them to 1.
142 In Linux 2.2 and earlier,
146 and so has no performance advantage.
150 implementations in older kernels and lesser used filesystems
151 does not know how to flush disk caches.
152 In these cases disk caches need to be disabled using
156 to guarantee safe operation.
161 .BR sync_file_range (2),