2023-03-12 14:32:09 +00:00
|
|
|
#include "Log.h"
|
2023-08-12 19:38:25 +00:00
|
|
|
#include "Pledge.h"
|
2023-03-12 14:32:09 +00:00
|
|
|
#include "fs/VFS.h"
|
|
|
|
#include "memory/MemoryManager.h"
|
|
|
|
#include "sys/Syscall.h"
|
2023-04-08 11:12:49 +00:00
|
|
|
#include "thread/Scheduler.h"
|
2023-03-12 14:32:09 +00:00
|
|
|
|
|
|
|
Result<u64> sys_mkdir(Registers*, SyscallArgs args)
|
|
|
|
{
|
2023-03-12 15:30:36 +00:00
|
|
|
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
2023-03-12 15:55:46 +00:00
|
|
|
mode_t mode = (mode_t)args[1];
|
2023-03-12 14:32:09 +00:00
|
|
|
|
2023-04-08 11:12:49 +00:00
|
|
|
Thread* current = Scheduler::current();
|
2023-08-12 19:38:25 +00:00
|
|
|
TRY(check_pledge(current, Promise::p_cpath));
|
2023-04-08 11:12:49 +00:00
|
|
|
|
2023-08-01 15:20:28 +00:00
|
|
|
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));
|
2023-03-12 14:32:09 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|