summaryrefslogtreecommitdiff
path: root/src/sys/statfs.rs
diff options
context:
space:
mode:
authorAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:27:08 -0800
committerAlex Saveau <saveau.alexandre@gmail.com>2022-11-06 11:39:09 -0800
commit17833268cb3269d83766bcdb4d9cbe0e25ebd38e (patch)
treeb86885991e1d8b6f9c610747c2e8c3a3370960cd /src/sys/statfs.rs
parent20df092bd067908fba23e49120eed7ad62f29108 (diff)
downloadnix-17833268cb3269d83766bcdb4d9cbe0e25ebd38e.zip
Reformat everything
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
Diffstat (limited to 'src/sys/statfs.rs')
-rw-r--r--src/sys/statfs.rs215
1 files changed, 148 insertions, 67 deletions
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs
index 9c28bc21..9be8ca66 100644
--- a/src/sys/statfs.rs
+++ b/src/sys/statfs.rs
@@ -1,25 +1,28 @@
//! Get filesystem statistics, non-portably
//!
//! See [`statvfs`](crate::sys::statvfs) for a portable alternative.
+#[cfg(not(any(target_os = "linux", target_os = "android")))]
+use std::ffi::CStr;
use std::fmt::{self, Debug};
use std::mem;
use std::os::unix::io::AsRawFd;
-#[cfg(not(any(target_os = "linux", target_os = "android")))]
-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")
+#[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;
+use crate::{errno::Errno, NixPath, Result};
/// Identifies a mounted file system
#[cfg(target_os = "android")]
@@ -65,7 +68,14 @@ type fs_type_t = libc::c_uint;
type fs_type_t = libc::c_ulong;
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
type fs_type_t = libc::c_int;
-#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
+#[cfg(all(
+ target_os = "linux",
+ not(any(
+ target_arch = "s390x",
+ target_env = "musl",
+ target_env = "uclibc"
+ ))
+))]
type fs_type_t = libc::__fsword_t;
/// Describes the file system type as known by the operating system.
@@ -74,7 +84,10 @@ type fs_type_t = libc::__fsword_t;
target_os = "android",
all(target_os = "linux", target_arch = "s390x"),
all(target_os = "linux", target_env = "musl"),
- all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))),
+ all(
+ target_os = "linux",
+ not(any(target_arch = "s390x", target_env = "musl"))
+ ),
))]
#[derive(Eq, Copy, Clone, PartialEq, Debug)]
pub struct FsType(pub fs_type_t);
@@ -83,31 +96,38 @@ pub struct FsType(pub fs_type_t);
// can't very well document them here.
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const ADFS_SUPER_MAGIC: FsType = FsType(libc::ADFS_SUPER_MAGIC as fs_type_t);
+pub const ADFS_SUPER_MAGIC: FsType =
+ FsType(libc::ADFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const AFFS_SUPER_MAGIC: FsType = FsType(libc::AFFS_SUPER_MAGIC as fs_type_t);
+pub const AFFS_SUPER_MAGIC: FsType =
+ FsType(libc::AFFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
pub const AFS_SUPER_MAGIC: FsType = FsType(libc::AFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const AUTOFS_SUPER_MAGIC: FsType = FsType(libc::AUTOFS_SUPER_MAGIC as fs_type_t);
+pub const AUTOFS_SUPER_MAGIC: FsType =
+ FsType(libc::AUTOFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
pub const BPF_FS_MAGIC: FsType = FsType(libc::BPF_FS_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const BTRFS_SUPER_MAGIC: FsType = FsType(libc::BTRFS_SUPER_MAGIC as fs_type_t);
+pub const BTRFS_SUPER_MAGIC: FsType =
+ FsType(libc::BTRFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const CGROUP2_SUPER_MAGIC: FsType = FsType(libc::CGROUP2_SUPER_MAGIC as fs_type_t);
+pub const CGROUP2_SUPER_MAGIC: FsType =
+ FsType(libc::CGROUP2_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const CGROUP_SUPER_MAGIC: FsType = FsType(libc::CGROUP_SUPER_MAGIC as fs_type_t);
+pub const CGROUP_SUPER_MAGIC: FsType =
+ FsType(libc::CGROUP_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const CODA_SUPER_MAGIC: FsType = FsType(libc::CODA_SUPER_MAGIC as fs_type_t);
+pub const CODA_SUPER_MAGIC: FsType =
+ FsType(libc::CODA_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
pub const CRAMFS_MAGIC: FsType = FsType(libc::CRAMFS_MAGIC as fs_type_t);
@@ -116,64 +136,82 @@ pub const CRAMFS_MAGIC: FsType = FsType(libc::CRAMFS_MAGIC as fs_type_t);
pub const DEBUGFS_MAGIC: FsType = FsType(libc::DEBUGFS_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const DEVPTS_SUPER_MAGIC: FsType = FsType(libc::DEVPTS_SUPER_MAGIC as fs_type_t);
+pub const DEVPTS_SUPER_MAGIC: FsType =
+ FsType(libc::DEVPTS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const ECRYPTFS_SUPER_MAGIC: FsType = FsType(libc::ECRYPTFS_SUPER_MAGIC as fs_type_t);
+pub const ECRYPTFS_SUPER_MAGIC: FsType =
+ FsType(libc::ECRYPTFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
pub const EFS_SUPER_MAGIC: FsType = FsType(libc::EFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const EXT2_SUPER_MAGIC: FsType = FsType(libc::EXT2_SUPER_MAGIC as fs_type_t);
+pub const EXT2_SUPER_MAGIC: FsType =
+ FsType(libc::EXT2_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const EXT3_SUPER_MAGIC: FsType = FsType(libc::EXT3_SUPER_MAGIC as fs_type_t);
+pub const EXT3_SUPER_MAGIC: FsType =
+ FsType(libc::EXT3_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const EXT4_SUPER_MAGIC: FsType = FsType(libc::EXT4_SUPER_MAGIC as fs_type_t);
+pub const EXT4_SUPER_MAGIC: FsType =
+ FsType(libc::EXT4_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const F2FS_SUPER_MAGIC: FsType = FsType(libc::F2FS_SUPER_MAGIC as fs_type_t);
+pub const F2FS_SUPER_MAGIC: FsType =
+ FsType(libc::F2FS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const FUSE_SUPER_MAGIC: FsType = FsType(libc::FUSE_SUPER_MAGIC as fs_type_t);
+pub const FUSE_SUPER_MAGIC: FsType =
+ FsType(libc::FUSE_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const FUTEXFS_SUPER_MAGIC: FsType = FsType(libc::FUTEXFS_SUPER_MAGIC as fs_type_t);
+pub const FUTEXFS_SUPER_MAGIC: FsType =
+ FsType(libc::FUTEXFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const HOSTFS_SUPER_MAGIC: FsType = FsType(libc::HOSTFS_SUPER_MAGIC as fs_type_t);
+pub const HOSTFS_SUPER_MAGIC: FsType =
+ FsType(libc::HOSTFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const HPFS_SUPER_MAGIC: FsType = FsType(libc::HPFS_SUPER_MAGIC as fs_type_t);
+pub const HPFS_SUPER_MAGIC: FsType =
+ FsType(libc::HPFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
pub const HUGETLBFS_MAGIC: FsType = FsType(libc::HUGETLBFS_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const ISOFS_SUPER_MAGIC: FsType = FsType(libc::ISOFS_SUPER_MAGIC as fs_type_t);
+pub const ISOFS_SUPER_MAGIC: FsType =
+ FsType(libc::ISOFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const JFFS2_SUPER_MAGIC: FsType = FsType(libc::JFFS2_SUPER_MAGIC as fs_type_t);
+pub const JFFS2_SUPER_MAGIC: FsType =
+ FsType(libc::JFFS2_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const MINIX2_SUPER_MAGIC2: FsType = FsType(libc::MINIX2_SUPER_MAGIC2 as fs_type_t);
+pub const MINIX2_SUPER_MAGIC2: FsType =
+ FsType(libc::MINIX2_SUPER_MAGIC2 as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const MINIX2_SUPER_MAGIC: FsType = FsType(libc::MINIX2_SUPER_MAGIC as fs_type_t);
+pub const MINIX2_SUPER_MAGIC: FsType =
+ FsType(libc::MINIX2_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const MINIX3_SUPER_MAGIC: FsType = FsType(libc::MINIX3_SUPER_MAGIC as fs_type_t);
+pub const MINIX3_SUPER_MAGIC: FsType =
+ FsType(libc::MINIX3_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const MINIX_SUPER_MAGIC2: FsType = FsType(libc::MINIX_SUPER_MAGIC2 as fs_type_t);
+pub const MINIX_SUPER_MAGIC2: FsType =
+ FsType(libc::MINIX_SUPER_MAGIC2 as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const MINIX_SUPER_MAGIC: FsType = FsType(libc::MINIX_SUPER_MAGIC as fs_type_t);
+pub const MINIX_SUPER_MAGIC: FsType =
+ FsType(libc::MINIX_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const MSDOS_SUPER_MAGIC: FsType = FsType(libc::MSDOS_SUPER_MAGIC as fs_type_t);
+pub const MSDOS_SUPER_MAGIC: FsType =
+ FsType(libc::MSDOS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
pub const NCP_SUPER_MAGIC: FsType = FsType(libc::NCP_SUPER_MAGIC as fs_type_t);
@@ -182,34 +220,44 @@ pub const NCP_SUPER_MAGIC: FsType = FsType(libc::NCP_SUPER_MAGIC as fs_type_t);
pub const NFS_SUPER_MAGIC: FsType = FsType(libc::NFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const NILFS_SUPER_MAGIC: FsType = FsType(libc::NILFS_SUPER_MAGIC as fs_type_t);
+pub const NILFS_SUPER_MAGIC: FsType =
+ FsType(libc::NILFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const OCFS2_SUPER_MAGIC: FsType = FsType(libc::OCFS2_SUPER_MAGIC as fs_type_t);
+pub const OCFS2_SUPER_MAGIC: FsType =
+ FsType(libc::OCFS2_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const OPENPROM_SUPER_MAGIC: FsType = FsType(libc::OPENPROM_SUPER_MAGIC as fs_type_t);
+pub const OPENPROM_SUPER_MAGIC: FsType =
+ FsType(libc::OPENPROM_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const OVERLAYFS_SUPER_MAGIC: FsType = FsType(libc::OVERLAYFS_SUPER_MAGIC as fs_type_t);
+pub const OVERLAYFS_SUPER_MAGIC: FsType =
+ FsType(libc::OVERLAYFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const PROC_SUPER_MAGIC: FsType = FsType(libc::PROC_SUPER_MAGIC as fs_type_t);
+pub const PROC_SUPER_MAGIC: FsType =
+ FsType(libc::PROC_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const QNX4_SUPER_MAGIC: FsType = FsType(libc::QNX4_SUPER_MAGIC as fs_type_t);
+pub const QNX4_SUPER_MAGIC: FsType =
+ FsType(libc::QNX4_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const QNX6_SUPER_MAGIC: FsType = FsType(libc::QNX6_SUPER_MAGIC as fs_type_t);
+pub const QNX6_SUPER_MAGIC: FsType =
+ FsType(libc::QNX6_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const RDTGROUP_SUPER_MAGIC: FsType = FsType(libc::RDTGROUP_SUPER_MAGIC as fs_type_t);
+pub const RDTGROUP_SUPER_MAGIC: FsType =
+ FsType(libc::RDTGROUP_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const REISERFS_SUPER_MAGIC: FsType = FsType(libc::REISERFS_SUPER_MAGIC as fs_type_t);
+pub const REISERFS_SUPER_MAGIC: FsType =
+ FsType(libc::REISERFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const SECURITYFS_MAGIC: FsType = FsType(libc::SECURITYFS_MAGIC as fs_type_t);
+pub const SECURITYFS_MAGIC: FsType =
+ FsType(libc::SECURITYFS_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
pub const SELINUX_MAGIC: FsType = FsType(libc::SELINUX_MAGIC as fs_type_t);
@@ -233,14 +281,19 @@ pub const TRACEFS_MAGIC: FsType = FsType(libc::TRACEFS_MAGIC as fs_type_t);
pub const UDF_SUPER_MAGIC: FsType = FsType(libc::UDF_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const USBDEVICE_SUPER_MAGIC: FsType = FsType(libc::USBDEVICE_SUPER_MAGIC as fs_type_t);
+pub const USBDEVICE_SUPER_MAGIC: FsType =
+ FsType(libc::USBDEVICE_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "android"))]
#[allow(missing_docs)]
-pub const XENFS_SUPER_MAGIC: FsType = FsType(libc::XENFS_SUPER_MAGIC as fs_type_t);
+pub const XENFS_SUPER_MAGIC: FsType =
+ FsType(libc::XENFS_SUPER_MAGIC as fs_type_t);
#[cfg(any(target_os = "linux", target_os = "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(
+ any(target_os = "linux", target_os = "android"),
+ not(target_env = "musl")
+))]
#[allow(missing_docs)]
pub const XFS_SUPER_MAGIC: FsType = FsType(libc::XFS_SUPER_MAGIC as fs_type_t);
@@ -297,7 +350,14 @@ impl Statfs {
}
/// Optimal transfer block size
- #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
+ #[cfg(all(
+ target_os = "linux",
+ not(any(
+ target_arch = "s390x",
+ target_env = "musl",
+ target_env = "uclibc"
+ ))
+ ))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> libc::__fsword_t {
self.0.f_bsize
@@ -357,7 +417,14 @@ impl Statfs {
/// Size of a block
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
- #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
+ #[cfg(all(
+ target_os = "linux",
+ not(any(
+ target_arch = "s390x",
+ target_env = "musl",
+ target_env = "uclibc"
+ ))
+ ))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> libc::__fsword_t {
self.0.f_bsize
@@ -385,15 +452,18 @@ impl Statfs {
}
/// 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(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
+ #[allow(clippy::unnecessary_cast)] // Not unnecessary on all arches
pub fn flags(&self) -> MntFlags {
MntFlags::from_bits_truncate(self.0.f_flags as i32)
}
@@ -436,7 +506,14 @@ impl Statfs {
}
/// Maximum length of filenames
- #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
+ #[cfg(all(
+ target_os = "linux",
+ not(any(
+ target_arch = "s390x",
+ target_env = "musl",
+ target_env = "uclibc"
+ ))
+ ))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn maximum_name_length(&self) -> libc::__fsword_t {
self.0.f_namelen
@@ -622,16 +699,18 @@ impl Debug for Statfs {
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")
+ #[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()
-
}
}
@@ -646,7 +725,9 @@ impl Debug for Statfs {
pub fn statfs<P: ?Sized + NixPath>(path: &P) -> Result<Statfs> {
unsafe {
let mut stat = mem::MaybeUninit::<type_of_statfs>::uninit();
- let res = path.with_nix_path(|path| LIBC_STATFS(path.as_ptr(), stat.as_mut_ptr()))?;
+ let res = path.with_nix_path(|path| {
+ LIBC_STATFS(path.as_ptr(), stat.as_mut_ptr())
+ })?;
Errno::result(res).map(|_| Statfs(stat.assume_init()))
}
}