Verified Commit 0f9030f0 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

0.2.5 - paths are required to be utf8

parent ee9a9236
Pipeline #9086 failed with stages
in 4 minutes and 36 seconds
[package]
name = "redox_syscall"
version = "0.2.4"
version = "0.2.5"
description = "A Rust library to access raw Redox system calls"
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
......
......@@ -26,7 +26,7 @@ extern "C" fn restorer() -> ! {
/// * `EIO` - an I/O error occurred
/// * `ENOENT` - `path` does not exit
/// * `ENOTDIR` - `path` is not a directory
pub fn chdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
pub fn chdir<T: AsRef<str>>(path: T) -> Result<usize> {
unsafe { syscall2(SYS_CHDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}
......@@ -34,7 +34,7 @@ pub fn chdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
since = "0.1.55",
note = "use fchmod instead"
)]
pub fn chmod<T: AsRef<[u8]>>(path: T, mode: usize) -> Result<usize> {
pub fn chmod<T: AsRef<str>>(path: T, mode: usize) -> Result<usize> {
unsafe { syscall3(SYS_CHMOD, path.as_ref().as_ptr() as usize, path.as_ref().len(), mode) }
}
......@@ -115,7 +115,7 @@ pub fn fpath(fd: usize, buf: &mut [u8]) -> Result<usize> {
}
/// Rename a file
pub fn frename<T: AsRef<[u8]>>(fd: usize, path: T) -> Result<usize> {
pub fn frename<T: AsRef<str>>(fd: usize, path: T) -> Result<usize> {
unsafe { syscall3(SYS_FRENAME, fd, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}
......@@ -242,7 +242,7 @@ pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result<usize> {
}
/// Open a file
pub fn open<T: AsRef<[u8]>>(path: T, flags: usize) -> Result<usize> {
pub fn open<T: AsRef<str>>(path: T, flags: usize) -> Result<usize> {
unsafe { syscall3(SYS_OPEN, path.as_ref().as_ptr() as usize, path.as_ref().len(), flags) }
}
......@@ -326,7 +326,7 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
}
/// Remove a directory
pub fn rmdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
pub fn rmdir<T: AsRef<str>>(path: T) -> Result<usize> {
unsafe { syscall2(SYS_RMDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}
......@@ -376,7 +376,7 @@ pub fn umask(mask: usize) -> Result<usize> {
}
/// Remove a file
pub fn unlink<T: AsRef<[u8]>>(path: T) -> Result<usize> {
pub fn unlink<T: AsRef<str>>(path: T) -> Result<usize> {
unsafe { syscall2(SYS_UNLINK, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}
......
use core::{slice, str};
pub use self::scheme::Scheme;
pub use self::scheme_mut::SchemeMut;
pub use self::scheme_block::SchemeBlock;
pub use self::scheme_block_mut::SchemeBlockMut;
pub use self::seek::*;
unsafe fn str_from_raw_parts(ptr: *const u8, len: usize) -> Option<&'static str> {
let slice = slice::from_raw_parts(ptr, len);
str::from_utf8(slice).ok()
}
mod scheme;
mod scheme_mut;
mod scheme_block;
......
......@@ -4,14 +4,31 @@ use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
use crate::scheme::str_from_raw_parts;
pub trait Scheme {
fn handle(&self, packet: &mut Packet) {
let res = 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_CHMOD => self.chmod(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_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.open(path, packet.d, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.chmod(path, packet.d as u16, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.rmdir(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.unlink(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
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) }),
......@@ -34,7 +51,11 @@ pub trait Scheme {
SYS_FUNMAP_OLD => self.funmap_old(packet.b),
SYS_FUNMAP => self.funmap(packet.b, packet.c),
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
self.frename(packet.b, path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
} else {
......@@ -62,22 +83,22 @@ pub trait Scheme {
/* Scheme operations */
#[allow(unused_variables)]
fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<usize> {
fn open(&self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<usize> {
fn chmod(&self, path: &str, 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> {
fn rmdir(&self, path: &str, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
fn unlink(&self, path: &str, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(ENOENT))
}
......@@ -154,7 +175,7 @@ pub trait Scheme {
}
#[allow(unused_variables)]
fn frename(&self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
fn frename(&self, id: usize, path: &str, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(EBADF))
}
......
......@@ -4,14 +4,31 @@ use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
use crate::scheme::str_from_raw_parts;
pub trait SchemeBlock {
fn handle(&self, packet: &Packet) -> Option<usize> {
let res = 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_CHMOD => self.chmod(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_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.open(path, packet.d, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.chmod(path, packet.d as u16, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.rmdir(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.unlink(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
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) }),
......@@ -34,7 +51,11 @@ pub trait SchemeBlock {
SYS_FUNMAP_OLD => self.funmap_old(packet.b),
SYS_FUNMAP => self.funmap(packet.b, packet.c),
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
self.frename(packet.b, path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
} else {
......@@ -62,22 +83,22 @@ pub trait SchemeBlock {
/* Scheme operations */
#[allow(unused_variables)]
fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
fn open(&self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
fn chmod(&self, path: &str, mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
fn rmdir(&self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
fn unlink(&self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
......@@ -154,7 +175,7 @@ pub trait SchemeBlock {
}
#[allow(unused_variables)]
fn frename(&self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
fn frename(&self, id: usize, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(EBADF))
}
......
......@@ -4,14 +4,31 @@ use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
use crate::scheme::str_from_raw_parts;
pub trait SchemeBlockMut {
fn handle(&mut self, packet: &Packet) -> Option<usize> {
let res = 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_CHMOD => self.chmod(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_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.open(path, packet.d, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.chmod(path, packet.d as u16, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.rmdir(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.unlink(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
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) }),
......@@ -34,7 +51,11 @@ pub trait SchemeBlockMut {
SYS_FUNMAP_OLD => self.funmap_old(packet.b),
SYS_FUNMAP => self.funmap(packet.b, packet.c),
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
self.frename(packet.b, path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
} else {
......@@ -62,22 +83,22 @@ pub trait SchemeBlockMut {
/* Scheme operations */
#[allow(unused_variables)]
fn open(&mut self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
fn open(&mut self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn chmod(&mut self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
fn chmod(&mut self, path: &str, mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn rmdir(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
fn rmdir(&mut self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn unlink(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
fn unlink(&mut self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(ENOENT))
}
......@@ -154,7 +175,7 @@ pub trait SchemeBlockMut {
}
#[allow(unused_variables)]
fn frename(&mut self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<Option<usize>> {
fn frename(&mut self, id: usize, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
Err(Error::new(EBADF))
}
......
......@@ -4,14 +4,31 @@ use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
use crate::scheme::str_from_raw_parts;
pub trait SchemeMut {
fn handle(&mut self, packet: &mut Packet) {
let res = 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_CHMOD => self.chmod(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_OPEN => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.open(path, packet.d, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.chmod(path, packet.d as u16, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_RMDIR => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.rmdir(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_UNLINK => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
self.unlink(path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
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) }),
......@@ -34,7 +51,11 @@ pub trait SchemeMut {
SYS_FUNMAP_OLD => self.funmap_old(packet.b),
SYS_FUNMAP => self.funmap(packet.b, packet.c),
SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
SYS_FRENAME => self.frename(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }, packet.uid, packet.gid),
SYS_FRENAME => if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
self.frename(packet.b, path, packet.uid, packet.gid)
} else {
Err(Error::new(EINVAL))
},
SYS_FSTAT => if packet.d >= mem::size_of::<Stat>() {
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
} else {
......@@ -62,22 +83,22 @@ pub trait SchemeMut {
/* Scheme operations */
#[allow(unused_variables)]
fn open(&mut self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result<usize> {
fn open(&mut self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn chmod(&mut self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result<usize> {
fn chmod(&mut self, path: &str, mode: u16, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn rmdir(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
fn rmdir(&mut self, path: &str, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(ENOENT))
}
#[allow(unused_variables)]
fn unlink(&mut self, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
fn unlink(&mut self, path: &str, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(ENOENT))
}
......@@ -154,7 +175,7 @@ pub trait SchemeMut {
}
#[allow(unused_variables)]
fn frename(&mut self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
fn frename(&mut self, id: usize, path: &str, uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(EBADF))
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment