From e2c2586a195451e356eb1459178f5c16ea7a723d Mon Sep 17 00:00:00 2001 From: Julien CLEMENT Date: Thu, 22 Dec 2022 21:25:35 +0100 Subject: [PATCH] add async trait to make FD methods async Signed-off-by: Julien CLEMENT --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + src/fd/mod.rs | 8 +++++--- src/fs/iso/fd.rs | 8 +++++--- src/fs/iso/mod.rs | 4 +--- src/lib.rs | 2 +- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12e097b..77f78bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. 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]] name = "atomic-polyfill" version = "0.1.11" @@ -146,6 +157,7 @@ dependencies = [ name = "julios" version = "0.1.0" dependencies = [ + "async-trait", "conquer-once", "crossbeam-queue", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index 79569e2..378a321 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ linked_list_allocator = "0.9.0" postcard = "1.0.0" serde = { version = "1.0", default-features = false, features = ["alloc"] } heapless = "0.7.16" +async-trait = "0.1.60" [dependencies.lazy_static] version = "1.0" diff --git a/src/fd/mod.rs b/src/fd/mod.rs index 7573b08..cbcba88 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -1,6 +1,7 @@ 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 lazy_static::lazy_static; @@ -35,7 +36,8 @@ impl FDTable { } } +#[async_trait] pub trait FileDescriptor { - fn write(&mut self, buf: *const u8, count: usize) -> isize; - fn read(&mut self, buf: *mut u8, count: usize) -> isize; + async fn write(&mut self, buf: &[u8], count: usize) -> isize; + async fn read(&mut self, buf: &[u8], count: usize) -> isize; } \ No newline at end of file diff --git a/src/fs/iso/fd.rs b/src/fs/iso/fd.rs index 15694a2..e37b55c 100644 --- a/src/fs/iso/fd.rs +++ b/src/fs/iso/fd.rs @@ -1,7 +1,8 @@ use crate::println; 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; pub struct IsoFD { @@ -16,12 +17,13 @@ impl IsoFD { } } +#[async_trait] 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 } - fn read(&mut self, buf: *mut u8, count: usize) -> isize { + async fn read(&mut self, buf: &[u8], count: usize) -> isize { println!("Read from fd"); 0 } diff --git a/src/fs/iso/mod.rs b/src/fs/iso/mod.rs index 851aa8c..94ce10c 100644 --- a/src/fs/iso/mod.rs +++ b/src/fs/iso/mod.rs @@ -3,14 +3,12 @@ mod fd; use crate::println; use crate::drivers::atapi::{DRIVE}; -use crate::fd::{FDId, FD_TABLE, FDt}; +use crate::fd::{FD_TABLE, FDt}; use crate::utils::unserialize; use iso9660::{IsoPrimVolDesc}; use fd::IsoFD; -use alloc::sync::Arc; - pub async fn get_prim_vol_desc() -> IsoPrimVolDesc { let desc_block = DRIVE .lock() diff --git a/src/lib.rs b/src/lib.rs index 5bd53fb..a2b8aad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,5 +65,5 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! { async fn get_file() { let fd = fs::iso::open().await; - fd.borrow_mut().read(0 as *mut u8, 0); + fd.borrow_mut().read(&[], 0).await; } \ No newline at end of file