diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-05-16 16:12:36 +0200 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-05-16 16:12:36 +0200 |
| commit | 3b2f36d242eb895fd893ec7a674ff608f44f69ac (patch) | |
| tree | 86d5515593b5e4dd937b20a626f9cf3a0d428cdd /kernel/include | |
| parent | 106e9731aaf856f940592c02953e49a496555822 (diff) | |
| download | kernel-3b2f36d242eb895fd893ec7a674ff608f44f69ac.tar.xz kernel-3b2f36d242eb895fd893ec7a674ff608f44f69ac.zip | |
refactoring
Diffstat (limited to 'kernel/include')
13 files changed, 51 insertions, 45 deletions
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 <cstddef> + 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<dentry> const &; + [[nodiscard]] auto parent() const -> kstd::shared_ptr<dentry> 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<kernel::filesystem::inode> const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr<kernel::filesystem::inode> const & parent, std::string_view name) const -> kstd::shared_ptr<kernel::filesystem::inode> 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 <string_view> #include <unistd.h> +#include <sys/types.h> + 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<kernel::filesystem::inode> const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr<kernel::filesystem::inode> const & parent, std::string_view name) const -> kstd::shared_ptr<kernel::filesystem::inode> 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<kernel::filesystem::ext2::inode>; - [[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<kernel::filesystem::ext2::inode>; + [[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<block_group_descriptor> 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<inode> const & parent, std::string_view name) -> kstd::shared_ptr<inode> = 0; + [[nodiscard]] virtual auto lookup(kstd::shared_ptr<inode> const & parent, std::string_view name) const + -> kstd::shared_ptr<inode> = 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<dentry> const &; + [[nodiscard]] auto mount_dentry() const -> kstd::shared_ptr<dentry> const &; /** @brief Get the root dentry of the mounted filesystem. */ - [[nodiscard]] auto get_root_dentry() const -> kstd::shared_ptr<dentry> const &; + [[nodiscard]] auto root_dentry() const -> kstd::shared_ptr<dentry> 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<mount> const &; + [[nodiscard]] auto parent_mount() const -> kstd::shared_ptr<mount> 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<dentry> 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 <kstd/memory> #include <kstd/vector> +#include <cstddef> +#include <unistd.h> + 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<open_file_descriptor> const & fd) -> int; + auto add_file(kstd::shared_ptr<open_file_descriptor> 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<open_file_descriptor>; + [[nodiscard]] auto file(size_t fd) const -> kstd::shared_ptr<open_file_descriptor>; /** @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<kernel::filesystem::inode> const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr<kernel::filesystem::inode> const & parent, std::string_view name) const -> kstd::shared_ptr<kernel::filesystem::inode> 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 <kstd/vector> #include <cstddef> + 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<dentry>, kstd::shared_ptr<mount>>; - [[nodiscard]] auto resolve_path(std::string_view path) -> kstd::shared_ptr<dentry>; - [[nodiscard]] auto find_mount(std::string_view path) -> kstd::shared_ptr<mount>; + [[nodiscard]] auto resolve_path(std::string_view path) const -> kstd::shared_ptr<dentry>; + [[nodiscard]] auto find_mount(std::string_view path) const -> kstd::shared_ptr<mount>; auto do_mount_internal(kstd::shared_ptr<dentry> const & mount_point_dentry, kstd::shared_ptr<mount> const & parent_mount, kstd::shared_ptr<filesystem> 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<kernel::filesystem::inode> const & parent, std::string_view name) + [[nodiscard]] auto lookup(kstd::shared_ptr<kernel::filesystem::inode> const & parent, std::string_view name) const -> kstd::shared_ptr<kernel::filesystem::inode> override; }; } // namespace kernel::tests::filesystem |
