From 992863a112089cc1814064bca754bf044eb4c6ad Mon Sep 17 00:00:00 2001 From: juls0730 <62722391+juls0730@users.noreply.github.com> Date: Mon, 27 May 2024 17:36:48 -0500 Subject: [PATCH] unmount vfs better --- src/drivers/fs/vfs.rs | 32 ++++++++++---------------------- src/main.rs | 2 -- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/drivers/fs/vfs.rs b/src/drivers/fs/vfs.rs index 88d099a..5db85b1 100755 --- a/src/drivers/fs/vfs.rs +++ b/src/drivers/fs/vfs.rs @@ -17,7 +17,8 @@ static mut ROOT_VFS: Vfs = Vfs::null(); #[allow(unused)] pub struct Vfs { mount_point: Option, - next: Option>, + next: Option>, + prev: Option>, pub fs: Option>, vnode_covered: Option>, flags: u32, @@ -32,6 +33,7 @@ impl Vfs { return Self { mount_point: None, next: None, + prev: None, fs: None, vnode_covered: None, flags: 0, @@ -44,6 +46,7 @@ impl Vfs { return Self { mount_point: Some(mount_point.to_string()), next: None, + prev: None, fs: Some(fs), vnode_covered: None, flags: 0, @@ -52,28 +55,15 @@ impl Vfs { }; } - // sketchy and dumb? yes, but it works - fn prev(&self) -> Option<&mut Box> { - let mut cur_vfs = unsafe { ROOT_VFS.next.as_mut() }; - while let Some(vfs) = cur_vfs { - if let Some(next_vfs) = &vfs.next { - if next_vfs.mount_point == self.mount_point { - return Some(vfs); - } - } - - cur_vfs = vfs.next.as_mut(); - } - - None - } - fn del_vfs(&mut self, target_name: &str) { let mut curr = self.next.as_mut(); while let Some(node) = curr { if node.mount_point.as_deref() == Some(target_name) { - node.prev().unwrap().next = node.next.take(); + if let Some(ref mut next_node) = node.next { + next_node.prev = node.prev + } + unsafe { node.prev.unwrap().as_mut().next = node.next.take() }; return; } @@ -81,12 +71,13 @@ impl Vfs { } } - fn add_vfs(&mut self, vfs: Box) { + fn add_vfs(&mut self, mut vfs: Box) { let mut current = self; while let Some(ref mut next_vfs) = current.next { current = next_vfs; } + vfs.prev = Some(current.as_ptr()); current.next = Some(vfs); } @@ -757,12 +748,9 @@ pub fn del_vfs(mount_point: &str) -> Result<(), ()> { unsafe { ROOT_VFS.next = None }; } else { if mount_point_busy(mount_point) { - crate::println!("busy"); return Err(()); } - crate::println!("Deleting VFS"); - unsafe { ROOT_VFS.del_vfs(mount_point) }; } diff --git a/src/main.rs b/src/main.rs index bda831d..c4dd831 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,8 +90,6 @@ pub fn kmain() -> ! { let _ = drivers::fs::vfs::del_vfs("/mnt"); - println!("wa"); - let limine_dir = vfs_open("/mnt/boot/limine").unwrap(); crate::println!(