Unlink syscall

This commit is contained in:
Jeremy Soller 2016-09-28 11:18:28 -06:00
parent be8cb1ff38
commit 4488cde338
3 changed files with 54 additions and 1 deletions

View file

@ -216,6 +216,30 @@ impl Scheme for UserScheme {
result
}
fn mkdir(&self, path: &[u8], mode: usize) -> Result<usize> {
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
let address = inner.capture(path)?;
let result = inner.call(SYS_MKDIR, address, path.len(), mode);
let _ = inner.release(address);
result
}
fn rmdir(&self, path: &[u8]) -> Result<usize> {
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
let address = inner.capture(path)?;
let result = inner.call(SYS_RMDIR, address, path.len(), 0);
let _ = inner.release(address);
result
}
fn unlink(&self, path: &[u8]) -> Result<usize> {
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
let address = inner.capture(path)?;
let result = inner.call(SYS_UNLINK, address, path.len(), 0);
let _ = inner.release(address);
result
}
fn dup(&self, file: usize) -> Result<usize> {
let inner = self.inner.upgrade().ok_or(Error::new(ENODEV))?;
inner.call(SYS_DUP, file, 0, 0)

View file

@ -62,6 +62,28 @@ pub fn open(path: &[u8], flags: usize) -> Result<usize> {
}).ok_or(Error::new(EMFILE))
}
/// Unlink syscall
pub fn unlink(path: &[u8]) -> Result<usize> {
let path_canon = {
let contexts = context::contexts();
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
let context = context_lock.read();
context.canonicalize(path)
};
let mut parts = path_canon.splitn(2, |&b| b == b':');
let namespace_opt = parts.next();
let reference_opt = parts.next();
let namespace = namespace_opt.ok_or(Error::new(ENOENT))?;
let scheme = {
let schemes = scheme::schemes();
let (_scheme_id, scheme) = schemes.get_name(namespace).ok_or(Error::new(ENOENT))?;
scheme.clone()
};
scheme.unlink(reference_opt.unwrap_or(b""))
}
/// Close syscall
pub fn close(fd: usize) -> Result<usize> {
let file = {

View file

@ -32,6 +32,7 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
SYS_OPEN => open(validate_slice(b as *const u8, c)?, d),
SYS_CLOSE => close(b),
SYS_WAITPID => waitpid(b, c, d),
SYS_UNLINK => unlink(validate_slice(b as *const u8, c)?),
SYS_EXECVE => exec(validate_slice(b as *const u8, c)?, validate_slice(d as *const [usize; 2], e)?),
SYS_CHDIR => chdir(validate_slice(b as *const u8, c)?),
SYS_LSEEK => lseek(b, c, d),
@ -59,5 +60,11 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
}
}
Error::mux(inner(a, b, c, d, e, f, stack))
let result = inner(a, b, c, d, e, f, stack);
if let Err(ref err) = result {
println!("{}, {}, {}, {}: {}", a, b, c, d, err);
}
Error::mux(result)
}