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
12 .BR "#include <linux/fs.h>" " /* Definition of " FICLONE* " constants */"
13 .B #include <sys/ioctl.h>
15 .BI "int ioctl(int " dest_fd ", FICLONERANGE, struct file_clone_range *" arg );
16 .BI "int ioctl(int " dest_fd ", FICLONE, int " src_fd );
19 If a filesystem supports files sharing physical storage between multiple
20 files ("reflink"), this
22 operation can be used to make some of the data in the
26 file by sharing the underlying storage, which is faster than making a separate
27 physical copy of the data.
28 Both files must reside within the same filesystem.
29 If a file write should occur to a shared region,
30 the filesystem must ensure that the changes remain private to the file being
32 This behavior is commonly referred to as "copy on write".
34 This ioctl reflinks up to
36 bytes from file descriptor
44 provided that both are files.
47 is zero, the ioctl reflinks to the end of the source file.
48 This information is conveyed in a structure of
53 struct file_clone_range {
62 Clones are atomic with regards to concurrent writes, so no locks need to be
63 taken to obtain a consistent cloned copy.
67 ioctl clones entire files.
69 On error, \-1 is returned, and
71 is set to indicate the error.
73 Error codes can be one of, but are not limited to, the following:
77 is not open for reading;
79 is not open for writing or is open for append-only writes;
80 or the filesystem which
82 resides on does not support reflink.
85 The filesystem does not support reflinking the ranges of the given files.
86 This error can also appear if either file descriptor represents
87 a device, FIFO, or socket.
88 Disk filesystems generally require the offset and length arguments
89 to be aligned to the fundamental block size.
90 XFS and Btrfs do not support
91 overlapping reflink ranges in the same file.
94 One of the files is a directory and the filesystem does not support shared
95 regions in directories.
98 This can appear if the filesystem does not support reflinking either file
99 descriptor, or if either file descriptor refers to special inodes.
106 One of the files is a swap file.
107 Swap files cannot share storage.
110 .IR dest_fd " and " src_fd
111 are not on the same mounted filesystem.
113 These ioctl operations first appeared in Linux 4.5.
114 They were previously known as
117 .BR BTRFS_IOC_CLONE_RANGE ,
118 and were private to Btrfs.
120 This API is Linux-specific.
122 Because a copy-on-write operation requires the allocation of new storage, the
124 operation may unshare shared blocks to guarantee that subsequent writes will
125 not fail because of lack of disk space.