Compare commits

..

2 Commits

Author SHA1 Message Date
8518982932 basic FileSystem trait
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-23 19:47:50 +01:00
b9e49dd946 Trying to implement FileSystem trait
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2022-12-23 19:37:30 +01:00
6 changed files with 42 additions and 20 deletions

@ -33,7 +33,7 @@ impl FDTable {
FDTable { table: BTreeMap::new() } FDTable { table: BTreeMap::new() }
} }
pub async fn register_fd(&mut self, fd: FDt) { pub fn register_fd(&mut self, fd: FDt) {
// TODO // TODO
self.table.insert(fd.borrow().get_fd(), fd.clone()); self.table.insert(fd.borrow().get_fd(), fd.clone());
println!("Registered fd: {:?}", self.table.get(&FDId(1)).unwrap().borrow().get_fd()); println!("Registered fd: {:?}", self.table.get(&FDId(1)).unwrap().borrow().get_fd());

@ -1,5 +1,6 @@
use crate::println; use crate::println;
use crate::fd::{FDId, FileDescriptor, FDt}; use crate::fd::{FDId, FileDescriptor, FDt};
use crate::utils::mutex::AsyncMutex;
use alloc::{sync::Arc, boxed::Box}; use alloc::{sync::Arc, boxed::Box};
use async_trait::async_trait; use async_trait::async_trait;

@ -6,21 +6,19 @@ use crate::drivers::atapi::{DRIVE};
use crate::fd::{FD_TABLE, FDt}; use crate::fd::{FD_TABLE, FDt};
use crate::utils::unserialize; use crate::utils::unserialize;
use super::FileSystem;
use iso9660::{IsoPrimVolDesc, IsoDir}; use iso9660::{IsoPrimVolDesc, IsoDir};
use fd::IsoFD; use fd::IsoFD;
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { use alloc::{sync::Arc, boxed::Box};
let desc_block = DRIVE use async_trait::async_trait;
.lock()
.await pub struct IsoFS {
.as_mut()
.unwrap()
.read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK)
.await;
*unserialize::<IsoPrimVolDesc>(desc_block.as_ptr())
} }
pub async fn open(path: &str, flags: u32) -> Option<FDt> { #[async_trait(?Send)]
impl FileSystem for IsoFS {
async fn open(path: &str, flags: u32) -> Option<FDt> {
if flags != crate::syscalls::io::O_RDONLY { if flags != crate::syscalls::io::O_RDONLY {
return None; return None;
} }
@ -32,6 +30,18 @@ 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()).await; FD_TABLE.lock().await.register_fd(fd.clone());
Some(fd) 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; pub mod iso;
use crate::fd::FDt;
use alloc::{sync::Arc, boxed::Box};
use async_trait::async_trait;
#[async_trait(?Send)]
pub trait FileSystem {
async fn open(path: &str, flags: u32) -> Option<FDt>;
}

@ -20,6 +20,7 @@ use core::panic::PanicInfo;
use drivers::vga::{self, Color, ColorCode}; use drivers::vga::{self, Color, ColorCode};
use multiboot2::BootInformation; use multiboot2::BootInformation;
use task::{executor::Executor, keyboard, Task}; use task::{executor::Executor, keyboard, Task};
use crate::fs::FileSystem;
#[alloc_error_handler] #[alloc_error_handler]
fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! { fn alloc_error_handler(layout: alloc::alloc::Layout) -> ! {
@ -65,6 +66,6 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! {
async fn get_file() { async fn get_file() {
let fd = fs::iso::open("test", syscalls::io::O_RDONLY).await.unwrap(); let fd = fs::iso::IsoFS::open("test", syscalls::io::O_RDONLY).await.unwrap();
fd.borrow_mut().read(&[], 0).await; fd.borrow_mut().read(&[], 0).await;
} }

@ -14,7 +14,7 @@ struct Lock {
waker: Arc<AtomicWaker>, waker: Arc<AtomicWaker>,
} }
pub struct AsyncMutex<T> { pub struct AsyncMutex<T: ?Sized> {
lock: Lock, lock: Lock,
inner: UnsafeCell<T>, inner: UnsafeCell<T>,
} }