Skip to content

refactor: cfg for stat/statfs #2219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/sys/stat.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#[cfg(any(apple_targets, target_os = "openbsd"))]
pub use libc::c_uint;
#[cfg(any(
target_os = "netbsd",
target_os = "freebsd",
target_os = "dragonfly"
))]
#[cfg(any(target_os = "netbsd", freebsdlike))]
pub use libc::c_ulong;
pub use libc::stat as FileStat;
pub use libc::{dev_t, mode_t};
Expand Down Expand Up @@ -67,11 +63,7 @@ libc_bitflags! {

#[cfg(any(apple_targets, target_os = "openbsd"))]
pub type type_of_file_flag = c_uint;
#[cfg(any(
target_os = "netbsd",
target_os = "freebsd",
target_os = "dragonfly"
))]
#[cfg(any(freebsdlike, target_os = "netbsd"))]
pub type type_of_file_flag = c_ulong;

#[cfg(bsd)]
Expand Down
39 changes: 12 additions & 27 deletions src/sys/statfs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Get filesystem statistics, non-portably
//!
//! See [`statvfs`](crate::sys::statvfs) for a portable alternative.
#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(linux_android))]
use std::ffi::CStr;
use std::fmt::{self, Debug};
use std::mem;
Expand All @@ -12,8 +12,7 @@ use cfg_if::cfg_if;
#[cfg(all(
feature = "mount",
any(
target_os = "dragonfly",
target_os = "freebsd",
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand All @@ -32,7 +31,7 @@ pub type fsid_t = libc::__fsid_t;
pub type fsid_t = libc::fsid_t;

cfg_if! {
if #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))] {
if #[cfg(any(linux_android, target_os = "fuchsia"))] {
type type_of_statfs = libc::statfs64;
const LIBC_FSTATFS: unsafe extern fn
(fd: libc::c_int, buf: *mut type_of_statfs) -> libc::c_int
Expand Down Expand Up @@ -288,10 +287,7 @@ pub const XENFS_SUPER_MAGIC: FsType =
#[cfg(linux_android)]
#[allow(missing_docs)]
pub const NSFS_MAGIC: FsType = FsType(libc::NSFS_MAGIC as fs_type_t);
#[cfg(all(
any(target_os = "linux", target_os = "android"),
not(target_env = "musl")
))]
#[cfg(all(linux_android, not(target_env = "musl")))]
#[allow(missing_docs)]
pub const XFS_SUPER_MAGIC: FsType = FsType(libc::XFS_SUPER_MAGIC as fs_type_t);

Expand All @@ -307,7 +303,7 @@ impl Statfs {
}

/// Magic code defining system type
#[cfg(not(any(target_os = "linux", target_os = "android")))]
#[cfg(not(linux_android))]
pub fn filesystem_type_name(&self) -> &str {
let c_str = unsafe { CStr::from_ptr(self.0.f_fstypename.as_ptr()) };
c_str.to_str().unwrap()
Expand Down Expand Up @@ -434,8 +430,7 @@ impl Statfs {
#[cfg(all(
feature = "mount",
any(
target_os = "dragonfly",
target_os = "freebsd",
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand Down Expand Up @@ -500,11 +495,10 @@ impl Statfs {
/// Total data blocks in filesystem
#[cfg(any(
apple_targets,
target_os = "android",
linux_android,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "openbsd",
target_os = "linux",
))]
pub fn blocks(&self) -> u64 {
self.0.f_blocks
Expand All @@ -525,11 +519,10 @@ impl Statfs {
/// Free blocks in filesystem
#[cfg(any(
apple_targets,
target_os = "android",
linux_android,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "openbsd",
target_os = "linux",
))]
pub fn blocks_free(&self) -> u64 {
self.0.f_bfree
Expand All @@ -548,12 +541,7 @@ impl Statfs {
}

/// Free blocks available to unprivileged user
#[cfg(any(
apple_targets,
target_os = "android",
target_os = "fuchsia",
target_os = "linux",
))]
#[cfg(any(apple_targets, linux_android, target_os = "fuchsia"))]
pub fn blocks_available(&self) -> u64 {
self.0.f_bavail
}
Expand All @@ -579,11 +567,10 @@ impl Statfs {
/// Total file nodes in filesystem
#[cfg(any(
apple_targets,
target_os = "android",
linux_android,
target_os = "freebsd",
target_os = "fuchsia",
target_os = "openbsd",
target_os = "linux",
))]
pub fn files(&self) -> u64 {
self.0.f_files
Expand All @@ -604,10 +591,9 @@ impl Statfs {
/// Free file nodes in filesystem
#[cfg(any(
apple_targets,
target_os = "android",
linux_android,
target_os = "fuchsia",
target_os = "openbsd",
target_os = "linux",
))]
pub fn files_free(&self) -> u64 {
self.0.f_ffree
Expand Down Expand Up @@ -651,8 +637,7 @@ impl Debug for Statfs {
#[cfg(all(
feature = "mount",
any(
target_os = "dragonfly",
target_os = "freebsd",
freebsdlike,
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"
Expand Down