48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#include "fs/VFS.h"
|
|
#include "Log.h"
|
|
#include <luna/PathParser.h>
|
|
|
|
namespace VFS
|
|
{
|
|
SharedPtr<FileSystem> root_fs;
|
|
|
|
Inode& root_inode()
|
|
{
|
|
return *root_fs->root_inode();
|
|
}
|
|
|
|
Result<SharedPtr<Inode>> resolve_path(const char* path)
|
|
{
|
|
auto parser = TRY(PathParser::create(path));
|
|
|
|
kdbgln("vfs: trying to resolve path %s", path);
|
|
|
|
SharedPtr<Inode> current_inode = root_fs->root_inode();
|
|
|
|
// FIXME: Properly handle relative paths.
|
|
|
|
const char* section;
|
|
while (parser.next().try_set_value(section))
|
|
{
|
|
kdbgln("vfs: searching for entry '%s' in inode %zu", section, current_inode->inode_number());
|
|
current_inode = TRY(current_inode->find(section));
|
|
}
|
|
|
|
return current_inode;
|
|
}
|
|
|
|
Result<SharedPtr<Inode>> create_directory(const char* path)
|
|
{
|
|
auto parser = TRY(PathParser::create(path));
|
|
auto parent_path = TRY(parser.dirname());
|
|
|
|
auto parent_inode = TRY(resolve_path(parent_path.chars()));
|
|
|
|
auto child_name = TRY(parser.basename());
|
|
|
|
kdbgln("vfs: creating directory '%s' in parent '%s'", child_name.chars(), parent_path.chars());
|
|
|
|
return parent_inode->create_subdirectory(child_name.chars());
|
|
}
|
|
}
|