diff options
Diffstat (limited to 'kernel/kernel/filesystem/inode.hpp')
| -rw-r--r-- | kernel/kernel/filesystem/inode.hpp | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/kernel/kernel/filesystem/inode.hpp b/kernel/kernel/filesystem/inode.hpp index f0fbf689..12be39b4 100644 --- a/kernel/kernel/filesystem/inode.hpp +++ b/kernel/kernel/filesystem/inode.hpp @@ -12,7 +12,11 @@ namespace kernel::filesystem { - //! Represents an inode in the filesystem. + //! An inode in the filesystem. + //! + //! Specific filesystems, or other subsystems, may provide their own implementation of this abstract base class. For + //! example, the ext2 filesystem provides its own inode implementation derived from this class, performing ext2 + //! specific operations to fulfill the contract of this class. struct inode { //! Create an inode. @@ -21,53 +25,72 @@ namespace kernel::filesystem //! Virtual destructor for the inode. virtual ~inode() = default; + //! @name I/O Operations + //! @{ + //! Read from this inode into a buffer //! + //! This function reads data from this inode into a given buffer. Implementations must guarantee, that if buffer is + //! larger than the entity represented by this inode, the buffer bytes beyond the range of the read bytes are left + //! untouched. + //! //! @param buffer Destination buffer. //! @param offset Read offset in bytes. - //! @param size Number of bytes requested. //! @return The number of bytes read on success, an error otherwise. [[nodiscard]] virtual auto read(std::span<std::byte> buffer, kstd::bytes offset) const -> kstd::result<kstd::bytes> = 0; //! Writes data from a buffer into this inode. //! + //! This function writes data from a buffer into this inode. Implementations must handle buffer sizes larger than + //! inode entity sizes gracefully. Specifically, all bytes in the buffer that do not fit into the entity represented + //! by this inode must be ignored. + //! //! @param buffer Source buffer. //! @param offset Write offset in bytes. - //! @param size Number of bytes to write. //! @return The number of bytes written on success, an error otherwise. virtual auto write(std::span<std::byte const> buffer, kstd::bytes offset) -> kstd::result<kstd::bytes> = 0; - //! Check if this inode is a directory. - //! - //! @return true iff. this inode is a directory, false otherwise. - [[nodiscard]] virtual auto is_directory() const -> bool; + //! @} - //! Check if this inode is a regular file. - //! - //! @return true iff. this inode is a regular file, false otherwise. - [[nodiscard]] virtual auto is_regular() const -> bool; + //! @name Property Checking + //! @{ - //! Check if this inode is a block device node. + //! Check if this inode describes a block device node. //! - //! @return true iff. this inode is a block device node, false otherwise. + //! @return @c true iff. this inode describes a block device node, @c false otherwise. [[nodiscard]] virtual auto is_block_device() const -> bool; - //! Check if this inode is a character device node. + //! Check if this inode describes a character device node. //! - //! @return true iff. this inode is a character device node, false otherwise. + //! @return @c true iff. this inode describes a character device node, @c false otherwise. [[nodiscard]] virtual auto is_character_device() const -> bool; - //! Check if this inode is a device. + //! Check if this inode describes a device. //! - //! @return true iff. this inode is either a block or character device node, false otherwise. + //! @return @c true iff. this inode is either a block or character device node, @c false otherwise. [[nodiscard]] auto is_device() const -> bool; - //! Returns whether the inode is a symbolic link. + //! Check if this inode describes a directory. + //! + //! @return @c true iff. this inode describes a directory, @c false otherwise. + [[nodiscard]] virtual auto is_directory() const -> bool; + + //! Check if this inode describes a regular file. + //! + //! @return @c true iff. this inode describes a regular file, @c false otherwise. + [[nodiscard]] virtual auto is_regular() const -> bool; + + //! Check if this inode describes a symbolic link. //! - //! @return true iff. this inode is a symbolic link, false otherwise. + //! @return @c true iff. this inode describes a symbolic link, @c false otherwise. [[nodiscard]] virtual auto is_symbolic_link() const -> bool; + //! @} + + //! @name POSIX Information Access + //! @{ + //! Get POSIX status information for this inode. //! //! @return a populated status information object, or an error or failure. @@ -77,6 +100,8 @@ namespace kernel::filesystem //! //! @return a device number if this inode refers to a device, an empty optional otherwise. [[nodiscard]] virtual auto raw_device() const -> std::optional<kapi::filesystem::device_number>; + + //! @} }; } // namespace kernel::filesystem |
