Compare commits

...

2 Commits

Author SHA1 Message Date
0c0af6414e Primary volume descriptor unserialization
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-19 20:47:33 +01:00
dcaea4454b refacto unserialize
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-19 20:25:52 +01:00
6 changed files with 64 additions and 54 deletions

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

@ -27,14 +27,6 @@ struct IsoPathTable {
}
impl IsoPathTable {
pub fn from(mapping: &u8) -> &Self {
let ptr: *const u8 = mapping;
let path_table_ptr: *const Self = ptr as *const Self;
unsafe {
&*path_table_ptr
}
}
#[allow(unaligned_references)]
pub fn get_idf(&self) -> &[u8] {
unsafe {
@ -77,14 +69,6 @@ pub struct IsoDir {
}
impl IsoDir {
pub fn from(mapping: &u8) -> &Self {
let ptr: *const u8 = mapping;
let path_table_ptr: *const Self = ptr as *const Self;
unsafe {
&*path_table_ptr
}
}
#[allow(unaligned_references)]
pub fn get_idf(&self) -> &[u8] {
unsafe {
@ -96,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;
@ -111,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::<IsoDir>()], // Padding
pub _unused4: [u8; 34 - core::mem::size_of::<IsoDir>()], // 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)
}

@ -1 +1,18 @@
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::<IsoPrimVolDesc>(desc_block.as_ptr());
serial_println!("{:?}", prim_vol_desc.std_identifier);
}

@ -8,6 +8,7 @@ mod interrupts;
mod memory;
mod task;
mod fs;
mod utils;
//#[macro_use]
extern crate alloc;
@ -56,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::<IsoPrimVolDesc>());
serial_println!("{}", core::mem::size_of::<IsoDir>());
serial_println!("{}", core::mem::size_of::<MultiEndian32>());
let mut executor = Executor::new();
executor.spawn(Task::new(keyboard::print_keypresses()));
executor.spawn(Task::new(fs::iso::init_prim_vol_desc()));
executor.run();
}

3
src/utils/mod.rs Normal file

@ -0,0 +1,3 @@
pub mod serialize;
pub use serialize::unserialize;

6
src/utils/serialize.rs Normal file

@ -0,0 +1,6 @@
pub fn unserialize<T>(ptr: *const u8) -> &'static T {
let path_table_ptr: *const T = ptr as *const T;
unsafe {
&*path_table_ptr
}
}