1 .\" Copyright (c) 2016, Oracle. All rights reserved.
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 .\" GNU General Public License for more details.
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
23 .TH IOCTL-FIDEDUPERANGE 2 2016-12-12 "Linux" "Linux Programmer's Manual"
25 ioctl_fideduperange \- share some the data of one file with another file
28 .B #include <sys/ioctl.h>
30 .B #include <linux/fs.h>
32 .BI "int ioctl(int " src_fd ", FIDEDUPERANGE, struct file_dedupe_range *" arg );
34 If a filesystem supports files sharing physical storage between multiple
37 operation can be used to make some of the data in the
41 file by sharing the underlying storage if the file data is identical
43 Both files must reside within the same filesystem.
44 This reduces storage consumption by allowing the filesystem
45 to store one shared copy of the data.
46 If a file write should occur to a shared
47 region, the filesystem must ensure that the changes remain private to the file
49 This behavior is commonly referred to as "copy on write".
51 This ioctl performs the "compare and share if identical" operation on up to
53 bytes from file descriptor
57 This information is conveyed in a structure of the following form:
61 struct file_dedupe_range {
67 struct file_dedupe_range_info info[0];
72 Deduplication is atomic with regards to concurrent writes, so no locks need to
73 be taken to obtain a consistent deduplicated copy.
76 .IR reserved1 " and " reserved2
79 Destinations for the deduplication operation are conveyed in the array at the
81 The number of destinations is given in
83 and the destination information is conveyed in the following form:
87 struct file_dedupe_range_info {
98 Each deduplication operation targets
100 bytes in file descriptor
109 must be open for reading and
111 must be open for writing.
112 The combined size of the struct
113 .IR file_dedupe_range
115 .IR file_dedupe_range_info
116 array must not exceed the system page size.
119 is filesystem dependent and is typically 16MiB.
120 This limit will be enforced silently by the filesystem.
121 By convention, the storage used by
125 and the previous contents in
129 Upon successful completion of this ioctl, the number of bytes successfully
130 deduplicated is returned in
132 and a status code for the deduplication operation is returned in
134 If even a single byte in the range does not match, the deduplication
135 request will be ignored and
138 .BR FILE_DEDUPE_RANGE_DIFFERS .
142 .B FILE_DEDUPE_RANGE_SAME
143 for success, a negative error code in case of error, or
144 .B FILE_DEDUPE_RANGE_DIFFERS
145 if the data did not match.
148 On error, \-1 is returned, and
150 is set to indicate the error.
153 Error codes can be one of, but are not limited to, the following:
156 The kernel was unable to allocate sufficient memory to perform the
159 is so large that the input argument description spans more than a single
164 is not open for reading;
166 is not open for writing or is open for append-only writes; or the filesystem
169 resides on does not support deduplication.
172 The filesystem does not support deduplicating the ranges of the given files.
173 This error can also appear if either file descriptor represents
174 a device, FIFO, or socket.
175 Disk filesystems generally require the offset and length arguments
176 to be aligned to the fundamental block size.
177 Neither Btrfs nor XFS support
178 overlapping deduplication ranges in the same file.
181 One of the files is a directory and the filesystem does not support shared
182 regions in directories.
185 This can appear if the filesystem does not support deduplicating either file
186 descriptor, or if either file descriptor refers to special inodes.
193 One of the files is a swap file.
194 Swap files cannot share storage.
197 .IR dest_fd " and " src_fd
198 are not on the same mounted filesystem.
200 This ioctl operation first appeared in Linux 4.5.
201 It was previously known as
202 .B BTRFS_IOC_FILE_EXTENT_SAME
203 and was private to Btrfs.
205 This API is Linux-specific.
207 Because a copy-on-write operation requires the allocation of new storage, the
209 operation may unshare shared blocks to guarantee that subsequent writes will
210 not fail because of lack of disk space.
212 Some filesystems may limit the amount of data that can be deduplicated in a