VFS: Implement resolve_path() using PathParser
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Already works better than old luna (handles .. correctly)
This commit is contained in:
parent
4c66017807
commit
6fbf97292a
@ -1,4 +1,6 @@
|
||||
#include "fs/VFS.h"
|
||||
#include "Log.h"
|
||||
#include <luna/PathParser.h>
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
@ -6,6 +8,31 @@ namespace VFS
|
||||
|
||||
Inode& root_inode()
|
||||
{
|
||||
return root_fs->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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ namespace VFS
|
||||
class FileSystem
|
||||
{
|
||||
public:
|
||||
virtual Inode& root_inode() const = 0;
|
||||
virtual SharedPtr<Inode> root_inode() const = 0;
|
||||
|
||||
virtual Result<SharedPtr<Inode>> create_file_inode() = 0;
|
||||
|
||||
@ -71,7 +71,7 @@ namespace VFS
|
||||
|
||||
extern SharedPtr<FileSystem> root_fs;
|
||||
|
||||
Result<Inode*> resolve_path(const char* path);
|
||||
Result<SharedPtr<Inode>> resolve_path(const char* path);
|
||||
|
||||
Inode& root_inode();
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ namespace TmpFS
|
||||
class FileSystem : public VFS::FileSystem
|
||||
{
|
||||
public:
|
||||
VFS::Inode& root_inode() const override
|
||||
SharedPtr<VFS::Inode> root_inode() const override
|
||||
{
|
||||
return *m_root_inode;
|
||||
return m_root_inode;
|
||||
}
|
||||
|
||||
Result<SharedPtr<VFS::Inode>> create_file_inode() override;
|
||||
|
@ -71,6 +71,10 @@ static Result<void> try_init_vfs()
|
||||
|
||||
kinfoln("etc inode's 'passwd' entry inode number: %zu", TRY(etc.find("passwd"))->inode_number());
|
||||
|
||||
auto& passwd = *TRY(VFS::resolve_path("/etc/passwd"));
|
||||
|
||||
kinfoln("/etc/passwd's inode number: %zu", passwd.inode_number());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user