NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |VERSIONS |STANDARDS |HISTORY |NOTES |SEE ALSO |COLOPHON | |
FIDEDUPERANGE(2const)FIDEDUPERANGE(2const)FIDEDUPERANGE - share some the data of one file with another file
Standard C library (libc,-lc)
#include <linux/fs.h>/* Definition ofFIDEDUPERANGEandFILE_DEDUPE_*constants*/#include <sys/ioctl.h>int ioctl(intsrc_fd, FIDEDUPERANGE, struct file_dedupe_range *arg);
If a filesystem supports files sharing physical storage between multiple files, thisioctl(2) operation can be used to make some of the data in thesrc_fdfile appear in thedest_fdfile 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 tosrc_length bytes from file descriptorsrc_fd at offsetsrc_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 fieldsreserved1 andreserved2 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 indest_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 targetssrc_length bytes in file descriptordest_fd at offsetdest_offset. The fieldreserved must be zero. During the call,src_fd must be open for reading anddest_fd must be open for writing. The combined size of the structfile_dedupe_range and the structfile_dedupe_range_info array must not exceed the system page size. The maximum size ofsrc_length is filesystem dependent and is typically 16 MiB. This limit will be enforced silently by the filesystem. By convention, the storage used bysrc_fd is mapped intodest_fd and the previous contents indest_fd are freed. Upon successful completion of this ioctl, the number of bytes successfully deduplicated is returned inbytes_deduped and a status code for the deduplication operation is returned instatus. If even a single byte in the range does not match, the deduplication operation request will be ignored andstatus set toFILE_DEDUPE_RANGE_DIFFERS. Thestatus code is set toFILE_DEDUPE_RANGE_SAMEfor success, a negative error code in case of error, orFILE_DEDUPE_RANGE_DIFFERSif the data did not match.On error, -1 is returned, anderrno is set to indicate the error.
Possible errors include (but are not limited to) the following:EBADFsrc_fd is not open for reading;dest_fd is not open for writing or is open for append-only writes; or the filesystem whichsrc_fd resides on does not support deduplication.EINVALThe 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.EISDIROne of the files is a directory and the filesystem does not support shared regions in directories.ENOMEMThe kernel was unable to allocate sufficient memory to perform the operation ordest_count is so large that the input argument description spans more than a single page of memory.EOPNOTSUPP This can appear if the filesystem does not support deduplicating either file descriptor, or if either file descriptor refers to special inodes.EPERMdest_fd is immutable.ETXTBSY One of the files is a swap file. Swap files cannot share storage.EXDEVdest_fd andsrc_fd are not on the same mounted filesystem.
Some filesystems may limit the amount of data that can be deduplicated in a single call.
Linux.
Linux 4.5. It was previously known asBTRFS_IOC_FILE_EXTENT_SAMEand was private to Btrfs.
Because a copy-on-write operation requires the allocation of new storage, thefallocate(2) operation may unshare shared blocks to guarantee that subsequent writes will not fail because of lack of disk space.
ioctl(2)
This page is part of theman-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.15.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgLinux man-pages 6.15 2025-05-17FIDEDUPERANGE(2const)Pages that refer to this page:ioctl_fs(2)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |