syscalls: implement chdir

Implement chdir(2).
This commit is contained in:
Matthew Leach
2025-11-21 21:18:47 +00:00
parent 8abda6dd9c
commit 29f52efe13
3 changed files with 28 additions and 13 deletions

View File

@@ -6,17 +6,8 @@ use crate::{
pipe::sys_pipe2,
syscalls::{
at::{
access::{sys_faccessat, sys_faccessat2},
open::sys_openat,
stat::sys_newfstatat,
},
close::sys_close,
ioctl::sys_ioctl,
iov::{sys_readv, sys_writev},
rw::{sys_read, sys_write},
seek::sys_lseek,
splice::sys_sendfile,
stat::sys_fstat,
access::{sys_faccessat, sys_faccessat2}, open::sys_openat, readlink::sys_readlinkat, stat::sys_newfstatat
}, chdir::sys_chdir, close::sys_close, ioctl::sys_ioctl, iov::{sys_readv, sys_writev}, rw::{sys_read, sys_write}, seek::sys_lseek, splice::sys_sendfile, stat::sys_fstat
},
},
kernel::uname::sys_uname,
@@ -36,12 +27,17 @@ use crate::{
},
sleep::sys_nanosleep,
thread_group::{
Pgid, pid::{sys_getpgid, sys_getpid, sys_getppid, sys_setpgid}, rsrc_lim::sys_prlimit64, signal::{
Pgid,
pid::{sys_getpgid, sys_getpid, sys_getppid, sys_setpgid},
rsrc_lim::sys_prlimit64,
signal::{
kill::{sys_kill, sys_tkill},
sigaction::sys_rt_sigaction,
sigaltstack::sys_sigaltstack,
sigprocmask::sys_rt_sigprocmask,
}, umask::sys_umask, wait::sys_wait4
},
umask::sys_umask,
wait::sys_wait4,
},
threading::sys_set_tid_address,
},
@@ -77,6 +73,7 @@ pub async fn handle_syscall() {
0x19 => sys_fcntl(arg1.into(), arg2 as _, arg3 as _).await,
0x1d => sys_ioctl(arg1.into(), arg2 as _, arg3 as _).await,
0x30 => sys_faccessat(arg1.into(), TUA::from_value(arg2 as _), arg3 as _).await,
0x31 => sys_chdir(TUA::from_value(arg1 as _)).await,
0x38 => {
sys_openat(
arg1.into(),

17
src/fs/syscalls/chdir.rs Normal file
View File

@@ -0,0 +1,17 @@
use crate::{fs::VFS, memory::uaccess::cstr::UserCStr, sched::current_task};
use core::ffi::c_char;
use libkernel::{error::Result, fs::path::Path, memory::address::TUA};
pub async fn sys_chdir(path: TUA<c_char>) -> Result<usize> {
let mut buf = [0; 1024];
let path = Path::new(UserCStr::from_ptr(path).copy_from_user(&mut buf).await?);
let task = current_task();
let current_path = task.cwd.lock_save_irq().clone();
let node = VFS.resolve_path(path, current_path).await?;
*task.cwd.lock_save_irq() = node;
Ok(0)
}

View File

@@ -1,4 +1,5 @@
pub mod at;
pub mod chdir;
pub mod close;
pub mod ioctl;
pub mod iov;