#![cfg_attr(not(test), no_std)]
extern crate alloc;
mod dir;
mod file;
mod interrupts;
#[cfg(test)]
mod tests;
pub use self::dir::DirNode;
pub use self::file::FileNode;
pub use self::interrupts::{Interrupts, INTERRUPT};
use alloc::sync::Arc;
use axfs_vfs::{VfsNodeRef, VfsOps, VfsResult};
use spin::once::Once;
pub struct RamFileSystem {
parent: Once<VfsNodeRef>,
root: Arc<DirNode>,
}
impl RamFileSystem {
pub fn new() -> Self {
Self {
parent: Once::new(),
root: DirNode::new(None),
}
}
pub fn root_dir_node(&self) -> Arc<DirNode> {
self.root.clone()
}
}
impl VfsOps for RamFileSystem {
fn mount(&self, _path: &str, mount_point: VfsNodeRef) -> VfsResult {
if let Some(parent) = mount_point.parent() {
self.root.set_parent(Some(self.parent.call_once(|| parent)));
} else {
self.root.set_parent(None);
}
Ok(())
}
fn root_dir(&self) -> VfsNodeRef {
self.root.clone()
}
}
impl Default for RamFileSystem {
fn default() -> Self {
Self::new()
}
}