From 5587face61efb494c0603727f060d71d78066cbc Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 5 Sep 2021 13:06:25 +0100 Subject: [PATCH] fsext build fix for OpenBSD. prioritising statfs over statvfs for this platform. --- src/uucore/src/lib/features/fsext.rs | 75 +++++++++++++++++++++------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 72471ff9e..7525d9e41 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -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 for MountInfo { fn from(statfs: StatFs) -> Self { let mut info = MountInfo { @@ -346,9 +354,19 @@ impl From 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 { @@ -394,7 +419,12 @@ pub fn read_fs_list() -> Vec { }) .collect::>() } - #[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