Kernel: Implement mkdir() from a single path

This is done using dirname() and basename() :)
This commit is contained in:
apio 2022-10-16 14:45:25 +02:00
parent 8c0a57f0c2
commit f8154ce230
3 changed files with 22 additions and 2 deletions

View File

@ -35,7 +35,8 @@ namespace VFS
ssize_t read(Node* node, size_t offset, size_t length, char* buffer);
ssize_t write(Node* node, size_t offset, size_t length, const char* buffer);
int mkdir(const char* path, const char* name); // FIXME: Support deducing this via a single path.
int mkdir(const char* path, const char* name);
int mkdir(const char* pathname);
void mount_root(Node* root);

View File

@ -3,6 +3,7 @@
#include "fs/VFS.h"
#include "errno.h"
#include "log/Log.h"
#include "std/libgen.h"
#include "std/stdlib.h"
#include "std/string.h"
@ -141,6 +142,24 @@ int VFS::mkdir(const char* path, const char* name)
return node->mkdir_func(node, name);
}
int VFS::mkdir(const char* pathname)
{
char* bstr = strdup(pathname);
char* dstr = strdup(pathname);
char* base = basename(bstr);
char* dir = dirname(dstr);
kdbgln("mkdir(): creating %s in directory %s", base, dir);
int result = mkdir(dir, base);
kfree(bstr);
kfree(dstr);
return result;
}
void VFS::mount(Node* mountpoint, Node* mounted)
{
if (!mountpoint || !mounted) return;

View File

@ -77,7 +77,7 @@ extern "C" void _start()
kinfoln("Prepared scheduler tasks");
ASSERT(VFS::mkdir("/", "dev") == 0);
ASSERT(VFS::mkdir("/dev") == 0);
VFS::mount("/dev", DeviceFS::get());
Init::finish_kernel_boot();