basic virtual file system
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
8518982932
commit
b2ffbc34b5
@ -18,7 +18,7 @@ pub struct IsoFS {
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl FileSystem for IsoFS {
|
||||
async fn open(path: &str, flags: u32) -> Option<FDt> {
|
||||
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
|
||||
if flags != crate::syscalls::io::O_RDONLY {
|
||||
return None;
|
||||
}
|
||||
|
@ -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<RefCell<dyn FileSystem>>;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref VIRTUAL_FS: AsyncMutex<VirtualFS> = {
|
||||
AsyncMutex::new(VirtualFS::new())
|
||||
};
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
pub trait FileSystem {
|
||||
async fn open(path: &str, flags: u32) -> Option<FDt>;
|
||||
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt>;
|
||||
}
|
||||
|
||||
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<FDt> {
|
||||
self.fs.borrow_mut().open(path, flags).await
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user