Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
23184f56a3
commit
184030a45e
@ -58,4 +58,5 @@ pub trait FileDescriptor {
|
|||||||
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: &mut [u8], count: usize) -> isize;
|
async fn read(&mut self, buf: &mut [u8], count: usize) -> isize;
|
||||||
async fn close(&mut self);
|
async fn close(&mut self);
|
||||||
|
async fn lseek(&mut self, offset: i32, whence: u32) -> i32;
|
||||||
}
|
}
|
||||||
|
@ -64,4 +64,15 @@ impl FileDescriptor for IsoFD {
|
|||||||
async fn close(&mut self) {
|
async fn close(&mut self) {
|
||||||
FD_TABLE.lock().await.unregister_fd(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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,5 +77,10 @@ async fn get_file() {
|
|||||||
serial_println!("{:?}", read);
|
serial_println!("{:?}", read);
|
||||||
serial_println!("{}", alloc::str::from_utf8(&buf).unwrap());
|
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;
|
fd.borrow_mut().close().await;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
pub const O_RDONLY: u32 = 0;
|
pub const O_RDONLY: u32 = 0;
|
||||||
|
|
||||||
// seek flags
|
// seek flags
|
||||||
#[allow(dead_code)]
|
|
||||||
pub const SEEK_SET: u32 = 0;
|
pub const SEEK_SET: u32 = 0;
|
||||||
#[allow(dead_code)]
|
|
||||||
pub const SEEK_CUR: u32 = 1;
|
pub const SEEK_CUR: u32 = 1;
|
||||||
#[allow(dead_code)]
|
|
||||||
pub const SEEK_END: u32 = 2;
|
pub const SEEK_END: u32 = 2;
|
||||||
|
Loading…
Reference in New Issue
Block a user