334 lines
7.9 KiB
HTML
334 lines
7.9 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of SYNC_FILE_RANGE</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>SYNC_FILE_RANGE</H1>
|
|
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
sync_file_range - sync a file segment with disk
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#define _GNU_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
<B>#include <<A HREF="file:///usr/include/fcntl.h">fcntl.h</A>></B>
|
|
|
|
<B>int sync_file_range(int </B><I>fd</I><B>, off64_t </B><I>offset</I><B>, off64_t </B><I>nbytes</I><B>,</B>
|
|
<B> unsigned int </B><I>flags</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<B>sync_file_range</B>()
|
|
|
|
permits fine control when synchronizing the open file referred to by the
|
|
file descriptor
|
|
<I>fd</I>
|
|
|
|
with disk.
|
|
<P>
|
|
|
|
<I>offset</I>
|
|
|
|
is the starting byte of the file range to be synchronized.
|
|
<I>nbytes</I>
|
|
|
|
specifies the length of the range to be synchronized, in bytes; if
|
|
<I>nbytes</I>
|
|
|
|
is zero, then all bytes from
|
|
<I>offset</I>
|
|
|
|
through to the end of file are synchronized.
|
|
Synchronization is in units of the system page size:
|
|
<I>offset</I>
|
|
|
|
is rounded down to a page boundary;
|
|
<I>(offset+nbytes-1)</I>
|
|
|
|
is rounded up to a page boundary.
|
|
<P>
|
|
|
|
The
|
|
<I>flags</I>
|
|
|
|
bit-mask argument can include any of the following values:
|
|
<DL COMPACT>
|
|
<DT id="1"><B>SYNC_FILE_RANGE_WAIT_BEFORE</B>
|
|
|
|
<DD>
|
|
Wait upon write-out of all pages in the specified range
|
|
that have already been submitted to the device driver for write-out
|
|
before performing any write.
|
|
<DT id="2"><B>SYNC_FILE_RANGE_WRITE</B>
|
|
|
|
<DD>
|
|
Initiate write-out of all dirty pages in the specified
|
|
range which are not presently submitted write-out.
|
|
Note that even this may block if you attempt to
|
|
write more than request queue size.
|
|
<DT id="3"><B>SYNC_FILE_RANGE_WAIT_AFTER</B>
|
|
|
|
<DD>
|
|
Wait upon write-out of all pages in the range
|
|
after performing any write.
|
|
</DL>
|
|
<P>
|
|
|
|
Specifying
|
|
<I>flags</I>
|
|
|
|
as 0 is permitted, as a no-op.
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Warning</H3>
|
|
|
|
This system call is extremely dangerous and should not be used in portable
|
|
programs.
|
|
None of these operations writes out the file's metadata.
|
|
Therefore, unless the application is strictly performing overwrites of
|
|
already-instantiated disk blocks, there are no guarantees that the data will
|
|
be available after a crash.
|
|
There is no user interface to know if a write is purely an overwrite.
|
|
On filesystems using copy-on-write semantics (e.g.,
|
|
<I>btrfs</I>)
|
|
|
|
an overwrite of existing allocated blocks is impossible.
|
|
When writing into preallocated space,
|
|
many filesystems also require calls into the block
|
|
allocator, which this system call does not sync out to disk.
|
|
This system call does not flush disk write caches and thus does not provide
|
|
any data integrity on systems with volatile disk write caches.
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Some details</H3>
|
|
|
|
<B>SYNC_FILE_RANGE_WAIT_BEFORE</B>
|
|
|
|
and
|
|
<B>SYNC_FILE_RANGE_WAIT_AFTER</B>
|
|
|
|
will detect any
|
|
I/O errors or
|
|
<B>ENOSPC</B>
|
|
|
|
conditions and will return these to the caller.
|
|
<P>
|
|
|
|
Useful combinations of the
|
|
<I>flags</I>
|
|
|
|
bits are:
|
|
<DL COMPACT>
|
|
<DT id="4"><B>SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE</B>
|
|
|
|
<DD>
|
|
Ensures that all pages
|
|
in the specified range which were dirty when
|
|
<B>sync_file_range</B>()
|
|
|
|
was called are placed
|
|
under write-out.
|
|
This is a start-write-for-data-integrity operation.
|
|
<DT id="5"><B>SYNC_FILE_RANGE_WRITE</B>
|
|
|
|
<DD>
|
|
Start write-out of all dirty pages in the specified range which
|
|
are not presently under write-out.
|
|
This is an asynchronous flush-to-disk
|
|
operation.
|
|
This is not suitable for data integrity operations.
|
|
<DT id="6"><B>SYNC_FILE_RANGE_WAIT_BEFORE</B> (or <B>SYNC_FILE_RANGE_WAIT_AFTER</B>)
|
|
|
|
<DD>
|
|
Wait for
|
|
completion of write-out of all pages in the specified range.
|
|
This can be used after an earlier
|
|
<B>SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE</B>
|
|
|
|
operation to wait for completion of that operation, and obtain its result.
|
|
<DT id="7"><B>SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE | SYNC_FILE_RANGE_WAIT_AFTER</B>
|
|
|
|
<DD>
|
|
This is a write-for-data-integrity operation
|
|
that will ensure that all pages in the specified range which were dirty when
|
|
<B>sync_file_range</B>()
|
|
|
|
was called are committed to disk.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success,
|
|
<B>sync_file_range</B>()
|
|
|
|
returns 0; on failure -1 is returned and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the error.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="8"><B>EBADF</B>
|
|
|
|
<DD>
|
|
<I>fd</I>
|
|
|
|
is not a valid file descriptor.
|
|
<DT id="9"><B>EINVAL</B>
|
|
|
|
<DD>
|
|
<I>flags</I>
|
|
|
|
specifies an invalid bit; or
|
|
<I>offset</I>
|
|
|
|
or
|
|
<I>nbytes</I>
|
|
|
|
is invalid.
|
|
<DT id="10"><B>EIO</B>
|
|
|
|
<DD>
|
|
I/O error.
|
|
<DT id="11"><B>ENOMEM</B>
|
|
|
|
<DD>
|
|
Out of memory.
|
|
<DT id="12"><B>ENOSPC</B>
|
|
|
|
<DD>
|
|
Out of disk space.
|
|
<DT id="13"><B>ESPIPE</B>
|
|
|
|
<DD>
|
|
<I>fd</I>
|
|
|
|
refers to something other than a regular file, a block device, or
|
|
a directory.
|
|
</DL>
|
|
<A NAME="lbAI"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>sync_file_range</B>()
|
|
|
|
appeared on Linux in kernel 2.6.17.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
This system call is Linux-specific, and should be avoided
|
|
in portable programs.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H3>sync_file_range2()</H3>
|
|
|
|
Some architectures (e.g., PowerPC, ARM)
|
|
need 64-bit arguments to be aligned in a suitable pair of registers.
|
|
|
|
On such architectures, the call signature of
|
|
<B>sync_file_range</B>()
|
|
|
|
shown in the SYNOPSIS would force
|
|
a register to be wasted as padding between the
|
|
<I>fd</I>
|
|
|
|
and
|
|
<I>offset</I>
|
|
|
|
arguments.
|
|
(See
|
|
<B><A HREF="/cgi-bin/man/man2html?2+syscall">syscall</A></B>(2)
|
|
|
|
for details.)
|
|
Therefore, these architectures define a different
|
|
system call that orders the arguments suitably:
|
|
<P>
|
|
|
|
|
|
|
|
<B>int sync_file_range2(int </B><I>fd</I><B>, unsigned int </B><I>flags</I><B>,</B>
|
|
|
|
<B> off64_t </B><I>offset</I><B>, off64_t </B><I>nbytes</I><B>);</B>
|
|
|
|
|
|
|
|
<P>
|
|
|
|
The behavior of this system call is otherwise exactly the same as
|
|
<B>sync_file_range</B>().
|
|
|
|
<P>
|
|
|
|
A system call with this signature first appeared on the ARM architecture
|
|
in Linux 2.6.20, with the name
|
|
<B>arm_sync_file_range</B>().
|
|
|
|
It was renamed in Linux 2.6.22,
|
|
when the analogous system call was added for PowerPC.
|
|
On architectures where glibc support is provided,
|
|
glibc transparently wraps
|
|
<B>sync_file_range2</B>()
|
|
|
|
under the name
|
|
<B>sync_file_range</B>().
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fdatasync">fdatasync</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+fsync">fsync</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+msync">msync</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+sync">sync</A></B>(2)
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="14"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="15"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="16"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="17"><A HREF="#lbAE">Warning</A><DD>
|
|
<DT id="18"><A HREF="#lbAF">Some details</A><DD>
|
|
</DL>
|
|
<DT id="19"><A HREF="#lbAG">RETURN VALUE</A><DD>
|
|
<DT id="20"><A HREF="#lbAH">ERRORS</A><DD>
|
|
<DT id="21"><A HREF="#lbAI">VERSIONS</A><DD>
|
|
<DT id="22"><A HREF="#lbAJ">CONFORMING TO</A><DD>
|
|
<DT id="23"><A HREF="#lbAK">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="24"><A HREF="#lbAL">sync_file_range2()</A><DD>
|
|
</DL>
|
|
<DT id="25"><A HREF="#lbAM">SEE ALSO</A><DD>
|
|
<DT id="26"><A HREF="#lbAN">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:35 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|