1ioctl_ficlonerange(2) System Calls Manual ioctl_ficlonerange(2)
2
3
4
6 ioctl_ficlonerange, ioctl_ficlone - share some the data of one file
7 with another file
8
10 Standard C library (libc, -lc)
11
13 #include <linux/fs.h> /* Definition of FICLONE* constants */
14 #include <sys/ioctl.h>
15
16 int ioctl(int dest_fd, FICLONERANGE, struct file_clone_range *arg);
17 int ioctl(int dest_fd, FICLONE, int src_fd);
18
20 If a filesystem supports files sharing physical storage between multi‐
21 ple files ("reflink"), this ioctl(2) operation can be used to make some
22 of the data in the src_fd file appear in the dest_fd file by sharing
23 the underlying storage, which is faster than making a separate physical
24 copy of the data. Both files must reside within the same filesystem.
25 If a file write should occur to a shared region, the filesystem must
26 ensure that the changes remain private to the file being written. This
27 behavior is commonly referred to as "copy on write".
28
29 This ioctl reflinks up to src_length bytes from file descriptor src_fd
30 at offset src_offset into the file dest_fd at offset dest_offset, pro‐
31 vided that both are files. If src_length is zero, the ioctl reflinks
32 to the end of the source file. This information is conveyed in a
33 structure of the following form:
34
35 struct file_clone_range {
36 __s64 src_fd;
37 __u64 src_offset;
38 __u64 src_length;
39 __u64 dest_offset;
40 };
41
42 Clones are atomic with regards to concurrent writes, so no locks need
43 to be taken to obtain a consistent cloned copy.
44
45 The FICLONE ioctl clones entire files.
46
48 On error, -1 is returned, and errno is set to indicate the error.
49
51 Error codes can be one of, but are not limited to, the following:
52
53 EBADF src_fd is not open for reading; dest_fd is not open for writing
54 or is open for append-only writes; or the filesystem which
55 src_fd resides on does not support reflink.
56
57 EINVAL The filesystem does not support reflinking the ranges of the
58 given files. This error can also appear if either file descrip‐
59 tor represents a device, FIFO, or socket. Disk filesystems gen‐
60 erally require the offset and length arguments to be aligned to
61 the fundamental block size. XFS and Btrfs do not support over‐
62 lapping reflink ranges in the same file.
63
64 EISDIR One of the files is a directory and the filesystem does not sup‐
65 port shared regions in directories.
66
67 EOPNOTSUPP
68 This can appear if the filesystem does not support reflinking
69 either file descriptor, or if either file descriptor refers to
70 special inodes.
71
72 EPERM dest_fd is immutable.
73
74 ETXTBSY
75 One of the files is a swap file. Swap files cannot share stor‐
76 age.
77
78 EXDEV dest_fd and src_fd are not on the same mounted filesystem.
79
81 Linux.
82
84 Linux 4.5.
85
86 They were previously known as BTRFS_IOC_CLONE and
87 BTRFS_IOC_CLONE_RANGE, and were private to Btrfs.
88
90 Because a copy-on-write operation requires the allocation of new stor‐
91 age, the fallocate(2) operation may unshare shared blocks to guarantee
92 that subsequent writes will not fail because of lack of disk space.
93
95 ioctl(2)
96
97
98
99Linux man-pages 6.04 2023-03-30 ioctl_ficlonerange(2)