ioctl_fideduperange — share some the data of one file with another file
#include <sys/ioctl.h> #include <linux/fs.h>
int
ioctl( |
int src_fd, |
FIDEDUPERANGE, | |
struct file_dedupe_range * arg) ; |
If a filesystem supports files sharing physical storage
between multiple files, this ioctl(2) operation can be
used to make some of the data in the src_fd
file appear in the
dest_fd
file by
sharing the underlying storage if the file data is identical
("deduplication"). Both files must reside within the same
filesystem. This reduces storage consumption by allowing the
filesystem to store one shared copy of the data. If a file
write should occur to a shared region, the filesystem must
ensure that the changes remain private to the file being
written. This behavior is commonly referred to as "copy on
write".
This ioctl performs the "compare and share if identical"
operation on up to src_length
bytes from file
descriptor src_fd
at
offset src_offset
.
This information is conveyed in a structure of the following
form:
struct file_dedupe_range { __u64 src_offset
;__u64 src_length
;__u16 dest_count
;__u16 reserved1
;__u32 reserved2
;struct file_dedupe_range_info info
[0];};
Deduplication is atomic with regards to concurrent writes, so no locks need to be taken to obtain a consistent deduplicated copy.
The fields reserved1
and reserved2
must be zero.
Destinations for the deduplication operation are conveyed
in the array at the end of the structure. The number of
destinations is given in dest_count
, and the destination
information is conveyed in the following form:
struct file_dedupe_range_info { __s64 dest_fd
;__u64 dest_offset
;__u64 bytes_deduped
;__s32 status
;__u32 reserved
;};
Each deduplication operation targets length
bytes in file
descriptor dest_fd
at
offset logical_offset
. The field
reserved
must be
zero.
Upon successful completion of this ioctl, the number of
bytes successfully deduplicated is returned in bytes_deduped
and a status code
for the deduplication operation is returned in status
.
The status
code is
set to 0
for success, a
negative error code in case of error, or FILE_DEDUPE_RANGE_DIFFERS
if the data did
not match.
Error codes can be one of, but are not limited to, the following:
dest_fd
and
src_fd
are not
on the same mounted filesystem.
One of the files is a directory and the filesystem does not support shared regions in directories.
The filesystem does not support deduplicating the ranges of the given files. This error can also appear if either file descriptor represents a device, FIFO, or socket. Disk filesystems generally require the offset and length arguments to be aligned to the fundamental block size. Neither Btrfs nor XFS support overlapping deduplication ranges in the same file.
src_fd
is
not open for reading; dest_fd
is not open for
writing or is open for append-only writes; or the
filesystem which src_fd
resides on does
not support deduplication.
dest_fd
is
immutable.
One of the files is a swap file. Swap files cannot share storage.
This can appear if the filesystem does not support deduplicating either file descriptor.
This ioctl operation first appeared in Linux 4.5. It was
previously known as BTRFS_IOC_FILE_EXTENT_SAME
and was private
to Btrfs.
Because a copy-on-write operation requires the allocation of new storage, the fallocate(2) operation may unshare shared blocks to guarantee that subsequent writes will not fail because of lack of disk space.
Some filesystems may limit the amount of data that can be deduplicated in a single call.
This page is part of release 4.07 of the Linux man-pages
project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
https://www.kernel.org/doc/man−pages/.
Copyright (c) 2016, Oracle. All rights reserved. %%%LICENSE_START(GPLv2+_DOC_FULL) This is free documentation; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU General Public License's references to "object code" and "executables" are to be interpreted as the output of any document formatting or typesetting system, including intermediate and printed output. This manual is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this manual; if not, see <http://www.gnu.org/licenses/>. %%%LICENSE_END |