1 .\" Copyright (c) 2006 Andrew Morton <akpm@osdl.org>
2 .\" and Copyright 2006 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" 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 2021-03-22 "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 filesystems using copy-on-write semantics (e.g.,
94 an overwrite of existing allocated blocks is impossible.
95 When writing into preallocated space,
96 many filesystems 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, or
175 .BR sync_file_range ()
176 appeared on Linux in kernel 2.6.17.
178 This system call is Linux-specific, and should be avoided
179 in portable programs.
181 .SS sync_file_range2()
182 Some architectures (e.g., PowerPC, ARM)
183 need 64-bit arguments to be aligned in a suitable pair of registers.
184 .\" See kernel commit edd5cd4a9424f22b0fa08bef5e299d41befd5622
185 On such architectures, the call signature of
186 .BR sync_file_range ()
187 shown in the SYNOPSIS would force
188 a register to be wasted as padding between the
196 Therefore, these architectures define a different
197 system call that orders the arguments suitably:
201 .BI "int sync_file_range2(int " fd ", unsigned int " flags ,
202 .BI " off64_t " offset ", off64_t " nbytes );
206 The behavior of this system call is otherwise exactly the same as
207 .BR sync_file_range ().
209 A system call with this signature first appeared on the ARM architecture
210 in Linux 2.6.20, with the name
211 .BR arm_sync_file_range ().
212 It was renamed in Linux 2.6.22,
213 when the analogous system call was added for PowerPC.
214 On architectures where glibc support is provided,
215 glibc transparently wraps
216 .BR sync_file_range2 ()
218 .BR sync_file_range ().