Add frename

This commit is contained in:
Jeremy Soller
2017-12-27 20:19:37 -07:00
parent e08f56a2de
commit 059cc8078d
6 changed files with 50 additions and 5 deletions

6
Cargo.lock generated
View File

@@ -32,13 +32,13 @@ dependencies = [
[[package]]
name = "kernel"
version = "0.1.32"
version = "0.1.33"
dependencies = [
"alloc_kernel 0.1.0",
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"goblin 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-cpuid 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.32",
"redox_syscall 0.1.33",
"spin 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"x86 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -75,7 +75,7 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.1.32"
version = "0.1.33"
[[package]]
name = "scroll"

View File

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

View File

@@ -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)?;

View File

@@ -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)

View File

@@ -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: 3c765737a5...414b8e0be0