syscalls: mkdir and chroot

This commit is contained in:
Matheus
2022-10-16 16:52:12 -03:00
parent 614c262690
commit b2746a5f01
3 changed files with 80 additions and 4 deletions
+23 -3
View File
@@ -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);
}