diff --git a/src/fd/mod.rs b/src/fd/mod.rs index 453ab24..123084c 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -58,4 +58,5 @@ pub trait FileDescriptor { 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; } diff --git a/src/fs/iso/fd.rs b/src/fs/iso/fd.rs index cb34b12..8825d40 100644 --- a/src/fs/iso/fd.rs +++ b/src/fs/iso/fd.rs @@ -64,4 +64,15 @@ impl FileDescriptor for IsoFD { 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 + } } diff --git a/src/lib.rs b/src/lib.rs index a8e2105..75c4a9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,5 +77,10 @@ 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; } diff --git a/src/syscalls/io.rs b/src/syscalls/io.rs index 1b45ac5..8eaad14 100644 --- a/src/syscalls/io.rs +++ b/src/syscalls/io.rs @@ -2,9 +2,6 @@ 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;