use alloc::string::String;
use alloc::vec::Vec;
use crate::cache::BlockCache;
use crate::error::Result;
use crate::source::BlockSource;
use crate::verify::Verifier;
pub type NodeId = u64;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FileKind {
Regular,
Directory,
Symlink,
Other,
}
#[derive(Clone, Debug)]
pub struct Metadata {
pub kind: FileKind,
pub size: u64,
pub mode: u32,
}
#[derive(Clone, Debug)]
pub struct DirEntry {
pub name: String,
pub node: NodeId,
pub kind: FileKind,
}
pub struct SubstrateCtx<'a> {
pub cache: &'a mut BlockCache,
pub verifier: &'a dyn Verifier,
}
pub trait FoldFrontend<S: BlockSource>: Sized {
const TAG: &'static str;
fn probe(src: &mut S) -> Result<bool>;
fn open(src: S, cx: &mut SubstrateCtx<'_>) -> Result<Self>;
fn root(&self) -> NodeId;
fn lookup(
&mut self,
dir: NodeId,
name: &str,
cx: &mut SubstrateCtx<'_>,
) -> Result<Option<NodeId>>;
fn read_dir(&mut self, dir: NodeId, cx: &mut SubstrateCtx<'_>) -> Result<Vec<DirEntry>>;
fn metadata(&mut self, node: NodeId, cx: &mut SubstrateCtx<'_>) -> Result<Metadata>;
fn read_at(
&mut self,
node: NodeId,
off: u64,
buf: &mut [u8],
cx: &mut SubstrateCtx<'_>,
) -> Result<usize>;
fn read_link(&mut self, node: NodeId, cx: &mut SubstrateCtx<'_>) -> Result<Option<Vec<u8>>> {
let _ = (node, cx);
Ok(None)
}
}