Compare commits

..

2 Commits

Author SHA1 Message Date
2e7415e1e6 more refactoring
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-25 13:02:25 +01:00
0ad8ba9adb refacto directory entries traversal
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-25 12:58:56 +01:00
4 changed files with 33 additions and 27 deletions

@ -325,3 +325,7 @@ pub async fn print_block(lba: u32) {
let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await; let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await;
serial_println!("{:x?}", block); serial_println!("{:x?}", block);
} }
pub async fn read_block(lba: u32) -> [u8; CD_SECTOR_SIZE] {
DRIVE.lock().await.as_mut().unwrap().read_block(lba).await
}

@ -75,6 +75,14 @@ impl IsoDir {
pub fn get_idf(&self) -> &[u8] { pub fn get_idf(&self) -> &[u8] {
unsafe { core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) } unsafe { core::slice::from_raw_parts(self.idf.as_ptr(), self.idf_len as usize) }
} }
pub fn next_entry(&self) -> &IsoDir {
crate::utils::ref_raw_offset(self, self.dir_size as isize)
}
pub fn matches(&self, path: &str) -> bool {
self.get_idf() == path.as_bytes()
}
} }
// Primary volume descriptor structure // Primary volume descriptor structure

@ -1,7 +1,7 @@
mod fd; mod fd;
pub mod iso9660; pub mod iso9660;
use crate::drivers::atapi::DRIVE; use crate::drivers::atapi::read_block;
use crate::fd::{FDt, FD_TABLE}; use crate::fd::{FDt, FD_TABLE};
use crate::println; use crate::println;
use crate::serial_println; use crate::serial_println;
@ -32,13 +32,7 @@ impl FileSystem for IsoFS {
} }
let root: IsoDir = voldesc.root_dir; let root: IsoDir = voldesc.root_dir;
let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE] = DRIVE let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE] = read_block(root.data_blk.le).await;
.lock()
.await
.as_mut()
.unwrap()
.read_block(root.data_blk.le)
.await;
let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr()); let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr());
@ -52,24 +46,15 @@ impl FileSystem for IsoFS {
serial_println!("{:?}", curr_entry.idf_len); serial_println!("{:?}", curr_entry.idf_len);
serial_println!("{:?}", alloc::str::from_utf8(curr_entry.get_idf()).unwrap()); serial_println!("{:?}", alloc::str::from_utf8(curr_entry.get_idf()).unwrap());
if curr_entry.get_idf() == path_component.as_bytes() { if curr_entry.matches(path_component) {
serial_println!("Found {}", path_component); serial_println!("Found {}", path_component);
curr_entry_block = DRIVE curr_entry_block = read_block(curr_entry.data_blk.le).await;
.lock()
.await
.as_mut()
.unwrap()
.read_block(curr_entry.data_blk.le)
.await;
curr_entry = unserialize(curr_entry_block.as_ptr()); curr_entry = unserialize(curr_entry_block.as_ptr());
break; break;
} }
// Next entry // Next entry
unsafe { curr_entry = curr_entry.next_entry();
let curr_ptr: *const IsoDir = curr_entry;
curr_entry = &*curr_ptr.cast::<u8>().offset(curr_entry.dir_size as isize).cast::<IsoDir>();
}
} }
} }
@ -79,13 +64,8 @@ impl FileSystem for IsoFS {
} }
} }
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { pub async fn get_prim_vol_desc() -> IsoPrimVolDesc {
let desc_block = DRIVE let desc_block = read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK).await;
.lock()
.await
.as_mut()
.unwrap()
.read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK)
.await;
*unserialize::<IsoPrimVolDesc>(desc_block.as_ptr()) *unserialize::<IsoPrimVolDesc>(desc_block.as_ptr())
} }

@ -3,3 +3,17 @@ pub mod serialize;
pub use mutex::AsyncMutex; pub use mutex::AsyncMutex;
pub use serialize::unserialize; pub use serialize::unserialize;
pub fn ref_offset<T>(r: &T, off: isize) -> &T {
let ref_ptr: *const T = r;
unsafe {
return &*ref_ptr.offset(off);
}
}
pub fn ref_raw_offset<T>(r: &T, off: isize) -> &T {
let ref_ptr: *const T = r;
unsafe {
return &*ref_ptr.cast::<u8>().offset(off).cast::<T>();
}
}