Skip to content
Permalink
Browse files

Add frename

  • Loading branch information...
jackpot51 committed Dec 28, 2017
1 parent e08f56a commit 059cc8078d778d238963525df8011635bc27bf66
Showing with 50 additions and 5 deletions.
  1. +3 −3 Cargo.lock
  2. +1 −1 Cargo.toml
  3. +8 −0 src/scheme/user.rs
  4. +36 −0 src/syscall/fs.rs
  5. +1 −0 src/syscall/mod.rs
  6. +1 −1 syscall

Some generated files are not rendered by default. Learn more.

@@ -1,6 +1,6 @@
[package]
name = "kernel"
version = "0.1.32"
version = "0.1.33"
build = "build.rs"

[lib]
@@ -334,6 +334,14 @@ impl Scheme for UserScheme {
result
}

fn frename(&self, file: usize, path: &[u8], _uid: u32, _gid: u32) -> Result<usize> {
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
let address = inner.capture(path)?;
let result = inner.call(SYS_FRENAME, file, address, path.len());
let _ = inner.release(address);
result
}

fn fstat(&self, file: usize, stat: &mut Stat) -> Result<usize> {
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
let address = inner.capture_mut(stat)?;
@@ -422,6 +422,42 @@ pub fn fevent(fd: FileHandle, flags: usize) -> Result<usize> {
Ok(0)
}

pub fn frename(fd: FileHandle, path: &[u8]) -> 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 (path_canon, uid, gid, scheme_ns) = {
let contexts = context::contexts();
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
let context = context_lock.read();
(context.canonicalize(path), context.euid, context.egid, context.ens)
};

let mut parts = path_canon.splitn(2, |&b| b == b':');
let scheme_name_opt = parts.next();
let reference_opt = parts.next();

let scheme_name = scheme_name_opt.ok_or(Error::new(ENODEV))?;
let (scheme_id, scheme) = {
let schemes = scheme::schemes();
let (scheme_id, scheme) = schemes.get_name(scheme_ns, scheme_name).ok_or(Error::new(ENODEV))?;
(scheme_id, scheme.clone())
};

let description = file.description.read();

if scheme_id == description.scheme {
scheme.frename(description.number, reference_opt.unwrap_or(b""), uid, gid)
} else {
Err(Error::new(EXDEV))
}
}

pub fn funmap(virtual_address: usize) -> Result<usize> {
if virtual_address == 0 {
Ok(0)
@@ -64,6 +64,7 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
SYS_DUP2 => dup2(fd, FileHandle::from(c), validate_slice(d as *const u8, e)?).map(FileHandle::into),
SYS_FCNTL => fcntl(fd, c, d),
SYS_FEVENT => fevent(fd, c),
SYS_FRENAME => frename(fd, validate_slice(c as *const u8, d)?),
SYS_FUNMAP => funmap(b),
_ => file_op(a, fd, c, d)
}
Submodule syscall updated 4 files
+1 −1 Cargo.toml
+5 −0 src/call.rs
+1 −0 src/number.rs
+12 −0 src/scheme.rs

0 comments on commit 059cc80

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