]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/ioctl_fideduperange.2
proc.5: Add "sf" to VmFlags in /proc/[pid]/smaps
[thirdparty/man-pages.git] / man2 / ioctl_fideduperange.2
1 .\" Copyright (c) 2016, Oracle. All rights reserved.
2 .\"
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.
8 .\"
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.
13 .\"
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.
18 .\"
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/>.
22 .\" %%%LICENSE_END
23 .TH IOCTL_FIDEDUPERANGE 2 2019-10-10 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 ioctl_fideduperange \- share some the data of one file with another file
26 .SH SYNOPSIS
27 .br
28 .B #include <sys/ioctl.h>
29 .br
30 .B #include <linux/fs.h>
31 .PP
32 .BI "int ioctl(int " src_fd ", FIDEDUPERANGE, struct file_dedupe_range *" arg );
33 .SH DESCRIPTION
34 If a filesystem supports files sharing physical storage between multiple
35 files, this
36 .BR ioctl (2)
37 operation can be used to make some of the data in the
38 .B src_fd
39 file appear in the
40 .B dest_fd
41 file by sharing the underlying storage if the file data is identical
42 ("deduplication").
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
48 being written.
49 This behavior is commonly referred to as "copy on write".
50 .PP
51 This ioctl performs the "compare and share if identical" operation on up to
52 .IR src_length
53 bytes from file descriptor
54 .IR src_fd
55 at offset
56 .IR src_offset ".
57 This information is conveyed in a structure of the following form:
58 .PP
59 .in +4n
60 .EX
61 struct file_dedupe_range {
62 __u64 src_offset;
63 __u64 src_length;
64 __u16 dest_count;
65 __u16 reserved1;
66 __u32 reserved2;
67 struct file_dedupe_range_info info[0];
68 };
69 .EE
70 .in
71 .PP
72 Deduplication is atomic with regards to concurrent writes, so no locks need to
73 be taken to obtain a consistent deduplicated copy.
74 .PP
75 The fields
76 .IR reserved1 " and " reserved2
77 must be zero.
78 .PP
79 Destinations for the deduplication operation are conveyed in the array at the
80 end of the structure.
81 The number of destinations is given in
82 .IR dest_count ",
83 and the destination information is conveyed in the following form:
84 .PP
85 .in +4n
86 .EX
87 struct file_dedupe_range_info {
88 __s64 dest_fd;
89 __u64 dest_offset;
90 __u64 bytes_deduped;
91 __s32 status;
92 __u32 reserved;
93 };
94 .EE
95 .in
96 .PP
97 Each deduplication operation targets
98 .IR src_length
99 bytes in file descriptor
100 .IR dest_fd
101 at offset
102 .IR dest_offset ".
103 The field
104 .IR reserved
105 must be zero.
106 During the call,
107 .IR src_fd
108 must be open for reading and
109 .IR dest_fd
110 must be open for writing.
111 The combined size of the struct
112 .IR file_dedupe_range
113 and the struct
114 .IR file_dedupe_range_info
115 array must not exceed the system page size.
116 The maximum size of
117 .IR src_length
118 is filesystem dependent and is typically 16\ MiB.
119 This limit will be enforced silently by the filesystem.
120 By convention, the storage used by
121 .IR src_fd
122 is mapped into
123 .IR dest_fd
124 and the previous contents in
125 .IR dest_fd
126 are freed.
127 .PP
128 Upon successful completion of this ioctl, the number of bytes successfully
129 deduplicated is returned in
130 .IR bytes_deduped
131 and a status code for the deduplication operation is returned in
132 .IR status ".
133 If even a single byte in the range does not match, the deduplication
134 request will be ignored and
135 .IR status
136 set to
137 .BR FILE_DEDUPE_RANGE_DIFFERS .
138 The
139 .IR status
140 code is set to
141 .B FILE_DEDUPE_RANGE_SAME
142 for success, a negative error code in case of error, or
143 .B FILE_DEDUPE_RANGE_DIFFERS
144 if the data did not match.
145 .PP
146 .SH RETURN VALUE
147 On error, \-1 is returned, and
148 .I errno
149 is set to indicate the error.
150 .PP
151 .SH ERRORS
152 Error codes can be one of, but are not limited to, the following:
153 .TP
154 .B EBADF
155 .IR src_fd
156 is not open for reading;
157 .IR dest_fd
158 is not open for writing or is open for append-only writes; or the filesystem
159 which
160 .IR src_fd
161 resides on does not support deduplication.
162 .TP
163 .B EINVAL
164 The filesystem does not support deduplicating the ranges of the given files.
165 This error can also appear if either file descriptor represents
166 a device, FIFO, or socket.
167 Disk filesystems generally require the offset and length arguments
168 to be aligned to the fundamental block size.
169 Neither Btrfs nor XFS support
170 overlapping deduplication ranges in the same file.
171 .TP
172 .B EISDIR
173 One of the files is a directory and the filesystem does not support shared
174 regions in directories.
175 .TP
176 .B ENOMEM
177 The kernel was unable to allocate sufficient memory to perform the
178 operation or
179 .IR dest_count
180 is so large that the input argument description spans more than a single
181 page of memory.
182 .TP
183 .B EOPNOTSUPP
184 This can appear if the filesystem does not support deduplicating either file
185 descriptor, or if either file descriptor refers to special inodes.
186 .TP
187 .B EPERM
188 .IR dest_fd
189 is immutable.
190 .TP
191 .B ETXTBSY
192 One of the files is a swap file.
193 Swap files cannot share storage.
194 .TP
195 .B EXDEV
196 .IR dest_fd " and " src_fd
197 are not on the same mounted filesystem.
198 .SH VERSIONS
199 This ioctl operation first appeared in Linux 4.5.
200 It was previously known as
201 .B BTRFS_IOC_FILE_EXTENT_SAME
202 and was private to Btrfs.
203 .SH CONFORMING TO
204 This API is Linux-specific.
205 .SH NOTES
206 Because a copy-on-write operation requires the allocation of new storage, the
207 .BR fallocate (2)
208 operation may unshare shared blocks to guarantee that subsequent writes will
209 not fail because of lack of disk space.
210 .PP
211 Some filesystems may limit the amount of data that can be deduplicated in a
212 single call.
213 .SH SEE ALSO
214 .BR ioctl (2)