33 lines
897 B
Rust
33 lines
897 B
Rust
use core::marker::PhantomData;
|
|
|
|
use alloc::boxed::Box;
|
|
|
|
use vfs::{Vnode, VnodeImpl, VnodeKind, VnodeRef};
|
|
use yggdrasil_abi::error::Error;
|
|
|
|
use crate::{block::BlockAllocator, bvec::BVec, file::FileNode};
|
|
|
|
pub(crate) struct DirectoryNode<A: BlockAllocator> {
|
|
_pd: PhantomData<A>,
|
|
}
|
|
|
|
impl<A: BlockAllocator> VnodeImpl for DirectoryNode<A> {
|
|
fn create(&mut self, _at: &VnodeRef, name: &str, kind: VnodeKind) -> Result<VnodeRef, Error> {
|
|
let child = Vnode::new(name, kind);
|
|
match kind {
|
|
VnodeKind::Directory => child.set_data(Box::new(Self { _pd: PhantomData })),
|
|
VnodeKind::Regular => child.set_data(Box::new(FileNode {
|
|
data: BVec::<A>::new(),
|
|
})),
|
|
_ => todo!(),
|
|
}
|
|
Ok(child)
|
|
}
|
|
}
|
|
|
|
impl<A: BlockAllocator> DirectoryNode<A> {
|
|
pub fn new() -> Self {
|
|
Self { _pd: PhantomData }
|
|
}
|
|
}
|