diff options
Diffstat (limited to 'kernel/kernel/filesystem/ext2/inode.hpp')
| -rw-r--r-- | kernel/kernel/filesystem/ext2/inode.hpp | 96 |
1 files changed, 73 insertions, 23 deletions
diff --git a/kernel/kernel/filesystem/ext2/inode.hpp b/kernel/kernel/filesystem/ext2/inode.hpp index 61961f6c..5393a853 100644 --- a/kernel/kernel/filesystem/ext2/inode.hpp +++ b/kernel/kernel/filesystem/ext2/inode.hpp @@ -1,6 +1,8 @@ #ifndef TEACHOS_KERNEL_FILESYSTEM_EXT2_INODE_HPP #define TEACHOS_KERNEL_FILESYSTEM_EXT2_INODE_HPP +#include <kernel/filesystem/ext2/mount_state.hpp> +#include <kernel/filesystem/ext2/write_batch.hpp> #include <kernel/filesystem/inode.hpp> #include <kapi/filesystem.hpp> @@ -44,33 +46,33 @@ namespace kernel::filesystem::ext2 struct inode : kernel::filesystem::inode { + //! @name Construction/Destruction + //! @{ + //! Create an ext2 inode associated with the given filesystem. //! - //! @param fs The ext2 filesystem that this inode belongs to. //! @param inode_number The inode number on disk. //! @param data The data associated with this inode, read from the disk. - explicit inode(filesystem * fs, uint32_t inode_number, inode_data const & data); + explicit inode(uint32_t inode_number, inode_data const & data); + + //! @} + + //! @name I/O Operations + //! @{ [[nodiscard]] auto read(std::span<std::byte> buffer, kstd::bytes offset) const -> kstd::result<kstd::bytes> override; auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> override; - //! Append the specified number of blocks to this inode. - //! - //! @param count The number of blocks to append. - //! @return true if the blocks were successfully appended, false otherwise. - auto append_blocks(size_t count) -> bool; + //! @} - //! Get the data associated with this inode. - //! - //! @return A const reference to the inode data. - [[nodiscard]] auto data() const -> inode_data const &; + //! @name Property Checking + //! @{ - //! Get the data associated with this inode. - //! - //! @return A reference to the inode data. - [[nodiscard]] auto data_mutable() -> inode_data &; + [[nodiscard]] auto is_block_device() const -> bool override; + + [[nodiscard]] auto is_character_device() const -> bool override; [[nodiscard]] auto is_directory() const -> bool override; @@ -78,32 +80,80 @@ namespace kernel::filesystem::ext2 [[nodiscard]] auto is_symbolic_link() const -> bool override; - [[nodiscard]] auto is_block_device() const -> bool override; + //! @} - [[nodiscard]] auto is_character_device() const -> bool override; + //! @name POSIX Information Access + //! @{ + + [[nodiscard]] auto raw_device() const -> std::optional<kapi::filesystem::device_number> override; [[nodiscard]] auto status() const -> kstd::result<kapi::filesystem::file_status> override; - [[nodiscard]] auto raw_device() const -> std::optional<kapi::filesystem::device_number> override; + //! @} - //! Get the size of the file represented by this inode. + //! @name Property Manipulation + //! @{ + + //! Append the specified number of blocks to this inode. //! - //! @return The size of the file in bytes. - [[nodiscard]] auto size() const -> kstd::bytes; + //! @param count The number of blocks to append. + //! @param batch The active write batch. + //! @return true if the blocks were successfully appended, false otherwise. + auto append_blocks(size_t count, write_batch & batch) -> bool; //! Set the size of the file represented by this inode. //! //! @param new_size The new size of the file in bytes. auto set_size(kstd::bytes new_size) -> void; + //! @} + + //! @name Ext2 Information Queries + //! @{ + + //! Get the data associated with this inode. + //! + //! @return A reference to the inode data. + [[nodiscard]] auto data() -> inode_data &; + + //! Get the data associated with this inode. + //! + //! @return A const reference to the inode data. + [[nodiscard]] auto data() const -> inode_data const &; + + //! Get the size of the file represented by this inode. + //! + //! @return The size of the file in bytes. + [[nodiscard]] auto size() const -> kstd::bytes; + //! @brief Get the inode number of this inode. //! //! @return The inode number. [[nodiscard]] auto number() const -> uint32_t; + //! @} + private: - //! The filesystem this inode belongs to. - filesystem * m_filesystem; + //! Get the filesystem driver associated with this inode. + //! + //! @return The filesystem driver on success, and error otherwise. + [[nodiscard]] auto get_filesystem() -> kstd::result<kstd::shared_ptr<filesystem>>; + + //! Get the filesystem driver associated with this inode. + //! + //! @return The filesystem driver on success, and error otherwise. + [[nodiscard]] auto get_filesystem() const -> kstd::result<kstd::shared_ptr<filesystem const>>; + + //! Get the filesystem driver data associated with this inode. + //! + //! @return The filesystem driver data on success, and error otherwise. + [[nodiscard]] auto get_driver_data() -> kstd::result<kstd::shared_ptr<mount_state>>; + + //! Get the filesystem driver data associated with this inode. + //! + //! @return The filesystem driver data on success, and error otherwise. + [[nodiscard]] auto get_driver_data() const -> kstd::result<kstd::shared_ptr<mount_state const>>; + //! The inode number on disk. uint32_t m_inode_number{}; //! The inode data. |
