From 3b2f36d242eb895fd893ec7a674ff608f44f69ac Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Sat, 16 May 2026 16:12:36 +0200 Subject: refactoring --- kernel/include/kernel/filesystem/constants.hpp | 1 + kernel/include/kernel/filesystem/dentry.hpp | 6 +-- .../include/kernel/filesystem/devfs/filesystem.hpp | 2 +- .../include/kernel/filesystem/ext2/filesystem.hpp | 48 +++++++++++----------- kernel/include/kernel/filesystem/ext2/inode.hpp | 2 +- kernel/include/kernel/filesystem/filesystem.hpp | 3 +- kernel/include/kernel/filesystem/mount.hpp | 12 +++--- .../kernel/filesystem/open_file_descriptor.hpp | 2 +- .../include/kernel/filesystem/open_file_table.hpp | 9 ++-- .../kernel/filesystem/rootfs/filesystem.hpp | 2 +- kernel/include/kernel/filesystem/rootfs/inode.hpp | 1 + kernel/include/kernel/filesystem/vfs.hpp | 6 +-- .../kernel/test_support/filesystem/filesystem.hpp | 2 +- 13 files changed, 51 insertions(+), 45 deletions(-) (limited to 'kernel/include') diff --git a/kernel/include/kernel/filesystem/constants.hpp b/kernel/include/kernel/filesystem/constants.hpp index aff512a..8388d05 100644 --- a/kernel/include/kernel/filesystem/constants.hpp +++ b/kernel/include/kernel/filesystem/constants.hpp @@ -2,6 +2,7 @@ #define TEACH_OS_KERNEL_FILESYSTEM_CONSTANTS_HPP #include + namespace kernel::filesystem::constants { constexpr size_t inline max_path_length = 4096; diff --git a/kernel/include/kernel/filesystem/dentry.hpp b/kernel/include/kernel/filesystem/dentry.hpp index 925768a..478596a 100644 --- a/kernel/include/kernel/filesystem/dentry.hpp +++ b/kernel/include/kernel/filesystem/dentry.hpp @@ -46,19 +46,19 @@ namespace kernel::filesystem @brief Get the parent dentry. @return A reference to the parent dentry. */ - [[nodiscard]] auto get_parent() const -> kstd::shared_ptr const &; + [[nodiscard]] auto parent() const -> kstd::shared_ptr const &; /** @brief Get the name of the dentry. @return The name of the dentry. */ - [[nodiscard]] auto get_name() const -> std::string_view; + [[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 get_absolute_path() const -> kstd::string; + [[nodiscard]] auto absolute_path() const -> kstd::string; /** @brief Add a @p child dentry. diff --git a/kernel/include/kernel/filesystem/devfs/filesystem.hpp b/kernel/include/kernel/filesystem/devfs/filesystem.hpp index 8d96555..dbaa387 100644 --- a/kernel/include/kernel/filesystem/devfs/filesystem.hpp +++ b/kernel/include/kernel/filesystem/devfs/filesystem.hpp @@ -33,7 +33,7 @@ namespace kernel::filesystem::devfs @param name The name of the inode to look up. @return A pointer to the found inode, or a null pointer if not found. */ - auto lookup(kstd::shared_ptr const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr const & parent, std::string_view name) const -> kstd::shared_ptr override; private: diff --git a/kernel/include/kernel/filesystem/ext2/filesystem.hpp b/kernel/include/kernel/filesystem/ext2/filesystem.hpp index 46be32f..a408c64 100644 --- a/kernel/include/kernel/filesystem/ext2/filesystem.hpp +++ b/kernel/include/kernel/filesystem/ext2/filesystem.hpp @@ -15,6 +15,8 @@ #include #include +#include + namespace kernel::filesystem::ext2 { /** @@ -61,20 +63,20 @@ namespace kernel::filesystem::ext2 @param name The name of the inode to look up. @return A pointer to the found inode, or a null pointer if not found. */ - auto lookup(kstd::shared_ptr const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr const & parent, std::string_view name) const -> kstd::shared_ptr override; /** @brief Gets the size of a block in the filesystem. @return The size of a block in bytes. */ - [[nodiscard]] auto get_block_size() const -> size_t; + [[nodiscard]] auto block_size() const -> size_t; /** @brief Gets the revision level of the filesystem. @return The revision level. */ - [[nodiscard]] auto get_revision_level() const -> size_t; + [[nodiscard]] auto revision_level() const -> size_t; /** @brief Maps an inode block index to a global block number. @@ -82,30 +84,28 @@ namespace kernel::filesystem::ext2 @param data The inode data. @return The global block number. */ - [[nodiscard]] auto map_inode_block_index_to_global_block_number(uint32_t inode_block_index, inode_data data) const + [[nodiscard]] auto map_inode_block_index_to_global_block_number(size_t inode_block_index, inode_data data) const -> ssize_t; private: - [[nodiscard]] auto read_inode(uint32_t inode_number) const -> kstd::shared_ptr; - [[nodiscard]] auto read_block_number_at_index(uint32_t block_number, uint32_t index) const -> uint32_t; - - [[nodiscard]] auto read_singly_indirect_block_number(uint32_t singly_indirect_block_number, - uint32_t block_index_in_singly_indirect_block) const - -> uint32_t; - [[nodiscard]] auto read_doubly_indirect_block_number(uint32_t doubly_indirect_block_number, - uint32_t block_index_in_doubly_indirect_block) const - -> uint32_t; - [[nodiscard]] auto read_triply_indirect_block_number(uint32_t triply_indirect_block_number, - uint32_t block_index_in_triply_indirect_block) const - -> uint32_t; - - [[nodiscard]] auto get_inode_size() const -> size_t; - [[nodiscard]] auto get_inode_block_count(inode_data const & data) const -> uint32_t; - - [[nodiscard]] auto block_numbers_per_block() const -> uint32_t; - [[nodiscard]] auto block_numbers_per_singly_indirect_block() const -> uint32_t; - [[nodiscard]] auto block_numbers_per_doubly_indirect_block() const -> uint32_t; - [[nodiscard]] auto block_numbers_per_triply_indirect_block() const -> uint32_t; + [[nodiscard]] auto read_inode(size_t inode_number) const -> kstd::shared_ptr; + [[nodiscard]] auto read_block_number_at_index(size_t block_number, size_t index) const -> size_t; + + [[nodiscard]] auto read_singly_indirect_block_number(size_t singly_indirect_block_number, + size_t block_index_in_singly_indirect_block) const -> size_t; + [[nodiscard]] auto read_doubly_indirect_block_number(size_t doubly_indirect_block_number, + size_t block_index_in_doubly_indirect_block) const -> size_t; + [[nodiscard]] auto read_triply_indirect_block_number(size_t triply_indirect_block_number, + size_t block_index_in_triply_indirect_block) const -> size_t; + + [[nodiscard]] auto inode_size() const -> size_t; + [[nodiscard]] auto inode_block_count(inode_data const & data) const -> size_t; + [[nodiscard]] auto block_group_descriptor_table_offset() const -> size_t; + + [[nodiscard]] auto block_numbers_per_block() const -> size_t; + [[nodiscard]] auto block_numbers_per_singly_indirect_block() const -> size_t; + [[nodiscard]] auto block_numbers_per_doubly_indirect_block() const -> size_t; + [[nodiscard]] auto block_numbers_per_triply_indirect_block() const -> size_t; superblock m_superblock{}; kstd::vector m_block_group_descriptors; diff --git a/kernel/include/kernel/filesystem/ext2/inode.hpp b/kernel/include/kernel/filesystem/ext2/inode.hpp index 000a5d8..5609319 100644 --- a/kernel/include/kernel/filesystem/ext2/inode.hpp +++ b/kernel/include/kernel/filesystem/ext2/inode.hpp @@ -94,7 +94,7 @@ namespace kernel::filesystem::ext2 @brief Get the size of the file represented by this inode. @return The size of the file in bytes. */ - [[nodiscard]] auto get_size() const -> size_t; + [[nodiscard]] auto size() const -> size_t; private: filesystem const * m_filesystem; diff --git a/kernel/include/kernel/filesystem/filesystem.hpp b/kernel/include/kernel/filesystem/filesystem.hpp index 2fdc0ed..bec1b16 100644 --- a/kernel/include/kernel/filesystem/filesystem.hpp +++ b/kernel/include/kernel/filesystem/filesystem.hpp @@ -56,7 +56,8 @@ namespace kernel::filesystem @param name The name of the child inode to look up. @return A pointer to the requested child inode, or a null pointer if not found. */ - virtual auto lookup(kstd::shared_ptr const & parent, std::string_view name) -> kstd::shared_ptr = 0; + [[nodiscard]] virtual auto lookup(kstd::shared_ptr const & parent, std::string_view name) const + -> kstd::shared_ptr = 0; /** @brief Returns a reference to the root inode of the filesystem. diff --git a/kernel/include/kernel/filesystem/mount.hpp b/kernel/include/kernel/filesystem/mount.hpp index 5d8ea69..4ce374f 100644 --- a/kernel/include/kernel/filesystem/mount.hpp +++ b/kernel/include/kernel/filesystem/mount.hpp @@ -33,12 +33,12 @@ namespace kernel::filesystem /** @brief Get the dentry where the filesystem is mounted. */ - [[nodiscard]] auto get_mount_dentry() const -> kstd::shared_ptr const &; + [[nodiscard]] auto mount_dentry() const -> kstd::shared_ptr const &; /** @brief Get the root dentry of the mounted filesystem. */ - [[nodiscard]] auto get_root_dentry() const -> kstd::shared_ptr const &; + [[nodiscard]] auto root_dentry() const -> kstd::shared_ptr const &; /** @brief Get the filesystem instance being mounted. @@ -48,12 +48,12 @@ namespace kernel::filesystem /** @brief Get the path at which the filesystem is mounted. */ - [[nodiscard]] auto get_mount_path() const -> kstd::string; + [[nodiscard]] auto mount_path() const -> kstd::string; /** @brief Get the parent mount that this mount was attached beneath. */ - [[nodiscard]] auto get_parent_mount() const -> kstd::shared_ptr const &; + [[nodiscard]] auto parent_mount() const -> kstd::shared_ptr const &; /** @brief Increment the reference count for this mount. @@ -64,7 +64,7 @@ namespace kernel::filesystem @brief Decrement the reference count for this mount. @return True if the reference count reached zero, false otherwise. */ - auto decrement_ref_count() -> bool; + [[nodiscard]] auto decrement_ref_count() -> bool; /** @brief Check if the mount is ready to be unmounted. @@ -76,7 +76,7 @@ namespace kernel::filesystem @brief Get the current reference count for this mount. @return The current reference count. */ - [[nodiscard]] auto get_ref_count() const -> size_t; + [[nodiscard]] auto ref_count() const -> size_t; private: kstd::shared_ptr m_mount_dentry; diff --git a/kernel/include/kernel/filesystem/open_file_descriptor.hpp b/kernel/include/kernel/filesystem/open_file_descriptor.hpp index 7ca7350..fd10e64 100644 --- a/kernel/include/kernel/filesystem/open_file_descriptor.hpp +++ b/kernel/include/kernel/filesystem/open_file_descriptor.hpp @@ -50,7 +50,7 @@ namespace kernel::filesystem @brief Returns the current file offset for this open file descriptor. @return The current file offset in bytes. */ - [[nodiscard]] auto get_offset() const -> size_t; + [[nodiscard]] auto offset() const -> size_t; /** @brief Return a reference to the dentry associated with this open file descriptor. diff --git a/kernel/include/kernel/filesystem/open_file_table.hpp b/kernel/include/kernel/filesystem/open_file_table.hpp index 694f3b6..5794e4c 100644 --- a/kernel/include/kernel/filesystem/open_file_table.hpp +++ b/kernel/include/kernel/filesystem/open_file_table.hpp @@ -6,6 +6,9 @@ #include #include +#include +#include + namespace kernel::filesystem { /** @@ -37,21 +40,21 @@ namespace kernel::filesystem @param fd The file descriptor to add. @return The file descriptor index assigned to the file, or -1 on failure. */ - auto add_file(kstd::shared_ptr const & fd) -> int; + auto add_file(kstd::shared_ptr const & fd) -> ssize_t; /** @brief Get a file from the open file table. @param fd The file descriptor index to retrieve. @return A pointer to the requested file descriptor, or a null pointer if not found. */ - [[nodiscard]] auto get_file(int fd) const -> kstd::shared_ptr; + [[nodiscard]] auto file(size_t fd) const -> kstd::shared_ptr; /** @brief Remove a file from the open file table. @param fd The file descriptor index to remove. @return 0 on success, or -1 on failure. */ - auto remove_file(int fd) -> int; + auto remove_file(size_t fd) -> ssize_t; private: open_file_table() = default; diff --git a/kernel/include/kernel/filesystem/rootfs/filesystem.hpp b/kernel/include/kernel/filesystem/rootfs/filesystem.hpp index f99440b..3c2dcb1 100644 --- a/kernel/include/kernel/filesystem/rootfs/filesystem.hpp +++ b/kernel/include/kernel/filesystem/rootfs/filesystem.hpp @@ -33,7 +33,7 @@ namespace kernel::filesystem::rootfs @param name The name of the inode to look up. @return Always returns nullptr. */ - auto lookup(kstd::shared_ptr const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr const & parent, std::string_view name) const -> kstd::shared_ptr override; }; } // namespace kernel::filesystem::rootfs diff --git a/kernel/include/kernel/filesystem/rootfs/inode.hpp b/kernel/include/kernel/filesystem/rootfs/inode.hpp index 2671207..0f21eaa 100644 --- a/kernel/include/kernel/filesystem/rootfs/inode.hpp +++ b/kernel/include/kernel/filesystem/rootfs/inode.hpp @@ -8,6 +8,7 @@ #include #include + namespace kernel::filesystem::rootfs { /** diff --git a/kernel/include/kernel/filesystem/vfs.hpp b/kernel/include/kernel/filesystem/vfs.hpp index 0058d04..aec8bfe 100644 --- a/kernel/include/kernel/filesystem/vfs.hpp +++ b/kernel/include/kernel/filesystem/vfs.hpp @@ -97,10 +97,10 @@ namespace kernel::filesystem * - resolve_path() for the dentry only. * - find_mount() for the mount context only. */ - [[nodiscard]] auto resolve_path_internal(std::string_view path) + [[nodiscard]] auto resolve_path_internal(std::string_view path) const -> std::pair, kstd::shared_ptr>; - [[nodiscard]] auto resolve_path(std::string_view path) -> kstd::shared_ptr; - [[nodiscard]] auto find_mount(std::string_view path) -> kstd::shared_ptr; + [[nodiscard]] auto resolve_path(std::string_view path) const -> kstd::shared_ptr; + [[nodiscard]] auto find_mount(std::string_view path) const -> kstd::shared_ptr; auto do_mount_internal(kstd::shared_ptr const & mount_point_dentry, kstd::shared_ptr const & parent_mount, kstd::shared_ptr const & fs) diff --git a/kernel/include/kernel/test_support/filesystem/filesystem.hpp b/kernel/include/kernel/test_support/filesystem/filesystem.hpp index dab0892..5f26022 100644 --- a/kernel/include/kernel/test_support/filesystem/filesystem.hpp +++ b/kernel/include/kernel/test_support/filesystem/filesystem.hpp @@ -14,7 +14,7 @@ namespace kernel::tests::filesystem { filesystem() = default; - auto lookup(kstd::shared_ptr const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr const & parent, std::string_view name) const -> kstd::shared_ptr override; }; } // namespace kernel::tests::filesystem -- cgit v1.2.3 From 3d8ea5b1b833f39b77f0591fb2a301842ed5eb1c Mon Sep 17 00:00:00 2001 From: Marcel Braun Date: Sat, 16 May 2026 17:00:10 +0200 Subject: Refactor data types in ext2 --- kernel/include/kernel/filesystem/ext2/filesystem.hpp | 16 ++++++++-------- kernel/include/kernel/filesystem/ext2/inode.hpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'kernel/include') diff --git a/kernel/include/kernel/filesystem/ext2/filesystem.hpp b/kernel/include/kernel/filesystem/ext2/filesystem.hpp index a408c64..45cd6a1 100644 --- a/kernel/include/kernel/filesystem/ext2/filesystem.hpp +++ b/kernel/include/kernel/filesystem/ext2/filesystem.hpp @@ -76,7 +76,7 @@ namespace kernel::filesystem::ext2 @brief Gets the revision level of the filesystem. @return The revision level. */ - [[nodiscard]] auto revision_level() const -> size_t; + [[nodiscard]] auto revision_level() const -> uint32_t; /** @brief Maps an inode block index to a global block number. @@ -88,18 +88,18 @@ namespace kernel::filesystem::ext2 -> ssize_t; private: - [[nodiscard]] auto read_inode(size_t inode_number) const -> kstd::shared_ptr; - [[nodiscard]] auto read_block_number_at_index(size_t block_number, size_t index) const -> size_t; + [[nodiscard]] auto read_inode(uint32_t inode_number) const -> kstd::shared_ptr; + [[nodiscard]] auto read_block_number_at_index(uint32_t block_number, size_t index) const -> uint32_t; - [[nodiscard]] auto read_singly_indirect_block_number(size_t singly_indirect_block_number, + [[nodiscard]] auto read_singly_indirect_block_number(uint32_t singly_indirect_block_number, size_t block_index_in_singly_indirect_block) const -> size_t; - [[nodiscard]] auto read_doubly_indirect_block_number(size_t doubly_indirect_block_number, + [[nodiscard]] auto read_doubly_indirect_block_number(uint32_t doubly_indirect_block_number, size_t block_index_in_doubly_indirect_block) const -> size_t; - [[nodiscard]] auto read_triply_indirect_block_number(size_t triply_indirect_block_number, + [[nodiscard]] auto read_triply_indirect_block_number(uint32_t triply_indirect_block_number, size_t block_index_in_triply_indirect_block) const -> size_t; - [[nodiscard]] auto inode_size() const -> size_t; - [[nodiscard]] auto inode_block_count(inode_data const & data) const -> size_t; + [[nodiscard]] auto inode_size() const -> uint16_t; + [[nodiscard]] auto inode_block_count(inode_data const & data) const -> uint32_t; [[nodiscard]] auto block_group_descriptor_table_offset() const -> size_t; [[nodiscard]] auto block_numbers_per_block() const -> size_t; diff --git a/kernel/include/kernel/filesystem/ext2/inode.hpp b/kernel/include/kernel/filesystem/ext2/inode.hpp index 5609319..f2496f0 100644 --- a/kernel/include/kernel/filesystem/ext2/inode.hpp +++ b/kernel/include/kernel/filesystem/ext2/inode.hpp @@ -94,7 +94,7 @@ namespace kernel::filesystem::ext2 @brief Get the size of the file represented by this inode. @return The size of the file in bytes. */ - [[nodiscard]] auto size() const -> size_t; + [[nodiscard]] auto size() const -> uint64_t; private: filesystem const * m_filesystem; -- cgit v1.2.3