Implement more system calls

This commit is contained in:
Jeremy Soller 2016-09-20 16:57:45 -06:00
parent f60661820d
commit ed3170bdcc
9 changed files with 224 additions and 124 deletions

View file

@ -1,8 +1,10 @@
use collections::BTreeMap;
use core::cmp;
use core::sync::atomic::{AtomicUsize, Ordering};
use spin::RwLock;
use syscall::error::*;
use syscall::flag::{SEEK_SET, SEEK_CUR, SEEK_END};
use syscall::scheme::Scheme;
struct Handle {
@ -76,6 +78,20 @@ impl Scheme for EnvScheme {
Ok(i)
}
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
let mut handles = self.handles.write();
let mut handle = handles.get_mut(&id).ok_or(Error::new(EBADF))?;
handle.seek = match whence {
SEEK_SET => cmp::min(handle.data.len(), pos),
SEEK_CUR => cmp::max(0, cmp::min(handle.data.len() as isize, handle.seek as isize + pos as isize)) as usize,
SEEK_END => cmp::max(0, cmp::min(handle.data.len() as isize, handle.data.len() as isize + pos as isize)) as usize,
_ => return Err(Error::new(EINVAL))
};
Ok(handle.seek)
}
fn fsync(&self, _file: usize) -> Result<usize> {
Ok(0)
}