add register fd and fix bug in mutex
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			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:
		
							parent
							
								
									d66fb31c9a
								
							
						
					
					
						commit
						e5eb05eb3d
					
				@ -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);
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
}
 | 
			
		||||
@ -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
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,6 @@ pub async fn open(path: &str, flags: u32) -> Option<FDt> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let fd = IsoFD::new();
 | 
			
		||||
    FD_TABLE.lock().await.register_fd(fd.clone());
 | 
			
		||||
    FD_TABLE.lock().await.register_fd(fd.clone()).await;
 | 
			
		||||
    Some(fd)
 | 
			
		||||
}
 | 
			
		||||
@ -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 }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
@ -48,18 +48,18 @@ impl Future for Lock {
 | 
			
		||||
    type Output = ();
 | 
			
		||||
 | 
			
		||||
    fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
 | 
			
		||||
        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,
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user