pub fn statx<P: Arg, Fd: AsFd>(
dirfd: Fd,
path: P,
flags: AtFlags,
mask: StatxFlags,
) -> Result<Statx>
Expand description
statx(dirfd, path, flags, mask, statxbuf)
This function returns io::Errno::NOSYS
if statx
is not available on
the platform, such as Linux before 4.11. This also includes older Docker
versions where the actual syscall fails with different error codes; rustix
handles this and translates them into NOSYS
.
§References
§Examples
/// Try to determine if the provided path is a mount root. Will return
/// `Ok(None)` if the kernel is not new enough to support `statx` or
/// [`libc::STATX_ATTR_MOUNT_ROOT`].
fn is_mountpoint(root: BorrowedFd<'_>, path: &Path) -> io::Result<Option<bool>> {
use rustix::fs::{AtFlags, StatxFlags};
let mountroot_flag = libc::STATX_ATTR_MOUNT_ROOT as u64;
match rustix::fs::statx(
root,
path,
AtFlags::NO_AUTOMOUNT | AtFlags::SYMLINK_NOFOLLOW,
StatxFlags::empty(),
) {
Ok(r) => {
let present = (r.stx_attributes_mask & mountroot_flag) > 0;
Ok(present.then(|| r.stx_attributes & mountroot_flag > 0))
}
Err(e) if e == rustix::io::Errno::NOSYS => Ok(None),
Err(e) => Err(e.into()),
}
}