diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-26 11:12:44 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-26 11:12:44 +0200 |
| commit | cddf1926591707121a3c1302a5ef7f5abd030d7e (patch) | |
| tree | 642b94a4b55d53d3c3d3abca7c76e8291b96bd37 | |
| parent | 0af5f147b67140ebb7b561fdde273c5123c61df8 (diff) | |
dev, kernel: add kernel on when the traversal hits 0 (it should never happen)
Signed-off-by: Amlal <amlal@nekernel.org>
| -rw-r--r-- | dev/boot/BootKit/BootKit.h | 2 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/DriveMgr.h | 4 | ||||
| -rw-r--r-- | dev/kernel/src/DriveMgr.cc | 4 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS.cc | 65 |
4 files changed, 66 insertions, 9 deletions
diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index 2bf95696..03902363 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -297,7 +297,7 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) { epm_boot.FsVersion = kNeFSVersionInteger; epm_boot.LbaStart = kNeFSRootCatalogStartAddress; - epm_boot.LbaEnd = fDiskDev.GetDiskSize(); + epm_boot.LbaEnd = fDiskDev.GetDiskSize() - 1; epm_boot.SectorSz = BootDev::kSectorSize; epm_boot.Kind = kEPMNeKernel; epm_boot.NumBlocks = 1; diff --git a/dev/kernel/KernelKit/DriveMgr.h b/dev/kernel/KernelKit/DriveMgr.h index 263b728e..b40cf0ad 100644 --- a/dev/kernel/KernelKit/DriveMgr.h +++ b/dev/kernel/KernelKit/DriveMgr.h @@ -71,6 +71,10 @@ struct DriveTrait final { const Char* (*fProtocol)(Void); }; +namespace Detail { + Void io_detect_drive(DriveTrait& trait); +} + ///! drive as a device. typedef DriveTrait* DriveTraitPtr; diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc index 763096b3..17c6c8cc 100644 --- a/dev/kernel/src/DriveMgr.cc +++ b/dev/kernel/src/DriveMgr.cc @@ -191,6 +191,10 @@ namespace Detail { trait.fPacket.fPacketReadOnly = YES; trait.fKind = kMassStorageDrive | kUnformattedDrive | kReadOnlyDrive; + + trait.fSectorSz = 512; + trait.fLbaEnd = drv_get_sector_count() - 1; + trait.fLbaStart = 0x400; } } diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 71d1d1d4..9333e53c 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -90,6 +90,14 @@ namespace Detail { else start = dir->fParent; } + + if (start == 0) { + kout << "Errror: Something went terribly wrong when traversing the RB-Tree.\r"; + + ke_panic(RUNTIME_CHECK_FILESYSTEM, "RB-Tree traversal failed, critical filesystem error!"); + + return; + } } /***********************************************************************************/ @@ -782,7 +790,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input root->fStartIND = drive->fLbaStart + sizeof(HEFS_BOOT_NODE); root->fEndIND = drive->fLbaEnd; - root->fINDCount = root->fEndIND - root->fStartIND; + root->fINDCount = 0; root->fDiskSize = drv_get_size(); root->fDiskStatus = kHeFSStatusUnlocked; @@ -811,8 +819,40 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input drive->fOutput(drive->fPacket); + if (!drive->fPacket.fPacketGood) { + delete root; + root = nullptr; + + err_global_get() = kErrorDiskIsCorrupted; + + return NO; + } + + HEFS_INDEX_NODE_DIRECTORY* root_dir = new HEFS_INDEX_NODE_DIRECTORY(); + rt_set_memory(root_dir, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); + + wrt_copy_memory((VoidPtr) u"/", root_dir->fName, wrt_string_len(u"/")); + + root_dir->fKind = kHeFSFileKindDirectory; + root_dir->fColor = kHeFSBlack; + root_dir->fParent = 0; // No parent (it's the real root) + root_dir->fChild = 0; // No children yet + root_dir->fNext = 0; // No next + root_dir->fPrev = 0; // No previous + + root_dir->fEntryCount = 0; + + drive->fPacket.fPacketLba = root->fStartIND; + drive->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); + drive->fPacket.fPacketContent = root_dir; + + drive->fOutput(drive->fPacket); + + delete root_dir; delete root; - root = nullptr; + + root = nullptr; + root_dir = nullptr; if (drive->fPacket.fPacketGood) return YES; @@ -827,7 +867,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 Utf16Char* dir) { NE_UNUSED(drive); NE_UNUSED(flags); NE_UNUSED(dir); @@ -881,9 +921,15 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu dirent->fDeleted = 0; dirent->fModified = 0; dirent->fEntryCount = 0; - dirent->fKind = kHeFSFileKindDirectory; - dirent->fFlags = flags; - dirent->fChecksum = 0; + + dirent->fParent = 0; // No parent (it's the real root) + dirent->fChild = 0; // No children yet + dirent->fNext = 0; // No next + dirent->fPrev = 0; // No previous + + dirent->fKind = kHeFSFileKindDirectory; + dirent->fFlags = flags; + dirent->fChecksum = 0; if (Detail::hefs_allocate_index_directory_node(root, drive, dirent)) { delete dirent; @@ -994,10 +1040,13 @@ Boolean fs_init_hefs(Void) noexcept { ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main filesystem cannot be mounted."); HeFileSystemParser parser; + parser.Format(&drv, kHeFSEncodingUTF16, kHeFSDefaultVoluneName); - parser.CreateDirectory(&drv, kHeFSEncodingUTF16, u"/"); - parser.CreateFile(&drv, kHeFSEncodingUTF16, u"/", u"boot.log"); + Kernel::Detail::io_detect_drive(drv); + + parser.CreateDirectory(&drv, kHeFSEncodingUTF16, u"boot"); + parser.CreateFile(&drv, kHeFSEncodingUTF16, u"boot", u".hefs"); return YES; } |
