Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
40b4191d2d
commit
446aff49ef
@ -47,5 +47,5 @@ impl FDTable {
|
|||||||
pub trait FileDescriptor {
|
pub trait FileDescriptor {
|
||||||
fn get_fd(&self) -> FDId;
|
fn get_fd(&self) -> FDId;
|
||||||
async fn write(&mut self, buf: &[u8], count: usize) -> isize;
|
async fn write(&mut self, buf: &[u8], count: usize) -> isize;
|
||||||
async fn read(&mut self, buf: &[u8], count: usize) -> isize;
|
async fn read(&mut self, buf: &mut [u8], count: usize) -> isize;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
use crate::drivers::atapi::read_block;
|
||||||
use crate::fd::{FDId, FDt, FileDescriptor};
|
use crate::fd::{FDId, FDt, FileDescriptor};
|
||||||
use crate::println;
|
use crate::println;
|
||||||
use crate::utils::mutex::AsyncMutex;
|
|
||||||
|
use super::iso9660::{IsoDir, ISO_BLOCK_SIZE};
|
||||||
|
|
||||||
use alloc::{boxed::Box, sync::Arc};
|
use alloc::{boxed::Box, sync::Arc};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@ -8,11 +10,19 @@ use core::cell::RefCell;
|
|||||||
|
|
||||||
pub struct IsoFD {
|
pub struct IsoFD {
|
||||||
pub fd: FDId,
|
pub fd: FDId,
|
||||||
|
offset: u32,
|
||||||
|
lba: u32,
|
||||||
|
size: u32
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IsoFD {
|
impl IsoFD {
|
||||||
pub fn new() -> FDt {
|
pub fn new(entry: &IsoDir) -> FDt {
|
||||||
Arc::new(RefCell::new(IsoFD { fd: FDId::new() }))
|
Arc::new(RefCell::new(IsoFD {
|
||||||
|
fd: FDId::new(),
|
||||||
|
offset: 0,
|
||||||
|
lba: entry.data_blk.le,
|
||||||
|
size: entry.file_size.le,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,8 +36,26 @@ impl FileDescriptor for IsoFD {
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read(&mut self, buf: &[u8], count: usize) -> isize {
|
#[allow(unaligned_references)]
|
||||||
println!("Read from fd");
|
async fn read(&mut self, buf: &mut [u8], count: usize) -> isize {
|
||||||
0
|
let mut block_offset = self.offset / ISO_BLOCK_SIZE;
|
||||||
|
let mut content = read_block(self.lba + block_offset).await;
|
||||||
|
let mut read: isize = 0;
|
||||||
|
for _ in 0..count {
|
||||||
|
if self.offset >= self.size {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[read as usize] = content[(self.offset % ISO_BLOCK_SIZE) as usize];
|
||||||
|
read += 1;
|
||||||
|
self.offset += 1;
|
||||||
|
|
||||||
|
if self.offset % ISO_BLOCK_SIZE == 0 {
|
||||||
|
block_offset += 1;
|
||||||
|
content = read_block(self.lba + block_offset).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
read
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pub const ISO_BLOCK_SIZE: usize = 2048;
|
pub const ISO_BLOCK_SIZE: u32 = 2048;
|
||||||
|
|
||||||
// Twin values structs
|
// Twin values structs
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ use async_trait::async_trait;
|
|||||||
pub struct IsoFS {}
|
pub struct IsoFS {}
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
|
#[allow(unaligned_references)]
|
||||||
impl FileSystem for IsoFS {
|
impl FileSystem for IsoFS {
|
||||||
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
|
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
|
||||||
// ISO is a read only file system
|
// ISO is a read only file system
|
||||||
@ -31,12 +32,13 @@ impl FileSystem for IsoFS {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let root: IsoDir = voldesc.root_dir;
|
let root: &IsoDir = &voldesc.root_dir;
|
||||||
let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE] = read_block(root.data_blk.le).await;
|
let mut curr_entry_block: [u8; iso9660::ISO_BLOCK_SIZE as usize] = read_block(root.data_blk.le).await;
|
||||||
|
|
||||||
let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr());
|
let mut curr_entry: &IsoDir = unserialize(curr_entry_block.as_ptr());
|
||||||
|
|
||||||
let path_s: String = String::from(path);
|
let path_s: String = String::from(path);
|
||||||
|
let path_split: Vec<&str> = path_s.split("/").collect();
|
||||||
let path_it = path_s
|
let path_it = path_s
|
||||||
.split("/")
|
.split("/")
|
||||||
.filter(|p| p != &"");
|
.filter(|p| p != &"");
|
||||||
@ -44,15 +46,14 @@ impl FileSystem for IsoFS {
|
|||||||
for path_component in path_it {
|
for path_component in path_it {
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
while curr_entry.idf_len != 0 {
|
while curr_entry.idf_len != 0 {
|
||||||
serial_println!("{:?}", curr_entry.idf_len);
|
|
||||||
serial_println!("{:?}", alloc::str::from_utf8(curr_entry.get_idf()).unwrap());
|
|
||||||
|
|
||||||
// Found entry
|
// Found entry
|
||||||
if curr_entry.matches(path_component) {
|
if curr_entry.matches(path_component) {
|
||||||
serial_println!("Found {}", path_component);
|
|
||||||
found = true;
|
found = true;
|
||||||
|
if path_component != path_split[path_split.len() - 1] {
|
||||||
curr_entry_block = read_block(curr_entry.data_blk.le).await;
|
curr_entry_block = read_block(curr_entry.data_blk.le).await;
|
||||||
curr_entry = unserialize(curr_entry_block.as_ptr());
|
curr_entry = unserialize(curr_entry_block.as_ptr());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,9 +65,9 @@ impl FileSystem for IsoFS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let fd = IsoFD::new();
|
let fd = IsoFD::new(curr_entry);
|
||||||
FD_TABLE.lock().await.register_fd(fd.clone());
|
FD_TABLE.lock().await.register_fd(fd.clone());
|
||||||
Some(fd.clone())
|
Some(fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,5 +71,9 @@ async fn get_file() {
|
|||||||
.open("///boot/grub//grub.cfg", syscalls::io::O_RDONLY)
|
.open("///boot/grub//grub.cfg", syscalls::io::O_RDONLY)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
fd.borrow_mut().read(&[], 0).await;
|
let mut buf: [u8; 100] = [0; 100];
|
||||||
|
let read = fd.borrow_mut().read(&mut buf, 100).await;
|
||||||
|
|
||||||
|
println!("{:?}", read);
|
||||||
|
println!("{:?}", alloc::str::from_utf8(&buf).unwrap());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user