From d66fb31c9a7f914be127c35333c4eff127e49f30 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Thu, 22 Dec 2022 22:03:06 +0100 Subject: [PATCH] starting to work on open(2) Signed-off-by: Julien CLEMENT --- src/fs/iso/mod.rs | 16 +++++++++++++--- src/lib.rs | 3 ++- src/syscalls/io.rs | 7 +++++++ src/syscalls/mod.rs | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/syscalls/io.rs create mode 100644 src/syscalls/mod.rs diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 94ce10c..a1b47d1 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -6,7 +6,7 @@ use crate::drivers::atapi::{DRIVE}; use crate::fd::{FD_TABLE, FDt}; use crate::utils::unserialize; -use iso9660::{IsoPrimVolDesc}; +use iso9660::{IsoPrimVolDesc, IsoDir}; use fd::IsoFD; pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { @@ -20,8 +20,18 @@ pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { *unserialize::(desc_block.as_ptr()) } -pub async fn open() -> FDt { +pub async fn open(path: &str, flags: u32) -> Option { + if flags != crate::syscalls::io::O_RDONLY { + return None; + } + + let voldesc = get_prim_vol_desc().await; + + if voldesc.std_identifier != "CD001".as_bytes() { + return None; + } + let fd = IsoFD::new(); FD_TABLE.lock().await.register_fd(fd.clone()); - fd + Some(fd) } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index a2b8aad..55bb752 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ mod task; mod fs; mod utils; mod fd; +mod syscalls; //#[macro_use] extern crate alloc; @@ -64,6 +65,6 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! { async fn get_file() { - let fd = fs::iso::open().await; + let fd = fs::iso::open("test", syscalls::io::O_RDONLY).await.unwrap(); fd.borrow_mut().read(&[], 0).await; } \ No newline at end of file diff --git a/src/syscalls/io.rs b/src/syscalls/io.rs new file mode 100644 index 0000000..be60c0f --- /dev/null +++ b/src/syscalls/io.rs @@ -0,0 +1,7 @@ +// open flags +pub const O_RDONLY: u32 = 0; + +// seek flags +pub const SEEK_SET: u32 = 0; +pub const SEEK_CUR: u32 = 1; +pub const SEEK_END: u32 = 2; \ No newline at end of file diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs new file mode 100644 index 0000000..678b90e --- /dev/null +++ b/src/syscalls/mod.rs @@ -0,0 +1 @@ +pub mod io; \ No newline at end of file