summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/FSKit/HeFS.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-04-19 10:10:09 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-04-19 10:10:09 +0200
commit4d1a1aa6862737b77f128f4d17caaa81acfe312f (patch)
tree28791ee8cfd6952bfecd43317459a181db25fc0e /dev/kernel/FSKit/HeFS.h
parent1740a0dff822d7666b8c1f056b6c411ef6b0f9fd (diff)
dev, fs: document HeFS, add Ext2 C++ source file.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/FSKit/HeFS.h')
-rw-r--r--dev/kernel/FSKit/HeFS.h128
1 files changed, 79 insertions, 49 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h
index 8fdf933e..15ed5ac2 100644
--- a/dev/kernel/FSKit/HeFS.h
+++ b/dev/kernel/FSKit/HeFS.h
@@ -79,24 +79,29 @@ inline constexpr UInt16 kHeFSFileKindCount = 0x08;
/// @details The blocks are used to store the data of a file. Each block is a pointer to a block of data on the disk.
inline constexpr UInt16 kHeFSBlockCount = 0x10;
+inline constexpr UInt16 kHeFSInvalidVID = 0xFFFF;
+
+/// @brief HeFS Boot node.
+/// @details Acts like a superblock, it contains the information about the filesystem.
+/// @note The boot node is the first block of the filesystem.
struct PACKED HeFS_BOOT_NODE final
{
- Kernel::Char fMagic[kHeFSMagicLen];
- Kernel::Utf16Char fVolName[kHeFSPartNameLen];
- Kernel::UInt32 fVersion;
- Kernel::UInt64 fBadSectors;
- Kernel::UInt64 fSectorCount;
- Kernel::UInt64 fSectorSize;
- Kernel::UInt32 fChecksum;
- Kernel::UInt8 fDriveKind;
- Kernel::UInt8 fEncoding;
- Kernel::UInt64 fStartIND;
- Kernel::UInt64 fEndIND;
- Kernel::UInt64 fINodeCount;
- Kernel::UInt64 fDiskSize;
- Kernel::UInt16 fDiskStatus;
- Kernel::UInt16 fDiskFlags;
- Kernel::UInt16 fVID; // virtual identification number within an EPM disk.
+ Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem.
+ Kernel::Utf16Char fVolName[kHeFSPartNameLen]; /// @brief Volume name.
+ Kernel::UInt32 fVersion; /// @brief Version of the filesystem.
+ Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem.
+ Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem.
+ Kernel::UInt64 fSectorSize; /// @brief Size of the sector.
+ Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node.
+ Kernel::UInt8 fDriveKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical Drive, etc).
+ Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc).
+ Kernel::UInt64 fStartIND; /// @brief Start of the INode tree.
+ Kernel::UInt64 fEndIND; /// @brief End of the INode tree.
+ Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree.
+ Kernel::UInt64 fDiskSize; /// @brief Size of the disk. (Could be a virtual size, that is not the real size of the disk.)
+ Kernel::UInt16 fDiskStatus; /// @brief Status of the disk. (locked, unlocked, error, invalid).
+ Kernel::UInt16 fDiskFlags; /// @brief Flags of the disk. (read-only, read-write, etc).
+ Kernel::UInt16 fVID; /// @brief Virtual Identification Number within an EPM disk. (0xFFFF if not used).
};
/// @brief Access time type.
@@ -112,27 +117,26 @@ inline constexpr ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF;
/// @note The index node is used to store the file information of a file.
struct PACKED HeFS_INDEX_NODE final
{
- Kernel::Utf16Char fName[kHeFSFileNameLen];
- Kernel::UInt32 fFlags;
- Kernel::UInt16 fKind;
- Kernel::UInt32 fSize;
- Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, fLinkChecksum;
+ Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief File name.
+ Kernel::UInt32 fFlags; /// @brief File flags.
+ Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown).
+ Kernel::UInt32 fSize; /// @brief File size.
+ Kernel::UInt32 fChecksum, fRecoverChecksum, fBlockChecksum, fLinkChecksum; /// @brief Checksum of the file, recovery checksum, block checksum, link checksum.
- ATime fCreated, fAccessed, fModified, fDeleted;
- Kernel::UInt32 fUID, fGID;
- Kernel::UInt32 fMode;
+ ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps.
+ Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file.
+ Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc).
- Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount];
- Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount];
+ Kernel::UInt64 fBlockLinkStart[kHeFSBlockCount]; /// @brief Start of the block link.
+ Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; /// @brief End of the block link.
- Kernel::UInt64 fBlockStart[kHeFSBlockCount];
- Kernel::UInt64 fBlockEnd[kHeFSBlockCount];
+ Kernel::UInt64 fBlockStart[kHeFSBlockCount]; /// @brief Start of the block.
+ Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; /// @brief End of the block.
- Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount];
- Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount];
+ Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount]; /// @brief Start of the block recovery.
+ Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; /// @brief End of the block recovery.
- /// @brief Red-black tree pointers.
- Kernel::Lba fNext, fPrev, fChild, fParent;
+ Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers.
};
/// @brief HeFS directory node.
@@ -140,22 +144,21 @@ struct PACKED HeFS_INDEX_NODE final
/// @note The directory node is a special type of INode that contains the directory entries.
struct PACKED HeFS_INDEX_NODE_DIRECTORY final
{
- Kernel::Utf16Char fName[kHeFSFileNameLen];
+ Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief Directory name.
- Kernel::UInt32 fFlags;
- Kernel::UInt16 fKind;
- Kernel::UInt32 fSize;
- Kernel::UInt32 fChecksum, fIndexNodeChecksum;
+ Kernel::UInt32 fFlags; /// @brief File flags.
+ Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, Symbolic Link, Unknown).
+ Kernel::UInt32 fSize; /// @brief Size of the directory.
+ Kernel::UInt32 fChecksum, fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum.
- ATime fCreated, fAccessed, fModified, fDeleted;
- Kernel::UInt32 fUID, fGID;
- Kernel::UInt32 fMode;
+ ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps.
+ Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file.
+ Kernel::UInt32 fMode; /// @brief File mode. (read, write, execute, etc).
- Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount];
- Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount];
+ Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount]; /// @brief Start of the index node.
+ Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; /// @brief End of the index node.
- /// @brief Red-black tree pointers.
- Kernel::Lba fNext, fPrev, fChild, fParent;
+ Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers.
};
namespace Kernel::Detail
@@ -166,7 +169,7 @@ namespace Kernel::Detail
/// @note The year is stored in the upper 32 bits of the ATime value.
inline UInt32 hefs_year_get(ATime raw_atime) noexcept
{
- return (raw_atime & 0x00000000FFFFFFFF) >> 32;
+ return (raw_atime) >> 32;
}
/// @brief HeFS get month from ATime.
@@ -175,7 +178,7 @@ namespace Kernel::Detail
/// @note The month is stored in the upper 24 bits of the ATime value.
inline UInt32 hefs_month_get(ATime raw_atime) noexcept
{
- return (raw_atime & 0x00000000FFFFFFFF) >> 24;
+ return (raw_atime) >> 24;
}
/// @brief HeFS get day from ATime.
@@ -184,7 +187,7 @@ namespace Kernel::Detail
/// @note The day is stored in the upper 16 bits of the ATime value.
inline UInt32 hefs_day_get(ATime raw_atime) noexcept
{
- return (raw_atime & 0x00000000FFFFFFFF) >> 16;
+ return (raw_atime) >> 16;
}
/// @brief HeFS get hour from ATime.
@@ -193,7 +196,7 @@ namespace Kernel::Detail
/// @note The hour is stored in the upper 8 bits of the ATime value.
inline UInt32 hefs_hour_get(ATime raw_atime) noexcept
{
- return (raw_atime & 0x00000000FFFFFFFF) >> 8;
+ return (raw_atime) >> 8;
}
/// @brief HeFS get minute from ATime.
@@ -202,7 +205,7 @@ namespace Kernel::Detail
/// @note The minute is stored in the lower 8 bits of the ATime value.
inline UInt32 hefs_minute_get(ATime raw_atime) noexcept
{
- return (raw_atime & 0x00000000FFFFFFFF);
+ return (raw_atime) & 0xFF;
}
inline constexpr UInt32 kHeFSBaseYear = 1970;
@@ -210,4 +213,31 @@ namespace Kernel::Detail
inline constexpr UInt32 kHeFSBaseDay = 1;
inline constexpr UInt32 kHeFSBaseHour = 0;
inline constexpr UInt32 kHeFSBaseMinute = 0;
+
+ inline const Char* hefs_status_to_string(UInt16 status) noexcept
+ {
+ switch (status)
+ {
+ case kHeFSStatusUnlocked: return "Unlocked";
+ case kHeFSStatusLocked: return "Locked";
+ case kHeFSStatusError: return "Error";
+ case kHeFSStatusInvalid: return "Invalid";
+ default: return "Unknown";
+ }
+ }
+
+ inline const Char* hefs_drive_kind_to_string(UInt8 kind) noexcept
+ {
+ switch (kind)
+ {
+ case kHeFSHardDrive: return "Hard Drive";
+ case kHeFSSolidStateDrive: return "Solid State Drive";
+ case kHeFSOpticalDrive: return "Optical Drive";
+ case kHeFSMassStorageDevice: return "Mass Storage Device";
+ case kHeFSScsiDrive: return "SCSI/SAS Drive";
+ case kHeFSFlashDrive: return "Flash Drive";
+ case kHeFSUnknown: return "Unknown";
+ default: return "Unknown";
+ }
+ }
} // namespace Kernel::Detail \ No newline at end of file