summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/procfs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/procfs.rs')
-rw-r--r--vendor/rustix/src/procfs.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/vendor/rustix/src/procfs.rs b/vendor/rustix/src/procfs.rs
index 010b93126..14ad631a7 100644
--- a/vendor/rustix/src/procfs.rs
+++ b/vendor/rustix/src/procfs.rs
@@ -20,9 +20,8 @@
use crate::backend::pid::syscalls::getpid;
use crate::fd::{AsFd, BorrowedFd, OwnedFd};
-use crate::ffi::CStr;
use crate::fs::{
- fstat, fstatfs, major, openat, renameat, Dir, FileType, Mode, OFlags, Stat, CWD,
+ fstat, fstatfs, major, openat, renameat, FileType, FsWord, Mode, OFlags, Stat, CWD,
PROC_SUPER_MAGIC,
};
use crate::io;
@@ -31,6 +30,8 @@ use crate::path::DecInt;
use core::lazy::OnceCell;
#[cfg(not(feature = "rustc-dep-of-std"))]
use once_cell::sync::OnceCell;
+#[cfg(feature = "alloc")]
+use {crate::ffi::CStr, crate::fs::Dir};
/// Linux's procfs always uses inode 1 for its root directory.
const PROC_ROOT_INO: u64 = 1;
@@ -41,6 +42,7 @@ enum Kind {
Proc,
Pid,
Fd,
+ #[cfg(feature = "alloc")]
File,
}
@@ -67,6 +69,7 @@ fn check_proc_entry_with_stat(
match kind {
Kind::Proc => check_proc_root(entry, &entry_stat)?,
Kind::Pid | Kind::Fd => check_proc_subdir(entry, &entry_stat, proc_stat)?,
+ #[cfg(feature = "alloc")]
Kind::File => check_proc_file(&entry_stat, proc_stat)?,
}
@@ -94,6 +97,7 @@ fn check_proc_entry_with_stat(
return Err(io::Errno::NOTSUP);
}
}
+ #[cfg(feature = "alloc")]
Kind::File => {
// Check that files in procfs don't have extraneous hard links to
// them (which might indicate hard links to other things).
@@ -149,6 +153,7 @@ fn check_proc_subdir(
Ok(())
}
+#[cfg(feature = "alloc")]
fn check_proc_file(stat: &Stat, proc_stat: Option<&Stat>) -> io::Result<()> {
// Check that we have a regular file.
if FileType::from_raw_mode(stat.st_mode) != FileType::RegularFile {
@@ -178,7 +183,7 @@ fn check_proc_nonroot(stat: &Stat, proc_stat: Option<&Stat>) -> io::Result<()> {
fn check_procfs(file: BorrowedFd<'_>) -> io::Result<()> {
let statfs = fstatfs(file)?;
let f_type = statfs.f_type;
- if f_type != PROC_SUPER_MAGIC.into() {
+ if f_type != FsWord::from(PROC_SUPER_MAGIC) {
return Err(io::Errno::NOTSUP);
}
@@ -309,6 +314,7 @@ fn new_static_fd(fd: OwnedFd, stat: Stat) -> (OwnedFd, Stat) {
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
+#[cfg(feature = "alloc")]
fn proc_self_fdinfo() -> io::Result<(BorrowedFd<'static>, &'static Stat)> {
static PROC_SELF_FDINFO: StaticFd = StaticFd::new();
@@ -338,12 +344,14 @@ fn proc_self_fdinfo() -> io::Result<(BorrowedFd<'static>, &'static Stat)> {
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
+#[cfg(feature = "alloc")]
#[inline]
#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))]
pub fn proc_self_fdinfo_fd<Fd: AsFd>(fd: Fd) -> io::Result<OwnedFd> {
_proc_self_fdinfo(fd.as_fd())
}
+#[cfg(feature = "alloc")]
fn _proc_self_fdinfo(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> {
let (proc_self_fdinfo, proc_self_fdinfo_stat) = proc_self_fdinfo()?;
let fd_str = DecInt::from_fd(fd);
@@ -361,6 +369,7 @@ fn _proc_self_fdinfo(fd: BorrowedFd<'_>) -> io::Result<OwnedFd> {
///
/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
/// [Linux pagemap]: https://www.kernel.org/doc/Documentation/vm/pagemap.txt
+#[cfg(feature = "alloc")]
#[inline]
#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))]
pub fn proc_self_pagemap() -> io::Result<OwnedFd> {
@@ -376,6 +385,7 @@ pub fn proc_self_pagemap() -> io::Result<OwnedFd> {
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
+#[cfg(feature = "alloc")]
#[inline]
#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))]
pub fn proc_self_maps() -> io::Result<OwnedFd> {
@@ -391,6 +401,7 @@ pub fn proc_self_maps() -> io::Result<OwnedFd> {
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man5/proc.5.html
+#[cfg(feature = "alloc")]
#[inline]
#[cfg_attr(doc_cfg, doc(cfg(feature = "procfs")))]
pub fn proc_self_status() -> io::Result<OwnedFd> {
@@ -398,13 +409,15 @@ pub fn proc_self_status() -> io::Result<OwnedFd> {
}
/// Open a file under `/proc/self`.
+#[cfg(feature = "alloc")]
fn proc_self_file(name: &CStr) -> io::Result<OwnedFd> {
let (proc_self, proc_self_stat) = proc_self()?;
open_and_check_file(proc_self, proc_self_stat, name)
}
/// Open a procfs file within in `dir` and check it for bind mounts.
-fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Result<OwnedFd> {
+#[cfg(feature = "alloc")]
+fn open_and_check_file(dir: BorrowedFd<'_>, dir_stat: &Stat, name: &CStr) -> io::Result<OwnedFd> {
let (_, proc_stat) = proc()?;
// Don't use `NOATIME`, because it [requires us to own the file], and when
@@ -418,10 +431,10 @@ fn open_and_check_file(dir: BorrowedFd, dir_stat: &Stat, name: &CStr) -> io::Res
let file_stat = fstat(&file)?;
// `is_mountpoint` only works on directory mount points, not file mount
- // points. To detect file mount points, scan the parent directory to see
- // if we can find a regular file with an inode and name that matches the
- // file we just opened. If we can't find it, there could be a file bind
- // mount on top of the file we want.
+ // points. To detect file mount points, scan the parent directory to see if
+ // we can find a regular file with an inode and name that matches the file
+ // we just opened. If we can't find it, there could be a file bind mount on
+ // top of the file we want.
//
// As we scan, we also check for ".", to make sure it's the same directory
// as our original directory, to detect mount points, since