From a4221a559c9120a4526662bb3a5071016243b086 Mon Sep 17 00:00:00 2001 From: NagiNikaido Date: Fri, 12 Apr 2019 13:10:34 +0800 Subject: [PATCH 1/2] .gitignore updated. --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 4b4a5a8..021a507 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,8 @@ Cargo.lock # for eclipse .project +# for vscode .vscode + +# for vim +*.swp From c3813c4b38a6e9a5f7c67add07482eae87ca76a1 Mon Sep 17 00:00:00 2001 From: NagiNikaido Date: Mon, 15 Apr 2019 00:41:28 +0800 Subject: [PATCH 2/2] BUGFIX: rewrited sys_chdir(). --- kernel/src/syscall/fs.rs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index f59c203..97138b7 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -474,12 +474,34 @@ pub fn sys_chdir(path: *const u8) -> SysResult { return Err(SysError::ENOTDIR); } - if path.len() > 0 && path.as_bytes()[0] == b'/' { - // absolute - proc.cwd = path; - } else { - // relative - proc.cwd += &path; + // BUGFIX: '..' and '.' + if path.len() > 0 { + let cwd = match path.as_bytes()[0] { + b'/' => String::from("/"), + _ => proc.cwd.clone() + }; + let mut cwd_vec:Vec<_> = + cwd.split("/") + .filter(|&x| x != "") + .collect(); + let path_split = path.split("/").filter(|&x| x != ""); + for seg in path_split { + if seg == ".." { + cwd_vec.pop(); + } else if seg == "." { + // nothing to do here. + } else { + cwd_vec.push(seg); + } + } + proc.cwd = String::from(""); + for seg in cwd_vec { + proc.cwd.push_str("/"); + proc.cwd.push_str(seg); + } + if proc.cwd == "" { + proc.cwd = String::from("/"); + } } Ok(0) }