Skip to content

Ticket #5082: add file cloning support for FreeBSD, Solaris and macOS#5083

Open
tuffnatty wants to merge 3 commits intoMidnightCommander:masterfrom
tuffnatty:5082-freebsd-file-cloning
Open

Ticket #5082: add file cloning support for FreeBSD, Solaris and macOS#5083
tuffnatty wants to merge 3 commits intoMidnightCommander:masterfrom
tuffnatty:5082-freebsd-file-cloning

Conversation

@tuffnatty
Copy link
Copy Markdown
Contributor

@tuffnatty tuffnatty commented Mar 31, 2026

Proposed changes

Use copy_file_range(2) on FreeBSD for file cloning.

It should resolve #5082 and probably #4991. copy_file_range(2) also supports remote NFS operations, but it's out of scope for this change.

While we're at it, also add support for clonefile(2) on macOS and reflink(3C) on Oracle Solaris.

The patch also adds support for cloning in Append/Reget modes. This is working only in Linux and FreeBSD and only if the filesystem allows it (e.g. the start offsets must be block-aligned).

As file cloning is not always a desired thing, a new configuration option is introduced to disable it.

Checklist

👉 Our coding style can be found here: https://midnight-commander.org/coding-style/ 👈

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

I have not added any tests for the feature, as it would involve actions fairly complicated from the ops point of view (like, create a test ZFS filesystem), and the test infrastructure does not offer any support for superuser/VM operations. But it's working locally, copy/move within one ZFS pool became instant, and the existing tests pass.

@github-actions github-actions bot added this to the Future Releases milestone Mar 31, 2026
@github-actions github-actions bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Mar 31, 2026
@zyv
Copy link
Copy Markdown
Member

zyv commented Mar 31, 2026

Wow, is it possible to test it in some way? As you can see, we now have CI on FreeBSD. Maybe some way to check that copy_file_range indeed gets called?

@tuffnatty
Copy link
Copy Markdown
Contributor Author

I've added a very dumb test that seems to work on Linux as well as on FreeBSD.

@zyv
Copy link
Copy Markdown
Member

zyv commented Apr 1, 2026

I've added a very dumb test that seems to work on Linux as well as on FreeBSD.

To me that looks fantastic, but can't you check that ENOTSUP is returned on other platforms? We have also CI that runs on Solaris and macOS. This way, all possibilities will be covered. Thank you!

@zyv zyv changed the title Add file cloning support for FreeBSD (#5082) Ticket #5082: add file cloning support for FreeBSD Apr 1, 2026
@zyv zyv added area: vfs Virtual File System support and removed needs triage Needs triage by maintainers labels Apr 1, 2026
@zyv zyv modified the milestones: Future Releases, 4.9.0 Apr 1, 2026
@tuffnatty tuffnatty changed the title Ticket #5082: add file cloning support for FreeBSD Ticket #5082: add file cloning support for FreeBSD, Solaris and macOS Apr 5, 2026
@tuffnatty tuffnatty force-pushed the 5082-freebsd-file-cloning branch from 2a80fa9 to e05e311 Compare April 5, 2026 03:11
@tuffnatty
Copy link
Copy Markdown
Contributor Author

Hi. It took a bit of time... The new pull request adds macOS and Oracle Solaris support as well. On these platforms, the syscalls for file cloning respond for destination file creation, that is, they take in a path instead of a file descriptor, so the logic around the copy operation had to be adapted.
So the test tests if both kinds of mocked syscalls are called with proper arguments, and that on unsupported platforms, ENOTSUP is returned.
Also, the patch introduces a new user configuration option to enable or disable COW file cloning, as it is not always a desired kind of operation. This part of the pull request depends on #5087 to be merged first.

Copy link
Copy Markdown
Member

@zyv zyv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this really looks fantastic. I'm much impressed. I wonder what the others think. I have but just a few minor comments.

Comment thread lib/vfs/vfs.c Outdated
Comment thread lib/global.c Outdated
Comment thread lib/global.h Outdated
Comment thread tests/lib/vfs/vfs_clone_file.c Outdated
@zyv zyv requested a review from mc-worker April 5, 2026 06:18
@tuffnatty tuffnatty force-pushed the 5082-freebsd-file-cloning branch 2 times, most recently from 8b2f8c0 to e52f20c Compare April 5, 2026 16:35
@tuffnatty
Copy link
Copy Markdown
Contributor Author

I've added support for file cloning in append/reget modes. It's working on FreeBSD and Linux when the file offsets are block-aligned. I've also removed the extra #ifs by moving the corresponding checks to autoconf.

@tuffnatty
Copy link
Copy Markdown
Contributor Author

The linter fails because I have touched a file with pre-existing invalid formatting.

@zyv
Copy link
Copy Markdown
Member

zyv commented Apr 5, 2026

I've added support for file cloning in append/reget modes. It's working on FreeBSD and Linux when the file offsets are block-aligned. I've also removed the extra #ifs by moving the corresponding checks to autoconf.

This looks good to me! I'm just left wondering whether this is a good idea to enable it by default.

Are you planning to do anything else in this PR, or are you considering it ready for review now?

@tuffnatty
Copy link
Copy Markdown
Contributor Author

I had to find and click the Submit review button as my previous review comments were in pending state.

I don't think I have anything to add or remove at this moment.

@zyv zyv force-pushed the 5082-freebsd-file-cloning branch from 236ce43 to 51a41a2 Compare April 6, 2026 06:09
Copy link
Copy Markdown
Member

@zyv zyv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the formatting error by adding a few hanging commas (in the same commit). Inasmuch as I'm concerned, this looks ready for merge. Thank you for your high-quality contribution! 👍

@tuffnatty
Copy link
Copy Markdown
Contributor Author

Thanks @zyv!

Comment thread src/filemanager/boxes.c
Comment thread src/filemanager/file.c Outdated
Comment thread src/filemanager/file.c Outdated
Comment thread configure.ac Outdated
@tuffnatty tuffnatty force-pushed the 5082-freebsd-file-cloning branch from 51a41a2 to 37990a8 Compare April 19, 2026 18:30
@tuffnatty
Copy link
Copy Markdown
Contributor Author

tuffnatty commented Apr 19, 2026

I've updated the pull request with man page updates; unfortunately, the localized man pages were partially outdated, so I had to fix that, and now the PR depends on #5093, #5095, #5096, #5097, #5098, #5099. My Hungarian is definitely not at the level where I could fix the Hungarian man page as well, so I had to keep it as-is.

@tuffnatty tuffnatty force-pushed the 5082-freebsd-file-cloning branch from 37990a8 to 5675b1f Compare April 19, 2026 21:01
@zyv
Copy link
Copy Markdown
Member

zyv commented Apr 20, 2026

Could you please rebase and resolve the conflicts? Thank you!

…macOS and Solaris

Signed-off-by: Phil Krylov <phil@krylov.eu>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Signed-off-by: Phil Krylov <phil@krylov.eu>
…he Use COW file cloning option

Signed-off-by: Phil Krylov <phil@krylov.eu>
@tuffnatty tuffnatty force-pushed the 5082-freebsd-file-cloning branch from 5675b1f to 1f95e8c Compare April 20, 2026 11:23
@tuffnatty
Copy link
Copy Markdown
Contributor Author

I've rebased the PR against master and updated the description above to match the actual content.

@zyv zyv requested a review from mc-worker April 20, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: vfs Virtual File System support prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

File clone VFS operation support on FreeBSD File move on ZFS TrueNAS

3 participants