mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 14:16:47 +00:00
feat(fs/syscall): 实现fchdir系统调用 (#1081)
Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
parent
bcf0382763
commit
a08191c719
@ -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 指向缓冲区的指针
|
||||
|
@ -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 => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user