Compare commits
No commits in common. "184030a45e0f8ddc4256bf67d6efbf334f89897c" and "eb5a3a6635499446454ff07ce91fd08126812264" have entirely different histories.
184030a45e
...
eb5a3a6635
@ -35,11 +35,11 @@ impl FDTable {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unregister_fd(&mut self, fd: &dyn FileDescriptor) {
|
||||
self.table.remove(&fd.get_fd());
|
||||
pub fn unregister_fd(&mut self, fd: FDt) {
|
||||
self.table.remove(&fd.borrow().get_fd());
|
||||
println!(
|
||||
"Unregistered fd: {:?}",
|
||||
fd.get_fd()
|
||||
fd.borrow().get_fd()
|
||||
);
|
||||
}
|
||||
|
||||
@ -57,6 +57,4 @@ pub trait FileDescriptor {
|
||||
fn get_fd(&self) -> FDId;
|
||||
async fn write(&mut self, buf: &[u8], count: usize) -> isize;
|
||||
async fn read(&mut self, buf: &mut [u8], count: usize) -> isize;
|
||||
async fn close(&mut self);
|
||||
async fn lseek(&mut self, offset: i32, whence: u32) -> i32;
|
||||
}
|
||||
|
@ -60,19 +60,4 @@ impl FileDescriptor for IsoFD {
|
||||
|
||||
read
|
||||
}
|
||||
|
||||
async fn close(&mut self) {
|
||||
FD_TABLE.lock().await.unregister_fd(self);
|
||||
}
|
||||
|
||||
async fn lseek(&mut self, offset: i32, whence: u32) -> i32 {
|
||||
use crate::syscalls::io::*;
|
||||
match whence {
|
||||
w if w == SEEK_SET => self.offset = offset as u32,
|
||||
w if w == SEEK_CUR => self.offset = (self.offset as i32 + offset) as u32,
|
||||
w if w == SEEK_END => self.offset = (self.size as i32 + offset) as u32,
|
||||
_ => {}
|
||||
};
|
||||
self.offset as i32
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ mod fd;
|
||||
pub mod iso9660;
|
||||
|
||||
use crate::drivers::atapi::read_block;
|
||||
use crate::fd::{FDt};
|
||||
use crate::fd::{FDt, FD_TABLE};
|
||||
use crate::utils::unserialize;
|
||||
|
||||
use super::FileSystem;
|
||||
@ -74,6 +74,10 @@ impl FileSystem for IsoFS {
|
||||
|
||||
Some(IsoFD::new(curr_entry).await)
|
||||
}
|
||||
|
||||
async fn close(&mut self, fd: FDt) {
|
||||
FD_TABLE.lock().await.unregister_fd(fd.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,6 +17,7 @@ lazy_static! {
|
||||
#[async_trait(?Send)]
|
||||
pub trait FileSystem {
|
||||
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt>;
|
||||
async fn close(&mut self, fd: FDt);
|
||||
}
|
||||
|
||||
pub struct VirtualFS {
|
||||
@ -36,4 +37,8 @@ impl FileSystem for VirtualFS {
|
||||
async fn open(&mut self, path: &str, flags: u32) -> Option<FDt> {
|
||||
self.fs.borrow_mut().open(path, flags).await
|
||||
}
|
||||
|
||||
async fn close(&mut self, fd: FDt) {
|
||||
self.fs.borrow_mut().close(fd).await
|
||||
}
|
||||
}
|
||||
|
@ -77,10 +77,5 @@ async fn get_file() {
|
||||
serial_println!("{:?}", read);
|
||||
serial_println!("{}", alloc::str::from_utf8(&buf).unwrap());
|
||||
|
||||
fd.borrow_mut().lseek(10, syscalls::io::SEEK_SET).await;
|
||||
|
||||
fd.borrow_mut().read(&mut buf, 100).await;
|
||||
serial_println!("{}", alloc::str::from_utf8(&buf).unwrap());
|
||||
|
||||
fd.borrow_mut().close().await;
|
||||
fs::VIRTUAL_FS.lock().await.close(fd).await;
|
||||
}
|
||||
|
@ -2,6 +2,9 @@
|
||||
pub const O_RDONLY: u32 = 0;
|
||||
|
||||
// seek flags
|
||||
#[allow(dead_code)]
|
||||
pub const SEEK_SET: u32 = 0;
|
||||
#[allow(dead_code)]
|
||||
pub const SEEK_CUR: u32 = 1;
|
||||
#[allow(dead_code)]
|
||||
pub const SEEK_END: u32 = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user