1SYNC_FILE_RANGE(2)         Linux Programmer's Manual        SYNC_FILE_RANGE(2)
2
3
4

NAME

6       sync_file_range - sync a file segment with disk
7

SYNOPSIS

9       #define _GNU_SOURCE
10       #include <fcntl.h>
11
12       int sync_file_range(int fd, off64_t offset, off64_t nbytes,
13                           unsigned int flags);
14

DESCRIPTION

16       sync_file_range() permits fine control when synchronizing the open file
17       referred to by the file descriptor fd with disk.
18
19       offset is the starting byte of  the  file  range  to  be  synchronized.
20       nbytes  specifies the length of the range to be synchronized, in bytes;
21       if nbytes is zero, then all bytes from offset through  to  the  end  of
22       file  are synchronized.  Synchronization is in units of the system page
23       size: offset is rounded down to a page boundary;  (offset+nbytes-1)  is
24       rounded up to a page boundary.
25
26       The flags bit-mask argument can include any of the following values:
27
28       SYNC_FILE_RANGE_WAIT_BEFORE
29              Wait  upon  write-out  of  all pages in the specified range that
30              have already been submitted to the device driver  for  write-out
31              before performing any write.
32
33       SYNC_FILE_RANGE_WRITE
34              Initiate  write-out  of  all  dirty pages in the specified range
35              which are not presently submitted  write-out.   Note  that  even
36              this  may  block if you attempt to write more than request queue
37              size.
38
39       SYNC_FILE_RANGE_WAIT_AFTER
40              Wait upon write-out of all pages in the range  after  performing
41              any write.
42
43       Specifying flags as 0 is permitted, as a no-op.
44
45   Warning
46       This  system call is extremely dangerous and should not be used in por‐
47       table programs.  None of these operations writes out the  file's  meta‐
48       data.   Therefore,  unless the application is strictly performing over‐
49       writes of already-instantiated disk blocks,  there  are  no  guarantees
50       that the data will be available after a crash.  There is no user inter‐
51       face to know if a write is purely an overwrite.  On file systems  using
52       copy-on-write  semantics  (e.g.,  btrfs) an overwrite of existing allo‐
53       cated blocks is impossible.  When writing into preallocated space, many
54       file  systems  also  require calls into the block allocator, which this
55       system call does not sync out to disk.  This system call does not flush
56       disk  write caches and thus does not provide any data integrity on sys‐
57       tems with volatile disk write caches.
58
59   Some details
60       SYNC_FILE_RANGE_WAIT_BEFORE and SYNC_FILE_RANGE_WAIT_AFTER will  detect
61       any  I/O errors or ENOSPC conditions and will return these to the call‐
62       er.
63
64       Useful combinations of the flags bits are:
65
66       SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE
67              Ensures that all pages in the specified range which  were  dirty
68              when  sync_file_range()  was  called are placed under write-out.
69              This is a start-write-for-data-integrity operation.
70
71       SYNC_FILE_RANGE_WRITE
72              Start write-out of all dirty pages in the specified range  which
73              are  not  presently  under  write-out.   This is an asynchronous
74              flush-to-disk  operation.   This  is  not  suitable   for   data
75              integrity operations.
76
77       SYNC_FILE_RANGE_WAIT_BEFORE (or SYNC_FILE_RANGE_WAIT_AFTER)
78              Wait  for  completion of write-out of all pages in the specified
79              range.     This    can    be    used    after     an     earlier
80              SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE operation to
81              wait for completion of that operation, and obtain its result.
82
83       SYNC_FILE_RANGE_WAIT_BEFORE       |       SYNC_FILE_RANGE_WRITE       |
84       SYNC_FILE_RANGE_WAIT_AFTER
85              This  is  a  write-for-data-integrity operation that will ensure
86              that all pages in the specified  range  which  were  dirty  when
87              sync_file_range() was called are committed to disk.
88

RETURN VALUE

90       On  success, sync_file_range() returns 0; on failure -1 is returned and
91       errno is set to indicate the error.
92

ERRORS

94       EBADF  fd is not a valid file descriptor.
95
96       EINVAL flags specifies an invalid bit; or offset or nbytes is invalid.
97
98       EIO    I/O error.
99
100       ENOMEM Out of memory.
101
102       ENOSPC Out of disk space.
103
104       ESPIPE fd refers to something  other  than  a  regular  file,  a  block
105              device, a directory, or a symbolic link.
106

VERSIONS

108       sync_file_range() appeared on Linux in kernel 2.6.17.
109

CONFORMING TO

111       This  system  call is Linux-specific, and should be avoided in portable
112       programs.
113

SEE ALSO

115       fdatasync(2), fsync(2), msync(2), sync(2), feature_test_macros(7)
116

COLOPHON

118       This page is part of release 3.25 of the Linux  man-pages  project.   A
119       description  of  the project, and information about reporting bugs, can
120       be found at http://www.kernel.org/doc/man-pages/.
121
122
123
124Linux                             2010-01-17                SYNC_FILE_RANGE(2)
Impressum