Remove mount point prefix in virtual FS open
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:
Julien CLEMENT 2022-12-28 18:50:47 +01:00
parent 5303ea4581
commit 7a443723e5
4 changed files with 16 additions and 8 deletions

@ -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()
}
}

@ -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<String> = 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;

@ -55,6 +55,7 @@ impl VirtualFS {
impl FileSystem for VirtualFS {
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
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<String> = 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 {

@ -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];