1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-17 04:06:18 +00:00

fsext build fix for OpenBSD.

prioritising statfs over statvfs for this platform.
This commit is contained in:
David Carlier 2021-09-05 13:06:25 +01:00
parent 6226a03214
commit 5587face61

View file

@ -88,13 +88,12 @@ use std::time::UNIX_EPOCH;
target_os = "linux",
target_vendor = "apple",
target_os = "android",
target_os = "freebsd"
target_os = "freebsd",
target_os = "openbsd"
))]
pub use libc::statfs as StatFs;
#[cfg(any(
target_os = "openbsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "bitrig",
target_os = "dragonfly",
target_os = "redox"
@ -105,13 +104,12 @@ pub use libc::statvfs as StatFs;
target_os = "linux",
target_vendor = "apple",
target_os = "android",
target_os = "freebsd"
target_os = "freebsd",
target_os = "openbsd",
))]
pub use libc::statfs as statfs_fn;
#[cfg(any(
target_os = "openbsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "bitrig",
target_os = "dragonfly",
target_os = "redox"
@ -311,9 +309,19 @@ impl MountInfo {
}
}
#[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(
target_vendor = "apple",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
use std::ffi::CStr;
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_vendor = "apple",
target_os = "netbsd",
target_os = "openbsd"
))]
impl From<StatFs> for MountInfo {
fn from(statfs: StatFs) -> Self {
let mut info = MountInfo {
@ -346,9 +354,19 @@ impl From<StatFs> for MountInfo {
}
}
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_vendor = "apple",
target_os = "netbsd",
target_os = "openbsd"
))]
use libc::c_int;
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_vendor = "apple",
target_os = "netbsd",
target_os = "openbsd"
))]
extern "C" {
#[cfg(all(target_vendor = "apple", target_arch = "x86_64"))]
#[link_name = "getmntinfo$INODE64"] // spell-checker:disable-line
@ -357,6 +375,7 @@ extern "C" {
#[cfg(any(
all(target_os = "freebsd"),
all(target_os = "netbsd"),
all(target_os = "openbsd"),
all(target_vendor = "apple", target_arch = "aarch64")
))]
#[link_name = "getmntinfo"] // spell-checker:disable-line
@ -371,10 +390,16 @@ use std::io::{BufRead, BufReader};
target_vendor = "apple",
target_os = "freebsd",
target_os = "windows",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd"
))]
use std::ptr;
#[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(
target_vendor = "apple",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
use std::slice;
/// Read file system list.
pub fn read_fs_list() -> Vec<MountInfo> {
@ -394,7 +419,12 @@ pub fn read_fs_list() -> Vec<MountInfo> {
})
.collect::<Vec<_>>()
}
#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))]
#[cfg(any(
target_os = "freebsd",
target_vendor = "apple",
target_os = "netbsd",
target_os = "openbsd"
))]
{
let mut mount_buffer_ptr: *mut StatFs = ptr::null_mut();
let len = unsafe { get_mount_info(&mut mount_buffer_ptr, 1_i32) };
@ -611,13 +641,23 @@ impl FsMeta for StatFs {
//
// Solaris, Irix and POSIX have a system call statvfs(2) that returns a
// struct statvfs, containing an unsigned long f_fsid
#[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "linux"))]
#[cfg(any(
target_vendor = "apple",
target_os = "freebsd",
target_os = "linux",
target_os = "openbsd"
))]
fn fsid(&self) -> u64 {
let f_fsid: &[u32; 2] =
unsafe { &*(&self.f_fsid as *const libc::fsid_t as *const [u32; 2]) };
(u64::from(f_fsid[0])) << 32 | u64::from(f_fsid[1])
}
#[cfg(not(any(target_vendor = "apple", target_os = "freebsd", target_os = "linux")))]
#[cfg(not(any(
target_vendor = "apple",
target_os = "freebsd",
target_os = "linux",
target_os = "openbsd"
)))]
fn fsid(&self) -> u64 {
self.f_fsid as u64
}
@ -630,7 +670,7 @@ impl FsMeta for StatFs {
fn namelen(&self) -> u64 {
1024
}
#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
#[cfg(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
fn namelen(&self) -> u64 {
self.f_namemax as u64 // spell-checker:disable-line
}
@ -639,7 +679,8 @@ impl FsMeta for StatFs {
target_vendor = "apple",
target_os = "freebsd",
target_os = "linux",
target_os = "netbsd"
target_os = "netbsd",
target_os = "openbsd"
)))]
fn namelen(&self) -> u64 {
self.f_namemax as u64 // spell-checker:disable-line