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",
"pic8259",
"postcard",
"prefix_tree_map",
"serde",
"spin 0.5.2",
"volatile 0.2.7",
@ -255,12 +254,6 @@ 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,7 +20,6 @@ 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,8 +58,7 @@ 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() {
@ -329,4 +328,4 @@ pub async fn print_block(lba: u32) {
pub async fn read_block(lba: u32) -> [u8; CD_SECTOR_SIZE] {
DRIVE.lock().await.as_mut().unwrap().read_block(lba).await
}
}

@ -37,7 +37,10 @@ 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 {

@ -77,7 +77,7 @@ impl IsoDir {
#[allow(unaligned_references)]
pub fn get_idf(&self) -> &[u8] {
let mut len: usize = self.idf_len as usize;
unsafe {
unsafe {
let mut idf = core::slice::from_raw_parts(self.idf.as_ptr(), len as usize);
if len > 2 && idf[len - 2] == b';' && idf[len - 1] == b'1' {
len -= 2;
@ -92,7 +92,7 @@ impl IsoDir {
}
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;
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;
@ -33,28 +31,26 @@ 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<String> = path_s
let path_split: Vec<&str> = path_s.split("/").collect();
let path_it = path_s
.split("/")
.filter(|p| p != &"")
.map(|s| s.to_uppercase())
.collect();
let path_it = path_split.iter();
.filter(|p| p != &"");
for path_component in path_it {
let mut found = false;
while curr_entry.idf_len != 0 {
// Found entry
if curr_entry.matches(path_component.as_str()) {
if curr_entry.matches(path_component) {
found = true;
// 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
if curr_entry.file_type != iso9660::IsoFileType::ISDIR {
return None;
@ -80,6 +76,7 @@ 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,11 +3,10 @@ pub mod iso;
use crate::fd::FDt;
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 core::cell::RefCell;
use lazy_static::lazy_static;
use prefix_tree_map::{PrefixTreeMap, PrefixTreeMapBuilder};
pub type FSt = Arc<RefCell<dyn FileSystem>>;
@ -21,59 +20,20 @@ pub trait FileSystem {
}
pub struct VirtualFS {
map_builder: PrefixTreeMapBuilder<String, String, FSt>,
map: Option<PrefixTreeMap<String, String, FSt>>,
fs: FSt,
}
impl VirtualFS {
fn new() -> Self {
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());
VirtualFS {
fs: Arc::new(RefCell::new(iso::IsoFS {})),
}
}
}
#[async_trait(?Send)]
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("/")
.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
}
self.fs.borrow_mut().open(path, flags).await
}
}

@ -68,7 +68,7 @@ async fn get_file() {
let fd = fs::VIRTUAL_FS
.lock()
.await
.open("/mnt/iso//boot/grub//grub.cfg", syscalls::io::O_RDONLY)
.open("///boot/grub//grub.cfg", syscalls::io::O_RDONLY)
.await
.unwrap();
let mut buf: [u8; 100] = [0; 100];

@ -16,4 +16,4 @@ pub fn ref_raw_offset<T>(r: &T, off: isize) -> &T {
unsafe {
return &*ref_ptr.cast::<u8>().offset(off).cast::<T>();
}
}
}