Implement sys_getcwd

master
Jiajie Chen 6 years ago
parent e543449836
commit 687caf804d

@ -51,7 +51,7 @@ impl Thread {
proc: Arc::new(Mutex::new(Process {
memory_set: MemorySet::new(),
files: BTreeMap::default(),
cwd: String::new(),
cwd: String::from("/"),
sockets: SocketSet::new(vec![])
})),
})
@ -67,7 +67,7 @@ impl Thread {
proc: Arc::new(Mutex::new(Process {
memory_set,
files: BTreeMap::default(),
cwd: String::new(),
cwd: String::from("/"),
sockets: SocketSet::new(vec![])
})),
})
@ -146,7 +146,7 @@ impl Thread {
proc: Arc::new(Mutex::new(Process {
memory_set,
files,
cwd: String::new(),
cwd: String::from("/"),
sockets: SocketSet::new(vec![])
})),
})
@ -178,7 +178,7 @@ impl Thread {
proc: Arc::new(Mutex::new(Process {
memory_set,
files: self.proc.lock().files.clone(),
cwd: String::new(),
cwd: self.proc.lock().cwd.clone(),
// TODO: duplicate sockets for child process
sockets: SocketSet::new(vec![])
})),

@ -115,6 +115,21 @@ pub fn sys_close(fd: usize) -> SysResult {
}
}
pub fn sys_getcwd(buf: *mut u8, len: usize) -> SysResult {
info!("getcwd: buf: {:?}, len: {:#x}", buf, len);
let mut proc = process();
if !proc.memory_set.check_mut_array(buf, len) {
return Err(SysError::EFAULT);
}
if proc.cwd.len() + 1 > len {
return Err(SysError::ERANGE);
}
unsafe {
util::write_cstr(buf, &proc.cwd)
}
Ok(0)
}
pub fn sys_stat(path: *const u8, stat_ptr: *mut Stat) -> SysResult {
warn!("stat is partial implemented as lstat");
sys_lstat(path, stat_ptr)

@ -73,7 +73,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
// 074 => sys_fsync(),
// 076 => sys_trunc(),
// 077 => sys_ftrunc(),
// 079 => sys_getcwd(),
079 => sys_getcwd(args[0] as *mut u8, args[1]),
// 080 => sys_chdir(),
// 082 => sys_rename(),
// 083 => sys_mkdir(),

Loading…
Cancel
Save