Skip to content

Commit 54107da

Browse files
committed
Fixed a bug in the vfs::get_cwd syscall
Remove the double `\` when the path is not empty
1 parent e08c0ef commit 54107da

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kernel/src/syscall/vfs.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,19 @@ pub fn get_cwd(buf: usize, len: usize) -> Result<usize, GetCwdError> {
467467

468468
// Write the path components to the buffer in reverse order
469469
// (from the last component to the first)
470-
let mut path = core::iter::successors(Some(cwd), |dentry| dentry.parent())
470+
let path = core::iter::successors(Some(cwd), |dentry| dentry.parent())
471471
.take_while(|dentry| !Arc::ptr_eq(dentry, &root))
472472
.map(|dentry| dentry.name().into_inner())
473473
.collect::<Vec<_>>();
474-
path.push(String::new());
474+
475+
// Handle the case where the current working directory is the root directory
476+
if path.is_empty() {
477+
if len >= 1 {
478+
_ = buffer.write_buffered("/".as_bytes());
479+
return Ok(1);
480+
}
481+
return Err(GetCwdError::BufferTooSmall);
482+
}
475483

476484
// Verify that the buffer is large enough to hold the path
477485
let path_len = path.iter().fold(0, |acc, name| acc + name.len() + 1);

0 commit comments

Comments
 (0)