From a08191c7193293308348dc5c7e35932082bb330d Mon Sep 17 00:00:00 2001 From: LoGin Date: Wed, 1 Jan 2025 23:36:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(fs/syscall):=20=E5=AE=9E=E7=8E=B0fchdir?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E8=B0=83=E7=94=A8=20(#1081)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: longjin --- kernel/src/filesystem/vfs/syscall.rs | 16 ++++++++++++++++ kernel/src/syscall/mod.rs | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/kernel/src/filesystem/vfs/syscall.rs b/kernel/src/filesystem/vfs/syscall.rs index 795469bd4..f9ca9528f 100644 --- a/kernel/src/filesystem/vfs/syscall.rs +++ b/kernel/src/filesystem/vfs/syscall.rs @@ -740,6 +740,22 @@ impl Syscall { } } + pub fn fchdir(fd: i32) -> Result { + 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 指向缓冲区的指针 diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index f9f7db29c..c904cd90f 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -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 => {