Add support in uucore for OpenBSD

- uucore/src/lib/features/fs.rs: add target_os = OpenBSD when needed
  - uucore/src/lib/features/fsext.rs: implement FsUsage::new for OpenBSD

  - fixes uutils/coreutils#5448

  - initial code by n1000 https://github.com/n1000/coreutils/tree/openbsd_compile_fixes

Signed-off-by: Laurent Cheylus <foxy@free.fr>
This commit is contained in:
Laurent Cheylus 2023-11-29 17:44:50 +01:00
parent 3cadeb734d
commit 420df3db3d
No known key found for this signature in database
2 changed files with 38 additions and 6 deletions

View file

@ -115,6 +115,7 @@ impl FileInformation {
not(target_os = "android"),
not(target_os = "freebsd"),
not(target_os = "netbsd"),
not(target_os = "openbsd"),
not(target_os = "illumos"),
not(target_os = "solaris"),
not(target_arch = "aarch64"),
@ -130,6 +131,7 @@ impl FileInformation {
target_os = "android",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "illumos",
target_os = "solaris",
target_arch = "aarch64",
@ -146,13 +148,14 @@ impl FileInformation {
#[cfg(unix)]
pub fn inode(&self) -> u64 {
#[cfg(all(
not(any(target_os = "freebsd", target_os = "netbsd")),
not(any(target_os = "freebsd", target_os = "netbsd", target_os = "openbsd")),
target_pointer_width = "64"
))]
return self.0.st_ino;
#[cfg(any(
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd",
not(target_pointer_width = "64")
))]
return self.0.st_ino.into();

View file

@ -497,7 +497,10 @@ impl FsUsage {
#[cfg(unix)]
pub fn new(statvfs: StatFs) -> Self {
{
#[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))]
#[cfg(all(
not(any(target_os = "freebsd", target_os = "openbsd")),
target_pointer_width = "64"
))]
return Self {
blocksize: statvfs.f_bsize as u64, // or `statvfs.f_frsize` ?
blocks: statvfs.f_blocks,
@ -507,7 +510,10 @@ impl FsUsage {
files: statvfs.f_files,
ffree: statvfs.f_ffree,
};
#[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))]
#[cfg(all(
not(any(target_os = "freebsd", target_os = "openbsd")),
not(target_pointer_width = "64")
))]
return Self {
blocksize: statvfs.f_bsize as u64, // or `statvfs.f_frsize` ?
blocks: statvfs.f_blocks.into(),
@ -530,6 +536,19 @@ impl FsUsage {
files: statvfs.f_files,
ffree: statvfs.f_ffree.try_into().unwrap(),
};
#[cfg(target_os = "openbsd")]
return Self {
blocksize: statvfs.f_bsize.into(),
blocks: statvfs.f_blocks,
bfree: statvfs.f_bfree,
bavail: statvfs.f_bavail.try_into().unwrap(),
bavail_top_bit_set: ((std::convert::TryInto::<u64>::try_into(statvfs.f_bavail)
.unwrap())
& (1u64.rotate_right(1)))
!= 0,
files: statvfs.f_files,
ffree: statvfs.f_ffree,
};
}
}
#[cfg(not(unix))]
@ -617,6 +636,7 @@ impl FsMeta for StatFs {
not(target_vendor = "apple"),
not(target_os = "android"),
not(target_os = "freebsd"),
not(target_os = "openbsd"),
not(target_os = "illumos"),
not(target_os = "solaris"),
not(target_arch = "s390x"),
@ -630,6 +650,7 @@ impl FsMeta for StatFs {
target_arch = "s390x",
target_vendor = "apple",
target_os = "android",
target_os = "openbsd",
not(target_pointer_width = "64")
)
))]
@ -655,11 +676,19 @@ impl FsMeta for StatFs {
return self.f_bfree.into();
}
fn avail_blocks(&self) -> u64 {
#[cfg(all(not(target_os = "freebsd"), target_pointer_width = "64"))]
#[cfg(all(
not(target_os = "freebsd"),
not(target_os = "openbsd"),
target_pointer_width = "64"
))]
return self.f_bavail;
#[cfg(all(not(target_os = "freebsd"), not(target_pointer_width = "64")))]
#[cfg(all(
not(target_os = "freebsd"),
not(target_os = "openbsd"),
not(target_pointer_width = "64")
))]
return self.f_bavail.into();
#[cfg(target_os = "freebsd")]
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
return self.f_bavail.try_into().unwrap();
}
fn total_file_nodes(&self) -> u64 {