1 .\" $NetBSD: fsync.2,v 1.18 2013/09/22 10:02:05 apb Exp $
3 .\" Copyright (c) 1983, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)fsync.2 8.1 (Berkeley) 6/4/93
32 .Dd September 22, 2013
38 .Nd "synchronize a file's in-core state with that on disk"
46 .Fn fsync_range "int fd" "int how" "off_t start" "off_t length"
49 causes all modified data and attributes of
51 to be written to a permanent storage device.
52 This normally results in all in-core modified copies
53 of buffers for the associated file to be written to a disk.
56 is similar, but provides control over the region of the file
57 to be synchronized, and the method of synchronization.
59 These functions should be used by programs that require a file to be
60 in a known state, for example, in building a simple transaction
63 Note that writing the data to a permanent storage device
64 does not necessarily write the data to permanent storage media
66 for example, after writing data to a disk device, the data might
67 reside in a cache within the device, but not yet on
68 more permanent storage within the device.
71 nor the default behavior of
76 will flush disk caches,
77 because they assume that storage devices are able to ensure that
78 completed writes are transferred to media some time between the
79 write and a power failure or system crash.
82 causes all modified data starting at
88 to be written to a permanent storage device.
93 will synchronize all of the file data.
98 parameter which contains one or more of the following flags:
99 .Bl -tag -width FDATASYNC -offset indent
101 Synchronize the file data and sufficient meta-data to retrieve the
102 data for the specified range.
103 This is equivalent to
105 on the specified range.
107 Synchronize all modified file data and meta-data for the specified range.
108 This is equivalent to
110 on the specified range.
112 Request the destination device to ensure that the relevant data
113 and meta-data is flushed from any cache to permanent storage media.
114 In the present implementation, the entire cache on the affected device will
115 be flushed, and this may have a significant impact on performance.
122 flags are mutually exclusive.
123 Either of those flags may be combined with the
129 requires that the file
131 must be open for writing, whereas
135 A 0 value is returned on success.
136 A \-1 value indicates an error.
145 is not a valid descriptor.
148 refers to a socket, not to a file.
150 An I/O error occurred while reading from or writing to the file system.
159 is not open for writing.
168 For optimal efficiency, the
170 call requires that the file system containing the file referenced by
172 support partial synchronization of file data.
173 For file systems which do
174 not support partial synchronization, the entire file will be synchronized
175 and the call will be the equivalent of calling
184 function call appeared in
189 function call first appeared in
191 and is modeled after the function available in AIX.