diff options
author | Alan Somers <asomers@gmail.com> | 2022-10-17 19:00:48 -0600 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2022-10-23 22:42:00 -0600 |
commit | b2c036164744bc06f2f194f4ea7c9b8acc19234c (patch) | |
tree | 8f118faa9b41860e5125135c1b92867ffc414744 /src/sys | |
parent | 3f66d1f4ce06403f646876864260c59ca3627ee4 (diff) | |
download | nix-b2c036164744bc06f2f194f4ea7c9b8acc19234c.zip |
Add a Statfs::flags method
It returns the mount flags on the BSDs. On Linux, it returns a slightly
different set of flags.
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/statfs.rs | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs index acbc75cd..9c28bc21 100644 --- a/src/sys/statfs.rs +++ b/src/sys/statfs.rs @@ -10,6 +10,16 @@ use std::ffi::CStr; use cfg_if::cfg_if; use crate::{NixPath, Result, errno::Errno}; +#[cfg(all(feature = "mount", + any(target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd") +))] +use crate::mount::MntFlags; +#[cfg(target_os = "linux")] +use crate::sys::statvfs::FsFlags; /// Identifies a mounted file system #[cfg(target_os = "android")] @@ -374,6 +384,29 @@ impl Statfs { self.0.f_bsize } + /// Get the mount flags + #[cfg(all(feature = "mount", + any(target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd") + ))] + #[cfg_attr(docsrs, doc(cfg(all())))] + #[allow(clippy::unnecessary_cast)] // Not unnecessary on all arches + pub fn flags(&self) -> MntFlags { + MntFlags::from_bits_truncate(self.0.f_flags as i32) + } + + /// Get the mount flags + // The f_flags field exists on Android and Fuchsia too, but without man + // pages I can't tell if it can be cast to FsFlags. + #[cfg(target_os = "linux")] + #[cfg_attr(docsrs, doc(cfg(all())))] + pub fn flags(&self) -> FsFlags { + FsFlags::from_bits_truncate(self.0.f_flags as libc::c_ulong) + } + /// Maximum length of filenames #[cfg(any(target_os = "freebsd", target_os = "openbsd"))] #[cfg_attr(docsrs, doc(cfg(all())))] @@ -580,16 +613,25 @@ impl Statfs { impl Debug for Statfs { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.debug_struct("Statfs") - .field("optimal_transfer_size", &self.optimal_transfer_size()) - .field("block_size", &self.block_size()) - .field("blocks", &self.blocks()) - .field("blocks_free", &self.blocks_free()) - .field("blocks_available", &self.blocks_available()) - .field("files", &self.files()) - .field("files_free", &self.files_free()) - .field("filesystem_id", &self.filesystem_id()) - .finish() + let mut ds = f.debug_struct("Statfs"); + ds.field("optimal_transfer_size", &self.optimal_transfer_size()); + ds.field("block_size", &self.block_size()); + ds.field("blocks", &self.blocks()); + ds.field("blocks_free", &self.blocks_free()); + ds.field("blocks_available", &self.blocks_available()); + ds.field("files", &self.files()); + ds.field("files_free", &self.files_free()); + ds.field("filesystem_id", &self.filesystem_id()); + #[cfg(all(feature = "mount", + any(target_os = "dragonfly", + target_os = "freebsd", + target_os = "macos", + target_os = "netbsd", + target_os = "openbsd") + ))] + ds.field("flags", &self.flags()); + ds.finish() + } } |