Include sys/statvfs.h for the definition of ST_LOCAL (Rust port regression)

See https://man.netbsd.org/statvfs.5.
According to https://github.com/NetBSD/src/blob/trunk/sys/sys/statvfs.h#L135,
NetBSD has "#define ST_LOCAL MNT_LOCAL".  So this commit likely makes no
difference on existing systems.

While at it
- comment include statements
- remove a code clone

See #11486

(cherry picked from commit d68f8bdd3b)
This commit is contained in:
Johannes Altmanninger
2025-05-16 07:12:56 +02:00
parent d5b46d6535
commit 7228cb15bf
2 changed files with 10 additions and 25 deletions

View File

@@ -1,14 +1,13 @@
#include <locale.h>
#include <paths.h>
#include <paths.h> // _PATH_BSHELL
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <stdlib.h> // MB_CUR_MAX
#include <sys/mount.h> // MNT_LOCAL
#include <sys/resource.h>
#include <unistd.h>
#define UNUSED(x) (void)(x)
#include <sys/statvfs.h> // ST_LOCAL
#include <unistd.h> // _CS_PATH, _PC_CASE_SENSITIVE
size_t C_MB_CUR_MAX() { return MB_CUR_MAX; }

View File

@@ -709,24 +709,10 @@ fn path_remoteness(path: &wstr) -> DirRemoteness {
}
#[cfg(not(target_os = "linux"))]
{
let st_local = ST_LOCAL();
if st_local != 0 {
// ST_LOCAL is a flag to statvfs, which is itself standardized.
// In practice the only system to use this path is NetBSD.
let mut buf: libc::statvfs = unsafe { std::mem::zeroed() };
if unsafe { libc::statvfs(narrow.as_ptr(), &mut buf) } < 0 {
return DirRemoteness::unknown;
}
// statvfs::f_flag is `unsigned long`, which is 4-bytes on most 32-bit targets.
#[cfg_attr(target_pointer_width = "64", allow(clippy::useless_conversion))]
return if u64::from(buf.f_flag) & st_local != 0 {
DirRemoteness::local
} else {
DirRemoteness::remote
};
}
let mnt_local = MNT_LOCAL();
if mnt_local != 0 {
// ST_LOCAL is a flag to statvfs, which is itself standardized.
// In practice the only system to define it is NetBSD.
let local_flag = ST_LOCAL() | MNT_LOCAL();
if local_flag != 0 {
let mut buf: libc::statvfs = unsafe { std::mem::zeroed() };
if unsafe { libc::statvfs(narrow.as_ptr(), &mut buf) } < 0 {
return DirRemoteness::unknown;
@@ -734,7 +720,7 @@ fn path_remoteness(path: &wstr) -> DirRemoteness {
// 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)]
return if u64::from(buf.f_flag) & mnt_local != 0 {
return if u64::from(buf.f_flag) & local_flag != 0 {
DirRemoteness::local
} else {
DirRemoteness::remote