mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: mkdir and chroot
This commit is contained in:
@@ -32,7 +32,9 @@ extern syscall_umask
|
||||
extern syscall_poll
|
||||
extern syscall_fchmodat
|
||||
extern syscall_openat
|
||||
func_count equ 31
|
||||
extern syscall_chroot
|
||||
extern syscall_mkdirat
|
||||
func_count equ 33
|
||||
|
||||
|
||||
func_table:
|
||||
@@ -67,6 +69,8 @@ func_table:
|
||||
dq syscall_poll
|
||||
dq syscall_fchmodat
|
||||
dq syscall_openat
|
||||
dq syscall_chroot
|
||||
dq syscall_mkdirat
|
||||
section .text
|
||||
global asm_syscall_entry
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <kernel/vfs.h>
|
||||
#include <kernel/sched.h>
|
||||
#include <kernel/vmm.h>
|
||||
#include <arch/cls.h>
|
||||
|
||||
syscallret syscall_chroot(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* vnode;
|
||||
|
||||
retv.errno = vfs_open(&vnode,
|
||||
buff[0] == '/' ? proc->root : proc->cwd,
|
||||
buff
|
||||
);
|
||||
|
||||
if(retv.errno)
|
||||
return retv;
|
||||
|
||||
if(GETTYPE(vnode->st.st_mode) != TYPE_DIR){
|
||||
retv.errno = ENOTDIR;
|
||||
goto _ret;
|
||||
}
|
||||
|
||||
dirnode_t* oldroot = proc->root;
|
||||
proc->root = (dirnode_t*)vnode;
|
||||
|
||||
retv.errno = 0;
|
||||
retv.ret = 0;
|
||||
|
||||
_ret:
|
||||
|
||||
vfs_close(vnode);
|
||||
|
||||
return retv;
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
syscallret syscall_mkdir(const char* pathname, mode_t mode){
|
||||
syscallret syscall_mkdirat(int dirfd, const char* pathname, mode_t mode){
|
||||
syscallret retv;
|
||||
retv.ret = -1;
|
||||
|
||||
@@ -19,12 +19,32 @@ syscallret syscall_mkdir(const char* pathname, mode_t mode){
|
||||
|
||||
strcpy(path, pathname);
|
||||
|
||||
retv.errno = vfs_mkdir(path[0] == '/' ? proc->root : proc->cwd, path, mode & ~proc->umask);
|
||||
dirnode_t* target;
|
||||
fd_t* targetfd;
|
||||
|
||||
if(dirfd != AT_FDCWD){
|
||||
|
||||
retv.errno = fd_access(&proc->fdtable, &targetfd, dirfd);
|
||||
if(retv.errno)
|
||||
return retv;
|
||||
|
||||
target = targetfd->node;
|
||||
|
||||
}
|
||||
else target = proc->cwd;
|
||||
|
||||
retv.errno = vfs_mkdir(path[0] == '/' ? proc->root : target, path, mode & ~proc->umask);
|
||||
|
||||
if(retv.errno == 0)
|
||||
retv.ret = 0;
|
||||
|
||||
|
||||
if(dirfd != AT_FDCWD)
|
||||
fd_release(targetfd);
|
||||
|
||||
return retv;
|
||||
|
||||
}
|
||||
|
||||
syscallret syscall_mkdir(const char* pathname, mode_t mode){
|
||||
return syscall_mkdirat(AT_FDCWD, pathname, mode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user