1IOCTL_FIDEDUPERANGE(2) Linux Programmer's Manual IOCTL_FIDEDUPERANGE(2)
2
3
4
6 ioctl_fideduperange - share some the data of one file with another file
7
9 #include <linux/fs.h> /* Definition of FIDEDUPERANGE and
10 FILE_DEDUPE_* constants*/
11 #include <sys/ioctl.h>
12
13 int ioctl(int src_fd, FIDEDUPERANGE, struct file_dedupe_range *arg);
14
16 If a filesystem supports files sharing physical storage between multi‐
17 ple files, this ioctl(2) operation can be used to make some of the data
18 in the src_fd file appear in the dest_fd file by sharing the underlying
19 storage if the file data is identical ("deduplication"). Both files
20 must reside within the same filesystem. This reduces storage consump‐
21 tion by allowing the filesystem to store one shared copy of the data.
22 If a file write should occur to a shared region, the filesystem must
23 ensure that the changes remain private to the file being written. This
24 behavior is commonly referred to as "copy on write".
25
26 This ioctl performs the "compare and share if identical" operation on
27 up to src_length bytes from file descriptor src_fd at offset src_off‐
28 set. This information is conveyed in a structure of the following
29 form:
30
31 struct file_dedupe_range {
32 __u64 src_offset;
33 __u64 src_length;
34 __u16 dest_count;
35 __u16 reserved1;
36 __u32 reserved2;
37 struct file_dedupe_range_info info[0];
38 };
39
40 Deduplication is atomic with regards to concurrent writes, so no locks
41 need to be taken to obtain a consistent deduplicated copy.
42
43 The fields reserved1 and reserved2 must be zero.
44
45 Destinations for the deduplication operation are conveyed in the array
46 at the end of the structure. The number of destinations is given in
47 dest_count, and the destination information is conveyed in the follow‐
48 ing form:
49
50 struct file_dedupe_range_info {
51 __s64 dest_fd;
52 __u64 dest_offset;
53 __u64 bytes_deduped;
54 __s32 status;
55 __u32 reserved;
56 };
57
58 Each deduplication operation targets src_length bytes in file descrip‐
59 tor dest_fd at offset dest_offset. The field reserved must be zero.
60 During the call, src_fd must be open for reading and dest_fd must be
61 open for writing. The combined size of the struct file_dedupe_range
62 and the struct file_dedupe_range_info array must not exceed the system
63 page size. The maximum size of src_length is filesystem dependent and
64 is typically 16 MiB. This limit will be enforced silently by the
65 filesystem. By convention, the storage used by src_fd is mapped into
66 dest_fd and the previous contents in dest_fd are freed.
67
68 Upon successful completion of this ioctl, the number of bytes success‐
69 fully deduplicated is returned in bytes_deduped and a status code for
70 the deduplication operation is returned in status. If even a single
71 byte in the range does not match, the deduplication request will be ig‐
72 nored and status set to FILE_DEDUPE_RANGE_DIFFERS. The status code is
73 set to FILE_DEDUPE_RANGE_SAME for success, a negative error code in
74 case of error, or FILE_DEDUPE_RANGE_DIFFERS if the data did not match.
75
77 On error, -1 is returned, and errno is set to indicate the error.
78
80 Possible errors include (but are not limited to) the following:
81
82 EBADF src_fd is not open for reading; dest_fd is not open for writing
83 or is open for append-only writes; or the filesystem which
84 src_fd resides on does not support deduplication.
85
86 EINVAL The filesystem does not support deduplicating the ranges of the
87 given files. This error can also appear if either file descrip‐
88 tor represents a device, FIFO, or socket. Disk filesystems gen‐
89 erally require the offset and length arguments to be aligned to
90 the fundamental block size. Neither Btrfs nor XFS support over‐
91 lapping deduplication ranges in the same file.
92
93 EISDIR One of the files is a directory and the filesystem does not sup‐
94 port shared regions in directories.
95
96 ENOMEM The kernel was unable to allocate sufficient memory to perform
97 the operation or dest_count is so large that the input argument
98 description spans more than a single page of memory.
99
100 EOPNOTSUPP
101 This can appear if the filesystem does not support deduplicating
102 either file descriptor, or if either file descriptor refers to
103 special inodes.
104
105 EPERM dest_fd is immutable.
106
107 ETXTBSY
108 One of the files is a swap file. Swap files cannot share stor‐
109 age.
110
111 EXDEV dest_fd and src_fd are not on the same mounted filesystem.
112
114 This ioctl operation first appeared in Linux 4.5. It was previously
115 known as BTRFS_IOC_FILE_EXTENT_SAME and was private to Btrfs.
116
118 This API is Linux-specific.
119
121 Because a copy-on-write operation requires the allocation of new stor‐
122 age, the fallocate(2) operation may unshare shared blocks to guarantee
123 that subsequent writes will not fail because of lack of disk space.
124
125 Some filesystems may limit the amount of data that can be deduplicated
126 in a single call.
127
129 ioctl(2)
130
132 This page is part of release 5.13 of the Linux man-pages project. A
133 description of the project, information about reporting bugs, and the
134 latest version of this page, can be found at
135 https://www.kernel.org/doc/man-pages/.
136
137
138
139Linux 2021-03-22 IOCTL_FIDEDUPERANGE(2)