Skip to content

Commit

Permalink
feat(fs/syscall): 实现fchdir系统调用
Browse files Browse the repository at this point in the history
Signed-off-by: longjin <[email protected]>
  • Loading branch information
fslongjin committed Jan 1, 2025
1 parent bcf0382 commit c67a7bc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions kernel/src/filesystem/vfs/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,22 @@ impl Syscall {
}
}

pub fn fchdir(fd: i32) -> Result<usize, SystemError> {
let pcb = ProcessManager::current_pcb();
let file = pcb
.fd_table()
.read()
.get_file_by_fd(fd)
.ok_or(SystemError::EBADF)?;
let inode = file.inode();
if inode.metadata()?.file_type != FileType::Dir {
return Err(SystemError::ENOTDIR);
}
let path = inode.absolute_path()?;
pcb.basic_mut().set_cwd(path);
return Ok(0);
}

/// @brief 获取当前进程的工作目录路径
///
/// @param buf 指向缓冲区的指针
Expand Down
4 changes: 4 additions & 0 deletions kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ impl Syscall {
let r = args[0] as *const u8;
Self::chdir(r)
}
SYS_FCHDIR => {
let fd = args[0] as i32;
Self::fchdir(fd)
}

#[allow(unreachable_patterns)]
SYS_GETDENTS64 | SYS_GETDENTS => {
Expand Down

0 comments on commit c67a7bc

Please sign in to comment.