diff --git a/src/drivers/atapi/mod.rs b/src/drivers/atapi/mod.rs index 84dbd77..8163541 100644 --- a/src/drivers/atapi/mod.rs +++ b/src/drivers/atapi/mod.rs @@ -8,7 +8,6 @@ use interrupt::{INTERRUPT_FUTURE}; use core::convert::TryInto; use lazy_static::lazy_static; -use spin::Mutex; use crate::utils::AsyncMutex; use x86_64::instructions::port::Port; diff --git a/src/fd/mod.rs b/src/fd/mod.rs new file mode 100644 index 0000000..7573b08 --- /dev/null +++ b/src/fd/mod.rs @@ -0,0 +1,41 @@ +use crate::utils::AsyncMutex; + +use alloc::{collections::BTreeMap, sync::Arc}; +use core::cell::RefCell; +use lazy_static::lazy_static; + +pub type FDt = Arc>; + +lazy_static! { + pub static ref FD_TABLE: AsyncMutex = { + AsyncMutex::new(FDTable::new()) + }; +} + +pub struct FDId(u64); + +impl FDId { + pub fn new() -> Self { + // TODO: search for first available fd + FDId(1) + } +} + +pub struct FDTable { + table: BTreeMap, +} + +impl FDTable { + pub fn new() -> Self { + FDTable { table: BTreeMap::new() } + } + + pub fn register_fd(&mut self, fd: FDt) { + // TODO + } +} + +pub trait FileDescriptor { + fn write(&mut self, buf: *const u8, count: usize) -> isize; + fn read(&mut self, buf: *mut u8, count: usize) -> isize; +} \ No newline at end of file diff --git a/src/fs/iso/fd.rs b/src/fs/iso/fd.rs new file mode 100644 index 0000000..15694a2 --- /dev/null +++ b/src/fs/iso/fd.rs @@ -0,0 +1,28 @@ +use crate::println; +use crate::fd::{FDId, FileDescriptor, FDt}; + +use alloc::sync::Arc; +use core::cell::RefCell; + +pub struct IsoFD { + pub fd: FDId, +} + +impl IsoFD { + pub fn new() -> FDt { + Arc::new(RefCell::new(IsoFD { + fd: FDId::new(), + })) + } +} + +impl FileDescriptor for IsoFD { + fn write(&mut self, buf: *const u8, count: usize) -> isize { + 0 + } + + fn read(&mut self, buf: *mut u8, count: usize) -> isize { + println!("Read from fd"); + 0 + } +} \ No newline at end of file diff --git a/src/fs/iso/iso9660.rs b/src/fs/iso/iso9660.rs index 37ba49b..1903983 100644 --- a/src/fs/iso/iso9660.rs +++ b/src/fs/iso/iso9660.rs @@ -3,12 +3,14 @@ const ISO_BLOCK_SIZE: usize = 2048; // Twin values structs #[repr(C, packed)] +#[derive(Copy, Clone)] pub struct MultiEndian32 { le: u32, // Little endian value be: u32, // Big endian value } #[repr(C, packed)] +#[derive(Copy, Clone)] pub struct MultiEndian16 { le: u16, // Little endian value be: u16, // Big endian value @@ -18,6 +20,7 @@ pub struct MultiEndian16 { // Path table structure #[repr(C, packed)] +#[derive(Copy, Clone)] struct IsoPathTable { idf_len: u8, // Identifier name length ext_size: u8, // Extended attribute record length @@ -41,6 +44,7 @@ impl IsoPathTable { const ISO_DATE_LEN: usize = 7; #[repr(u8)] +#[derive(Copy, Clone)] enum IsoFileType { HIDDEN = 0x1, // Hidden file ISDIR = 0x2, // Directory @@ -51,6 +55,7 @@ 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 @@ -94,6 +99,7 @@ const ISO_BIBFIL_LEN: usize = 37; const ISO_LDATE_LEN: usize = 17; #[repr(C, packed)] +#[derive(Copy, Clone)] pub struct IsoPrimVolDesc { pub vol_desc_type: u8, // Volume descripto type (1) pub std_identifier: [u8; 5], // standard identifier ("CD001") diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index d6310ad..851aa8c 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -1,11 +1,17 @@ pub mod iso9660; +mod fd; use crate::println; use crate::drivers::atapi::{DRIVE}; +use crate::fd::{FDId, FD_TABLE, FDt}; use crate::utils::unserialize; -use iso9660::{IsoPrimVolDesc}; -pub async fn init_prim_vol_desc() { +use iso9660::{IsoPrimVolDesc}; +use fd::IsoFD; + +use alloc::sync::Arc; + +pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { let desc_block = DRIVE .lock() .await @@ -13,7 +19,11 @@ pub async fn init_prim_vol_desc() { .unwrap() .read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK) .await; - let prim_vol_desc: &IsoPrimVolDesc = unserialize::(desc_block.as_ptr()); + *unserialize::(desc_block.as_ptr()) +} - println!("{:?}", alloc::string::String::from_utf8_lossy(&prim_vol_desc.std_identifier)); +pub async fn open() -> FDt { + let fd = IsoFD::new(); + FD_TABLE.lock().await.register_fd(fd.clone()); + fd } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index a8d3b5a..5bd53fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ mod memory; mod task; mod fs; mod utils; +mod fd; //#[macro_use] extern crate alloc; @@ -57,6 +58,12 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! { let mut executor = Executor::new(); executor.spawn(Task::new(drivers::atapi::init())); executor.spawn(Task::new(keyboard::print_keypresses())); - executor.spawn(Task::new(fs::iso::init_prim_vol_desc())); + executor.spawn(Task::new(get_file())); executor.run(); } + + +async fn get_file() { + let fd = fs::iso::open().await; + fd.borrow_mut().read(0 as *mut u8, 0); +} \ No newline at end of file