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.
This commit is contained in:
Peter Ammon
2025-10-13 14:00:57 -07:00
parent 0ded3ed6f9
commit c8262929e1

View File

@@ -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 {