From c8262929e15d697494cdb73252a3242548d66d80 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Mon, 13 Oct 2025 14:00:57 -0700 Subject: [PATCH] Restore statfs instead of statvfs behavior MNT_LOCAL is NOT a flag for statvfs on macOS or possibly other BSDs (except NetBSD which does not have statfs). Revert to statfs on other platforms. --- src/path.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/path.rs b/src/path.rs index 906ec8c67..d77d6541f 100644 --- a/src/path.rs +++ b/src/path.rs @@ -692,15 +692,15 @@ pub fn path_remoteness(path: &wstr) -> DirRemoteness { } } } - #[cfg(not(any(target_os = "linux", cygwin)))] + + // NetBSD doesn't have statfs, but MNT_LOCAL works for statvfs. + #[cfg(target_os = "netbsd")] { let mut buf = MaybeUninit::uninit(); if unsafe { libc::statvfs(narrow.as_ptr(), buf.as_mut_ptr()) } < 0 { return DirRemoteness::unknown; } let buf = unsafe { buf.assume_init() }; - // statfs::f_flag is hard-coded as 64-bits on 32/64-bit FreeBSD but it's a (4-byte) - // long on 32-bit NetBSD.. and always 4-bytes on macOS (even on 64-bit builds). #[allow(clippy::useless_conversion)] let flags = buf.f_flag as u64; #[allow(clippy::unnecessary_cast)] @@ -710,6 +710,24 @@ pub fn path_remoteness(path: &wstr) -> DirRemoteness { DirRemoteness::remote } } + + #[cfg(not(any(target_os = "linux", target_os = "netbsd", cygwin)))] + { + let mut buf = MaybeUninit::uninit(); + if unsafe { libc::statfs(narrow.as_ptr(), buf.as_mut_ptr()) } < 0 { + return DirRemoteness::unknown; + } + let buf = unsafe { buf.assume_init() }; + // statfs::f_flags types differ. + #[allow(clippy::useless_conversion)] + let flags = buf.f_flags as u64; + #[allow(clippy::unnecessary_cast)] + if flags & (libc::MNT_LOCAL as u64) != 0 { + DirRemoteness::local + } else { + DirRemoteness::remote + } + } } fn get_data_directory() -> &'static BaseDirectory {