add lseek
continuous-integration/drone/push Build is passing

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
juju committed 2022-12-25 17:07:40 +01:00
1 parent 23184f56a3
commit 184030a45e
4 files changed
+17 -3

No files matched your search

+1
View File
@@ -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;
}
+11
View File
@@ -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
}
}
+5
View File
@@ -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;
}
-3
View File
@@ -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;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.