mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2026-04-24 00:59:12 -04:00
syscalls: implement chdir
Implement chdir(2).
This commit is contained in:
@@ -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
17
src/fs/syscalls/chdir.rs
Normal 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)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod at;
|
||||
pub mod chdir;
|
||||
pub mod close;
|
||||
pub mod ioctl;
|
||||
pub mod iov;
|
||||
|
||||
Reference in New Issue
Block a user