basic FileSystem trait
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 19:47:50 +01:00
parent b9e49dd946
commit 8518982932
5 changed files with 9 additions and 8 deletions

@ -6,7 +6,7 @@ use async_trait::async_trait;
use core::cell::RefCell; use core::cell::RefCell;
use lazy_static::lazy_static; use lazy_static::lazy_static;
pub type FDt = Arc<AsyncMutex<dyn FileDescriptor>>; pub type FDt = Arc<RefCell<dyn FileDescriptor>>;
lazy_static! { lazy_static! {
pub static ref FD_TABLE: AsyncMutex<FDTable> = { pub static ref FD_TABLE: AsyncMutex<FDTable> = {

@ -12,7 +12,7 @@ pub struct IsoFD {
impl IsoFD { impl IsoFD {
pub fn new() -> FDt { pub fn new() -> FDt {
Arc::new(AsyncMutex::new(IsoFD { Arc::new(RefCell::new(IsoFD {
fd: FDId::new(), fd: FDId::new(),
})) }))
} }

@ -13,12 +13,12 @@ use fd::IsoFD;
use alloc::{sync::Arc, boxed::Box}; use alloc::{sync::Arc, boxed::Box};
use async_trait::async_trait; use async_trait::async_trait;
struct IsoFS { pub struct IsoFS {
} }
#[async_trait] #[async_trait(?Send)]
impl FileSystem for IsoFS { impl FileSystem for IsoFS {
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> { 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;
} }

@ -5,7 +5,7 @@ use crate::fd::FDt;
use alloc::{sync::Arc, boxed::Box}; use alloc::{sync::Arc, boxed::Box};
use async_trait::async_trait; use async_trait::async_trait;
#[async_trait] #[async_trait(?Send)]
pub trait FileSystem { pub trait FileSystem {
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt>; 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;
} }