Move absolute/relative path resolution to rcore-fs, implement dummy sys_fchown, sys_fchownat and sys_symlinkat

master
Jiajie Chen 6 years ago
parent 48ebf98f11
commit 285ffc7618

4
kernel/Cargo.lock generated

@ -338,12 +338,12 @@ dependencies = [
[[package]]
name = "rcore-fs"
version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#c9322710b4ba67c086f500befb8208c6ae353493"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#166616e5ade1a5c929f705fd1564ef0ea337ba72"
[[package]]
name = "rcore-fs-sfs"
version = "0.1.0"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#c9322710b4ba67c086f500befb8208c6ae353493"
source = "git+https://github.com/rcore-os/rcore-fs?branch=sefs#166616e5ade1a5c929f705fd1564ef0ea337ba72"
dependencies = [
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

@ -69,6 +69,7 @@ macro_rules! impl_inode {
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self }
fn chmod(&self, _mode: u16) -> Result<()> { Ok(()) }
};
}

@ -64,6 +64,7 @@ macro_rules! impl_inode {
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
fn fs(&self) -> Arc<FileSystem> { unimplemented!() }
fn as_any_ref(&self) -> &Any { self }
fn chmod(&self, _mode: u16) -> Result<()> { Ok(()) }
};
}

@ -725,19 +725,9 @@ impl Process {
}
})
}
fn lookup_inode(&self, path: &str) -> Result<Arc<INode>, SysError> {
pub fn lookup_inode(&self, path: &str) -> Result<Arc<INode>, SysError> {
debug!("lookup_inode: cwd {} path {}", self.cwd, path);
if path.len() > 0 && path.as_bytes()[0] == b'/' {
// absolute path
let abs_path = path.split_at(1).1; // skip start '/'
let inode = ROOT_INODE.lookup_follow(abs_path, FOLLOW_MAX_DEPTH)?;
Ok(inode)
} else {
// relative path
let cwd = self.cwd.split_at(1).1; // skip start '/'
let inode = ROOT_INODE.lookup(cwd)?.lookup_follow(path, FOLLOW_MAX_DEPTH)?;
Ok(inode)
}
Ok(ROOT_INODE.lookup(&self.cwd)?.lookup_follow(path, FOLLOW_MAX_DEPTH)?)
}
}

@ -131,11 +131,15 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
SYS_GETCWD => sys_getcwd(args[0] as *mut u8, args[1]),
// 80
SYS_CHDIR => sys_chdir(args[0] as *const u8),
SYS_GETTIMEOFDAY => sys_gettimeofday(args[0] as *mut TimeVal, args[1] as *const u8),
SYS_FCHOWN => {
warn!("sys_fchown is unimplemented");
Ok(0)
}
SYS_UMASK => {
warn!("sys_umask is unimplemented");
Ok(0o777)
}
SYS_GETTIMEOFDAY => sys_gettimeofday(args[0] as *mut TimeVal, args[1] as *const u8),
// SYS_GETRLIMIT => sys_getrlimit(),
SYS_GETRUSAGE => sys_getrusage(args[0], args[1] as *mut RUsage),
SYS_SYSINFO => sys_sysinfo(args[0] as *mut SysInfo),
@ -202,10 +206,16 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
SYS_OPENAT => sys_openat(args[0], args[1] as *const u8, args[2], args[3]), // TODO: handle `dfd`
SYS_MKDIRAT => sys_mkdir(args[1] as *const u8, args[2]), // TODO: handle `dfd`
// SYS_MKNODAT => sys_mknod(),
// 260
SYS_FCHOWNAT => {
warn!("sys_fchownat is unimplemented");
Ok(0)
},
SYS_NEWFSTATAT => sys_stat(args[1] as *const u8, args[2] as *mut Stat), // TODO: handle `dfd`, `flag`
SYS_UNLINKAT => sys_unlink(args[1] as *const u8), // TODO: handle `dfd`, `flag`
SYS_RENAMEAT => sys_renameat(args[0], args[1] as *const u8, args[2], args[3] as *const u8), // TODO: handle `olddfd`, `newdfd`
SYS_LINKAT => sys_link(args[1] as *const u8, args[3] as *const u8), // TODO: handle `olddfd`, `newdfd`, `flags`
SYS_SYMLINKAT => Err(SysError::EACCES),
SYS_FACCESSAT => sys_access(args[1] as *const u8, args[2]), // TODO: handle `dfd`
// 280
SYS_UTIMENSAT => {

@ -1,7 +1,7 @@
//! Syscalls for process
use super::*;
use crate::fs::{INodeExt, FOLLOW_MAX_DEPTH};
use crate::fs::INodeExt;
/// Fork the current process. Return the child's PID.
pub fn sys_fork(tf: &TrapFrame) -> SysResult {
@ -120,7 +120,7 @@ pub fn sys_exec(name: *const u8, argv: *const *const u8, envp: *const *const u8,
// Read program file
let path = args[0].as_str();
let inode = crate::fs::ROOT_INODE.lookup_follow(path, FOLLOW_MAX_DEPTH)?;
let inode = proc.lookup_inode(path)?;
let buf = inode.read_as_vec()?;
// Make new Thread

Loading…
Cancel
Save