]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/ioctl_fideduperange.2
ioctl_ficlonerange.2, ioctl_fideduperange.2: Clarify the behavior of the FIDEDUPERANG...
[thirdparty/man-pages.git] / man2 / ioctl_fideduperange.2
CommitLineData
8c93a5df 1.\" Copyright (c) 2016, Oracle. All rights reserved.
2998d8b8 2.\"
8c93a5df
DW
3.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4.\" This is free documentation; you can redistribute it and/or
2998d8b8 5.\" modify it under the terms of the GNU General Public License as
8c93a5df
DW
6.\" published by the Free Software Foundation; either version 2 of
7.\" the License, or (at your option) any later version.
2998d8b8 8.\"
8c93a5df
DW
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,
2998d8b8
DW
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.\"
8c93a5df
DW
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/>.
2998d8b8 22.\" %%%LICENSE_END
3df541c0 23.TH IOCTL-FIDEDUPERANGE 2 2016-07-17 "Linux" "Linux Programmer's Manual"
2998d8b8
DW
24.SH NAME
25ioctl_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.sp
32.BI "int ioctl(int " src_fd ", FIDEDUPERANGE, struct file_dedupe_range * " arg );
33.SH DESCRIPTION
34If a filesystem supports files sharing physical storage between multiple
35files, this
36.BR ioctl (2)
2db75216 37operation can be used to make some of the data in the
2998d8b8
DW
38.B src_fd
39file appear in the
40.B dest_fd
41file by sharing the underlying storage if the file data is identical
990a64f7 42("deduplication").
8592ec74 43Both files must reside within the same filesystem.
990a64f7
MK
44This reduces storage consumption by allowing the filesystem
45to store one shared copy of the data.
46If a file write should occur to a shared
2998d8b8 47region, the filesystem must ensure that the changes remain private to the file
990a64f7
MK
48being written.
49This behavior is commonly referred to as "copy on write".
2998d8b8
DW
50
51This ioctl performs the "compare and share if identical" operation on up to
52.IR src_length
53bytes from file descriptor
54.IR src_fd
55at offset
56.IR src_offset ".
57This information is conveyed in a structure of the following form:
58.in +4n
59.nf
60
61struct file_dedupe_range {
2db75216
MK
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];
2998d8b8
DW
68};
69.fi
70.in
71Deduplication is atomic with regards to concurrent writes, so no locks need to
72be taken to obtain a consistent deduplicated copy.
73
2ae96e8a 74The fields
2998d8b8
DW
75.IR reserved1 " and " reserved2
76must be zero.
77
78Destinations for the deduplication operation are conveyed in the array at the
990a64f7
MK
79end of the structure.
80The number of destinations is given in
2998d8b8
DW
81.IR dest_count ",
82and the destination information is conveyed in the following form:
83
84.in +4n
85.nf
86struct file_dedupe_range_info {
87 __s64 dest_fd;
88 __u64 dest_offset;
89 __u64 bytes_deduped;
90 __s32 status;
91 __u32 reserved;
92};
93
94.fi
95.in
96
97Each deduplication operation targets
98.IR length
99bytes in file descriptor
100.IR dest_fd
101at offset
2046b8ac 102.IR dest_offset ".
2998d8b8
DW
103The field
104.IR reserved
105must be zero.
2046b8ac
DW
106During the call,
107.IR src_fd
108must be open for reading and
109.IR dest_fd
110must be open for writing.
111For any call to this ioctl, there may not be more than 65,536
112requests attached; each request may not exceed 16MiB.
113By convention, the storage used by
114.IR src_fd
115is mapped into
116.IR dest_fd
117and the previous contents in
118.IR dest_fd
119are freed.
2998d8b8
DW
120
121Upon successful completion of this ioctl, the number of bytes successfully
122deduplicated is returned in
123.IR bytes_deduped
124and a status code for the deduplication operation is returned in
125.IR status ".
2046b8ac
DW
126If even a single byte in the range does not match, the deduplication
127request will be ignored and
128.IR status
129set to
130.BR FILE_DEDUPE_RANGE_DIFFERS .
2998d8b8
DW
131The
132.IR status
133code is set to
2046b8ac 134.B FILE_DEDUPE_RANGE_SAME
2998d8b8
DW
135for success, a negative error code in case of error, or
136.B FILE_DEDUPE_RANGE_DIFFERS
137if the data did not match.
138
139.SH RETURN VALUE
140On error, \-1 is returned, and
141.I errno
142is set to indicate the error.
143.PP
144.SH ERRORS
145Error codes can be one of, but are not limited to, the following:
146.TP
a9985427
MK
147.B EBADF
148.IR src_fd
149is not open for reading;
150.IR dest_fd
151is not open for writing or is open for append-only writes; or the filesystem
152which
153.IR src_fd
154resides on does not support deduplication.
2998d8b8
DW
155.TP
156.B EINVAL
157The filesystem does not support deduplicating the ranges of the given files.
2db75216
MK
158This error can also appear if either file descriptor represents
159a device, FIFO, or socket.
990a64f7
MK
160Disk filesystems generally require the offset and length arguments
161to be aligned to the fundamental block size.
2db75216 162Neither Btrfs nor XFS support
2998d8b8
DW
163overlapping deduplication ranges in the same file.
164.TP
a9985427
MK
165.B EISDIR
166One of the files is a directory and the filesystem does not support shared
167regions in directories.
168.TP
169.B EOPNOTSUPP
170This can appear if the filesystem does not support deduplicating either file
2046b8ac 171descriptor, or if either file descriptor refers to special inodes.
2998d8b8
DW
172.TP
173.B EPERM
174.IR dest_fd
175is immutable.
176.TP
177.B ETXTBSY
990a64f7
MK
178One of the files is a swap file.
179Swap files cannot share storage.
2998d8b8 180.TP
a9985427
MK
181.B EXDEV
182.IR dest_fd " and " src_fd
183are not on the same mounted filesystem.
5711c5f7
MK
184.SH VERSIONS
185This ioctl operation first appeared in Linux 4.5.
186It was previously known as
2db75216
MK
187.B BTRFS_IOC_FILE_EXTENT_SAME
188and was private to Btrfs.
5711c5f7
MK
189.SH CONFORMING TO
190This API is Linux-specific.
2998d8b8 191.SH NOTES
2db75216
MK
192Because a copy-on-write operation requires the allocation of new storage, the
193.BR fallocate (2)
194operation may unshare shared blocks to guarantee that subsequent writes will
2998d8b8
DW
195not fail because of lack of disk space.
196
197Some filesystems may limit the amount of data that can be deduplicated in a
198single call.
2998d8b8
DW
199.SH SEE ALSO
200.BR ioctl (2)