working on ISO fs open
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:
Julien CLEMENT 2022-12-24 16:49:35 +01:00
parent 43eec9621c
commit 91095b7d08
6 changed files with 42 additions and 22 deletions

@ -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() {

@ -9,7 +9,7 @@ use lazy_static::lazy_static;
pub type FDt = Arc<RefCell<dyn FileDescriptor>>; pub type FDt = Arc<RefCell<dyn FileDescriptor>>;
lazy_static! { lazy_static! {
pub static ref FD_TABLE: AsyncMutex<FDTable> = { AsyncMutex::new(FDTable::new()) }; pub static ref FD_TABLE: AsyncMutex<FDTable> = AsyncMutex::new(FDTable::new());
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]

@ -5,15 +5,15 @@ const ISO_BLOCK_SIZE: usize = 2048;
#[repr(C, packed)] #[repr(C, packed)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct MultiEndian32 { pub struct MultiEndian32 {
le: u32, // Little endian value pub le: u32, // Little endian value
be: u32, // Big endian value pub be: u32, // Big endian value
} }
#[repr(C, packed)] #[repr(C, packed)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct MultiEndian16 { pub struct MultiEndian16 {
le: u16, // Little endian value pub le: u16, // Little endian value
be: u16, // Big endian value pub be: u16, // Big endian value
} }
// Path table structure // Path table structure
@ -41,7 +41,7 @@ const ISO_DATE_LEN: usize = 7;
#[repr(u8)] #[repr(u8)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
enum IsoFileType { pub enum IsoFileType {
HIDDEN = 0x1, // Hidden file HIDDEN = 0x1, // Hidden file
ISDIR = 0x2, // Directory ISDIR = 0x2, // Directory
ASSOCIAT = 0x4, // Associated ASSOCIAT = 0x4, // Associated
@ -53,20 +53,20 @@ enum IsoFileType {
#[repr(C, packed)] #[repr(C, packed)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct IsoDir { pub struct IsoDir {
dir_size: u8, // Length of directory record pub dir_size: u8, // Length of directory record
ext_size: u8, // Length of extended attribute record pub ext_size: u8, // Length of extended attribute record
data_blk: MultiEndian32, // File data block index pub data_blk: MultiEndian32, // File data block index
file_size: MultiEndian32, // File size pub file_size: MultiEndian32, // File size
date: [u8; ISO_DATE_LEN], pub date: [u8; ISO_DATE_LEN],
file_type: IsoFileType, pub file_type: IsoFileType,
unit_size: u8, pub unit_size: u8,
gap_size: u8, pub gap_size: u8,
vol_seq: MultiEndian16, pub vol_seq: MultiEndian16,
idf_len: u8, // File name length pub idf_len: u8, // File name length
idf: [u8; 0], // File name pub idf: [u8; 0], // File name
} }
impl IsoDir { impl IsoDir {

@ -10,7 +10,7 @@ use super::FileSystem;
use fd::IsoFD; use fd::IsoFD;
use iso9660::{IsoDir, IsoPrimVolDesc}; 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; use async_trait::async_trait;
pub struct IsoFS {} pub struct IsoFS {}
@ -18,16 +18,37 @@ pub struct IsoFS {}
#[async_trait(?Send)] #[async_trait(?Send)]
impl FileSystem for IsoFS { impl FileSystem for IsoFS {
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> { async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
// ISO is a read only file system
if flags != crate::syscalls::io::O_RDONLY { if flags != crate::syscalls::io::O_RDONLY {
return None; return None;
} }
let voldesc = get_prim_vol_desc().await; let voldesc = get_prim_vol_desc().await;
// Invalid ISO
if voldesc.std_identifier != "CD001".as_bytes() { if voldesc.std_identifier != "CD001".as_bytes() {
return None; 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(); let fd = IsoFD::new();
FD_TABLE.lock().await.register_fd(fd.clone()); FD_TABLE.lock().await.register_fd(fd.clone());
Some(fd.clone()) Some(fd.clone())

@ -11,7 +11,7 @@ use lazy_static::lazy_static;
pub type FSt = Arc<RefCell<dyn FileSystem>>; pub type FSt = Arc<RefCell<dyn FileSystem>>;
lazy_static! { lazy_static! {
pub static ref VIRTUAL_FS: AsyncMutex<VirtualFS> = { AsyncMutex::new(VirtualFS::new()) }; pub static ref VIRTUAL_FS: AsyncMutex<VirtualFS> = AsyncMutex::new(VirtualFS::new());
} }
#[async_trait(?Send)] #[async_trait(?Send)]

@ -68,7 +68,7 @@ async fn get_file() {
let fd = fs::VIRTUAL_FS let fd = fs::VIRTUAL_FS
.lock() .lock()
.await .await
.open("test", syscalls::io::O_RDONLY) .open("///boot///grub.cfg", syscalls::io::O_RDONLY)
.await .await
.unwrap(); .unwrap();
fd.borrow_mut().read(&[], 0).await; fd.borrow_mut().read(&[], 0).await;