From 8a7396493c3effb356d2dc4484b993b4698bc422 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sun, 27 Apr 2025 23:31:27 +0200 Subject: dev, kernel: HeFS had to be redesigned to be less problematic with hard-drives. why? the struct were way too big to fit wihin a sector. Signed-off-by: Amlal --- dev/kernel/FSKit/HeFS.h | 49 ++++++------- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 2 - dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 18 ++--- dev/kernel/NewKit/KString.h | 9 +-- dev/kernel/NewKit/Utils.h | 4 +- dev/kernel/src/FS/HeFS.cc | 96 +++++++++++-------------- dev/kernel/src/KString.cc | 4 +- dev/kernel/src/UtfUtils.cc | 33 +++++++++ dev/kernel/src/WideUtils.cc | 33 --------- 9 files changed, 112 insertions(+), 136 deletions(-) create mode 100644 dev/kernel/src/UtfUtils.cc delete mode 100644 dev/kernel/src/WideUtils.cc (limited to 'dev/kernel') diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index bdc8a338..90a2e274 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -26,15 +26,15 @@ #define kHeFSMinimumDiskSize (gib_cast(4)) -#define kHeFSDefaultVoluneName u"HeFS Volume" +#define kHeFSDefaultVoluneName u8"HeFS Volume" -#define kHeFSDIMBootDir u"boot-x/dir" -#define kHeFSMIMEBootFile u"boot-x/file" +#define kHeFSDIMBootDir u8"boot-x/dir" +#define kHeFSMIMEBootFile u8"boot-x/file" -#define kHeFSDIMSystemDir u"system-x/dir" -#define kHeFSMIMESystemFile u"system-x/file" +#define kHeFSDIMSystemDir u8"system-x/dir" +#define kHeFSMIMESystemFile u8"system-x/file" -#define kHeFSSearchAllStr u"*" +#define kHeFSSearchAllStr u8"*" struct HEFS_BOOT_NODE; struct HEFS_INDEX_NODE; @@ -102,7 +102,7 @@ typedef UInt64 ATime; /// @note The boot node is the first block of the filesystem. struct PACKED HEFS_BOOT_NODE final { Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. - Kernel::Utf16Char fVolName[kHeFSPartNameLen]; /// @brief Volume name. + Kernel::Utf8Char 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. @@ -124,6 +124,7 @@ struct PACKED HEFS_BOOT_NODE final { Kernel::UInt64 fReserved2; /// @brief Reserved for future use. Kernel::UInt64 fReserved3; /// @brief Reserved for future use. Kernel::UInt64 fReserved4; /// @brief Reserved for future use. + Kernel::Char fPad[272]; }; inline constexpr Kernel::ATime kHeFSTimeInvalid = 0x0000000000000000; @@ -134,16 +135,12 @@ inline constexpr Kernel::ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF - 1; /// @note The index node is a special type of INode that contains the file information. /// @note The index node is used to store the file information of a file. struct PACKED ALIGN(8) HEFS_INDEX_NODE final { - Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief File name. + Kernel::Utf8Char 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. - - Kernel::Utf16Char fMime[kHeFSFileNameLen]; /// @brief File mime type. + Kernel::UInt32 fChecksum; /// @brief Checksum. Kernel::Boolean fSymLink; /// @brief Is this a symbolic link? (if yes, the fName is the path to /// the file and blocklinkstart and end contains it's inodes.) @@ -152,14 +149,9 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE final { 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]; /// @brief Start of the block link. - Kernel::UInt64 fBlockLinkEnd[kHeFSBlockCount]; /// @brief End of the block link. - - Kernel::UInt64 fBlockStart[kHeFSBlockCount]; /// @brief Start of the block. - Kernel::UInt64 fBlockEnd[kHeFSBlockCount]; /// @brief End of the block. + Kernel::UInt64 fBlock[kHeFSBlockCount]; /// @brief block slice. - Kernel::UInt64 fBlockRecoveryStart[kHeFSBlockCount]; /// @brief Start of the block recovery. - Kernel::UInt64 fBlockRecoveryEnd[kHeFSBlockCount]; /// @brief End of the block recovery. + Kernel::Char fPad[62]; }; enum { @@ -173,7 +165,7 @@ enum { /// @details This structure is used to store the directory information of a file. /// @note The directory node is a special type of INode that contains the directory entries. struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final { - Kernel::Utf16Char fName[kHeFSFileNameLen]; /// @brief Directory name. + Kernel::Utf8Char fName[kHeFSFileNameLen]; /// @brief Directory name. Kernel::UInt32 fFlags; /// @brief File flags. Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, @@ -182,8 +174,6 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final { Kernel::UInt32 fChecksum, fIndexNodeChecksum; /// @brief Checksum of the file, index node checksum. - Kernel::Utf16Char fDim[kHeFSFileNameLen]; /// @brief Directiory Immatriculation magic. - Kernel::ATime fCreated, fAccessed, fModified, fDeleted; /// @brief File timestamps and allocation status. Kernel::UInt32 fUID, fGID; /// @brief User ID and Group ID of the file. @@ -193,11 +183,12 @@ struct PACKED ALIGN(8) HEFS_INDEX_NODE_DIRECTORY final { /// [0] = OFFSET /// [1] = SIZE /// @note Thus the += 2 when iterating over them. - Kernel::UInt64 fIndexNodeStart[kHeFSBlockCount]; /// @brief Start of the index node. - Kernel::UInt64 fIndexNodeEnd[kHeFSBlockCount]; /// @brief End of the index node. + Kernel::UInt64 fIndexNode[kHeFSBlockCount]; /// @brief Start of the index node. Kernel::UInt8 fColor; /// @brief Color of the node. (Red or Black). Kernel::Lba fNext, fPrev, fChild, fParent; /// @brief Red-black tree pointers. + + Kernel::Char fPad[32]; }; namespace Kernel::Detail { @@ -369,13 +360,13 @@ class HeFileSystemParser final { /// @param drive The drive to write on. /// @return If it was sucessful, see err_local_get(). _Output Bool Format(_Input _Output DriveTrait* drive, _Input const Int32 flags, - const Utf16Char* part_name); + const Utf8Char* part_name); _Output Bool CreateDirectory(_Input DriveTrait* drive, _Input const Int32 flags, - const Utf16Char* dir); + const Utf8Char* dir); - _Output Bool CreateFile(_Input DriveTrait* drive, _Input const Int32 flags, const Utf16Char* dir, - const Utf16Char* name); + _Output Bool CreateFile(_Input DriveTrait* drive, _Input const Int32 flags, const Utf8Char* dir, + const Utf8Char* name); public: UInt32 mDriveIndex{MountpointInterface::kDriveIndexA}; /// @brief The drive index which this diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 5a826a9d..66793aa6 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -106,9 +106,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { hal_pre_init_scheduler(); -#if defined(__FSKIT_INCLUDES_HEFS__) Kernel::HeFS::fs_init_hefs(); -#endif Kernel::HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index deea30e1..06c7781c 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -162,7 +162,7 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz SizeT prdt_index = 0; UIntPtr buffer_phys = (UIntPtr) ptr; - while (bytes_remaining > 0 && prdt_index < 8) { + while (bytes_remaining > 0) { SizeT chunk_size = bytes_remaining; if (chunk_size > kib_cast(32)) chunk_size = kib_cast(32); @@ -234,9 +234,11 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz err_global_get() = kErrorDiskIsCorrupted; return; } else { - rtl_dma_flush(ptr, size_buffer); - rt_copy_memory(ptr, buffer, size_buffer); - rtl_dma_flush(ptr, size_buffer); + if (!Write) { + rtl_dma_flush(ptr, size_buffer); + rt_copy_memory(ptr, buffer, size_buffer); + rtl_dma_flush(ptr, size_buffer); + } rtl_dma_free(size_buffer); @@ -424,7 +426,7 @@ Bool drv_std_detected_ahci() { /// //////////////////////////////////////////////////// Void drv_std_write(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) { - drv_std_input_output_ahci(lba, reinterpret_cast(buffer), sector_sz, + drv_std_input_output_ahci(lba / sector_sz, reinterpret_cast(buffer), sector_sz, size_buffer); } @@ -432,7 +434,7 @@ Void drv_std_write(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) /// //////////////////////////////////////////////////// Void drv_std_read(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) { - drv_std_input_output_ahci(lba, reinterpret_cast(buffer), sector_sz, + drv_std_input_output_ahci(lba / sector_sz, reinterpret_cast(buffer), sector_sz, size_buffer); } @@ -499,7 +501,7 @@ namespace Detail { err_global_get() = kErrorSuccess; - drv_std_input_output_ahci(disk->fPacket.fPacketLba, + drv_std_input_output_ahci(disk->fPacket.fPacketLba / kAHCISectorSize, (UInt8*) disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize); } @@ -521,7 +523,7 @@ namespace Detail { err_global_get() = kErrorSuccess; - drv_std_input_output_ahci(disk->fPacket.fPacketLba, + drv_std_input_output_ahci(disk->fPacket.fPacketLba / kAHCISectorSize, (UInt8*) disk->fPacket.fPacketContent, kAHCISectorSize, disk->fPacket.fPacketSize); } diff --git a/dev/kernel/NewKit/KString.h b/dev/kernel/NewKit/KString.h index 133fe945..a9a58b7e 100644 --- a/dev/kernel/NewKit/KString.h +++ b/dev/kernel/NewKit/KString.h @@ -12,14 +12,14 @@ #include #include -#define cMinimumStringSize 8196 +#define kMinimumStringSize (8196U) namespace Kernel { /// @brief Kernel string class, not dynamic. class KString final { public: explicit KString() { - fDataSz = cMinimumStringSize; + fDataSz = kMinimumStringSize; fData = new Char[fDataSz]; MUST_PASS(fData); @@ -70,12 +70,13 @@ class KString final { friend class KStringBuilder; }; -struct KStringBuilder final { +class KStringBuilder final { +public: static ErrorOr Construct(const Char* data); static const Char* FromBool(const Char* fmt, bool n); static const Char* Format(const Char* fmt, const Char* from); static bool Equals(const Char* lhs, const Char* rhs); - static bool Equals(const Utf16Char* lhs, const Utf16Char* rhs); + static bool Equals(const Utf8Char* lhs, const Utf8Char* rhs); static bool Equals(const WideChar* lhs, const WideChar* rhs); }; } // namespace Kernel diff --git a/dev/kernel/NewKit/Utils.h b/dev/kernel/NewKit/Utils.h index 2f0fc60b..0cf0484a 100644 --- a/dev/kernel/NewKit/Utils.h +++ b/dev/kernel/NewKit/Utils.h @@ -27,6 +27,6 @@ Int rt_to_lower(Int c); voidPtr rt_string_in_string(const Char* in, const Char* needle); char* rt_string_has_char(Char* str, Char chr); -Int wrt_copy_memory(const voidPtr src, voidPtr dst, Size len); -Size wrt_string_len(const Utf16Char* str); +Int urt_copy_memory(const voidPtr src, voidPtr dst, Size len); +Size urt_string_len(const Utf8Char* str); } // namespace Kernel diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index a27712e3..37c2f8fb 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -39,7 +39,7 @@ namespace Detail { /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic /// link, unknown). STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefs_fetch_index_node( - HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, + HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name, const Utf8Char* file_name, UInt8 kind, SizeT* cnt) noexcept; /// @brief Get the index node size. @@ -50,8 +50,8 @@ namespace Detail { /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic /// link, unknown). STATIC ATTRIBUTE(unused) _Output SizeT - hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, - const Utf16Char* file_name, UInt8 kind) noexcept; + hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name, + const Utf8Char* file_name, UInt8 kind) noexcept; /// @brief Allocate a new index node. /// @param root The root node of the filesystem. @@ -60,7 +60,7 @@ namespace Detail { /// @return Status, see err_global_get(). STATIC ATTRIBUTE(unused) _Output BOOL hefs_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, - const Utf16Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept; + const Utf8Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept; /// @brief Balance RB-Tree of the filesystem. /// @param root The root node of the filesystem. @@ -206,8 +206,8 @@ namespace Detail { /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic /// link, unknown). STATIC ATTRIBUTE(unused) _Output SizeT - hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, - const Utf16Char* file_name, UInt8 kind) noexcept { + hefs_fetch_index_node_size(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name, + const Utf8Char* file_name, UInt8 kind) noexcept { if (root && mnt) { HEFS_INDEX_NODE* node = new HEFS_INDEX_NODE(); HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); @@ -252,17 +252,10 @@ namespace Detail { if (KStringBuilder::Equals(dir_name, dir->fName) || KStringBuilder::Equals(dir_name, kHeFSSearchAllStr)) { for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) { - if (dir->fIndexNodeStart[inode_index]) { - mnt->fPacket.fPacketLba = dir->fIndexNodeStart[inode_index]; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); - mnt->fPacket.fPacketContent = node; - mnt->fInput(mnt->fPacket); - } else if (dir->fIndexNodeEnd[inode_index]) { - mnt->fPacket.fPacketLba = dir->fIndexNodeEnd[inode_index]; - mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); - mnt->fPacket.fPacketContent = node; - mnt->fInput(mnt->fPacket); - } + mnt->fPacket.fPacketLba = dir->fIndexNode[inode_index]; + mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); + mnt->fPacket.fPacketContent = node; + mnt->fInput(mnt->fPacket); if (KStringBuilder::Equals(file_name, node->fName) && node->fKind == kind) { if (node->fKind == kHeFSFileKindDirectory) { @@ -338,7 +331,7 @@ namespace Detail { } STATIC _Output HEFS_INDEX_NODE_DIRECTORY* hefs_fetch_index_node_directory( - HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name) { + HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name) { if (root && mnt) { HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); @@ -402,7 +395,7 @@ namespace Detail { /// @param kind The kind of the file (regular, directory, block, character, FIFO, socket, symbolic /// link, unknown). STATIC ATTRIBUTE(unused) _Output HEFS_INDEX_NODE* hefs_fetch_index_node( - HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf16Char* dir_name, const Utf16Char* file_name, + HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name, const Utf8Char* file_name, UInt8 kind, SizeT* cnt) noexcept { if (root && mnt) { HEFS_INDEX_NODE* node_arr = new HEFS_INDEX_NODE[*cnt]; @@ -455,10 +448,8 @@ namespace Detail { if (KStringBuilder::Equals(dir_name, dir->fName) || KStringBuilder::Equals(dir_name, kHeFSSearchAllStr)) { for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) { - if (dir->fIndexNodeStart[inode_index] != 0 || dir->fIndexNodeEnd[inode_index] != 0) { - mnt->fPacket.fPacketLba = (!dir->fIndexNodeStart[inode_index]) - ? dir->fIndexNodeEnd[inode_index] - : dir->fIndexNodeStart[inode_index]; + if (dir->fIndexNode[inode_index] != 0) { + mnt->fPacket.fPacketLba = dir->fIndexNode[inode_index]; mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); mnt->fPacket.fPacketContent = node; @@ -523,7 +514,7 @@ namespace Detail { /// @return Status, see err_global_get(). STATIC ATTRIBUTE(unused) _Output BOOL hefs_allocate_index_node(HEFS_BOOT_NODE* root, DriveTrait* mnt, - const Utf16Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept { + const Utf8Char* parent_dir_name, HEFS_INDEX_NODE* node) noexcept { if (root && mnt) { HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); @@ -547,11 +538,10 @@ namespace Detail { if (KStringBuilder::Equals(dir->fName, parent_dir_name)) { for (SizeT inode_index = 0UL; inode_index < kHeFSBlockCount; inode_index += 2) { - if (dir->fIndexNodeStart[inode_index] != 0 || dir->fIndexNodeEnd[inode_index] != 0) { + if (dir->fIndexNode[inode_index] != 0) { HEFS_INDEX_NODE prev_node; - auto lba = (!dir->fIndexNodeStart[inode_index]) ? dir->fIndexNodeEnd[inode_index] - : dir->fIndexNodeStart[inode_index]; + auto lba = dir->fIndexNode[inode_index]; mnt->fPacket.fPacketLba = lba; mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE); @@ -761,7 +751,7 @@ namespace Kernel::HeFS { /// @param drive The drive to write on. /// @return If it was sucessful, see err_local_get(). _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const Int32 flags, - _Input const Utf16Char* part_name) { + _Input const Utf8Char* part_name) { NE_UNUSED(drive); NE_UNUSED(flags); NE_UNUSED(part_name); @@ -815,16 +805,18 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input rt_copy_memory((VoidPtr) "fs/hefs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/hefs-packet")); - wrt_copy_memory((VoidPtr) part_name, root->fVolName, wrt_string_len(part_name)); + urt_copy_memory((VoidPtr) part_name, root->fVolName, urt_string_len(part_name)); rt_copy_memory((VoidPtr) kHeFSMagic, root->fMagic, sizeof(kHeFSMagic)); root->fBadSectors = 0; - root->fSectorCount = drv_get_sector_count() - 1; + root->fSectorCount = drv_get_sector_count(); root->fSectorSize = drive->fSectorSz; - root->fStartIND = drive->fLbaStart + sizeof(HEFS_BOOT_NODE); + Lba start = drive->fLbaStart; + + root->fStartIND = start + sizeof(HEFS_BOOT_NODE); root->fEndIND = drive->fLbaEnd; root->fINDCount = 0; @@ -852,7 +844,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input root->fVID = kHeFSInvalidVID; - drive->fPacket.fPacketLba = drive->fLbaStart; + drive->fPacket.fPacketLba = start; drive->fPacket.fPacketSize = sizeof(HEFS_BOOT_NODE); drive->fPacket.fPacketContent = root; @@ -867,17 +859,16 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input return NO; } - /// @note this allocates 4 ind at format. - SizeT cnt = 4UL; + start = root->fStartIND; - Lba next = root->fStartIND + sizeof(HEFS_BOOT_NODE); + constexpr SizeT kHeFSPreallocateCount = 16UL; HEFS_INDEX_NODE_DIRECTORY* index_node = new HEFS_INDEX_NODE_DIRECTORY(); // Pre-allocate index node directory tree - for (SizeT i = 0; i < cnt; ++i) { + for (SizeT i = 0; i < kHeFSPreallocateCount; ++i) { rt_set_memory(index_node, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); - wrt_copy_memory((VoidPtr) u"/$", index_node->fName, wrt_string_len(u"/$")); + urt_copy_memory((VoidPtr) u8"?", index_node->fName, urt_string_len(u8"?")); index_node->fFlags = flags; index_node->fKind = kHeFSFileKindDirectory; @@ -899,11 +890,11 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input index_node->fNext = 0; index_node->fPrev = 0; - drive->fPacket.fPacketLba = next; + drive->fPacket.fPacketLba = start; drive->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); drive->fPacket.fPacketContent = index_node; - next += sizeof(HEFS_INDEX_NODE_DIRECTORY); + start += sizeof(HEFS_INDEX_NODE_DIRECTORY); drive->fOutput(drive->fPacket); } @@ -911,22 +902,11 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input delete index_node; index_node = nullptr; - // Create the directories, something UNIX inspired but more explicit and forward looking. - - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/boot"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/netdevices"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/binaries"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/users"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config/xml"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/config/json"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/devices"); - this->CreateDirectory(drive, kHeFSEncodingUTF16, u"/media"); - this->CreateFile(drive, kHeFSEncodingBinary, u"/", u".hefs"); - delete root; root = nullptr; + Detail::hefsi_balance_filesystem(root, drive); + if (drive->fPacket.fPacketGood) return YES; err_global_get() = kErrorDiskIsCorrupted; @@ -940,7 +920,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input /// @param dir The directory to create the file in. /// @return If it was sucessful, see err_local_get(). _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Input const Int32 flags, - const Utf16Char* dir) { + const Utf8Char* dir) { NE_UNUSED(drive); NE_UNUSED(flags); NE_UNUSED(dir); @@ -948,6 +928,8 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu HEFS_BOOT_NODE* root = new HEFS_BOOT_NODE(); HEFS_INDEX_NODE* node = new HEFS_INDEX_NODE(); + kout << "CreateDirectory...\r"; + if (!root || !node) { kout << "Error: Failed to allocate memory for boot node.\r"; @@ -975,7 +957,7 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu rt_set_memory(dirent, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); - wrt_copy_memory((VoidPtr) dir, dirent->fName, wrt_string_len(dir)); + urt_copy_memory((VoidPtr) dir, dirent->fName, urt_string_len(dir)); dirent->fAccessed = 0; dirent->fCreated = kHeFSTimeMax; /// TODO: Add the current time. @@ -1015,7 +997,7 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu /// @param name The name of the file. /// @return If it was sucessful, see err_local_get(). _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input const Int32 flags, - const Utf16Char* dir, const Utf16Char* name) { + const Utf8Char* dir, const Utf8Char* name) { NE_UNUSED(drive); NE_UNUSED(flags); NE_UNUSED(dir); @@ -1024,6 +1006,8 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con HEFS_BOOT_NODE* root = new HEFS_BOOT_NODE(); HEFS_INDEX_NODE* node = new HEFS_INDEX_NODE(); + kout << "CreateFile...\r"; + if (!root || !node) { kout << "Error: Failed to allocate memory for boot node.\r"; @@ -1082,7 +1066,7 @@ _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input con node->fGID = 0; node->fUID = 0; - wrt_copy_memory((VoidPtr) name, node->fName, wrt_string_len(name)); + urt_copy_memory((VoidPtr) name, node->fName, urt_string_len(name)); if (Detail::hefs_allocate_index_node(root, drive, dir, node)) { delete node; diff --git a/dev/kernel/src/KString.cc b/dev/kernel/src/KString.cc index a13bb364..479eb2fc 100644 --- a/dev/kernel/src/KString.cc +++ b/dev/kernel/src/KString.cc @@ -112,8 +112,8 @@ bool KStringBuilder::Equals(const Char* lhs, const Char* rhs) { } /// @note This is unsafe!!! -bool KStringBuilder::Equals(const Utf16Char* lhs, const Utf16Char* rhs) { - for (Size index = 0; index < wrt_string_len(rhs); ++index) { +bool KStringBuilder::Equals(const Utf8Char* lhs, const Utf8Char* rhs) { + for (Size index = 0; index < urt_string_len(rhs); ++index) { if (rhs[index] != lhs[index]) return false; } diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc new file mode 100644 index 00000000..db1dfaf4 --- /dev/null +++ b/dev/kernel/src/UtfUtils.cc @@ -0,0 +1,33 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include + +namespace Kernel { +Size urt_string_len(const Utf8Char* str) { + SizeT len{0}; + + while (str[len] != u'\0') ++len; + + return len; +} + +Int urt_copy_memory(const voidPtr src, voidPtr dst, Size len) { + Utf8Char* srcChr = reinterpret_cast(src); + Utf8Char* dstChar = reinterpret_cast(dst); + + Size index = 0; + + while (index < len) { + dstChar[index] = srcChr[index]; + ++index; + } + + dstChar[index] = 0; + + return index; +} +} // namespace Kernel \ No newline at end of file diff --git a/dev/kernel/src/WideUtils.cc b/dev/kernel/src/WideUtils.cc deleted file mode 100644 index 0f628e00..00000000 --- a/dev/kernel/src/WideUtils.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include - -namespace Kernel { -Size wrt_string_len(const Utf16Char* str) { - SizeT len{0}; - - while (str[len] != u'\0') ++len; - - return len; -} - -Int wrt_copy_memory(const voidPtr src, voidPtr dst, Size len) { - Utf16Char* srcChr = reinterpret_cast(src); - Utf16Char* dstChar = reinterpret_cast(dst); - - Size index = 0; - - while (index < len) { - dstChar[index] = srcChr[index]; - ++index; - } - - dstChar[index] = 0; - - return index; -} -} // namespace Kernel \ No newline at end of file -- cgit v1.2.3