Implement more system calls
This commit is contained in:
parent
f60661820d
commit
ed3170bdcc
9 changed files with 224 additions and 124 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
use context;
|
||||
use scheme;
|
||||
use syscall::data::Stat;
|
||||
use syscall::error::*;
|
||||
|
||||
/// Change the current working directory
|
||||
|
@ -97,6 +98,24 @@ pub fn dup(fd: usize) -> Result<usize> {
|
|||
scheme.dup(file.number)
|
||||
}
|
||||
|
||||
/// Get information about the file
|
||||
pub fn fstat(fd: usize, stat: &mut Stat) -> Result<usize> {
|
||||
let file = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
let file = context.get_file(fd).ok_or(Error::new(EBADF))?;
|
||||
file
|
||||
};
|
||||
|
||||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(file.scheme).ok_or(Error::new(EBADF))?;
|
||||
scheme.clone()
|
||||
};
|
||||
scheme.fstat(file.number, stat)
|
||||
}
|
||||
|
||||
/// Sync the file descriptor
|
||||
pub fn fsync(fd: usize) -> Result<usize> {
|
||||
let file = {
|
||||
|
@ -115,6 +134,24 @@ pub fn fsync(fd: usize) -> Result<usize> {
|
|||
scheme.fsync(file.number)
|
||||
}
|
||||
|
||||
/// Seek to an offset
|
||||
pub fn lseek(fd: usize, pos: usize, whence: usize) -> Result<usize> {
|
||||
let file = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
let file = context.get_file(fd).ok_or(Error::new(EBADF))?;
|
||||
file
|
||||
};
|
||||
|
||||
let scheme = {
|
||||
let schemes = scheme::schemes();
|
||||
let scheme = schemes.get(file.scheme).ok_or(Error::new(EBADF))?;
|
||||
scheme.clone()
|
||||
};
|
||||
scheme.seek(file.number, pos, whence)
|
||||
}
|
||||
|
||||
/// Read syscall
|
||||
pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let file = {
|
||||
|
|
|
@ -2,14 +2,16 @@
|
|||
|
||||
extern crate syscall;
|
||||
|
||||
pub use self::syscall::{error, number, scheme};
|
||||
pub use self::syscall::{data, error, flag, number, scheme};
|
||||
|
||||
use self::error::{Error, Result, ENOSYS};
|
||||
use self::number::*;
|
||||
pub use self::fs::*;
|
||||
pub use self::process::*;
|
||||
pub use self::validate::*;
|
||||
|
||||
use self::data::Stat;
|
||||
use self::error::{Error, Result, ENOSYS};
|
||||
use self::number::*;
|
||||
|
||||
/// Filesystem syscalls
|
||||
pub mod fs;
|
||||
|
||||
|
@ -32,7 +34,9 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
|
|||
SYS_WAITPID => waitpid(b, c, d),
|
||||
SYS_EXECVE => exec(validate_slice(b as *const u8, c)?, validate_slice(d as *const [usize; 2], e)?),
|
||||
SYS_CHDIR => chdir(validate_slice(b as *const u8, c)?),
|
||||
SYS_LSEEK => lseek(b, c, d),
|
||||
SYS_GETPID => getpid(),
|
||||
SYS_FSTAT => fstat(b, &mut validate_slice_mut(b as *mut Stat, 1)?[0]),
|
||||
SYS_DUP => dup(b),
|
||||
SYS_BRK => brk(b),
|
||||
SYS_IOPL => iopl(b),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue