working on ISO fs open
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
43eec9621c
commit
91095b7d08
@ -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() {
|
||||
|
@ -9,7 +9,7 @@ use lazy_static::lazy_static;
|
||||
pub type FDt = Arc<RefCell<dyn FileDescriptor>>;
|
||||
|
||||
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)]
|
||||
|
@ -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 {
|
||||
|
@ -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<FDt> {
|
||||
// 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())
|
||||
|
@ -11,7 +11,7 @@ use lazy_static::lazy_static;
|
||||
pub type FSt = Arc<RefCell<dyn FileSystem>>;
|
||||
|
||||
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)]
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user