diff --git a/kernel/src/fs/VFS.cpp b/kernel/src/fs/VFS.cpp index 1da679c4..adaf43a3 100644 --- a/kernel/src/fs/VFS.cpp +++ b/kernel/src/fs/VFS.cpp @@ -1,4 +1,6 @@ #include "fs/VFS.h" +#include "Log.h" +#include namespace VFS { @@ -6,6 +8,31 @@ namespace VFS Inode& root_inode() { - return root_fs->root_inode(); + return *root_fs->root_inode(); + } + + Result> resolve_path(const char* path) + { + auto parser = TRY(PathParser::create(path)); + + kdbgln("vfs: trying to resolve path %s", path); + + SharedPtr 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; } } diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index ea065ddb..cc8e0f8c 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -60,7 +60,7 @@ namespace VFS class FileSystem { public: - virtual Inode& root_inode() const = 0; + virtual SharedPtr root_inode() const = 0; virtual Result> create_file_inode() = 0; @@ -71,7 +71,7 @@ namespace VFS extern SharedPtr root_fs; - Result resolve_path(const char* path); + Result> resolve_path(const char* path); Inode& root_inode(); } diff --git a/kernel/src/fs/tmpfs/FileSystem.h b/kernel/src/fs/tmpfs/FileSystem.h index 6212daea..2959790a 100644 --- a/kernel/src/fs/tmpfs/FileSystem.h +++ b/kernel/src/fs/tmpfs/FileSystem.h @@ -10,9 +10,9 @@ namespace TmpFS class FileSystem : public VFS::FileSystem { public: - VFS::Inode& root_inode() const override + SharedPtr root_inode() const override { - return *m_root_inode; + return m_root_inode; } Result> create_file_inode() override; diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp index b015f611..739cfb72 100644 --- a/kernel/src/main.cpp +++ b/kernel/src/main.cpp @@ -71,6 +71,10 @@ static Result 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 {}; }