Add runtime detection for macFUSE 4.x/5.x rename protocol#453
Add runtime detection for macFUSE 4.x/5.x rename protocol#453zah wants to merge 1 commit intocberner:masterfrom
Conversation
macFUSE 5.x changed the FUSE_RENAME protocol format: - macFUSE 4.x sent extended 16-byte format unconditionally (bug) - macFUSE 5.x only sends extended format when capabilities are granted This patch adds: - FUSE_RENAME_SWAP and FUSE_RENAME_EXCL capability negotiation during FUSE_INIT - Runtime format detection using filename byte inspection heuristic - Zero-copy skip_bytes() and peek_byte() helpers for argument parsing Fixes rename operations that were broken after upgrading to macFUSE 5.x. See macfuse/macfuse#839 for context.
| // 1. The kernel may refuse to grant the capabilities | ||
| // 2. We need backward compatibility with macFUSE 4.x behavior | ||
| // | ||
| // Detection heuristic: |
There was a problem hiding this comment.
Filenames can definitely contain ASCII control sequences. Finder won't allow it, but the terminal and system calls will. The only actual restriction is that filenames cannot contain NUL or /.
| // - flags: u32 (4 bytes) | ||
| // - padding: u32 (4 bytes) | ||
| // | ||
| // The problem: |
There was a problem hiding this comment.
Do we need this detection mechanism? macFUSE 4.x always uses extended. macFUSE 5.x will always use extended since we request the capabilities. I guess there is a theoretical chance the kernel refuses the capabilities, but I don't know if that's possible in practice.
|
@zah I'm looking to support the There is now a Linux-only |
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