Add runtime detection for macFUSE 4.x/5.x rename protocol #453
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This patch adds support for macFUSE's extended rename format and the RENAME_SWAP/RENAME_EXCL capabilities, enabling atomic rename operations on macOS.
Problem
macFUSE supports extended rename operations (
renamex_npsyscall withRENAME_SWAPandRENAME_EXCLflags) through an extendedfuse_rename_instructure. However, there's an ABI incompatibility between macFUSE versions:macFUSE 4.x: Had a bug where it sent the extended 16-byte format unconditionally, regardless of whether RENAME_SWAP/RENAME_EXCL capabilities were negotiated during FUSE_INIT.
macFUSE 5.x: Fixed this behavior - only sends the extended format when capabilities ARE granted; otherwise sends the standard 8-byte format.
This caused fuser to break on macFUSE 5.x when parsing rename requests, as the library wasn't handling both format variations.
References
Solution
This patch implements a two-pronged approach:
1. Capability Negotiation (lib.rs)
Request
FUSE_RENAME_SWAPandFUSE_RENAME_EXCLcapabilities during FUSE_INIT:This tells macFUSE 5.x that we want extended rename support, so it will grant the capabilities and send the extended format.
2. Runtime Format Detection (request.rs)
Parse FUSE_RENAME requests with runtime detection of the format:
The detection heuristic is based on the observation that filenames cannot start with null bytes or ASCII control characters (< 32). By inspecting the first byte after
newdir:< 32: Extended format (flags field contains a small number or zero)>= 32: Short format (filename starts with a printable character)This handles:
Files Changed
src/lib.rsFUSE_RENAME_SWAPandFUSE_RENAME_EXCLto macOSINIT_FLAGSsrc/ll/fuse_abi.rsFUSE_RENAME_SWAP(bit 25) andFUSE_RENAME_EXCL(bit 26) capability constants for macOSfuse_rename_indocumentation to explain the variable formatsrc/ll/request.rsflagsfield to theRenamestructsrc/ll/argument.rsskip_bytes()method toArgumentIteratorfor skipping optional fieldspeek_byte()method for non-consuming byte inspectionsrc/request.rsx.flags()toFilesystem::rename()instead of hardcoded0