add basic file descriptor trait architecture
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
519633b769
commit
ffe889a934
@ -8,7 +8,6 @@ use interrupt::{INTERRUPT_FUTURE};
|
||||
use core::convert::TryInto;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use crate::utils::AsyncMutex;
|
||||
use x86_64::instructions::port::Port;
|
||||
|
||||
|
41
src/fd/mod.rs
Normal file
41
src/fd/mod.rs
Normal file
@ -0,0 +1,41 @@
|
||||
use crate::utils::AsyncMutex;
|
||||
|
||||
use alloc::{collections::BTreeMap, sync::Arc};
|
||||
use core::cell::RefCell;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
pub type FDt = Arc<RefCell<dyn FileDescriptor>>;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref FD_TABLE: AsyncMutex<FDTable> = {
|
||||
AsyncMutex::new(FDTable::new())
|
||||
};
|
||||
}
|
||||
|
||||
pub struct FDId(u64);
|
||||
|
||||
impl FDId {
|
||||
pub fn new() -> Self {
|
||||
// TODO: search for first available fd
|
||||
FDId(1)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FDTable {
|
||||
table: BTreeMap<FDId, FDt>,
|
||||
}
|
||||
|
||||
impl FDTable {
|
||||
pub fn new() -> Self {
|
||||
FDTable { table: BTreeMap::new() }
|
||||
}
|
||||
|
||||
pub fn register_fd(&mut self, fd: FDt) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FileDescriptor {
|
||||
fn write(&mut self, buf: *const u8, count: usize) -> isize;
|
||||
fn read(&mut self, buf: *mut u8, count: usize) -> isize;
|
||||
}
|
28
src/fs/iso/fd.rs
Normal file
28
src/fs/iso/fd.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use crate::println;
|
||||
use crate::fd::{FDId, FileDescriptor, FDt};
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use core::cell::RefCell;
|
||||
|
||||
pub struct IsoFD {
|
||||
pub fd: FDId,
|
||||
}
|
||||
|
||||
impl IsoFD {
|
||||
pub fn new() -> FDt {
|
||||
Arc::new(RefCell::new(IsoFD {
|
||||
fd: FDId::new(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl FileDescriptor for IsoFD {
|
||||
fn write(&mut self, buf: *const u8, count: usize) -> isize {
|
||||
0
|
||||
}
|
||||
|
||||
fn read(&mut self, buf: *mut u8, count: usize) -> isize {
|
||||
println!("Read from fd");
|
||||
0
|
||||
}
|
||||
}
|
@ -3,12 +3,14 @@ const ISO_BLOCK_SIZE: usize = 2048;
|
||||
// Twin values structs
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct MultiEndian32 {
|
||||
le: u32, // Little endian value
|
||||
be: u32, // Big endian value
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct MultiEndian16 {
|
||||
le: u16, // Little endian value
|
||||
be: u16, // Big endian value
|
||||
@ -18,6 +20,7 @@ pub struct MultiEndian16 {
|
||||
// Path table structure
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
struct IsoPathTable {
|
||||
idf_len: u8, // Identifier name length
|
||||
ext_size: u8, // Extended attribute record length
|
||||
@ -41,6 +44,7 @@ impl IsoPathTable {
|
||||
const ISO_DATE_LEN: usize = 7;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Copy, Clone)]
|
||||
enum IsoFileType {
|
||||
HIDDEN = 0x1, // Hidden file
|
||||
ISDIR = 0x2, // Directory
|
||||
@ -51,6 +55,7 @@ enum IsoFileType {
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct IsoDir {
|
||||
dir_size: u8, // Length of directory record
|
||||
ext_size: u8, // Length of extended attribute record
|
||||
@ -94,6 +99,7 @@ const ISO_BIBFIL_LEN: usize = 37;
|
||||
const ISO_LDATE_LEN: usize = 17;
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct IsoPrimVolDesc {
|
||||
pub vol_desc_type: u8, // Volume descripto type (1)
|
||||
pub std_identifier: [u8; 5], // standard identifier ("CD001")
|
||||
|
@ -1,11 +1,17 @@
|
||||
pub mod iso9660;
|
||||
mod fd;
|
||||
|
||||
use crate::println;
|
||||
use crate::drivers::atapi::{DRIVE};
|
||||
use crate::fd::{FDId, FD_TABLE, FDt};
|
||||
use crate::utils::unserialize;
|
||||
use iso9660::{IsoPrimVolDesc};
|
||||
|
||||
pub async fn init_prim_vol_desc() {
|
||||
use iso9660::{IsoPrimVolDesc};
|
||||
use fd::IsoFD;
|
||||
|
||||
use alloc::sync::Arc;
|
||||
|
||||
pub async fn get_prim_vol_desc() -> IsoPrimVolDesc {
|
||||
let desc_block = DRIVE
|
||||
.lock()
|
||||
.await
|
||||
@ -13,7 +19,11 @@ pub async fn init_prim_vol_desc() {
|
||||
.unwrap()
|
||||
.read_block(iso9660::ISO_PRIM_VOLDESC_BLOCK)
|
||||
.await;
|
||||
let prim_vol_desc: &IsoPrimVolDesc = unserialize::<IsoPrimVolDesc>(desc_block.as_ptr());
|
||||
|
||||
println!("{:?}", alloc::string::String::from_utf8_lossy(&prim_vol_desc.std_identifier));
|
||||
*unserialize::<IsoPrimVolDesc>(desc_block.as_ptr())
|
||||
}
|
||||
|
||||
pub async fn open() -> FDt {
|
||||
let fd = IsoFD::new();
|
||||
FD_TABLE.lock().await.register_fd(fd.clone());
|
||||
fd
|
||||
}
|
@ -9,6 +9,7 @@ mod memory;
|
||||
mod task;
|
||||
mod fs;
|
||||
mod utils;
|
||||
mod fd;
|
||||
|
||||
//#[macro_use]
|
||||
extern crate alloc;
|
||||
@ -57,6 +58,12 @@ pub extern "C" fn julios_main(multiboot_info_addr: usize) -> ! {
|
||||
let mut executor = Executor::new();
|
||||
executor.spawn(Task::new(drivers::atapi::init()));
|
||||
executor.spawn(Task::new(keyboard::print_keypresses()));
|
||||
executor.spawn(Task::new(fs::iso::init_prim_vol_desc()));
|
||||
executor.spawn(Task::new(get_file()));
|
||||
executor.run();
|
||||
}
|
||||
|
||||
|
||||
async fn get_file() {
|
||||
let fd = fs::iso::open().await;
|
||||
fd.borrow_mut().read(0 as *mut u8, 0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user