Trying to implement FileSystem trait
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
e5eb05eb3d
commit
b9e49dd946
@ -6,7 +6,7 @@ use async_trait::async_trait;
|
||||
use core::cell::RefCell;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
pub type FDt = Arc<RefCell<dyn FileDescriptor>>;
|
||||
pub type FDt = Arc<AsyncMutex<dyn FileDescriptor>>;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref FD_TABLE: AsyncMutex<FDTable> = {
|
||||
@ -33,7 +33,7 @@ impl FDTable {
|
||||
FDTable { table: BTreeMap::new() }
|
||||
}
|
||||
|
||||
pub async fn register_fd(&mut self, fd: FDt) {
|
||||
pub 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());
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::println;
|
||||
use crate::fd::{FDId, FileDescriptor, FDt};
|
||||
use crate::utils::mutex::AsyncMutex;
|
||||
|
||||
use alloc::{sync::Arc, boxed::Box};
|
||||
use async_trait::async_trait;
|
||||
@ -11,7 +12,7 @@ pub struct IsoFD {
|
||||
|
||||
impl IsoFD {
|
||||
pub fn new() -> FDt {
|
||||
Arc::new(RefCell::new(IsoFD {
|
||||
Arc::new(AsyncMutex::new(IsoFD {
|
||||
fd: FDId::new(),
|
||||
}))
|
||||
}
|
||||
|
@ -6,21 +6,19 @@ use crate::drivers::atapi::{DRIVE};
|
||||
use crate::fd::{FD_TABLE, FDt};
|
||||
use crate::utils::unserialize;
|
||||
|
||||
use super::FileSystem;
|
||||
use iso9660::{IsoPrimVolDesc, IsoDir};
|
||||
use fd::IsoFD;
|
||||
|
||||
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc {
|
||||
let desc_block = DRIVE
|
||||
.lock()
|
||||
.await
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK)
|
||||
.await;
|
||||
*unserialize::<IsoPrimVolDesc>(desc_block.as_ptr())
|
||||
use alloc::{sync::Arc, boxed::Box};
|
||||
use async_trait::async_trait;
|
||||
|
||||
struct IsoFS {
|
||||
}
|
||||
|
||||
pub async fn open(path: &str, flags: u32) -> Option<FDt> {
|
||||
#[async_trait]
|
||||
impl FileSystem for IsoFS {
|
||||
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
|
||||
if flags != crate::syscalls::io::O_RDONLY {
|
||||
return None;
|
||||
}
|
||||
@ -32,6 +30,18 @@ pub async fn open(path: &str, flags: u32) -> Option<FDt> {
|
||||
}
|
||||
|
||||
let fd = IsoFD::new();
|
||||
FD_TABLE.lock().await.register_fd(fd.clone()).await;
|
||||
Some(fd)
|
||||
FD_TABLE.lock().await.register_fd(fd.clone());
|
||||
Some(fd.clone())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc {
|
||||
let desc_block = DRIVE
|
||||
.lock()
|
||||
.await
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK)
|
||||
.await;
|
||||
*unserialize::<IsoPrimVolDesc>(desc_block.as_ptr())
|
||||
}
|
@ -1 +1,11 @@
|
||||
pub mod iso;
|
||||
|
||||
use crate::fd::FDt;
|
||||
|
||||
use alloc::{sync::Arc, boxed::Box};
|
||||
use async_trait::async_trait;
|
||||
|
||||
#[async_trait]
|
||||
pub trait FileSystem {
|
||||
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt>;
|
||||
}
|
@ -14,7 +14,7 @@ struct Lock {
|
||||
waker: Arc<AtomicWaker>,
|
||||
}
|
||||
|
||||
pub struct AsyncMutex<T> {
|
||||
pub struct AsyncMutex<T: ?Sized> {
|
||||
lock: Lock,
|
||||
inner: UnsafeCell<T>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user