Skip to content
Permalink
Browse files

Add frename

  • Loading branch information...
jackpot51 committed Dec 28, 2017
1 parent 3c76573 commit 414b8e0be011c70d5c55692f4dd835184f33579f
Showing with 19 additions and 1 deletion.
  1. +1 −1 Cargo.toml
  2. +5 −0 src/call.rs
  3. +1 −0 src/number.rs
  4. +12 −0 src/scheme.rs
@@ -1,6 +1,6 @@
[package]
name = "redox_syscall"
version = "0.1.32"
version = "0.1.33"
description = "A Rust library to access raw Redox system calls"
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
@@ -120,6 +120,11 @@ pub fn fpath(fd: usize, buf: &mut [u8]) -> Result<usize> {
unsafe { syscall3(SYS_FPATH, fd, buf.as_mut_ptr() as usize, buf.len()) }
}

/// Rename a file
pub fn frename<T: AsRef<[u8]>>(fd: usize, path: T) -> Result<usize> {
unsafe { syscall3(SYS_FRENAME, fd, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}

/// Get metadata about a file
pub fn fstat(fd: usize, stat: &mut Stat) -> Result<usize> {
unsafe { syscall3(SYS_FSTAT, fd, stat as *mut Stat as usize, mem::size_of::<Stat>()) }
@@ -29,6 +29,7 @@ pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927;
pub const SYS_FMAP: usize = SYS_CLASS_FILE | 90;
pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 91;
pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928;
pub const SYS_FRENAME: usize = SYS_CLASS_FILE | SYS_ARG_PATH | 38;
pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28;
pub const SYS_FSTATVFS: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 100;
pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118;
@@ -20,6 +20,7 @@ pub trait Scheme {
SYS_FEVENT => self.fevent(packet.b, packet.c),
SYS_FMAP => self.fmap(packet.b, packet.c, packet.d),
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_FSTAT => if packet.d >= mem::size_of::<Stat>() {
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
} else {
@@ -115,6 +116,11 @@ pub trait Scheme {
Err(Error::new(EBADF))
}

#[allow(unused_variables)]
fn frename(&self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(EBADF))
}

#[allow(unused_variables)]
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
Err(Error::new(EBADF))
@@ -164,6 +170,7 @@ pub trait SchemeMut {
SYS_FEVENT => self.fevent(packet.b, packet.c),
SYS_FMAP => self.fmap(packet.b, packet.c, packet.d),
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_FSTAT => if packet.d >= mem::size_of::<Stat>() {
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
} else {
@@ -258,6 +265,11 @@ pub trait SchemeMut {
Err(Error::new(EBADF))
}

#[allow(unused_variables)]
fn frename(&mut self, id: usize, path: &[u8], uid: u32, gid: u32) -> Result<usize> {
Err(Error::new(EBADF))
}

#[allow(unused_variables)]
fn fstat(&mut self, id: usize, stat: &mut Stat) -> Result<usize> {
Err(Error::new(EBADF))

0 comments on commit 414b8e0

Please sign in to comment.
You can’t perform that action at this time.