vahanafs/src/fs/stackable/fuse_overlay.rs
2025-03-01 04:24:25 -06:00

80 lines
2.3 KiB
Rust

use std::fmt::Display;
use crate::fs::{id_mapping::IdMapping, AsIter, FileSystem, Mountpoint};
use super::{Stack, Stackable};
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FuseOverlayOption {
CloneFd,
MaxIdleThreads(isize),
MaxThreads(usize),
AllowOther,
AllowRoot,
SquashToRoot,
SquashToUid(usize),
SquashToGid(usize),
StaticNLink,
NoAcl,
UidMapping(IdMapping),
GidMapping(IdMapping),
}
impl Display for FuseOverlayOption {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
FuseOverlayOption::CloneFd => "clone_fd".to_string(),
FuseOverlayOption::MaxIdleThreads(n) => format!("max_idle_threads={n}"),
FuseOverlayOption::MaxThreads(n) => format!("max_threads={n}"),
FuseOverlayOption::AllowOther => "allow_other".to_string(),
FuseOverlayOption::AllowRoot => "allow_root".to_string(),
FuseOverlayOption::SquashToRoot => "squash_to_root".to_string(),
FuseOverlayOption::SquashToUid(uid) => format!("squash_to_uid={uid}"),
FuseOverlayOption::SquashToGid(gid) => format!("squash_to_gid={gid}"),
FuseOverlayOption::StaticNLink => "static_nlink".to_string(),
FuseOverlayOption::NoAcl => "noacl".to_string(),
FuseOverlayOption::UidMapping(map) => format!("uidmapping={map}"),
FuseOverlayOption::GidMapping(map) => format!("gidmapping={map}"),
}
)
}
}
#[derive(Debug)]
pub struct FuseOverlay {
fs: Stackable,
options: Vec<FuseOverlayOption>,
}
impl Stack for FuseOverlay {
fn lower_dirs(&self) -> impl Iterator<Item = &std::path::Path> {
self.fs.lower_dirs()
}
fn upper_dir(&self) -> Option<&std::path::Path> {
self.fs.upper_dir()
}
fn work_dir(&self) -> Option<&std::path::Path> {
self.fs.work_dir()
}
}
impl Mountpoint for FuseOverlay {
fn options(&self) -> impl Iterator<Item = impl Display> {
self.options.as_iter()
}
}
impl FileSystem for FuseOverlay {
fn mount(&mut self) -> std::io::Result<()> {
todo!()
}
fn unmount(&mut self) -> std::io::Result<()> {
todo!()
}
}