The
copy_file_range()
system call
copies up to
len
bytes from
infd
to
outfd
in the kernel.
It may do this using a file system specific technique if
infd
and
outfd
are on the same file system.
If
infd
and
outfd
refer to the same file, the byte ranges defined by
the input file offset, output file offset and
len
cannot overlap.
The
infd
argument must be opened for reading and the
outfd
argument must be opened for writing, but not
O_APPEND.
If
inoffp
or
outoffp
is
NULL,
the file offset for
infd
or
outfd
respectively will be used and updated by
the number of bytes copied.
If
inoffp
or
outoffp
is not
NULL,
the byte offset pointed to by
inoffp
or
outoffp
respectively will be used/updated and the file offset for
infd
or
outfd
respectively will not be affected.
The
flags
argument must be 0.
This system call attempts to maintain holes in the output file for
the byte range being copied.
However, this does not always work well.
It is recommended that sparse files be copied in a loop using
lseek(2)
with
SEEK_HOLE,
SEEK_DATA
arguments and this system call for the
data ranges found.
For best performance, call
copy_file_range()
with the largest
len
value possible.
It is interruptible on most file systems,
so there is no penalty for using very large len values, even SSIZE_MAX.