diff --git a/src/fd/mod.rs b/src/fd/mod.rs index 23aee57..453ab24 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -35,11 +35,11 @@ impl FDTable { } } - pub fn unregister_fd(&mut self, fd: FDt) { - self.table.remove(&fd.borrow().get_fd()); + pub fn unregister_fd(&mut self, fd: &dyn FileDescriptor) { + self.table.remove(&fd.get_fd()); println!( "Unregistered fd: {:?}", - fd.borrow().get_fd() + fd.get_fd() ); } @@ -57,4 +57,5 @@ pub trait FileDescriptor { fn get_fd(&self) -> FDId; async fn write(&mut self, buf: &[u8], count: usize) -> isize; async fn read(&mut self, buf: &mut [u8], count: usize) -> isize; + async fn close(&mut self); } diff --git a/src/fs/iso/fd.rs b/src/fs/iso/fd.rs index 5d57cda..cb34b12 100644 --- a/src/fs/iso/fd.rs +++ b/src/fs/iso/fd.rs @@ -60,4 +60,8 @@ impl FileDescriptor for IsoFD { read } + + async fn close(&mut self) { + FD_TABLE.lock().await.unregister_fd(self); + } } diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 6e4e8ce..3334d59 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -2,7 +2,7 @@ mod fd; pub mod iso9660; use crate::drivers::atapi::read_block; -use crate::fd::{FDt, FD_TABLE}; +use crate::fd::{FDt}; use crate::utils::unserialize; use super::FileSystem; @@ -74,10 +74,6 @@ impl FileSystem for IsoFS { Some(IsoFD::new(curr_entry).await) } - - async fn close(&mut self, fd: FDt) { - FD_TABLE.lock().await.unregister_fd(fd.clone()); - } } diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 7d6ebde..e9f9d44 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -17,7 +17,6 @@ lazy_static! { #[async_trait(?Send)] pub trait FileSystem { async fn open(&mut self, path: &str, flags: u32) -> Option; - async fn close(&mut self, fd: FDt); } pub struct VirtualFS { @@ -37,8 +36,4 @@ impl FileSystem for VirtualFS { async fn open(&mut self, path: &str, flags: u32) -> Option { self.fs.borrow_mut().open(path, flags).await } - - async fn close(&mut self, fd: FDt) { - self.fs.borrow_mut().close(fd).await - } } diff --git a/src/lib.rs b/src/lib.rs index 6493d25..a8e2105 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,5 +77,5 @@ async fn get_file() { serial_println!("{:?}", read); serial_println!("{}", alloc::str::from_utf8(&buf).unwrap()); - fs::VIRTUAL_FS.lock().await.close(fd).await; + fd.borrow_mut().close().await; }