feat(fs/syscall): 实现fchdir系统调用 (#1081)

Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
LoGin 2025-01-01 23:36:37 +08:00 committed by GitHub
parent bcf0382763
commit a08191c719
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -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 指向缓冲区的指针

View File

@ -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 => {