From 0c0af6414efaf969feb956554a795633a46ca862 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Mon, 19 Dec 2022 20:47:33 +0100 Subject: [PATCH] Primary volume descriptor unserialization Signed-off-by: Julien CLEMENT --- src/drivers/atapi/mod.rs | 4 ++- src/fs/iso/iso9660.rs | 64 ++++++++++++++++++++-------------------- src/fs/iso/mod.rs | 19 +++++++++++- src/lib.rs | 5 +--- src/utils/serialize.rs | 3 +- 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/drivers/atapi/mod.rs b/src/drivers/atapi/mod.rs index e3ff635..cf31e3e 100644 --- a/src/drivers/atapi/mod.rs +++ b/src/drivers/atapi/mod.rs @@ -248,7 +248,7 @@ impl ATABus { self.wait_command_end(); } - pub async fn read_block(&mut self, lba: u32) { + pub async fn read_block(&mut self, lba: u32) -> [u8; CD_SECTOR_SIZE] { let mut packet = SCSIPacket::new(); packet.op_code = SCSI_READ_12; @@ -277,6 +277,8 @@ impl ATABus { //(*INTERRUPT_FUTURE).await; self.wait_command_end(); + + self.block } fn wait_busy(&mut self) { diff --git a/src/fs/iso/iso9660.rs b/src/fs/iso/iso9660.rs index ac7fc16..37ba49b 100644 --- a/src/fs/iso/iso9660.rs +++ b/src/fs/iso/iso9660.rs @@ -80,7 +80,7 @@ impl IsoDir { // Primary volume descriptor structure -const ISO_PRIM_VOLDESC_BLOCK: usize = 16; +pub const ISO_PRIM_VOLDESC_BLOCK: u32 = 16; const ISO_SYSIDF_LEN: usize = 32; const ISO_VOLIDF_LEN: usize = 32; @@ -95,47 +95,47 @@ const ISO_LDATE_LEN: usize = 17; #[repr(C, packed)] pub struct IsoPrimVolDesc { - vol_desc_type: u8, // Volume descripto type (1) - std_identifier: [u8; 5], // standard identifier ("CD001") - vol_desc_version: u8, // Volume descriptor version (1) + pub vol_desc_type: u8, // Volume descripto type (1) + pub std_identifier: [u8; 5], // standard identifier ("CD001") + pub vol_desc_version: u8, // Volume descriptor version (1) - _unused1: u8, + pub _unused1: u8, - sys_idf: [u8; ISO_SYSIDF_LEN], // System identifier - vol_idf: [u8; ISO_VOLIDF_LEN], // Volume identifier + pub sys_idf: [u8; ISO_SYSIDF_LEN], // System identifier + pub vol_idf: [u8; ISO_VOLIDF_LEN], // Volume identifier - _unused2: [u8; 8], + pub _unused2: [u8; 8], - vol_blk_count: MultiEndian32, // Number of logical blocks in the volume + pub vol_blk_count: MultiEndian32, // Number of logical blocks in the volume - _unused3: [u8; 32], + pub _unused3: [u8; 32], - vol_set_size: MultiEndian16, // The Volume Set size of the volume - vol_seq_num: MultiEndian16, // The number of the volume in the set - vol_blk_size: MultiEndian16, // The size in bytes of a logical block + pub vol_set_size: MultiEndian16, // The Volume Set size of the volume + pub vol_seq_num: MultiEndian16, // The number of the volume in the set + pub vol_blk_size: MultiEndian16, // The size in bytes of a logical block - path_table_size: MultiEndian32, // Length in bytes of the path table - le_path_table_blk: u32, // Path table block index little endian - le_opt_path_table_blk: u32, // Optionnal path table block index little endian - be_path_table_blk: u32, - be_opt_path_table_blk: u32, + pub path_table_size: MultiEndian32, // Length in bytes of the path table + pub le_path_table_blk: u32, // Path table block index little endian + pub le_opt_path_table_blk: u32, // Optionnal path table block index little endian + pub be_path_table_blk: u32, + pub be_opt_path_table_blk: u32, - root_dir: IsoDir, // Root directory entry + pub root_dir: IsoDir, // Root directory entry - _unused4: [u8; 34 - core::mem::size_of::()], // Padding + pub _unused4: [u8; 34 - core::mem::size_of::()], // Padding - volset_idf: [u8; ISO_VOLSET_LEN], // name of the multiple volume set - pub_idf: [u8; ISO_PUBIDF_LEN], // Publisher name - dprep_idf: [u8; ISO_DPREP_LEN], // Data preparer name - app_idf: [u8; ISO_APP_LEN], // Application name + pub volset_idf: [u8; ISO_VOLSET_LEN], // name of the multiple volume set + pub pub_idf: [u8; ISO_PUBIDF_LEN], // Publisher name + pub dprep_idf: [u8; ISO_DPREP_LEN], // Data preparer name + pub app_idf: [u8; ISO_APP_LEN], // Application name - copyright_file: [u8; ISO_CPRFIL_LEN], // Copyright file name in root dir - abstract_file: [u8; ISO_ABSFIL_LEN], // Abstract file name in root dir - bibli_file: [u8; ISO_BIBFIL_LEN], // Bibliograpgic file name in root dir - date_creat: [u8; ISO_LDATE_LEN], // Creation date - date_modif: [u8; ISO_LDATE_LEN], // Modification date - date_expir: [u8; ISO_LDATE_LEN], // Expiration date - date_effect: [u8; ISO_LDATE_LEN], // Effective date + pub copyright_file: [u8; ISO_CPRFIL_LEN], // Copyright file name in root dir + pub abstract_file: [u8; ISO_ABSFIL_LEN], // Abstract file name in root dir + pub bibli_file: [u8; ISO_BIBFIL_LEN], // Bibliograpgic file name in root dir + pub date_creat: [u8; ISO_LDATE_LEN], // Creation date + pub date_modif: [u8; ISO_LDATE_LEN], // Modification date + pub date_expir: [u8; ISO_LDATE_LEN], // Expiration date + pub date_effect: [u8; ISO_LDATE_LEN], // Effective date - file_struct_version: u8, // File structure version (1) + pub file_struct_version: u8, // File structure version (1) } \ No newline at end of file diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 9432660..19f997a 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -1 +1,18 @@ -pub mod iso9660; \ No newline at end of file +pub mod iso9660; + +use crate::serial_println; +use crate::drivers::atapi::{DRIVE}; +use crate::utils::unserialize; +use iso9660::{IsoPrimVolDesc}; + +pub async fn init_prim_vol_desc() { + let desc_block = DRIVE + .lock() + .as_mut() + .unwrap() + .read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK) + .await; + let prim_vol_desc: &IsoPrimVolDesc = unserialize::(desc_block.as_ptr()); + + serial_println!("{:?}", prim_vol_desc.std_identifier); +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index f8db8e1..58db943 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,11 +57,8 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! { println!("***JuliOS V0.1.0***"); serial_println!("Hello serial"); - serial_println!("{}", core::mem::size_of::()); - serial_println!("{}", core::mem::size_of::()); - serial_println!("{}", core::mem::size_of::()); - let mut executor = Executor::new(); executor.spawn(Task::new(keyboard::print_keypresses())); + executor.spawn(Task::new(fs::iso::init_prim_vol_desc())); executor.run(); } diff --git a/src/utils/serialize.rs b/src/utils/serialize.rs index bfb075e..6ddac65 100644 --- a/src/utils/serialize.rs +++ b/src/utils/serialize.rs @@ -1,5 +1,4 @@ -pub fn unserialize(mapping: &u8) -> &T { - let ptr: *const u8 = mapping; +pub fn unserialize(ptr: *const u8) -> &'static T { let path_table_ptr: *const T = ptr as *const T; unsafe { &*path_table_ptr