From 91095b7d087dd21069892a8ab596b2ccd00a92b0 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Sat, 24 Dec 2022 16:49:35 +0100 Subject: [PATCH] working on ISO fs open Signed-off-by: Julien CLEMENT --- src/drivers/atapi/mod.rs | 3 +-- src/fd/mod.rs | 2 +- src/fs/iso/iso9660.rs | 32 ++++++++++++++++---------------- src/fs/iso/mod.rs | 23 ++++++++++++++++++++++- src/fs/mod.rs | 2 +- src/lib.rs | 2 +- 6 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/drivers/atapi/mod.rs b/src/drivers/atapi/mod.rs index 6a50729..4f0730a 100644 --- a/src/drivers/atapi/mod.rs +++ b/src/drivers/atapi/mod.rs @@ -58,8 +58,7 @@ static ATAPI_SIG: [u8; 4] = [ ]; lazy_static! { - pub static ref DRIVE: AsyncMutex> = - { AsyncMutex::new(ATABus::discover_atapi_drive()) }; + pub static ref DRIVE: AsyncMutex> = AsyncMutex::new(ATABus::discover_atapi_drive()); } pub async fn init() { diff --git a/src/fd/mod.rs b/src/fd/mod.rs index 4e91a0b..7aaec5e 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -9,7 +9,7 @@ use lazy_static::lazy_static; pub type FDt = Arc>; lazy_static! { - pub static ref FD_TABLE: AsyncMutex = { AsyncMutex::new(FDTable::new()) }; + pub static ref FD_TABLE: AsyncMutex = AsyncMutex::new(FDTable::new()); } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] diff --git a/src/fs/iso/iso9660.rs b/src/fs/iso/iso9660.rs index d3b42b7..663c03a 100644 --- a/src/fs/iso/iso9660.rs +++ b/src/fs/iso/iso9660.rs @@ -5,15 +5,15 @@ const ISO_BLOCK_SIZE: usize = 2048; #[repr(C, packed)] #[derive(Copy, Clone)] pub struct MultiEndian32 { - le: u32, // Little endian value - be: u32, // Big endian value + pub le: u32, // Little endian value + pub be: u32, // Big endian value } #[repr(C, packed)] #[derive(Copy, Clone)] pub struct MultiEndian16 { - le: u16, // Little endian value - be: u16, // Big endian value + pub le: u16, // Little endian value + pub be: u16, // Big endian value } // Path table structure @@ -41,7 +41,7 @@ const ISO_DATE_LEN: usize = 7; #[repr(u8)] #[derive(Copy, Clone)] -enum IsoFileType { +pub enum IsoFileType { HIDDEN = 0x1, // Hidden file ISDIR = 0x2, // Directory ASSOCIAT = 0x4, // Associated @@ -53,20 +53,20 @@ enum IsoFileType { #[repr(C, packed)] #[derive(Copy, Clone)] pub struct IsoDir { - dir_size: u8, // Length of directory record - ext_size: u8, // Length of extended attribute record - data_blk: MultiEndian32, // File data block index - file_size: MultiEndian32, // File size - date: [u8; ISO_DATE_LEN], - file_type: IsoFileType, + pub dir_size: u8, // Length of directory record + pub ext_size: u8, // Length of extended attribute record + pub data_blk: MultiEndian32, // File data block index + pub file_size: MultiEndian32, // File size + pub date: [u8; ISO_DATE_LEN], + pub file_type: IsoFileType, - unit_size: u8, - gap_size: u8, + pub unit_size: u8, + pub gap_size: u8, - vol_seq: MultiEndian16, + pub vol_seq: MultiEndian16, - idf_len: u8, // File name length - idf: [u8; 0], // File name + pub idf_len: u8, // File name length + pub idf: [u8; 0], // File name } impl IsoDir { diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 80a97ff..6336383 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -10,7 +10,7 @@ use super::FileSystem; use fd::IsoFD; use iso9660::{IsoDir, IsoPrimVolDesc}; -use alloc::{boxed::Box, sync::Arc}; +use alloc::{boxed::Box, sync::Arc, string::String, vec::Vec}; use async_trait::async_trait; pub struct IsoFS {} @@ -18,16 +18,37 @@ pub struct IsoFS {} #[async_trait(?Send)] impl FileSystem for IsoFS { async fn open(&mut self, path: &str, flags: u32) -> Option { + // ISO is a read only file system if flags != crate::syscalls::io::O_RDONLY { return None; } let voldesc = get_prim_vol_desc().await; + // Invalid ISO if voldesc.std_identifier != "CD001".as_bytes() { return None; } + let root: IsoDir = voldesc.root_dir; + let curr_entry_block: [u8; 2048] = DRIVE + .lock() + .await + .as_mut() + .unwrap() + .read_block(root.data_blk.le) + .await; + + let curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr()); + + let path_s: String = String::from(path); + let split_path: Vec<&str> = path_s + .split("/") + .filter(|p| p != &"") + .collect(); + + println!("{:?}", split_path); + let fd = IsoFD::new(); FD_TABLE.lock().await.register_fd(fd.clone()); Some(fd.clone()) diff --git a/src/fs/mod.rs b/src/fs/mod.rs index 8ab3b1f..e9f9d44 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -11,7 +11,7 @@ use lazy_static::lazy_static; pub type FSt = Arc>; lazy_static! { - pub static ref VIRTUAL_FS: AsyncMutex = { AsyncMutex::new(VirtualFS::new()) }; + pub static ref VIRTUAL_FS: AsyncMutex = AsyncMutex::new(VirtualFS::new()); } #[async_trait(?Send)] diff --git a/src/lib.rs b/src/lib.rs index 70c4b6a..b050757 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,7 +68,7 @@ async fn get_file() { let fd = fs::VIRTUAL_FS .lock() .await - .open("test", syscalls::io::O_RDONLY) + .open("///boot///grub.cfg", syscalls::io::O_RDONLY) .await .unwrap(); fd.borrow_mut().read(&[], 0).await;