2023-02-03 21:18:52 +00:00
|
|
|
#include "fs/VFS.h"
|
2023-03-10 21:18:48 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include <luna/PathParser.h>
|
2023-02-03 21:18:52 +00:00
|
|
|
|
|
|
|
namespace VFS
|
|
|
|
{
|
|
|
|
SharedPtr<FileSystem> root_fs;
|
2023-02-25 17:05:25 +00:00
|
|
|
|
|
|
|
Inode& root_inode()
|
|
|
|
{
|
2023-03-10 21:18:48 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
if (parser.is_absolute()) { current_inode = root_fs->root_inode(); }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kwarnln("vfs: cannot resolve path '%s', as relative paths are not supported yet", path);
|
|
|
|
return err(ENOTSUP);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2023-02-25 17:05:25 +00:00
|
|
|
}
|
2023-02-03 21:18:52 +00:00
|
|
|
}
|