Luna/kernel/src/sys/mkdir.cpp
apio e2a77bb3da
Some checks failed
continuous-integration/drone/push Build is failing
kernel+libc: Add pledge support
2023-08-12 21:38:25 +02:00

25 lines
703 B
C++

#include "Log.h"
#include "Pledge.h"
#include "fs/VFS.h"
#include "memory/MemoryManager.h"
#include "sys/Syscall.h"
#include "thread/Scheduler.h"
Result<u64> sys_mkdir(Registers*, SyscallArgs args)
{
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
mode_t mode = (mode_t)args[1];
Thread* current = Scheduler::current();
TRY(check_pledge(current, Promise::p_cpath));
auto inode =
TRY(VFS::create_directory(path.chars(), mode & ~current->umask, current->auth, current->current_directory));
auto metadata = inode->metadata();
metadata.uid = current->auth.euid;
metadata.gid = current->auth.egid;
TRY(inode->set_metadata(metadata));
return 0;
}