1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 2006 Andrew Morton <akpm@osdl.org>
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 .\" 2006-07-05 Initial creation, Michael Kerrisk based on
27 .\" Andrew Morton's comments in fs/sync.c
28 .\" 2010-10-09, mtk, Document sync_file_range2()
30 .TH SYNC_FILE_RANGE 2 2010-10-09 "Linux" "Linux Programmer's Manual"
32 sync_file_range \- sync a file segment with disk
35 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
38 .BI "int sync_file_range(int " fd ", off64_t " offset ", off64_t " nbytes ,
39 .BI " unsigned int " flags );
42 .BR sync_file_range ()
43 permits fine control when synchronizing the open file referred to by the
49 is the starting byte of the file range to be synchronized.
51 specifies the length of the range to be synchronized, in bytes; if
53 is zero, then all bytes from
55 through to the end of file are synchronized.
56 Synchronization is in units of the system page size:
58 is rounded down to a page boundary;
60 is rounded up to a page boundary.
64 bit-mask argument can include any of the following values:
66 .B SYNC_FILE_RANGE_WAIT_BEFORE
67 Wait upon write-out of all pages in the specified range
68 that have already been submitted to the device driver for write-out
69 before performing any write.
71 .B SYNC_FILE_RANGE_WRITE
72 Initiate write-out of all dirty pages in the specified
73 range which are not presently submitted write-out.
74 Note that even this may block if you attempt to
75 write more than request queue size.
77 .B SYNC_FILE_RANGE_WAIT_AFTER
78 Wait upon write-out of all pages in the range
79 after performing any write.
83 as 0 is permitted, as a no-op.
85 This system call is extremely dangerous and should not be used in portable
87 None of these operations writes out the file's metadata.
88 Therefore, unless the application is strictly performing overwrites of
89 already-instantiated disk blocks, there are no guarantees that the data will
90 be available after a crash.
91 There is no user interface to know if a write is purely an overwrite.
92 On file systems using copy-on-write semantics (e.g.,
94 an overwrite of existing allocated blocks is impossible.
95 When writing into preallocated space,
96 many file systems also require calls into the block
97 allocator, which this system call does not sync out to disk.
98 This system call does not flush disk write caches and thus does not provide
99 any data integrity on systems with volatile disk write caches.
101 .B SYNC_FILE_RANGE_WAIT_BEFORE
103 .B SYNC_FILE_RANGE_WAIT_AFTER
107 conditions and will return these to the caller.
109 Useful combinations of the
113 .B SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE
114 Ensures that all pages
115 in the specified range which were dirty when
116 .BR sync_file_range ()
117 was called are placed
119 This is a start-write-for-data-integrity operation.
121 .B SYNC_FILE_RANGE_WRITE
122 Start write-out of all dirty pages in the specified range which
123 are not presently under write-out.
124 This is an asynchronous flush-to-disk
126 This is not suitable for data integrity operations.
128 .BR SYNC_FILE_RANGE_WAIT_BEFORE " (or " SYNC_FILE_RANGE_WAIT_AFTER )
130 completion of write-out of all pages in the specified range.
131 This can be used after an earlier
132 .B SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE
133 operation to wait for completion of that operation, and obtain its result.
135 .B SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE | \
136 SYNC_FILE_RANGE_WAIT_AFTER
137 This is a write-for-data-integrity operation
138 that will ensure that all pages in the specified range which were dirty when
139 .BR sync_file_range ()
140 was called are committed to disk.
143 .BR sync_file_range ()
144 returns 0; on failure \-1 is returned and
146 is set to indicate the error.
151 is not a valid file descriptor.
155 specifies an invalid bit; or
172 refers to something other than a regular file, a block device,
173 a directory, or a symbolic link.
174 .\" FIXME . (bug?) Actually, how can 'fd' refer to a symbolic link (S_ISLNK)?
175 .\" (In userspace at least) it isn't possible to obtain a file descriptor
176 .\" for a symbolic link.
178 .BR sync_file_range ()
179 appeared on Linux in kernel 2.6.17.
181 This system call is Linux-specific, and should be avoided
182 in portable programs.
184 Some architectures (e.g., PowerPC, ARM)
185 need 64-bit arguments to be aligned in a suitable pair of registers.
186 .\" See kernel commit edd5cd4a9424f22b0fa08bef5e299d41befd5622
187 On such architectures, the call signature of
188 .BR sync_file_range ()
189 is flawed, since it forces a register to be wasted as padding between the
194 Therefore, these architectures define a different
195 system call that orders the arguments suitably:
199 .BI "int sync_file_range2(int " fd ", unsigned int " flags ,
200 .BI " off64_t " offset ", off64_t " nbytes );
204 The behavior of this system call is otherwise exactly the same as
205 .BR sync_file_range().
207 A system call with this signature first appeared on the ARM architecture
208 in Linux 2.6.20, with the name
209 .BR arm_sync_file_range ().
210 It was renamed in Linux 2.6.22,
211 when the analogous system call was added for PowerPC.
212 On architectures where glibc support is provided,
213 glibc transparently wraps
214 .BR sync_file_range2 ()
216 .BR sync_file_range ().