1copy_file_range(2) System Calls Manual copy_file_range(2)
2
3
4
6 copy_file_range - Copy a range of data from one file to another
7
9 Standard C library (libc, -lc)
10
12 #define _GNU_SOURCE
13 #include <unistd.h>
14
15 ssize_t copy_file_range(int fd_in, off64_t *_Nullable off_in,
16 int fd_out, off64_t *_Nullable off_out,
17 size_t len, unsigned int flags);
18
20 The copy_file_range() system call performs an in-kernel copy between
21 two file descriptors without the additional cost of transferring data
22 from the kernel to user space and then back into the kernel. It copies
23 up to len bytes of data from the source file descriptor fd_in to the
24 target file descriptor fd_out, overwriting any data that exists within
25 the requested range of the target file.
26
27 The following semantics apply for off_in, and similar statements apply
28 to off_out:
29
30 • If off_in is NULL, then bytes are read from fd_in starting from the
31 file offset, and the file offset is adjusted by the number of bytes
32 copied.
33
34 • If off_in is not NULL, then off_in must point to a buffer that spec‐
35 ifies the starting offset where bytes from fd_in will be read. The
36 file offset of fd_in is not changed, but off_in is adjusted appro‐
37 priately.
38
39 fd_in and fd_out can refer to the same file. If they refer to the same
40 file, then the source and target ranges are not allowed to overlap.
41
42 The flags argument is provided to allow for future extensions and cur‐
43 rently must be set to 0.
44
46 Upon successful completion, copy_file_range() will return the number of
47 bytes copied between files. This could be less than the length origi‐
48 nally requested. If the file offset of fd_in is at or past the end of
49 file, no bytes are copied, and copy_file_range() returns zero.
50
51 On error, copy_file_range() returns -1 and errno is set to indicate the
52 error.
53
55 EBADF One or more file descriptors are not valid.
56
57 EBADF fd_in is not open for reading; or fd_out is not open for writ‐
58 ing.
59
60 EBADF The O_APPEND flag is set for the open file description (see
61 open(2)) referred to by the file descriptor fd_out.
62
63 EFBIG An attempt was made to write at a position past the maximum file
64 offset the kernel supports.
65
66 EFBIG An attempt was made to write a range that exceeds the allowed
67 maximum file size. The maximum file size differs between
68 filesystem implementations and can be different from the maximum
69 allowed file offset.
70
71 EFBIG An attempt was made to write beyond the process's file size re‐
72 source limit. This may also result in the process receiving a
73 SIGXFSZ signal.
74
75 EINV