Skip to content
Snippets Groups Projects
Commit d50a1485 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

mkdir and rmdir

parent af5b43ca
No related branches found
No related tags found
No related merge requests found
...@@ -62,6 +62,50 @@ pub fn open(path: &[u8], flags: usize) -> Result<usize> { ...@@ -62,6 +62,50 @@ pub fn open(path: &[u8], flags: usize) -> Result<usize> {
}).ok_or(Error::new(EMFILE)) }).ok_or(Error::new(EMFILE))
} }
/// mkdir syscall
pub fn mkdir(path: &[u8], mode: usize) -> 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.mkdir(reference_opt.unwrap_or(b""), mode)
}
/// rmdir syscall
pub fn rmdir(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.rmdir(reference_opt.unwrap_or(b""))
}
/// Unlink syscall /// Unlink syscall
pub fn unlink(path: &[u8]) -> Result<usize> { pub fn unlink(path: &[u8]) -> Result<usize> {
let path_canon = { let path_canon = {
......
...@@ -38,6 +38,8 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize ...@@ -38,6 +38,8 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
SYS_LSEEK => lseek(b, c, d), SYS_LSEEK => lseek(b, c, d),
SYS_GETPID => getpid(), SYS_GETPID => getpid(),
SYS_FSTAT => fstat(b, &mut validate_slice_mut(c as *mut Stat, 1)?[0]), SYS_FSTAT => fstat(b, &mut validate_slice_mut(c as *mut Stat, 1)?[0]),
SYS_MKDIR => mkdir(validate_slice(b as *const u8, c)?, d),
SYS_RMDIR => rmdir(validate_slice(b as *const u8, c)?),
SYS_DUP => dup(b), SYS_DUP => dup(b),
SYS_BRK => brk(b), SYS_BRK => brk(b),
SYS_FTRUNCATE => ftruncate(b, c), SYS_FTRUNCATE => ftruncate(b, c),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment