mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
syscalls: chdir
This commit is contained in:
@@ -23,7 +23,8 @@ extern syscall_fcntl
|
|||||||
extern syscall_getpid
|
extern syscall_getpid
|
||||||
extern syscall_getdirent
|
extern syscall_getdirent
|
||||||
extern syscall_ioctl
|
extern syscall_ioctl
|
||||||
func_count equ 22
|
extern syscall_chdir
|
||||||
|
func_count equ 23
|
||||||
|
|
||||||
|
|
||||||
func_table:
|
func_table:
|
||||||
@@ -49,6 +50,7 @@ func_table:
|
|||||||
dq syscall_getpid
|
dq syscall_getpid
|
||||||
dq syscall_getdirent
|
dq syscall_getdirent
|
||||||
dq syscall_ioctl
|
dq syscall_ioctl
|
||||||
|
dq syscall_chdir
|
||||||
section .text
|
section .text
|
||||||
global asm_syscall_entry
|
global asm_syscall_entry
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#include <kernel/syscalls.h>
|
||||||
|
#include <kernel/vmm.h>
|
||||||
|
#include <kernel/vfs.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <arch/cls.h>
|
||||||
|
#include <kernel/sched.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
syscallret syscall_chdir(const char* path){
|
||||||
|
syscallret retv;
|
||||||
|
|
||||||
|
retv.ret = -1;
|
||||||
|
|
||||||
|
if(path > USER_SPACE_END){
|
||||||
|
retv.errno = EFAULT;
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t len = strlen(path);
|
||||||
|
char buff[len+1];
|
||||||
|
|
||||||
|
strcpy(buff, path);
|
||||||
|
|
||||||
|
proc_t* proc = arch_getcls()->thread->proc;
|
||||||
|
|
||||||
|
vnode_t* node;
|
||||||
|
|
||||||
|
retv.errno = vfs_open(&node, buff[0] == '/' ? proc->root : proc->cwd, buff);
|
||||||
|
|
||||||
|
if(retv.errno)
|
||||||
|
return retv;
|
||||||
|
|
||||||
|
if(GETTYPE(node->st.st_mode) != TYPE_DIR){
|
||||||
|
vfs_close(node);
|
||||||
|
retv.errno = ENOTDIR;
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
|
vnode_t* old = proc->cwd;
|
||||||
|
proc->cwd = node;
|
||||||
|
|
||||||
|
vfs_close(old);
|
||||||
|
|
||||||
|
retv.ret = 0;
|
||||||
|
|
||||||
|
return retv;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user