Remove resource_sceme, Fix syscall crate name, add fmap
This commit is contained in:
parent
db4acfbe8c
commit
e3317f05f7
39 changed files with 130 additions and 221 deletions
|
@ -3,4 +3,4 @@ name = "dma"
|
|||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
syscall = { path = "../../syscall/" }
|
||||
redox_syscall = { path = "../../syscall/" }
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
name = "event"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies.syscall]
|
||||
path = "../../syscall/"
|
||||
[dependencies]
|
||||
redox_syscall = { path = "../../syscall/" }
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "resource_scheme"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies.syscall]
|
||||
path = "../../syscall/"
|
|
@ -1,7 +0,0 @@
|
|||
extern crate syscall;
|
||||
|
||||
pub use resource::Resource;
|
||||
pub use scheme::ResourceScheme;
|
||||
|
||||
mod resource;
|
||||
mod scheme;
|
|
@ -1,52 +0,0 @@
|
|||
use syscall::data::Stat;
|
||||
use syscall::error::*;
|
||||
|
||||
pub trait Resource {
|
||||
/// Duplicate the resource
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn dup(&self, _buf: &[u8]) -> Result<Box<Self>> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
|
||||
/// Return the path of this resource
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn path(&self, _buf: &mut [u8]) -> Result<usize> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
|
||||
/// Read data to buffer
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn read(&mut self, _buf: &mut [u8]) -> Result<usize> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
|
||||
/// Write to resource
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn write(&mut self, _buf: &[u8]) -> Result<usize> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
|
||||
/// Seek to the given offset
|
||||
/// Returns `ESPIPE` if the operation is not supported.
|
||||
fn seek(&mut self, _pos: usize, _whence: usize) -> Result<usize> {
|
||||
Err(Error::new(ESPIPE))
|
||||
}
|
||||
|
||||
/// Get informations about the resource, such as mode and size
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn stat(&self, _stat: &mut Stat) -> Result<usize> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
|
||||
/// Sync all buffers
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn sync(&mut self) -> Result<usize> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
|
||||
/// Truncate to the given length
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn truncate(&mut self, _len: usize) -> Result<usize> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
use std::slice;
|
||||
|
||||
use syscall::data::{Packet, Stat};
|
||||
use syscall::error::*;
|
||||
use syscall::number::*;
|
||||
|
||||
use super::Resource;
|
||||
|
||||
pub trait ResourceScheme<T: Resource> {
|
||||
fn open_resource(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<Box<T>>;
|
||||
|
||||
fn handle(&self, packet: &mut Packet) {
|
||||
packet.a = Error::mux(match packet.a {
|
||||
SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid),
|
||||
SYS_MKDIR => self.mkdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid),
|
||||
SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
||||
SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
||||
|
||||
SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
||||
SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
|
||||
SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
||||
SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
|
||||
SYS_FEVENT => self.fevent(packet.b, packet.c),
|
||||
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
|
||||
SYS_FSTAT => self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }),
|
||||
SYS_FSYNC => self.fsync(packet.b),
|
||||
SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
|
||||
SYS_CLOSE => self.close(packet.b),
|
||||
|
||||
_ => Err(Error::new(ENOSYS))
|
||||
});
|
||||
}
|
||||
|
||||
/* Scheme operations */
|
||||
fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<usize> {
|
||||
let resource = self.open_resource(path, flags, uid, gid)?;
|
||||
let resource_ptr = Box::into_raw(resource);
|
||||
Ok(resource_ptr as usize)
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn mkdir(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
/* Resource operations */
|
||||
fn dup(&self, old_id: usize, buf: &[u8]) -> Result<usize> {
|
||||
let old = unsafe { &*(old_id as *const T) };
|
||||
let resource = old.dup(buf)?;
|
||||
let resource_ptr = Box::into_raw(resource);
|
||||
Ok(resource_ptr as usize)
|
||||
}
|
||||
|
||||
fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
||||
resource.read(buf)
|
||||
}
|
||||
|
||||
fn write(&self, id: usize, buf: &[u8]) -> Result<usize> {
|
||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
||||
resource.write(buf)
|
||||
}
|
||||
|
||||
fn seek(&self, id: usize, pos: usize, whence: usize) -> Result<usize> {
|
||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
||||
resource.seek(pos, whence)
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fevent(&self, id: usize, flags: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
let resource = unsafe { &*(id as *const T) };
|
||||
resource.path(buf)
|
||||
}
|
||||
|
||||
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
|
||||
let resource = unsafe { &*(id as *const T) };
|
||||
resource.stat(stat)
|
||||
}
|
||||
|
||||
fn fsync(&self, id: usize) -> Result<usize> {
|
||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
||||
resource.sync()
|
||||
}
|
||||
|
||||
fn ftruncate(&self, id: usize, len: usize) -> Result<usize> {
|
||||
let mut resource = unsafe { &mut *(id as *mut T) };
|
||||
resource.truncate(len)
|
||||
}
|
||||
|
||||
fn close(&self, id: usize) -> Result<usize> {
|
||||
let resource = unsafe { Box::from_raw(id as *mut T) };
|
||||
drop(resource);
|
||||
Ok(0)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue