]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/fsync.2
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / man / man2 / fsync.2
CommitLineData
9bccf70c
A
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
2d21ac55
A
45.Fo fsync
46.Fa "int fildes"
47.Fc
9bccf70c 48.Sh DESCRIPTION
39037602 49.Fn fsync
9bccf70c 50causes all modified data and attributes of
2d21ac55 51.Fa fildes
9bccf70c
A
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
91447636
A
56Note that while
57.Fn fsync
2d21ac55
A
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.
91447636
A
63.Pp
64Specifically, if the drive loses power
65or the OS crashes,
2d21ac55
A
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.
91447636 69.Pp
2d21ac55
A
70This is not a theoretical edge case.
71This scenario is easily reproduced with real world workloads
72and drive power failures.
91447636 73.Pp
2d21ac55
A
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.
91447636
A
83Please see
84.Xr fcntl 2
85for more detail.
86.Pp
9bccf70c 87.Sh RETURN VALUES
2d21ac55 88.Rv -std fsync
9bccf70c
A
89.Sh ERRORS
90The
91.Fn fsync
2d21ac55 92system call will fail if:
9bccf70c 93.Bl -tag -width Er
2d21ac55 94.\" ==========
9bccf70c 95.It Bq Er EBADF
2d21ac55 96.Fa fildes
9bccf70c 97is not a valid descriptor.
2d21ac55
A
98.\" ==========
99.It Bq Er EINTR
100Its execution is interrupted by a signal.
101.\" ==========
9bccf70c 102.It Bq Er EINVAL
2d21ac55
A
103.Fa fildes
104refers to a file type (e.g., a socket)
105that does not support this operation.
106.\" ==========
9bccf70c
A
107.It Bq Er EIO
108An I/O error occurred while reading from or writing to the file system.
109.El
2d21ac55
A
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 .
9bccf70c 117.Sh SEE ALSO
2d21ac55
A
118.Xr fcntl 2 ,
119.Xr read 2 ,
9bccf70c 120.Xr sync 2 ,
2d21ac55 121.Xr write 2 ,
9bccf70c 122.Xr sync 8 ,
2d21ac55 123.Xr update 8
9bccf70c
A
124.Sh HISTORY
125The
126.Fn fsync
127function call appeared in
128.Bx 4.2 .