add async trait to make FD methods async
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-22 21:25:35 +01:00
parent ffe889a934
commit e2c2586a19
6 changed files with 25 additions and 10 deletions

12
Cargo.lock generated

@ -2,6 +2,17 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "async-trait"
version = "0.1.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d1d8ab452a3936018a687b20e6f7cf5363d713b732b8884001317b0e48aa3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "atomic-polyfill" name = "atomic-polyfill"
version = "0.1.11" version = "0.1.11"
@ -146,6 +157,7 @@ dependencies = [
name = "julios" name = "julios"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-trait",
"conquer-once", "conquer-once",
"crossbeam-queue", "crossbeam-queue",
"futures-util", "futures-util",

@ -19,6 +19,7 @@ linked_list_allocator = "0.9.0"
postcard = "1.0.0" postcard = "1.0.0"
serde = { version = "1.0", default-features = false, features = ["alloc"] } serde = { version = "1.0", default-features = false, features = ["alloc"] }
heapless = "0.7.16" heapless = "0.7.16"
async-trait = "0.1.60"
[dependencies.lazy_static] [dependencies.lazy_static]
version = "1.0" version = "1.0"

@ -1,6 +1,7 @@
use crate::utils::AsyncMutex; use crate::utils::AsyncMutex;
use alloc::{collections::BTreeMap, sync::Arc}; use alloc::{collections::BTreeMap, sync::Arc, boxed::Box};
use async_trait::async_trait;
use core::cell::RefCell; use core::cell::RefCell;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -35,7 +36,8 @@ impl FDTable {
} }
} }
#[async_trait]
pub trait FileDescriptor { pub trait FileDescriptor {
fn write(&mut self, buf: *const u8, count: usize) -> isize; async fn write(&mut self, buf: &[u8], count: usize) -> isize;
fn read(&mut self, buf: *mut u8, count: usize) -> isize; async fn read(&mut self, buf: &[u8], count: usize) -> isize;
} }

@ -1,7 +1,8 @@
use crate::println; use crate::println;
use crate::fd::{FDId, FileDescriptor, FDt}; use crate::fd::{FDId, FileDescriptor, FDt};
use alloc::sync::Arc; use alloc::{sync::Arc, boxed::Box};
use async_trait::async_trait;
use core::cell::RefCell; use core::cell::RefCell;
pub struct IsoFD { pub struct IsoFD {
@ -16,12 +17,13 @@ impl IsoFD {
} }
} }
#[async_trait]
impl FileDescriptor for IsoFD { impl FileDescriptor for IsoFD {
fn write(&mut self, buf: *const u8, count: usize) -> isize { async fn write(&mut self, buf: &[u8], count: usize) -> isize {
0 0
} }
fn read(&mut self, buf: *mut u8, count: usize) -> isize { async fn read(&mut self, buf: &[u8], count: usize) -> isize {
println!("Read from fd"); println!("Read from fd");
0 0
} }

@ -3,14 +3,12 @@ mod fd;
use crate::println; use crate::println;
use crate::drivers::atapi::{DRIVE}; use crate::drivers::atapi::{DRIVE};
use crate::fd::{FDId, FD_TABLE, FDt}; use crate::fd::{FD_TABLE, FDt};
use crate::utils::unserialize; use crate::utils::unserialize;
use iso9660::{IsoPrimVolDesc}; use iso9660::{IsoPrimVolDesc};
use fd::IsoFD; use fd::IsoFD;
use alloc::sync::Arc;
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { pub async fn get_prim_vol_desc() -> IsoPrimVolDesc {
let desc_block = DRIVE let desc_block = DRIVE
.lock() .lock()

@ -65,5 +65,5 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! {
async fn get_file() { async fn get_file() {
let fd = fs::iso::open().await; let fd = fs::iso::open().await;
fd.borrow_mut().read(0 as *mut u8, 0); fd.borrow_mut().read(&[], 0).await;
} }