diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 610c5a7..52236c6 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -18,7 +18,7 @@ pub struct IsoFS { #[async_trait(?Send)] impl FileSystem for IsoFS { - async fn open(path: &str, flags: u32) -> Option { + async fn open(&mut self, path: &str, flags: u32) -> Option { if flags != crate::syscalls::io::O_RDONLY { return None; } diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 7631314..6ea55db 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -1,11 +1,41 @@ pub mod iso; use crate::fd::FDt; +use crate::utils::mutex::AsyncMutex; use alloc::{sync::Arc, boxed::Box}; use async_trait::async_trait; +use core::cell::RefCell; +use lazy_static::lazy_static; + +pub type FSt = Arc>; + +lazy_static! { + pub static ref VIRTUAL_FS: AsyncMutex = { + AsyncMutex::new(VirtualFS::new()) + }; +} #[async_trait(?Send)] pub trait FileSystem { - async fn open(path: &str, flags: u32) -> Option; + async fn open(&mut self, path: &str, flags: u32) -> Option; +} + +pub struct VirtualFS { + fs: FSt, +} + +impl VirtualFS { + fn new() -> Self { + VirtualFS { + fs: Arc::new(RefCell::new(iso::IsoFS {})) + } + } +} + +#[async_trait(?Send)] +impl FileSystem for VirtualFS { + async fn open(&mut self, path: &str, flags: u32) -> Option { + self.fs.borrow_mut().open(path, flags).await + } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 240a2ec..4b96f0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,6 +66,6 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! { async fn get_file() { - let fd = fs::iso::IsoFS::open("test", syscalls::io::O_RDONLY).await.unwrap(); + let fd = fs::VIRTUAL_FS.lock().await.open("test", syscalls::io::O_RDONLY).await.unwrap(); fd.borrow_mut().read(&[], 0).await; } \ No newline at end of file