Compare commits

...

3 Commits

Author SHA1 Message Date
7a443723e5 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>
2022-12-28 18:50:47 +01:00
5303ea4581 add prefix tree map to search for mount points
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-27 21:38:45 +01:00
ec98428697 add trie map dependency
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-26 21:28:44 +01:00
10 changed files with 75 additions and 26 deletions

7
Cargo.lock generated

@ -168,6 +168,7 @@ dependencies = [
"pc-keyboard",
"pic8259",
"postcard",
"prefix_tree_map",
"serde",
"spin 0.5.2",
"volatile 0.2.7",
@ -254,6 +255,12 @@ dependencies = [
"serde",
]
[[package]]
name = "prefix_tree_map"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff18d4689013a9426f91537e79fcc8ccdb1b8f595a42b510fcbb7687e96f71da"
[[package]]
name = "proc-macro2"
version = "1.0.47"

@ -20,6 +20,7 @@ postcard = "1.0.0"
serde = { version = "1.0", default-features = false, features = ["alloc"] }
heapless = "0.7.16"
async-trait = "0.1.60"
prefix_tree_map = { version = "0.2.1", default-features = false }
[dependencies.lazy_static]
version = "1.0"

@ -58,7 +58,8 @@ static ATAPI_SIG: [u8; 4] = [
];
lazy_static! {
pub static ref DRIVE: AsyncMutex<Option<ATABus>> = AsyncMutex::new(ATABus::discover_atapi_drive());
pub static ref DRIVE: AsyncMutex<Option<ATABus>> =
AsyncMutex::new(ATABus::discover_atapi_drive());
}
pub async fn init() {

@ -37,10 +37,7 @@ impl FDTable {
pub fn unregister_fd(&mut self, fd: &dyn FileDescriptor) {
self.table.remove(&fd.get_fd());
println!(
"Unregistered fd: {:?}",
fd.get_fd()
);
println!("Unregistered fd: {:?}", fd.get_fd());
}
pub fn register_fd(&mut self, fd: FDt) {

@ -11,7 +11,7 @@ pub struct IsoFD {
pub fd: FDId,
offset: u32,
lba: u32,
size: u32
size: u32,
}
impl IsoFD {

@ -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,8 +1,10 @@
mod fd;
pub mod iso9660;
use crate::serial_println;
use crate::drivers::atapi::read_block;
use crate::fd::{FDt};
use crate::fd::FDt;
use crate::utils::unserialize;
use super::FileSystem;
@ -31,26 +33,28 @@ impl FileSystem for IsoFS {
}
let root: &IsoDir = &voldesc.root_dir;
let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE as usize] = read_block(root.data_blk.le).await;
let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE as usize] =
read_block(root.data_blk.le).await;
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
let path_split: Vec<String> = path_s
.split("/")
.filter(|p| p != &"");
.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;
@ -76,7 +80,6 @@ impl FileSystem for IsoFS {
}
}
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc {
let desc_block = read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK).await;
*unserialize::<IsoPrimVolDesc>(desc_block.as_ptr())

@ -3,10 +3,11 @@ pub mod iso;
use crate::fd::FDt;
use crate::utils::mutex::AsyncMutex;
use alloc::{boxed::Box, sync::Arc};
use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec};
use async_trait::async_trait;
use core::cell::RefCell;
use lazy_static::lazy_static;
use prefix_tree_map::{PrefixTreeMap, PrefixTreeMapBuilder};
pub type FSt = Arc<RefCell<dyn FileSystem>>;
@ -20,20 +21,59 @@ pub trait FileSystem {
}
pub struct VirtualFS {
fs: FSt,
map_builder: PrefixTreeMapBuilder<String, String, FSt>,
map: Option<PrefixTreeMap<String, String, FSt>>,
}
impl VirtualFS {
fn new() -> Self {
VirtualFS {
fs: Arc::new(RefCell::new(iso::IsoFS {})),
let mut res = VirtualFS {
map_builder: PrefixTreeMapBuilder::new(),
map: None,
};
let fs = Arc::new(RefCell::new(iso::IsoFS {}));
let fs2 = Arc::new(RefCell::new(iso::IsoFS {}));
res.mount("/", fs);
res.mount("/mnt/iso", fs2);
res
}
fn mount(&mut self, path: &str, fs: FSt) {
let path_s: String = String::from(path);
self.map_builder.insert_exact(
path_s
.split("/")
.filter(|p| p != &"")
.map(|s| String::from(s)),
fs,
);
self.map = Some(self.map_builder.clone().build());
}
}
#[async_trait(?Send)]
impl FileSystem for VirtualFS {
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
self.fs.borrow_mut().open(path, flags).await
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("/")
.filter(|p| p != &"")
.map(|s| String::from(s))
.collect();
loop {
if let Some(fs) = map.find_exact(&path_split) {
// TODO, remove path prefix of the mount point
return fs.borrow_mut().open(mnt_relative_path.as_str(), flags).await;
}
else {
let component = path_split.remove(path_split.len() - 1);
mnt_relative_path = String::from("/") + component.as_str() + mnt_relative_path.as_str();
}
}
} else {
None
}
}
}

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