FIDEDUPERANGE(2const)
π FIDEDUPERANGE π (that's the 2const man page bestie, we're in the Linux section)
okay so like. imagine two files. they have the SAME data in them. why are they both hogging disk space?? π that's the whole drama this page is about.
β¨ NAME β¨
FIDEDUPERANGE β share some the data of one file with another file π«
π LIBRARY π
Standard C library (libc, -lc) π«Ά
π SYNOPSIS π
#include <linux/fs.h> /* Definition of FIDEDUPERANGE and
FILE_DEDUPE_* constants*/
#include <sys/ioctl.h>
int ioctl(int src_fd, FIDEDUPERANGE, struct file_dedupe_range *arg);
πΈ DESCRIPTION πΈ
so if your filesystem supports files sharing physical storage between multiple files (iykyk), this ioctl(2) operation lets you make some of the data in the src_fd file appear in the dest_fd file β by literally sharing the underlying storage, as long as the file data is identical. that's what "deduplication" means, bestie. β¨
Both files must reside within the same filesystem. no long-distance situationships here. this reduces storage consumption by letting the filesystem store one shared copy of the data. and if a file write should happen to a shared region, the filesystem must make sure the changes stay private to the file being written. this behavior is commonly called "copy on write". the way that it protects your data?? iconic. π
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. and that info travels in a struct that looks like this:
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 like. no locks need to be taken to obtain a consistent deduplicated copy. we love a low-maintenance king π
The fields reserved1 and reserved2 must be zero. no negotiating.
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 info is conveyed in this form:
struct file_dedupe_range_info {
__s64 dest_fd;
__u64 dest_offset;
__u64 bytes_deduped;
__s32 status;
__u32 reserved;
};
Each deduplication operation targets src_length bytes in file descriptor dest_fd at offset dest_offset. The field reserved must be zero. During the call, src_fd must be open for reading and dest_fd must be open for writing. πβοΈ
The combined size of the struct file_dedupe_range and the struct file_dedupe_range_info array must not exceed the system page size. and the maximum size of src_length is filesystem dependent and is typically 16 MiB β and heads up, this limit will be enforced silently by the filesystem. π sneaky. By convention, the storage used by src_fd is mapped into dest_fd and the previous contents in dest_fd are freed.
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.
and here's the tea: if even a single byte in the range does not match, the whole deduplication operation request will be ignored and status gets set to FILE_DEDUPE_RANGE_DIFFERS. all-or-nothing, periodt.
So status ends up as:
FILE_DEDUPE_RANGE_SAMEfor success π- a negative error code in case of error π
FILE_DEDUPE_RANGE_DIFFERSif the data did not match
π RETURN VALUE π
On error, -1 is returned, and errno is set to indicate the error. classic.
π₯ ERRORS π₯
Possible errors include (but are not limited to) the following:
EBADFβsrc_fdis not open for reading;dest_fdis not open for writing or is open for append-only writes; or the filesystem whichsrc_fdresides on does not support deduplication.EINVALβ 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. π βοΈEISDIRβ One of the files is a directory and the filesystem does not support shared regions in directories.ENOMEMβ The kernel was unable to allocate sufficient memory to perform the operation ordest_countis so large that the input argument description spans more than a single page of memory. bestie that's a lot of destinations.EOPNOTSUPPβ This can appear if the filesystem does not support deduplicating either file descriptor, or if either file descriptor refers to special inodes.EPERMβdest_fdis immutable. it said no and it meant it.ETXTBSYβ One of the files is a swap file. Swap files cannot share storage.EXDEVβdest_fdandsrc_fdare not on the same mounted filesystem. long distance relationship denied π
π VERSIONS π
Some filesystems may limit the amount of data that can be deduplicated in a single call.
β STANDARDS β
Linux. π§
π¦ HISTORY π¦
Linux 4.5.
It was previously known as BTRFS_IOC_FILE_EXTENT_SAME and was private to Btrfs. glow-up arc fr fr π
β¨
π NOTES π
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. plan ahead bestie, disk space is not infinite π₯²
π SEE ALSO π
and that's the whole page, no cap! this gem came from Linux man-pages 6.20, dated 2026-02-08 β go forth and dedupe responsibly, you absolute main character π«ΆππΈ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-2.0-or-later
- Copyright 2016, Oracle
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms