]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/man/man2/fsync.2
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / man / man2 / fsync.2
... / ...
CommitLineData
1.\" $NetBSD: fsync.2,v 1.4 1995/02/27 12:32:38 cgd Exp $
2.\"
3.\" Copyright (c) 1983, 1993
4.\" The Regents of the University of California. All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\" must display the following acknowledgement:
16.\" This product includes software developed by the University of
17.\" California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\" may be used to endorse or promote products derived from this software
20.\" without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\" @(#)fsync.2 8.1 (Berkeley) 6/4/93
35.\"
36.Dd June 4, 1993
37.Dt FSYNC 2
38.Os BSD 4.2
39.Sh NAME
40.Nm fsync
41.Nd "synchronize a file's in-core state with that on disk"
42.Sh SYNOPSIS
43.Fd #include <unistd.h>
44.Ft int
45.Fo fsync
46.Fa "int fildes"
47.Fc
48.Sh DESCRIPTION
49.Fn fsync
50causes all modified data and attributes of
51.Fa fildes
52to be moved to a permanent storage device.
53This normally results in all in-core modified copies
54of buffers for the associated file to be written to a disk.
55.Pp
56Note that while
57.Fn fsync
58will flush all data from the host to the drive
59(i.e. the "permanent storage device"),
60the drive itself may not physically write the data
61to the platters for quite some time
62and it may be written in an out-of-order sequence.
63.Pp
64Specifically, if the drive loses power
65or the OS crashes,
66the application may find that only some or none of their data was written.
67The disk drive may also re-order the data
68so that later writes may be present, while earlier writes are not.
69.Pp
70This is not a theoretical edge case.
71This scenario is easily reproduced with real world workloads
72and drive power failures.
73.Pp
74For applications that require tighter guarantees
75about the integrity of their data,
76Mac OS X provides the F_FULLFSYNC fcntl.
77The F_FULLFSYNC fcntl asks the drive to flush all buffered data
78to permanent storage.
79Applications, such as databases,
80that require a strict ordering of writes
81should use F_FULLFSYNC to ensure that their data
82is written in the order they expect.
83Please see
84.Xr fcntl 2
85for more detail.
86.Pp
87.Sh RETURN VALUES
88.Rv -std fsync
89.Sh ERRORS
90The
91.Fn fsync
92system call will fail if:
93.Bl -tag -width Er
94.\" ==========
95.It Bq Er EBADF
96.Fa fildes
97is not a valid descriptor.
98.\" ==========
99.It Bq Er EINTR
100Its execution is interrupted by a signal.
101.\" ==========
102.It Bq Er EINVAL
103.Fa fildes
104refers to a file type (e.g., a socket)
105that does not support this operation.
106.\" ==========
107.It Bq Er EIO
108An I/O error occurred while reading from or writing to the file system.
109.El
110.Pp
111If a queued I/O operation fails,
112.Fn fsync
113may fail with any of the errors defined for
114.Xr read 2
115or
116.Xr write 2 .
117.Sh SEE ALSO
118.Xr fcntl 2 ,
119.Xr read 2 ,
120.Xr sync 2 ,
121.Xr write 2 ,
122.Xr sync 8 ,
123.Xr update 8
124.Sh HISTORY
125The
126.Fn fsync
127function call appeared in
128.Bx 4.2 .