diff options
Diffstat (limited to 'kernel/kernel/filesystem/dentry.hpp')
| -rw-r--r-- | kernel/kernel/filesystem/dentry.hpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/kernel/kernel/filesystem/dentry.hpp b/kernel/kernel/filesystem/dentry.hpp new file mode 100644 index 00000000..096a6bbb --- /dev/null +++ b/kernel/kernel/filesystem/dentry.hpp @@ -0,0 +1,104 @@ +#ifndef TEACH_OS_KERNEL_FILESYSTEM_DENTRY_HPP +#define TEACH_OS_KERNEL_FILESYSTEM_DENTRY_HPP + +#include <kernel/filesystem/inode.hpp> + +#include <kstd/memory> +#include <kstd/string> +#include <kstd/vector> + +#include <cstdint> +#include <string_view> + +namespace kernel::filesystem +{ + /** + @brief Represents a directory entry (dentry) in the filesystem. A dentry is a node in the directory tree that + represents a file or directory. It contains a reference to its parent dentry, a reference to the associated real + filesystem inode, and a list of child dentries. + */ + struct dentry + { + /** + @brief Flags for the dentry. + */ + enum class dentry_flags : uint32_t + { + is_mount_point = 1 << 0 + }; + + /** + @brief Create a dentry with the given @p parent, associated @p inode, and optional @p name. The dentry is + initialized with the provided parent and inode, and the name is stored for lookup purposes. + @param parent The parent dentry. + @param inode The associated inode for this dentry. + @param name The name of the dentry (optional). + */ + dentry(kstd::shared_ptr<dentry> const & parent, kstd::shared_ptr<inode> const & inode, std::string_view name); + + /** + @brief Get the associated inode. + @return A reference to the associated inode. + */ + [[nodiscard]] auto get_inode() const -> kstd::shared_ptr<inode> const &; + + /** + @brief Get the parent dentry. + @return A reference to the parent dentry. + */ + [[nodiscard]] auto parent() const -> kstd::shared_ptr<dentry>; + + /** + @brief Get the name of the dentry. + @return The name of the dentry. + */ + [[nodiscard]] auto name() const -> std::string_view; + + /** + @brief Get the full path of the dentry by traversing up to the root. + @return The full path of the dentry. + */ + [[nodiscard]] auto absolute_path() const -> kstd::string; + + /** + @brief Add a @p child dentry. + @param child The child dentry to add. + */ + auto add_child(kstd::shared_ptr<dentry> const & child) -> void; + + /** + @brief Find a child dentry by @p name. + @param name The name of the child dentry to find. + @return A pointer to the found child dentry, or a null pointer if not found. + */ + [[nodiscard]] auto find_child(std::string_view name) const -> kstd::shared_ptr<dentry>; + + /** + @brief Set a @p flag for the dentry. + @param flag The flag to set. + */ + auto set_flag(dentry_flags flag) -> void; + + /** + @brief Unset a @p flag for the dentry. + @param flag The flag to unset. + */ + auto unset_flag(dentry_flags flag) -> void; + + /** + @brief Check if the dentry has a specific @p flag. + @param flag The flag to check. + @return True if the dentry has the flag, false otherwise. + */ + [[nodiscard]] auto has_flag(dentry_flags flag) const -> bool; + + private: + kstd::string m_name; + kstd::weak_ptr<dentry> m_parent; + kstd::vector<kstd::shared_ptr<dentry>> m_children; + kstd::shared_ptr<inode> m_inode; + uint32_t m_flags; + }; +} // namespace kernel::filesystem + +#endif
\ No newline at end of file |
