From e5eb05eb3db4ad94dc292a94262c49a9df3985d1 Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Fri, 23 Dec 2022 01:08:00 +0100 Subject: [PATCH] add register fd and fix bug in mutex Signed-off-by: Julien CLEMENT --- src/drivers/atapi/mod.rs | 6 +++++- src/fd/mod.rs | 7 ++++++- src/fs/iso/fd.rs | 4 ++++ src/fs/iso/mod.rs | 2 +- src/interrupts/pic/pit.rs | 1 + src/syscalls/io.rs | 3 +++ src/utils/mutex.rs | 6 +++--- 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/drivers/atapi/mod.rs b/src/drivers/atapi/mod.rs index 8163541..6614374 100644 --- a/src/drivers/atapi/mod.rs +++ b/src/drivers/atapi/mod.rs @@ -211,7 +211,8 @@ impl ATABus { } } - pub fn sync_read_block(&mut self, lba: u32) { + #[allow(dead_code)] + pub fn sync_read_block(&mut self, lba: u32) -> [u8; CD_SECTOR_SIZE] { let mut packet = SCSIPacket::new(); packet.op_code = SCSI_READ_12; @@ -246,6 +247,8 @@ impl ATABus { } } self.wait_command_end(); + + self.block } pub async fn read_block(&mut self, lba: u32) -> [u8; CD_SECTOR_SIZE] { @@ -321,6 +324,7 @@ impl ATABus { } +#[allow(dead_code)] pub async fn print_block(lba: u32) { let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await; serial_println!("{:x?}", block); diff --git a/src/fd/mod.rs b/src/fd/mod.rs index cbcba88..7f1e168 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -1,3 +1,4 @@ +use crate::println; use crate::utils::AsyncMutex; use alloc::{collections::BTreeMap, sync::Arc, boxed::Box}; @@ -13,6 +14,7 @@ lazy_static! { }; } +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct FDId(u64); impl FDId { @@ -31,13 +33,16 @@ impl FDTable { FDTable { table: BTreeMap::new() } } - pub fn register_fd(&mut self, fd: FDt) { + pub async fn register_fd(&mut self, fd: FDt) { // TODO + self.table.insert(fd.borrow().get_fd(), fd.clone()); + println!("Registered fd: {:?}", self.table.get(&FDId(1)).unwrap().borrow().get_fd()); } } #[async_trait] pub trait FileDescriptor { + fn get_fd(&self) -> FDId; async fn write(&mut self, buf: &[u8], count: usize) -> isize; async fn read(&mut self, buf: &[u8], count: usize) -> isize; } \ No newline at end of file diff --git a/src/fs/iso/fd.rs b/src/fs/iso/fd.rs index e37b55c..452f61e 100644 --- a/src/fs/iso/fd.rs +++ b/src/fs/iso/fd.rs @@ -19,6 +19,10 @@ impl IsoFD { #[async_trait] impl FileDescriptor for IsoFD { + fn get_fd(&self) -> FDId { + self.fd + } + async fn write(&mut self, buf: &[u8], count: usize) -> isize { 0 } diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index a1b47d1..48d938f 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -32,6 +32,6 @@ pub async fn open(path: &str, flags: u32) -> Option { } let fd = IsoFD::new(); - FD_TABLE.lock().await.register_fd(fd.clone()); + FD_TABLE.lock().await.register_fd(fd.clone()).await; Some(fd) } \ No newline at end of file diff --git a/src/interrupts/pic/pit.rs b/src/interrupts/pic/pit.rs index feb75cf..23a1cc1 100644 --- a/src/interrupts/pic/pit.rs +++ b/src/interrupts/pic/pit.rs @@ -3,6 +3,7 @@ use x86_64::structures::idt::InterruptStackFrame; static mut TICKS: u64 = 0; +#[allow(dead_code)] pub fn gettick() -> u64 { unsafe { return TICKS } } diff --git a/src/syscalls/io.rs b/src/syscalls/io.rs index be60c0f..a43aa0c 100644 --- a/src/syscalls/io.rs +++ b/src/syscalls/io.rs @@ -2,6 +2,9 @@ pub const O_RDONLY: u32 = 0; // seek flags +#[allow(dead_code)] pub const SEEK_SET: u32 = 0; +#[allow(dead_code)] pub const SEEK_CUR: u32 = 1; +#[allow(dead_code)] pub const SEEK_END: u32 = 2; \ No newline at end of file diff --git a/src/utils/mutex.rs b/src/utils/mutex.rs index 6802dea..d23a7d9 100644 --- a/src/utils/mutex.rs +++ b/src/utils/mutex.rs @@ -48,18 +48,18 @@ impl Future for Lock { type Output = (); fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { - if self.try_lock() { + if !self.try_lock() { return Poll::Ready(()); } self.waker.register(&cx.waker()); match self.try_lock() { - true => { + false => { self.waker.take(); Poll::Ready(()) }, - false => Poll::Pending, + true => Poll::Pending, } } }