From 554d53c0edd1d3513eb615ea15e95aed389d155e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 23 Aug 2021 16:21:18 +0100 Subject: [PATCH] uucore netbsd update fsext build fix and utmpx implementation proposal. --- src/uucore/src/lib/features/fsext.rs | 38 ++++++++++++++++++++-------- src/uucore/src/lib/features/utmpx.rs | 26 ++++++++++++++++++- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/uucore/src/lib/features/fsext.rs b/src/uucore/src/lib/features/fsext.rs index 56e078c56..75375c7e2 100644 --- a/src/uucore/src/lib/features/fsext.rs +++ b/src/uucore/src/lib/features/fsext.rs @@ -309,9 +309,9 @@ impl MountInfo { } } -#[cfg(any(target_vendor = "apple", target_os = "freebsd"))] +#[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))] use std::ffi::CStr; -#[cfg(any(target_os = "freebsd", target_vendor = "apple"))] +#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))] impl From for MountInfo { fn from(statfs: StatFs) -> Self { let mut info = MountInfo { @@ -344,9 +344,9 @@ impl From for MountInfo { } } -#[cfg(any(target_os = "freebsd", target_vendor = "apple"))] +#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))] use libc::c_int; -#[cfg(any(target_os = "freebsd", target_vendor = "apple"))] +#[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))] extern "C" { #[cfg(all(target_vendor = "apple", target_arch = "x86_64"))] #[link_name = "getmntinfo$INODE64"] // spell-checker:disable-line @@ -354,6 +354,7 @@ extern "C" { #[cfg(any( all(target_os = "freebsd"), + all(target_os = "netbsd"), all(target_vendor = "apple", target_arch = "aarch64") ))] #[link_name = "getmntinfo"] // spell-checker:disable-line @@ -364,9 +365,14 @@ extern "C" { use std::fs::File; #[cfg(target_os = "linux")] use std::io::{BufRead, BufReader}; -#[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "windows"))] +#[cfg(any( + target_vendor = "apple", + target_os = "freebsd", + target_os = "windows", + target_os = "netbsd" +))] use std::ptr; -#[cfg(any(target_vendor = "apple", target_os = "freebsd"))] +#[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))] use std::slice; /// Read file system list. pub fn read_fs_list() -> Vec { @@ -386,7 +392,7 @@ pub fn read_fs_list() -> Vec { }) .collect::>() } - #[cfg(any(target_os = "freebsd", target_vendor = "apple"))] + #[cfg(any(target_os = "freebsd", target_vendor = "apple", target_os = "netbsd"))] { let mut mount_buffer_ptr: *mut StatFs = ptr::null_mut(); let len = unsafe { get_mount_info(&mut mount_buffer_ptr, 1_i32) }; @@ -582,12 +588,17 @@ impl FsMeta for StatFs { fn io_size(&self) -> u64 { self.f_frsize as u64 } - #[cfg(any(target_vendor = "apple", target_os = "freebsd"))] + #[cfg(any(target_vendor = "apple", target_os = "freebsd", target_os = "netbsd"))] fn io_size(&self) -> u64 { self.f_iosize as u64 } // XXX: dunno if this is right - #[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 = "netbsd" + )))] fn io_size(&self) -> u64 { self.f_bsize as u64 } @@ -617,12 +628,17 @@ impl FsMeta for StatFs { fn namelen(&self) -> u64 { 1024 } - #[cfg(target_os = "freebsd")] + #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] fn namelen(&self) -> u64 { self.f_namemax as u64 // spell-checker:disable-line } // XXX: should everything just use statvfs? - #[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 = "netbsd" + )))] fn namelen(&self) -> u64 { self.f_namemax as u64 // spell-checker:disable-line } diff --git a/src/uucore/src/lib/features/utmpx.rs b/src/uucore/src/lib/features/utmpx.rs index 5077d9e59..8f43ba769 100644 --- a/src/uucore/src/lib/features/utmpx.rs +++ b/src/uucore/src/lib/features/utmpx.rs @@ -47,7 +47,7 @@ use libc::utmpx; pub use libc::endutxent; pub use libc::getutxent; pub use libc::setutxent; -#[cfg(any(target_vendor = "apple", target_os = "linux"))] +#[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "netbsd"))] pub use libc::utmpxname; #[cfg(target_os = "freebsd")] pub unsafe extern "C" fn utmpxname(_file: *const libc::c_char) -> libc::c_int { @@ -130,6 +130,30 @@ mod ut { pub use libc::USER_PROCESS; } +#[cfg(target_os = "netbsd")] +mod ut { + pub static DEFAULT_FILE: &str = "/var/run/utmpx"; + + pub const ACCOUNTING: usize = 9; + pub const SHUTDOWN_TIME: usize = 11; + + pub use libc::_UTX_HOSTSIZE as UT_HOSTSIZE; + pub use libc::_UTX_IDSIZE as UT_IDSIZE; + pub use libc::_UTX_LINESIZE as UT_LINESIZE; + pub use libc::_UTX_USERSIZE as UT_NAMESIZE; + + pub use libc::ACCOUNTING; + pub use libc::DEAD_PROCESS; + pub use libc::EMPTY; + pub use libc::INIT_PROCESS; + pub use libc::LOGIN_PROCESS; + pub use libc::NEW_TIME; + pub use libc::OLD_TIME; + pub use libc::RUN_LVL; + pub use libc::SIGNATURE; + pub use libc::USER_PROCESS; +} + pub struct Utmpx { inner: utmpx, }