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