Compare commits

..

No commits in common. "7a443723e52d79e078ef3b858f207d2e608ca131" and "184030a45e0f8ddc4256bf67d6efbf334f89897c" have entirely different histories.

10 changed files with 26 additions and 75 deletions

7
Cargo.lock generated

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

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

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

@ -37,7 +37,10 @@ impl FDTable {
pub fn unregister_fd(&mut self, fd: &dyn FileDescriptor) { pub fn unregister_fd(&mut self, fd: &dyn FileDescriptor) {
self.table.remove(&fd.get_fd()); 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) { pub fn register_fd(&mut self, fd: FDt) {

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

@ -92,7 +92,7 @@ impl IsoDir {
} }
pub fn matches(&self, path: &str) -> bool { pub fn matches(&self, path: &str) -> bool {
self.get_idf().to_ascii_uppercase() == path.as_bytes() self.get_idf() == path.as_bytes()
} }
} }

@ -1,10 +1,8 @@
mod fd; mod fd;
pub mod iso9660; pub mod iso9660;
use crate::serial_println;
use crate::drivers::atapi::read_block; use crate::drivers::atapi::read_block;
use crate::fd::FDt; use crate::fd::{FDt};
use crate::utils::unserialize; use crate::utils::unserialize;
use super::FileSystem; use super::FileSystem;
@ -33,28 +31,26 @@ impl FileSystem for IsoFS {
} }
let root: &IsoDir = &voldesc.root_dir; let root: &IsoDir = &voldesc.root_dir;
let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE as usize] = let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE as usize] = read_block(root.data_blk.le).await;
read_block(root.data_blk.le).await;
let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr()); let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr());
let path_s: String = String::from(path); let path_s: String = String::from(path);
let path_split: Vec<String> = path_s let path_split: Vec<&str> = path_s.split("/").collect();
let path_it = path_s
.split("/") .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 { for path_component in path_it {
let mut found = false; let mut found = false;
while curr_entry.idf_len != 0 { while curr_entry.idf_len != 0 {
// Found entry // Found entry
if curr_entry.matches(path_component.as_str()) { if curr_entry.matches(path_component) {
found = true; found = true;
// Not the last component, go 1 directory deeper // Not the last component, go 1 directory deeper
if path_component.as_str() != path_split[path_split.len() - 1] { if path_component != path_split[path_split.len() - 1] {
// Not a directory // Not a directory
if curr_entry.file_type != iso9660::IsoFileType::ISDIR { if curr_entry.file_type != iso9660::IsoFileType::ISDIR {
return None; return None;
@ -80,6 +76,7 @@ impl FileSystem for IsoFS {
} }
} }
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { pub async fn get_prim_vol_desc() -> IsoPrimVolDesc {
let desc_block = read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK).await; let desc_block = read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK).await;
*unserialize::<IsoPrimVolDesc>(desc_block.as_ptr()) *unserialize::<IsoPrimVolDesc>(desc_block.as_ptr())

@ -3,11 +3,10 @@ pub mod iso;
use crate::fd::FDt; use crate::fd::FDt;
use crate::utils::mutex::AsyncMutex; use crate::utils::mutex::AsyncMutex;
use alloc::{boxed::Box, string::String, sync::Arc, vec::Vec}; use alloc::{boxed::Box, sync::Arc};
use async_trait::async_trait; use async_trait::async_trait;
use core::cell::RefCell; use core::cell::RefCell;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use prefix_tree_map::{PrefixTreeMap, PrefixTreeMapBuilder};
pub type FSt = Arc<RefCell<dyn FileSystem>>; pub type FSt = Arc<RefCell<dyn FileSystem>>;
@ -21,59 +20,20 @@ pub trait FileSystem {
} }
pub struct VirtualFS { pub struct VirtualFS {
map_builder: PrefixTreeMapBuilder<String, String, FSt>, fs: FSt,
map: Option<PrefixTreeMap<String, String, FSt>>,
} }
impl VirtualFS { impl VirtualFS {
fn new() -> Self { fn new() -> Self {
let mut res = VirtualFS { VirtualFS {
map_builder: PrefixTreeMapBuilder::new(), fs: Arc::new(RefCell::new(iso::IsoFS {})),
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)] #[async_trait(?Send)]
impl FileSystem for VirtualFS { impl FileSystem for VirtualFS {
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> { async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
if let Some(map) = &self.map { self.fs.borrow_mut().open(path, flags).await
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 let fd = fs::VIRTUAL_FS
.lock() .lock()
.await .await
.open("/mnt/iso//boot/grub//grub.cfg", syscalls::io::O_RDONLY) .open("///boot/grub//grub.cfg", syscalls::io::O_RDONLY)
.await .await
.unwrap(); .unwrap();
let mut buf: [u8; 100] = [0; 100]; let mut buf: [u8; 100] = [0; 100];