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   Some details
46       None  of  these  operations  write out the file's metadata.  Therefore,
47       unless the application is strictly performing  overwrites  of  already-
48       instantiated disk blocks, there are no guarantees that the data will be
49       available after a crash.
50
51       SYNC_FILE_RANGE_WAIT_BEFORE and SYNC_FILE_RANGE_WAIT_AFTER will  detect
52       any  I/O errors or ENOSPC conditions and will return these to the call‐
53       er.
54
55       Useful combinations of the flags bits are:
56
57       SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE
58              Ensures that all pages in the specified range which  were  dirty
59              when  sync_file_range()  was  called are placed under write-out.
60              This is a start-write-for-data-integrity operation.
61
62       SYNC_FILE_RANGE_WRITE
63              Start write-out of all dirty pages in the specified range  which
64              are  not  presently  under  write-out.   This is an asynchronous
65              flush-to-disk  operation.   This  is  not  suitable   for   data
66              integrity operations.
67
68       SYNC_FILE_RANGE_WAIT_BEFORE (or SYNC_FILE_RANGE_WAIT_AFTER)
69              Wait  for  completion of write-out of all pages in the specified
70              range.     This    can    be    used    after     an     earlier
71              SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE operation to
72              wait for completion of that operation, and obtain its result.
73
74       SYNC_FILE_RANGE_WAIT_BEFORE       |       SYNC_FILE_RANGE_WRITE       |
75       SYNC_FILE_RANGE_WAIT_AFTER
76              This  is  a  write-for-data-integrity operation that will ensure
77              that all pages in the specified  range  which  were  dirty  when
78              sync_file_range() was called are committed to disk.
79

RETURN VALUE

81       On  success, sync_file_range() returns 0; on failure -1 is returned and
82       errno is set to indicate the error.
83

ERRORS

85       EBADF  fd is not a valid file descriptor.
86
87       EINVAL flags specifies an invalid bit; or offset or nbytes is invalid.
88
89       EIO    I/O error.
90
91       ENOMEM Out of memory.
92
93       ENOSPC Out of disk space.
94
95       ESPIPE fd refers to something  other  than  a  regular  file,  a  block
96              device, a directory, or a symbolic link.
97

VERSIONS

99       sync_file_range() appeared on Linux in kernel 2.6.17.
100

CONFORMING TO

102       This  system  call is Linux-specific, and should be avoided in portable
103       programs.
104

SEE ALSO

106       fdatasync(2), fsync(2), msync(2), sync(2), feature_test_macros(7)
107

COLOPHON

109       This page is part of release 3.22 of the Linux  man-pages  project.   A
110       description  of  the project, and information about reporting bugs, can
111       be found at http://www.kernel.org/doc/man-pages/.
112
113
114
115Linux                             2008-05-27                SYNC_FILE_RANGE(2)
Impressum