34 lines
901 B
C++
34 lines
901 B
C++
#include "Log.h"
|
|
#include "fs/VFS.h"
|
|
#include "memory/MemoryManager.h"
|
|
#include "sys/Syscall.h"
|
|
#include "thread/Scheduler.h"
|
|
#include <bits/makedev.h>
|
|
#include <luna/PathParser.h>
|
|
|
|
Result<u64> sys_mknod(Registers*, SyscallArgs args)
|
|
{
|
|
auto path = TRY(MemoryManager::strdup_from_user(args[0]));
|
|
mode_t mode = (mode_t)args[1];
|
|
dev_t dev = (dev_t)args[2];
|
|
|
|
u32 maj = luna_dev_major(dev);
|
|
u32 min = luna_dev_minor(dev);
|
|
|
|
kdbgln("mknod: attempting to create device %u:%u in path %s", maj, min, path.chars());
|
|
|
|
auto parser = TRY(PathParser::create(path.chars()));
|
|
|
|
auto dirname = TRY(parser.dirname());
|
|
auto basename = TRY(parser.basename());
|
|
|
|
auto parent = TRY(VFS::resolve_path(dirname.chars()));
|
|
|
|
auto inode = TRY(parent->fs().create_device_inode(maj, min));
|
|
TRY(parent->add_entry(inode, basename.chars()));
|
|
|
|
TRY(inode->chmod(mode));
|
|
|
|
return 0;
|
|
}
|