Skip to main content

whyno_core/state/
path.rs

1//! Path walk types for per-component permission state.
2//!
3//! Each ancestor from `/` to target is a [`PathComponent`] carrying
4//! its own stat, ACL, flags, and mount reference.
5
6use std::path::PathBuf;
7
8use serde::Serialize;
9
10use super::acl::PosixAcl;
11use super::fsflags::FsFlags;
12use super::Probe;
13
14/// Single component in the path walk from `/` to target.
15///
16/// Each component independently carries its permissions state. `mount`
17/// indexes into [`SystemState`](super::SystemState)'s mount table,
18/// linking this component to its filesystem's mount options.
19#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
20pub struct PathComponent {
21    /// Absolute path of this component.
22    pub path: PathBuf,
23    /// `stat()` result for this component.
24    pub stat: Probe<StatResult>,
25    /// POSIX ACL entries from `system.posix_acl_access` xattr.
26    pub acl: Probe<PosixAcl>,
27    /// Filesystem flags from `ioctl(FS_IOC_GETFLAGS)`.
28    pub flags: Probe<FsFlags>,
29    /// Index into `SystemState::mounts` for this component's filesystem.
30    pub mount: Option<usize>,
31}
32
33/// Result of `stat()` on a path component.
34#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
35pub struct StatResult {
36    /// File permission mode bits (e.g., `0o755`).
37    pub mode: u32,
38    /// Owner user ID.
39    pub uid: u32,
40    /// Owner group ID.
41    pub gid: u32,
42    /// Device ID (`st_dev`) -- used to join with mount table.
43    pub dev: u64,
44    /// Number of hard links.
45    pub nlink: u64,
46    /// Type of filesystem object.
47    pub file_type: FileType,
48}
49
50/// Classification of a filesystem object.
51#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
52#[non_exhaustive]
53pub enum FileType {
54    /// Regular file.
55    Regular,
56    /// Directory.
57    Directory,
58    /// Symbolic link.
59    Symlink,
60    /// Anything else (block device, char device, FIFO, socket).
61    Other,
62}