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_SAME for success πŸŽ‰
  • a negative error code in case of error πŸ’€
  • FILE_DEDUPE_RANGE_DIFFERS if 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_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.
  • 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 or dest_count is 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_fd is immutable. it said no and it meant it.
  • ETXTBSY β€” One of the files is a swap file. Swap files cannot share storage.
  • EXDEV β€” dest_fd and src_fd are 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms