Kernel: Implement mkdir() from a single path
This is done using dirname() and basename() :)
This commit is contained in:
parent
8c0a57f0c2
commit
f8154ce230
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user