From 988977b80cd118749b6b813e0909f4607a4f27fe Mon Sep 17 00:00:00 2001 From: Marcel Braun Date: Tue, 12 May 2026 13:50:56 +0200 Subject: Determine ext2 inode size depending on revision level, add const to several methods --- .../include/kernel/filesystem/ext2/filesystem.hpp | 22 ++++++++++++++++------ kernel/include/kernel/filesystem/ext2/inode.hpp | 12 +++++++++--- 2 files changed, 25 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 d22433f..18ef372 100644 --- a/kernel/include/kernel/filesystem/ext2/filesystem.hpp +++ b/kernel/include/kernel/filesystem/ext2/filesystem.hpp @@ -25,6 +25,9 @@ namespace kernel::filesystem::ext2 constexpr size_t inline superblock_offset = base_block_size; constexpr uint16_t inline magic_number = 0xEF53; + constexpr uint32_t inline good_old_revision = 0; + constexpr uint32_t inline dynamic_revision = 1; + constexpr uint32_t inline root_inode_number = 2; constexpr size_t inline direct_block_count = 12; @@ -64,7 +67,13 @@ namespace kernel::filesystem::ext2 @brief Gets the size of a block in the filesystem. @return The size of a block in bytes. */ - auto get_block_size() -> size_t; + [[nodiscard]] auto get_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; /** @brief Maps an inode block index to a global block number. @@ -72,14 +81,15 @@ namespace kernel::filesystem::ext2 @param data The inode data. @return The global block number. */ - auto map_inode_block_index_to_global_block_number(uint32_t inode_block_index, inode_data data) -> uint32_t; + [[nodiscard]] auto map_inode_block_index_to_global_block_number(uint32_t inode_block_index, inode_data data) const + -> uint32_t; private: - auto read_inode(uint32_t inode_number) -> kstd::shared_ptr; - auto read_block_number_at_index(uint32_t block_number, uint32_t index) -> uint32_t; + [[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; - auto get_inode_size() -> size_t; - auto get_inode_block_count(inode_data const & data) -> uint32_t; + [[nodiscard]] auto get_inode_size() const -> size_t; + [[nodiscard]] auto get_inode_block_count(inode_data const & data) const -> uint32_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 b8f892a..000a5d8 100644 --- a/kernel/include/kernel/filesystem/ext2/inode.hpp +++ b/kernel/include/kernel/filesystem/ext2/inode.hpp @@ -20,7 +20,7 @@ namespace kernel::filesystem::ext2 { uint16_t mode; uint16_t uid; - uint32_t size; // TODO BA-FS26 signed? + uint32_t size; uint32_t atime; uint32_t ctime; uint32_t mtime; @@ -45,7 +45,7 @@ namespace kernel::filesystem::ext2 @param fs The ext2 filesystem that this inode belongs to. @param data The data associated with this inode, read from the disk. */ - explicit inode(filesystem * fs, inode_data const & data); + explicit inode(filesystem const * fs, inode_data const & data); /** @brief Reads from the ext2 inode into a @p buffer, starting at the specified @p offset and for a given @p size. @@ -90,8 +90,14 @@ namespace kernel::filesystem::ext2 */ [[nodiscard]] auto is_symbolic_link() const -> bool override; + /** + @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; + private: - filesystem * m_filesystem; + filesystem const * m_filesystem; inode_data m_data{}; }; } // namespace kernel::filesystem::ext2 -- cgit v1.2.3