-
Notifications
You must be signed in to change notification settings - Fork 181
Add runtime detection for macFUSE 4.x/5.x rename protocol #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zah
wants to merge
1
commit into
cberner:master
Choose a base branch
from
blocksense-network:agent-harbor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,9 @@ | |
| //! A request represents information about a filesystem operation the kernel driver wants us to | ||
| //! perform. | ||
|
|
||
| use super::fuse_abi::{InvalidOpcodeError, fuse_in_header, fuse_opcode}; | ||
| use super::fuse_abi::{fuse_in_header, fuse_opcode, InvalidOpcodeError}; | ||
|
|
||
| use super::{Errno, Response, fuse_abi as abi}; | ||
| use super::{fuse_abi as abi, Errno, Response}; | ||
| #[cfg(feature = "serializable")] | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::{convert::TryFrom, fmt::Display, path::Path}; | ||
|
|
@@ -260,11 +260,11 @@ mod op { | |
| use crate::ll::Response; | ||
|
|
||
| use super::{ | ||
| super::{TimeOrNow, argument::ArgumentIterator}, | ||
| super::{argument::ArgumentIterator, TimeOrNow}, | ||
| FilenameInDir, Request, | ||
| }; | ||
| use super::{ | ||
| FileHandle, INodeNo, Lock, LockOwner, Operation, RequestId, abi::consts::*, abi::*, | ||
| abi::consts::*, abi::*, FileHandle, INodeNo, Lock, LockOwner, Operation, RequestId, | ||
| }; | ||
| use std::{ | ||
| convert::TryInto, | ||
|
|
@@ -587,6 +587,9 @@ mod op { | |
| arg: &'a fuse_rename_in, | ||
| name: &'a Path, | ||
| newname: &'a Path, | ||
| /// Rename flags (macOS only, from extended format). | ||
| /// On other platforms or when macFUSE sends short format, this is 0. | ||
| flags: u32, | ||
| } | ||
| impl_request!(Rename<'_>); | ||
| impl<'a> Rename<'a> { | ||
|
|
@@ -602,6 +605,14 @@ mod op { | |
| name: self.newname, | ||
| } | ||
| } | ||
| /// Rename flags (macOS only: RENAME_SWAP, RENAME_EXCL). | ||
| /// | ||
| /// On macOS, if FUSE_RENAME_SWAP or FUSE_RENAME_EXCL capabilities were granted | ||
| /// during init, the kernel sends extended rename requests with flags. | ||
| /// On other platforms or when macFUSE sends the short format, this returns 0. | ||
| pub(crate) fn flags(&self) -> u32 { | ||
| self.flags | ||
| } | ||
| } | ||
|
|
||
| /// Create a hard link. | ||
|
|
@@ -1651,12 +1662,74 @@ mod op { | |
| header, | ||
| name: data.fetch_str()?.as_ref(), | ||
| }), | ||
| fuse_opcode::FUSE_RENAME => Operation::Rename(Rename { | ||
| header, | ||
| arg: data.fetch()?, | ||
| name: data.fetch_str()?.as_ref(), | ||
| newname: data.fetch_str()?.as_ref(), | ||
| }), | ||
| fuse_opcode::FUSE_RENAME => { | ||
| let arg: &fuse_rename_in = data.fetch()?; | ||
|
|
||
| // macOS macFUSE protocol version detection for FUSE_RENAME | ||
| // ========================================================= | ||
| // | ||
| // Background: | ||
| // macFUSE supports extended rename operations (RENAME_SWAP, RENAME_EXCL) | ||
| // via flags in the rename request. When these capabilities are negotiated | ||
| // during FUSE_INIT, macFUSE sends an extended 16-byte fuse_rename_in: | ||
| // - newdir: u64 (8 bytes) | ||
| // - flags: u32 (4 bytes) | ||
| // - padding: u32 (4 bytes) | ||
| // | ||
| // The problem: | ||
| // - macFUSE 4.x had a bug where it sent the extended format unconditionally, | ||
| // regardless of whether capabilities were actually granted. | ||
| // - macFUSE 5.x fixed this: it only sends extended format when capabilities | ||
| // ARE granted; otherwise it sends the short 8-byte format. | ||
| // | ||
| // Our solution: | ||
| // We request FUSE_RENAME_SWAP/FUSE_RENAME_EXCL at INIT (see lib.rs), which | ||
| // should cause macFUSE 5.x to grant them and send extended format. However, | ||
| // we use runtime detection as a safety measure because: | ||
| // 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
| // Filenames cannot start with null bytes or ASCII control characters (< 32). | ||
| // If the first byte after newdir is in the control range, we have extended | ||
| // format (flags field starts there). If it's >= 32, it's the start of a | ||
| // filename, indicating short format. | ||
| // | ||
| // References: | ||
| // - Issue: https://github.com/osxfuse/osxfuse/issues/839 | ||
| // - macFUSE kernel header: https://github.com/osxfuse/fuse/blob/master/include/fuse_kernel.h | ||
| #[cfg(target_os = "macos")] | ||
| let flags = { | ||
| let first_byte = data.peek_byte(0); | ||
| if first_byte.is_some_and(|b| b < 32) { | ||
| // Extended format detected: extract flags as little-endian u32 | ||
| let flags_bytes = [ | ||
| data.peek_byte(0).unwrap_or(0), | ||
| data.peek_byte(1).unwrap_or(0), | ||
| data.peek_byte(2).unwrap_or(0), | ||
| data.peek_byte(3).unwrap_or(0), | ||
| ]; | ||
| let flags = u32::from_le_bytes(flags_bytes); | ||
| // Skip flags (4 bytes) + padding (4 bytes) = 8 bytes total | ||
| data.skip_bytes(8); | ||
| flags | ||
| } else { | ||
| // Short format: filename starts immediately, no flags available | ||
| 0 | ||
| } | ||
| }; | ||
|
|
||
| #[cfg(not(target_os = "macos"))] | ||
| let flags = 0u32; | ||
|
|
||
| Operation::Rename(Rename { | ||
| header, | ||
| arg, | ||
| name: data.fetch_str()?.as_ref(), | ||
| newname: data.fetch_str()?.as_ref(), | ||
| flags, | ||
| }) | ||
| } | ||
| fuse_opcode::FUSE_LINK => Operation::Link(Link { | ||
| header, | ||
| arg: data.fetch()?, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.