1 .\" Copyright (c) 2016, Oracle. All rights reserved.
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
4 .TH IOCTL_FICLONERANGE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
6 ioctl_ficlonerange, ioctl_ficlone \- share some the data of one file with another file
9 .BR "#include <linux/fs.h>" " /* Definition of " FICLONE* " constants */"
10 .B #include <sys/ioctl.h>
12 .BI "int ioctl(int " dest_fd ", FICLONERANGE, struct file_clone_range *" arg );
13 .BI "int ioctl(int " dest_fd ", FICLONE, int " src_fd );
16 If a filesystem supports files sharing physical storage between multiple
17 files ("reflink"), this
19 operation can be used to make some of the data in the
23 file by sharing the underlying storage, which is faster than making a separate
24 physical copy of the data.
25 Both files must reside within the same filesystem.
26 If a file write should occur to a shared region,
27 the filesystem must ensure that the changes remain private to the file being
29 This behavior is commonly referred to as "copy on write".
31 This ioctl reflinks up to
33 bytes from file descriptor
41 provided that both are files.
44 is zero, the ioctl reflinks to the end of the source file.
45 This information is conveyed in a structure of
50 struct file_clone_range {
59 Clones are atomic with regards to concurrent writes, so no locks need to be
60 taken to obtain a consistent cloned copy.
64 ioctl clones entire files.
66 On error, \-1 is returned, and
68 is set to indicate the error.
70 Error codes can be one of, but are not limited to, the following:
74 is not open for reading;
76 is not open for writing or is open for append-only writes;
77 or the filesystem which
79 resides on does not support reflink.
82 The filesystem does not support reflinking the ranges of the given files.
83 This error can also appear if either file descriptor represents
84 a device, FIFO, or socket.
85 Disk filesystems generally require the offset and length arguments
86 to be aligned to the fundamental block size.
87 XFS and Btrfs do not support
88 overlapping reflink ranges in the same file.
91 One of the files is a directory and the filesystem does not support shared
92 regions in directories.
95 This can appear if the filesystem does not support reflinking either file
96 descriptor, or if either file descriptor refers to special inodes.
103 One of the files is a swap file.
104 Swap files cannot share storage.
107 .IR dest_fd " and " src_fd
108 are not on the same mounted filesystem.
110 These ioctl operations first appeared in Linux 4.5.
111 They were previously known as
114 .BR BTRFS_IOC_CLONE_RANGE ,
115 and were private to Btrfs.
117 This API is Linux-specific.
119 Because a copy-on-write operation requires the allocation of new storage, the
121 operation may unshare shared blocks to guarantee that subsequent writes will
122 not fail because of lack of disk space.