diff options
Diffstat (limited to 'kernel/kernel/filesystem/ext2/inode.hpp')
| -rw-r--r-- | kernel/kernel/filesystem/ext2/inode.hpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/kernel/kernel/filesystem/ext2/inode.hpp b/kernel/kernel/filesystem/ext2/inode.hpp new file mode 100644 index 00000000..f2496f0f --- /dev/null +++ b/kernel/kernel/filesystem/ext2/inode.hpp @@ -0,0 +1,105 @@ +#ifndef TEACH_OS_KERNEL_FILESYSTEM_EXT2_INODE_HPP +#define TEACH_OS_KERNEL_FILESYSTEM_EXT2_INODE_HPP + +#include <kernel/filesystem/inode.hpp> + +#include <kstd/memory> + +#include <array> +#include <cstddef> +#include <cstdint> + +namespace kernel::filesystem::ext2 +{ + struct filesystem; + + /** + @brief Represents the data associated with an ext2 inode. + */ + struct [[gnu::packed]] inode_data + { + uint16_t mode; + uint16_t uid; + uint32_t size; + uint32_t atime; + uint32_t ctime; + uint32_t mtime; + uint32_t dtime; + uint16_t gid; + uint16_t links_count; + uint32_t blocks; + uint32_t flags; + uint32_t osd1; + std::array<uint32_t, 15> block; // NOLINT(readability-magic-numbers) + uint32_t generation; + uint32_t file_acl; + uint32_t dir_acl; + uint32_t faddr; + std::array<uint8_t, 12> osd2; // NOLINT(readability-magic-numbers) + }; + + struct inode : kernel::filesystem::inode + { + /** + @brief Create an ext2 inode associated with the given filesystem. + @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 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. + @param buffer Destination buffer. + @param offset Read offset in bytes. + @param size Number of bytes requested. + @return Number of bytes read. + */ + auto read(void * buffer, size_t offset, size_t size) const -> size_t override; + + /** + @brief Writes to the ext2 inode into a @p buffer, starting at the specified @p offset and for a given @p size. + @warning This method is not implemented yet and will panic if called. + @param buffer Source buffer. + @param offset Write offset in bytes. + @param size Number of bytes requested. + @return Number of bytes written. + */ + auto write(void const * buffer, size_t offset, size_t size) -> size_t override; + + /** + @brief Get the data associated with this inode. + @return A reference to the inode data. + */ + [[nodiscard]] auto data() const -> inode_data const &; + + /** + @brief Check if this inode represents a directory. + @return returns true if this inode represents a directory, false otherwise. + */ + [[nodiscard]] auto is_directory() const -> bool override; + + /** + @brief Check if this inode represents a regular file. + @return returns true if this inode represents a regular file, false otherwise. + */ + [[nodiscard]] auto is_regular() const -> bool override; + + /** + @brief Check if this inode represents a symbolic link. + @return returns true if this inode represents a symbolic link, false otherwise. + */ + [[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 size() const -> uint64_t; + + private: + filesystem const * m_filesystem; + inode_data m_data{}; + }; +} // namespace kernel::filesystem::ext2 + +#endif
\ No newline at end of file |
