Skip to content

Commit

Permalink
Add frename
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Dec 28, 2017
1 parent 3c76573 commit 414b8e0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -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>"]
Expand Down
5 changes: 5 additions & 0 deletions src/call.rs
Expand Up @@ -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>()) }
Expand Down
1 change: 1 addition & 0 deletions src/number.rs
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/scheme.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 414b8e0

Please sign in to comment.