diff options
Diffstat (limited to 'kernel/src/filesystem/dentry.cpp')
| -rw-r--r-- | kernel/src/filesystem/dentry.cpp | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/kernel/src/filesystem/dentry.cpp b/kernel/src/filesystem/dentry.cpp index a3bd7f4..7617b28 100644 --- a/kernel/src/filesystem/dentry.cpp +++ b/kernel/src/filesystem/dentry.cpp @@ -23,6 +23,10 @@ namespace kernel::filesystem { kapi::system::panic("[FILESYSTEM] dentry constructed with null inode."); } + if (m_name.empty()) + { + kapi::system::panic("[FILESYSTEM] dentry constructed with empty name."); + } } auto dentry::get_inode() const -> kstd::shared_ptr<inode> const & @@ -42,33 +46,25 @@ namespace kernel::filesystem auto dentry::get_full_path() const -> kstd::string { - if (m_name == "/") - { - return "/"; - } - - kstd::vector<std::string_view> components; - components.push_back(m_name.view()); - components.push_back("/"); + kstd::string path = m_name; auto parent = m_parent; - - while (parent && parent->m_name != "/") - { - components.push_back(parent->m_name.view()); - components.push_back("/"); - parent = parent->get_parent(); - } - - std::ranges::reverse(components); - - kstd::string full_path = ""; - for (auto const & view : components) + while (parent) { - full_path += view; + auto parent_name = parent->m_name; + if (parent_name == "/") + { + path = "/" + path; + } + else + { + path = parent_name + "/" + path; + } + + parent = parent->m_parent; } - return full_path; + return path; } auto dentry::add_child(kstd::shared_ptr<dentry> const & child) -> void |
