From ca42248fbed727b51576da4670ab50c2f52cd314 Mon Sep 17 00:00:00 2001 From: Aster Boese Date: Sun, 27 Oct 2024 22:37:19 -0400 Subject: [PATCH] Add a `rustix::fs::STATX_ATTR_MOUNT_ROOT` constant. Add a `STATX_ATTR_MOUNT_ROOT` constant for musl libc compat --- src/backend/libc/c.rs | 6 ++++++ src/backend/linux_raw/c.rs | 10 ++++++++-- src/fs/mod.rs | 2 ++ src/fs/statx.rs | 5 +++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/backend/libc/c.rs b/src/backend/libc/c.rs index ec140a327..e17c884cb 100644 --- a/src/backend/libc/c.rs +++ b/src/backend/libc/c.rs @@ -14,6 +14,12 @@ pub(crate) const PROC_SUPER_MAGIC: u32 = 0x0000_9fa0; #[cfg(all(linux_kernel, target_env = "musl"))] pub(crate) const NFS_SUPER_MAGIC: u32 = 0x0000_6969; +/// `STATX_ATTR_MOUNT_ROOT`—Address of the root of a mount +#[cfg(all(linux_kernel, target_env = "musl"))] +pub(crate) const STATX_ATTR_MOUNT_ROOT: c_int = 0x2000; +#[cfg(all(linux_kernel, target_env = "glibc"))] +pub(crate) const STATX_ATTR_MOUNT_ROOT: c_int = libc::STATX_ATTR_MOUNT_ROOT; + #[cfg(feature = "process")] #[cfg(not(any(target_os = "espidf", target_os = "wasi")))] pub(crate) const EXIT_SIGNALED_SIGABRT: c_int = 128 + SIGABRT as c_int; diff --git a/src/backend/linux_raw/c.rs b/src/backend/linux_raw/c.rs index 08ded6b35..72dcc9e95 100644 --- a/src/backend/linux_raw/c.rs +++ b/src/backend/linux_raw/c.rs @@ -37,9 +37,15 @@ pub(crate) use linux_raw_sys::general::epoll_event; ) ) ))] +#[cfg(all(target_env = "musl"))] pub(crate) use linux_raw_sys::general::{ - AT_FDCWD, NFS_SUPER_MAGIC, O_LARGEFILE, PROC_SUPER_MAGIC, UTIME_NOW, UTIME_OMIT, XATTR_CREATE, - XATTR_REPLACE, + AT_FDCWD, NFS_SUPER_MAGIC, O_LARGEFILE, PROC_SUPER_MAGIC, STATX_ATTR_MOUNT_ROOT, UTIME_NOW, + UTIME_OMIT, XATTR_CREATE, XATTR_REPLACE, +}; +#[cfg(all(not(target_env = "musl")))] +pub(crate) use linux_raw_sys::general::{ + AT_FDCWD, NFS_SUPER_MAGIC, O_LARGEFILE, PROC_SUPER_MAGIC, UTIME_NOW, + UTIME_OMIT, XATTR_CREATE, XATTR_REPLACE, }; pub(crate) use linux_raw_sys::ioctl::{BLKPBSZGET, BLKSSZGET, FICLONE}; diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 07fd66479..afadbcbde 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -116,6 +116,8 @@ pub use sendfile::sendfile; pub use special::*; #[cfg(linux_kernel)] pub use statx::statx; +#[cfg(all(linux_kernel, any(target_env = "musl", target_env = "gnu")))] +pub use statx::STATX_ATTR_MOUNT_ROOT; #[cfg(not(any( target_os = "espidf", target_os = "redox", diff --git a/src/fs/statx.rs b/src/fs/statx.rs index cb9875c49..83904d4d4 100644 --- a/src/fs/statx.rs +++ b/src/fs/statx.rs @@ -10,6 +10,11 @@ use backend::fs::syscalls::statx as _statx; #[cfg(not(feature = "linux_4_11"))] use compat::statx as _statx; +/// `STATX_ATTR_MOUNT_ROOT`—Address of the root of a mount +#[allow(dead_code)] +#[cfg(all(linux_kernel, any(target_env = "musl", target_env = "gnu")))] +pub const STATX_ATTR_MOUNT_ROOT: u32 = backend::c::STATX_ATTR_MOUNT_ROOT as u32; + /// `statx(dirfd, path, flags, mask, statxbuf)` /// /// This function returns [`io::Errno::NOSYS`] if `statx` is not available on