Skip to content

Conversation

romanstingler
Copy link

@romanstingler romanstingler commented Aug 2, 2025

This adds copy-on-write file cloning to improve storage efficiency on supported filesystems.

New reflink.rs module with Linux FICLONE ioctl support.
Updated copy operation to try reflink first, fall back to standard copy.
Works transparently on Btrfs, XFS, Bcachefs - falls back on others, or non-linux OS.

I think checking filesystem type is unreliable because:

Btrfs supports reflink but only on same filesystem
XFS supports reflink but has version requirements
ZFS supports reflink but via different mechanism
ext4 doesn't support reflink at all

In my opinion the cleanest approach is what we're doing:
Attempt the ioctl directly
Let the kernel tell us if it works or not
Clean up and fallback on failure

This is actually the standard approach used by tools like cp --reflink=auto - they don't pre-check, they just attempt and handle the failure gracefully.

/srv/opensource/cosmic/cosmic-files/target/release/tmp master
❯ btrfs filesystem du .
     Total   Exclusive  Set shared  Filename
  73.80MiB       0.00B           -  ./cosmic-files
  73.80MiB       0.00B    61.33MiB  .

tested on BTRFS and EXT4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant