From 7a443723e52d79e078ef3b858f207d2e608ca131 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Wed, 28 Dec 2022 18:50:47 +0100 Subject: [PATCH] Remove mount point prefix in virtual FS open Signed-off-by: Julien CLEMENT --- src/fs/iso/iso9660.rs | 2 +- src/fs/iso/mod.rs | 14 ++++++++++---- src/fs/mod.rs | 6 ++++-- src/lib.rs | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/fs/iso/iso9660.rs b/src/fs/iso/iso9660.rs index caa653d..825cbfc 100644 --- a/src/fs/iso/iso9660.rs +++ b/src/fs/iso/iso9660.rs @@ -92,7 +92,7 @@ impl IsoDir { } pub fn matches(&self, path: &str) -> bool { - self.get_idf() == path.as_bytes() + self.get_idf().to_ascii_uppercase() == path.as_bytes() } } diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index ee9098e..8cd48dd 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -1,6 +1,8 @@ mod fd; pub mod iso9660; +use crate::serial_println; + use crate::drivers::atapi::read_block; use crate::fd::FDt; use crate::utils::unserialize; @@ -37,18 +39,22 @@ impl FileSystem for IsoFS { let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr()); let path_s: String = String::from(path); - let path_split: Vec<&str> = path_s.split("/").collect(); - let path_it = path_s.split("/").filter(|p| p != &""); + let path_split: Vec = path_s + .split("/") + .filter(|p| p != &"") + .map(|s| s.to_uppercase()) + .collect(); + let path_it = path_split.iter(); for path_component in path_it { let mut found = false; while curr_entry.idf_len != 0 { // Found entry - if curr_entry.matches(path_component) { + if curr_entry.matches(path_component.as_str()) { found = true; // Not the last component, go 1 directory deeper - if path_component != path_split[path_split.len() - 1] { + if path_component.as_str() != path_split[path_split.len() - 1] { // Not a directory if curr_entry.file_type != iso9660::IsoFileType::ISDIR { return None; diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 9fffa68..31d1708 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -55,6 +55,7 @@ impl VirtualFS { impl FileSystem for VirtualFS { async fn open(&mut self, path: &str, flags: u32) -> Option { if let Some(map) = &self.map { + let mut mnt_relative_path: String = String::from(""); let path_s: String = String::from(path); let mut path_split: Vec = path_s .split("/") @@ -64,10 +65,11 @@ impl FileSystem for VirtualFS { loop { if let Some(fs) = map.find_exact(&path_split) { // TODO, remove path prefix of the mount point - return fs.borrow_mut().open(path, flags).await; + return fs.borrow_mut().open(mnt_relative_path.as_str(), flags).await; } else { - path_split.truncate(path_split.len() - 1); + let component = path_split.remove(path_split.len() - 1); + mnt_relative_path = String::from("/") + component.as_str() + mnt_relative_path.as_str(); } } } else { diff --git a/src/lib.rs b/src/lib.rs index 75c4a9a..de964ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,7 +68,7 @@ async fn get_file() { let fd = fs::VIRTUAL_FS .lock() .await - .open("///boot/grub//grub.cfg", syscalls::io::O_RDONLY) + .open("/mnt/iso//boot/grub//grub.cfg", syscalls::io::O_RDONLY) .await .unwrap(); let mut buf: [u8; 100] = [0; 100];