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