From 69fffdd906c02b6ea65f5346c31719ea0f8c3bbc Mon Sep 17 00:00:00 2001 From: Amlal Date: Tue, 6 May 2025 15:45:48 +0200 Subject: feat(kernel): Working on the last parts of HeFS V1, which will act as the base layer of the filesystem. Signed-off-by: Amlal --- dev/kernel/FSKit/HeFS.h | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'dev/kernel/FSKit') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 27fe2838..ce9b9226 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -21,10 +21,11 @@ #define kHeFSMagic " HeFS" #define kHeFSMagicLen (8) +#define kHeFSBlockLen (512U) #define kHeFSFileNameLen (256U) #define kHeFSPartNameLen (128U) -#define kHeFSMinimumDiskSize (mib_cast(16)) +#define kHeFSMinimumDiskSize (gib_cast(1)) #define kHeFSDefaultVoluneName u8"HeFS Volume" @@ -36,6 +37,7 @@ struct HEFS_BOOT_NODE; struct HEFS_INDEX_NODE; struct HEFS_INDEX_NODE_DIRECTORY; struct HEFS_JOURNAL_NODE; +struct HEFS_INODE_SLICE; enum : UInt8 { kHeFSHardDrive = 0xC0, // Hard Drive @@ -123,16 +125,21 @@ struct PACKED HEFS_BOOT_NODE final { 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). - Kernel::UInt64 fStartIN; /// @brief Reserved for future use. - Kernel::UInt64 fEndIN; /// @brief Reserved for future use. - Kernel::UInt64 fReserved; /// @brief Reserved for future use. - Kernel::UInt64 fReserved1; /// @brief Reserved for future use. + Kernel::UInt64 fStartIN; /// @brief Reserved for future use. + Kernel::UInt64 fEndIN; /// @brief Reserved for future use. + Kernel::UInt64 fStartBlock; /// @brief Reserved for future use. + Kernel::UInt64 fEndBlock; /// @brief Reserved for future use. Kernel::Char fPad[272]; }; inline constexpr Kernel::ATime kHeFSTimeInvalid = 0x0000000000000000; inline constexpr Kernel::ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF - 1; +struct PACKED HEFS_INODE_SLICE { + Kernel::UInt32 fBase; + Kernel::UInt32 fLength; +}; + /// @brief HeFS index node. /// @details This structure is used to store the file information of a file. /// @note The index node is a special type of INode that contains the file information. @@ -156,10 +163,7 @@ struct PACKED HEFS_INDEX_NODE final { /// @details Using an offset to ask fBase, and fLength to compute each slice's length. Kernel::UInt64 fOffsetSlices; - struct { - Kernel::UInt32 fBase; - Kernel::UInt32 fLength; - } fSlices[kHeFSSliceCount]; /// @brief block slice + HEFS_INODE_SLICE fSlices[kHeFSSliceCount]; /// @brief block slice Kernel::Char fPad[309]; }; @@ -378,23 +382,22 @@ class HeFileSystemParser final { const Utf8Char* dir); _Output Bool CreateINode(_Input DriveTrait* drive, _Input const Int32 flags, const Utf8Char* dir, - const Utf8Char* name); + const Utf8Char* name, const UInt8 kind); _Output Bool DeleteINode(_Input DriveTrait* drive, _Input const Int32 flags, const Utf8Char* dir, - const Utf8Char* name); - - _Output Bool WriteINode(_Input DriveTrait* drive, VoidPtr block, SizeT block_sz, - const Utf8Char* dir, const Utf8Char* name); + const Utf8Char* name, const UInt8 kind); - _Output Bool ReadINode(_Input DriveTrait* drive, VoidPtr block, SizeT block_sz, - const Utf8Char* dir, const Utf8Char* name); + _Output Bool INodeManip(_Input DriveTrait* drive, VoidPtr block, SizeT block_sz, + const Utf8Char* dir, const UInt8 kind, const Utf8Char* name, + const BOOL in); private: - _Output Bool INodeCtl_(_Input DriveTrait* drive, _Input const Int32 flags, const Utf8Char* dir, - const Utf8Char* name, const BOOL delete_or_create); + _Output Bool INodeCtlManip(_Input DriveTrait* drive, _Input const Int32 flags, + const Utf8Char* dir, const Utf8Char* name, const BOOL delete_or_create, + const UInt8 kind); - _Output Bool INodeDirectoryCtl_(_Input DriveTrait* drive, _Input const Int32 flags, - const Utf8Char* dir, const BOOL delete_or_create); + _Output Bool INodeDirectoryCtlManip(_Input DriveTrait* drive, _Input const Int32 flags, + const Utf8Char* dir, const BOOL delete_or_create); }; /// @brief Initialize HeFS inside the main disk. -- cgit v1.2.3 From 4a80c0e7eaa36817f52e0f3cd6d8c8e07bf860dc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 6 May 2025 21:07:48 +0200 Subject: dev(kernel): Fix typo of `kHeFSDefaultVoluneName` to `kHeFSDefaultVolumeName` in HeFS. --- dev/kernel/FSKit/HeFS.h | 2 +- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 2 +- docs/tex/hefs.tex | 2 +- tooling/hefs.h | 2 +- tooling/mkfs.hefs.cc | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'dev/kernel/FSKit') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index ce9b9226..f7e1d648 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -27,7 +27,7 @@ #define kHeFSMinimumDiskSize (gib_cast(1)) -#define kHeFSDefaultVoluneName u8"HeFS Volume" +#define kHeFSDefaultVolumeName u8"HeFS Volume" #define kHeFSINDStartOffset (sizeof(HEFS_INDEX_NODE_DIRECTORY) + sizeof(HEFS_BOOT_NODE)) diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 53e05c08..d3331710 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -1166,7 +1166,7 @@ Boolean fs_init_hefs(Void) { HeFileSystemParser parser; - parser.Format(&kMountPoint, kHeFSEncodingFlagsUTF8, kHeFSDefaultVoluneName); + parser.Format(&kMountPoint, kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName); MUST_PASS(parser.CreateINode(&kMountPoint, kHeFSEncodingFlagsBinary | kHeFSFlagsReadOnly, u8"/boot", u8"ジェット警察.txt", kHeFSFileKindRegular)); diff --git a/docs/tex/hefs.tex b/docs/tex/hefs.tex index afafc472..dd857795 100644 --- a/docs/tex/hefs.tex +++ b/docs/tex/hefs.tex @@ -25,7 +25,7 @@ The High-throughput Extended File System (HeFS) is a custom filesystem tailored \texttt{kHeFSFileNameLen} & 256 characters \\ \texttt{kHeFSPartNameLen} & 128 characters \\ \texttt{kHeFSMinimumDiskSize} & 16 MiB \\ -\texttt{kHeFSDefaultVoluneName} & "HeFS Volume" \\ +\texttt{kHeFSDefaultVolumeName} & "HeFS Volume" \\ \texttt{kHeFSINDStartOffset} & Offset after boot + dir nodes \\ \texttt{kHeFSSearchAllStr} & "\*" (wildcard string) \\ \hline diff --git a/tooling/hefs.h b/tooling/hefs.h index ded6cbef..f281e7a3 100644 --- a/tooling/hefs.h +++ b/tooling/hefs.h @@ -16,7 +16,7 @@ #define kHeFSFileNameLen (256U) #define kHeFSPartNameLen (128U) -#define kHeFSDefaultVoluneName u8"HeFS Volume" +#define kHeFSDefaultVolumeName u8"HeFS Volume" namespace mkfs::hefs { diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc index bc1f3d3c..5a706646 100644 --- a/tooling/mkfs.hefs.cc +++ b/tooling/mkfs.hefs.cc @@ -11,7 +11,7 @@ static size_t kDiskSize = 1024 * 1024 * 1024 * 4UL; static uint16_t kVersion = kHeFSVersion; -static std::u8string kLabel = kHeFSDefaultVoluneName; +static std::u8string kLabel = kHeFSDefaultVolumeName; static size_t kSectorSize = 512; int main(int argc, char** argv) { @@ -43,7 +43,7 @@ int main(int argc, char** argv) { kSectorSize = std::strtol(mkfs::get_option(args, "-s").data(), nullptr, 10); kLabel = mkfs::get_option(args_wide, u8"-L"); - if (kLabel.empty()) kLabel = kHeFSDefaultVoluneName; + if (kLabel.empty()) kLabel = kHeFSDefaultVolumeName; kDiskSize = std::strtol(mkfs::get_option(args, "-S").data(), nullptr, 10) * 1024 * 1024 * 1024; -- cgit v1.2.3 From a8782019a20f5487494e436f79b876b57f7229e1 Mon Sep 17 00:00:00 2001 From: Amlal Date: Thu, 8 May 2025 08:48:57 +0200 Subject: feat(tooling): update HeFS headers, and better HeFS tooling. Signed-off-by: Amlal --- dev/kernel/FSKit/HeFS.h | 8 +-- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 20 ++----- dev/modules/MBCI/MBCI.h | 5 +- tooling/hefs.h | 4 +- tooling/mkfs.hefs.cc | 92 ++++++++++++++++++------------ 5 files changed, 68 insertions(+), 61 deletions(-) (limited to 'dev/kernel/FSKit') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index f7e1d648..f5f42b47 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -125,10 +125,10 @@ struct PACKED HEFS_BOOT_NODE final { 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). - Kernel::UInt64 fStartIN; /// @brief Reserved for future use. - Kernel::UInt64 fEndIN; /// @brief Reserved for future use. - Kernel::UInt64 fStartBlock; /// @brief Reserved for future use. - Kernel::UInt64 fEndBlock; /// @brief Reserved for future use. + Kernel::UInt64 fStartIN; /// @brief Start INodes range + Kernel::UInt64 fEndIN; /// @brief End INodes range + Kernel::UInt64 fStartBlock; /// @brief Start Blocks range + Kernel::UInt64 fEndBlock; /// @brief End Blocks range Kernel::Char fPad[272]; }; diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 1cd7e61a..a324da2a 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -459,7 +459,7 @@ namespace Detail { const Utf8Char* dir_name, const Utf8Char* file_name, UInt8 kind, SizeT* cnt) { - if (mnt) { + if (mnt && cnt) { auto start = root->fStartIND; if (start > root->fEndIND) return nullptr; @@ -514,7 +514,7 @@ namespace Detail { if (start > root->fEndIND) break; } - err_global_get() = kErrorSuccess; + err_global_get() = kErrorSuccess; delete dir; if (start_cnt == 0) { @@ -535,7 +535,7 @@ namespace Detail { STATIC ATTRIBUTE(unused) _Output BOOL hefsi_update_in_status(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name, HEFS_INDEX_NODE* node, BOOL delete_or_create) { - if (!root) return NO; + if (!root || !mnt) return NO; auto start = root->fStartIND; @@ -555,8 +555,6 @@ namespace Detail { mnt->fInput(mnt->fPacket); - kout8 << dir_name << u8"\r"; - (Void)(kout << hex_number(hefsi_hash_64(dir_name)) << kendl); (Void)(kout << hex_number(dir->fHashPath) << kendl); @@ -621,12 +619,6 @@ namespace Detail { mnt->fInput(mnt->fPacket); - kout8 << u8"HashPath: "; - (Void)(kout << hex_number(tmp_node.fHashPath) << kendl); - - kout8 << u8"HashPath: "; - (Void)(kout << hex_number(hash_file) << kendl); - if (tmp_node.fHashPath != hash_file) { continue; } @@ -690,7 +682,7 @@ namespace Detail { auto start = root->fStartIND; while (YES) { - if (start == 0 || start > root->fEndIND) break; + if (start == 0UL || start > root->fEndIND) break; mnt->fPacket.fPacketLba = start; mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); @@ -714,10 +706,10 @@ namespace Detail { mnt->fOutput(mnt->fPacket); } - if (dir->fColor == kHeFSBlack && dir->fChild != 0) { + if (dir->fColor == kHeFSBlack && dir->fChild != 0UL) { dir->fColor = kHeFSRed; hefsi_rotate_tree(start, mnt); - } else if (dir->fColor == kHeFSBlack && dir->fChild == 0) { + } else if (dir->fColor == kHeFSBlack && dir->fChild == 0UL) { dir->fColor = kHeFSBlack; mnt->fPacket.fPacketLba = start; diff --git a/dev/modules/MBCI/MBCI.h b/dev/modules/MBCI/MBCI.h index 37f802ec..99ecf802 100644 --- a/dev/modules/MBCI/MBCI.h +++ b/dev/modules/MBCI/MBCI.h @@ -100,12 +100,11 @@ typedef UInt32 MBCIAuthKeyType; inline BOOL busi_test_mmio(_Input struct IMBCIHost* host, _Input const UInt32 test) { host->MMIOTest = test; UInt16 timeout = 0UL; - + while (host->MMIOTest == test) { ++timeout; - if (timeout > 0x1000) - return NO; + if (timeout > 0x1000) return NO; } return host->MMIOTest == 0; diff --git a/tooling/hefs.h b/tooling/hefs.h index f281e7a3..68e0f906 100644 --- a/tooling/hefs.h +++ b/tooling/hefs.h @@ -102,8 +102,8 @@ struct __attribute__((packed)) BootNode { std::uint16_t vid{}; std::uint64_t startIN{}; std::uint64_t endIN{}; - std::uint64_t reserved3{}; - std::uint64_t reserved4{}; + std::uint64_t startBlock{}; + std::uint64_t endBlock{}; char pad[272]{}; }; } // namespace mkfs::hefs diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc index 5a706646..2ddc7484 100644 --- a/tooling/mkfs.hefs.cc +++ b/tooling/mkfs.hefs.cc @@ -16,9 +16,10 @@ static size_t kSectorSize = 512; int main(int argc, char** argv) { if (argc < 2) { - mkfs::console_out() << "hefs: Usage: mkfs.hefs -L