Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading