add register fd and fix bug in mutex
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
Julien CLEMENT 2022-12-23 01:08:00 +01:00
parent d66fb31c9a
commit e5eb05eb3d
7 changed files with 23 additions and 6 deletions

@ -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(); let mut packet = SCSIPacket::new();
packet.op_code = SCSI_READ_12; packet.op_code = SCSI_READ_12;
@ -246,6 +247,8 @@ impl ATABus {
} }
} }
self.wait_command_end(); self.wait_command_end();
self.block
} }
pub async fn read_block(&mut self, lba: u32) -> [u8; CD_SECTOR_SIZE] { 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) { pub async fn print_block(lba: u32) {
let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await; let block = DRIVE.lock().await.as_mut().unwrap().read_block(lba).await;
serial_println!("{:x?}", block); serial_println!("{:x?}", block);

@ -1,3 +1,4 @@
use crate::println;
use crate::utils::AsyncMutex; use crate::utils::AsyncMutex;
use alloc::{collections::BTreeMap, sync::Arc, boxed::Box}; 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); pub struct FDId(u64);
impl FDId { impl FDId {
@ -31,13 +33,16 @@ impl FDTable {
FDTable { table: BTreeMap::new() } FDTable { table: BTreeMap::new() }
} }
pub fn register_fd(&mut self, fd: FDt) { pub async fn register_fd(&mut self, fd: FDt) {
// TODO // TODO
self.table.insert(fd.borrow().get_fd(), fd.clone());
println!("Registered fd: {:?}", self.table.get(&FDId(1)).unwrap().borrow().get_fd());
} }
} }
#[async_trait] #[async_trait]
pub trait FileDescriptor { pub trait FileDescriptor {
fn get_fd(&self) -> FDId;
async fn write(&mut self, buf: &[u8], count: usize) -> isize; async fn write(&mut self, buf: &[u8], count: usize) -> isize;
async fn read(&mut self, buf: &[u8], count: usize) -> isize; async fn read(&mut self, buf: &[u8], count: usize) -> isize;
} }

@ -19,6 +19,10 @@ impl IsoFD {
#[async_trait] #[async_trait]
impl FileDescriptor for IsoFD { impl FileDescriptor for IsoFD {
fn get_fd(&self) -> FDId {
self.fd
}
async fn write(&mut self, buf: &[u8], count: usize) -> isize { async fn write(&mut self, buf: &[u8], count: usize) -> isize {
0 0
} }

@ -32,6 +32,6 @@ pub async fn open(path: &str, flags: u32) -> Option<FDt> {
} }
let fd = IsoFD::new(); let fd = IsoFD::new();
FD_TABLE.lock().await.register_fd(fd.clone()); FD_TABLE.lock().await.register_fd(fd.clone()).await;
Some(fd) Some(fd)
} }

@ -3,6 +3,7 @@ use x86_64::structures::idt::InterruptStackFrame;
static mut TICKS: u64 = 0; static mut TICKS: u64 = 0;
#[allow(dead_code)]
pub fn gettick() -> u64 { pub fn gettick() -> u64 {
unsafe { return TICKS } unsafe { return TICKS }
} }

@ -2,6 +2,9 @@
pub const O_RDONLY: u32 = 0; pub const O_RDONLY: u32 = 0;
// seek flags // seek flags
#[allow(dead_code)]
pub const SEEK_SET: u32 = 0; pub const SEEK_SET: u32 = 0;
#[allow(dead_code)]
pub const SEEK_CUR: u32 = 1; pub const SEEK_CUR: u32 = 1;
#[allow(dead_code)]
pub const SEEK_END: u32 = 2; pub const SEEK_END: u32 = 2;

@ -48,18 +48,18 @@ impl Future for Lock {
type Output = (); type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> { fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
if self.try_lock() { if !self.try_lock() {
return Poll::Ready(()); return Poll::Ready(());
} }
self.waker.register(&cx.waker()); self.waker.register(&cx.waker());
match self.try_lock() { match self.try_lock() {
true => { false => {
self.waker.take(); self.waker.take();
Poll::Ready(()) Poll::Ready(())
}, },
false => Poll::Pending, true => Poll::Pending,
} }
} }
} }