diff --git a/src/fd/mod.rs b/src/fd/mod.rs index 7f1e168..e2a4eff 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -6,7 +6,7 @@ use async_trait::async_trait; use core::cell::RefCell; use lazy_static::lazy_static; -pub type FDt = Arc>; +pub type FDt = Arc>; lazy_static! { pub static ref FD_TABLE: AsyncMutex = { @@ -33,7 +33,7 @@ impl FDTable { FDTable { table: BTreeMap::new() } } - pub async fn register_fd(&mut self, fd: FDt) { + pub fn register_fd(&mut self, fd: FDt) { // TODO self.table.insert(fd.borrow().get_fd(), fd.clone()); println!("Registered fd: {:?}", self.table.get(&FDId(1)).unwrap().borrow().get_fd()); diff --git a/src/fs/iso/fd.rs b/src/fs/iso/fd.rs index 452f61e..95b8e04 100644 --- a/src/fs/iso/fd.rs +++ b/src/fs/iso/fd.rs @@ -1,5 +1,6 @@ use crate::println; use crate::fd::{FDId, FileDescriptor, FDt}; +use crate::utils::mutex::AsyncMutex; use alloc::{sync::Arc, boxed::Box}; use async_trait::async_trait; @@ -11,7 +12,7 @@ pub struct IsoFD { impl IsoFD { pub fn new() -> FDt { - Arc::new(RefCell::new(IsoFD { + Arc::new(AsyncMutex::new(IsoFD { fd: FDId::new(), })) } diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 48d938f..81297b3 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -6,9 +6,35 @@ use crate::drivers::atapi::{DRIVE}; use crate::fd::{FD_TABLE, FDt}; use crate::utils::unserialize; +use super::FileSystem; use iso9660::{IsoPrimVolDesc, IsoDir}; use fd::IsoFD; +use alloc::{sync::Arc, boxed::Box}; +use async_trait::async_trait; + +struct IsoFS { +} + +#[async_trait] +impl FileSystem for IsoFS { + async fn open(&mut self, path: &str, flags: u32) -> Option { + if flags != crate::syscalls::io::O_RDONLY { + return None; + } + + let voldesc = get_prim_vol_desc().await; + + if voldesc.std_identifier != "CD001".as_bytes() { + return None; + } + + let fd = IsoFD::new(); + FD_TABLE.lock().await.register_fd(fd.clone()); + Some(fd.clone()) + } +} + pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { let desc_block = DRIVE .lock() @@ -18,20 +44,4 @@ pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { .read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK) .await; *unserialize::(desc_block.as_ptr()) -} - -pub async fn open(path: &str, flags: u32) -> Option { - if flags != crate::syscalls::io::O_RDONLY { - return None; - } - - let voldesc = get_prim_vol_desc().await; - - if voldesc.std_identifier != "CD001".as_bytes() { - return None; - } - - let fd = IsoFD::new(); - FD_TABLE.lock().await.register_fd(fd.clone()).await; - Some(fd) } \ No newline at end of file diff --git a/src/fs/mod.rs b/src/fs/mod.rs index b5da632..76d187f 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -1 +1,11 @@ -pub mod iso; \ No newline at end of file +pub mod iso; + +use crate::fd::FDt; + +use alloc::{sync::Arc, boxed::Box}; +use async_trait::async_trait; + +#[async_trait] +pub trait FileSystem { + async fn open(&mut self, path: &str, flags: u32) -> Option; +} \ No newline at end of file diff --git a/src/utils/mutex.rs b/src/utils/mutex.rs index d23a7d9..48f0c38 100644 --- a/src/utils/mutex.rs +++ b/src/utils/mutex.rs @@ -14,7 +14,7 @@ struct Lock { waker: Arc, } -pub struct AsyncMutex { +pub struct AsyncMutex { lock: Lock, inner: UnsafeCell, }