whyno-core 0.5.0

Permission check pipeline, fix engine, and state types
Documentation
//! Path walk types for per-component permission state.
//!
//! Each ancestor from `/` to target is a [`PathComponent`] carrying
//! its own stat, ACL, flags, and mount reference.

use std::path::PathBuf;

use serde::Serialize;

use super::acl::PosixAcl;
use super::fsflags::FsFlags;
use super::Probe;

/// Single component in the path walk from `/` to target.
///
/// Each component independently carries its permissions state. `mount`
/// indexes into [`SystemState`](super::SystemState)'s mount table,
/// linking this component to its filesystem's mount options.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct PathComponent {
    /// Absolute path of this component.
    pub path: PathBuf,
    /// `stat()` result for this component.
    pub stat: Probe<StatResult>,
    /// POSIX ACL entries from `system.posix_acl_access` xattr.
    pub acl: Probe<PosixAcl>,
    /// Filesystem flags from `ioctl(FS_IOC_GETFLAGS)`.
    pub flags: Probe<FsFlags>,
    /// Index into `SystemState::mounts` for this component's filesystem.
    pub mount: Option<usize>,
}

/// Result of `stat()` on a path component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
pub struct StatResult {
    /// File permission mode bits (e.g., `0o755`).
    pub mode: u32,
    /// Owner user ID.
    pub uid: u32,
    /// Owner group ID.
    pub gid: u32,
    /// Device ID (`st_dev`) -- used to join with mount table.
    pub dev: u64,
    /// Number of hard links.
    pub nlink: u64,
    /// Type of filesystem object.
    pub file_type: FileType,
}

/// Classification of a filesystem object.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[non_exhaustive]
pub enum FileType {
    /// Regular file.
    Regular,
    /// Directory.
    Directory,
    /// Symbolic link.
    Symlink,
    /// Anything else (block device, char device, FIFO, socket).
    Other,
}