Implement fpath in initfs

This commit is contained in:
Jeremy Soller 2016-09-22 21:13:17 -06:00
parent d5ac1a70bd
commit 0d762918e2
4 changed files with 65 additions and 12 deletions

View file

@ -98,6 +98,24 @@ pub fn dup(fd: usize) -> Result<usize> {
scheme.dup(file.number)
}
/// Get the canonical path of the file
pub fn fpath(fd: usize, buf: &mut [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 scheme = {
let schemes = scheme::schemes();
let scheme = schemes.get(file.scheme).ok_or(Error::new(EBADF))?;
scheme.clone()
};
scheme.fpath(file.number, buf)
}
/// Get information about the file
pub fn fstat(fd: usize, stat: &mut Stat) -> Result<usize> {
let file = {

View file

@ -44,6 +44,7 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
SYS_CLONE => clone(b, stack),
SYS_YIELD => sched_yield(),
SYS_GETCWD => getcwd(validate_slice_mut(b as *mut u8, c)?),
SYS_FPATH => fpath(b, validate_slice_mut(c as *mut u8, d)?),
SYS_PHYSMAP => physmap(b, c, d),
SYS_PHYSUNMAP => physunmap(b),
_ => {