add prefix tree map to search for mount points
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			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:
		
							parent
							
								
									ec98428697
								
							
						
					
					
						commit
						5303ea4581
					
				@ -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() {
 | 
			
		||||
@ -328,4 +329,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,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 {
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -2,7 +2,7 @@ mod fd;
 | 
			
		||||
pub mod iso9660;
 | 
			
		||||
 | 
			
		||||
use crate::drivers::atapi::read_block;
 | 
			
		||||
use crate::fd::{FDt};
 | 
			
		||||
use crate::fd::FDt;
 | 
			
		||||
use crate::utils::unserialize;
 | 
			
		||||
 | 
			
		||||
use super::FileSystem;
 | 
			
		||||
@ -31,20 +31,18 @@ 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
 | 
			
		||||
            .split("/")
 | 
			
		||||
            .filter(|p| p != &"");
 | 
			
		||||
        let path_it = path_s.split("/").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) {
 | 
			
		||||
                    found = true;
 | 
			
		||||
@ -76,7 +74,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,57 @@ 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 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(path, flags).await;
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    path_split.truncate(path_split.len() - 1);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            None
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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>();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user