From bf2fc74c6552f9359955210c8f60e45308ae1d31 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 3 Jan 2025 15:25:06 +0100 Subject: IMPL: Work In Progress efforts in Journaling and SysChk. Signed-off-by: Amlal El Mahrouss --- dev/Boot/BootKit/BootKit.h | 4 ++-- dev/Boot/Mod/SysChk/Module.cc | 6 +++++- dev/Boot/src/HEL/AMD64/BootATA.cc | 7 ++++++- dev/Boot/src/HEL/AMD64/BootMain.cc | 17 +++++++++++------ dev/Kernel/FSKit/NeFS.h | 28 ++++++++++++++++++++++++++-- dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc | 2 +- dev/Kernel/src/FS/NeFS.cc | 5 +---- dev/Kernel/src/KernelMain.cc | 4 +++- 8 files changed, 55 insertions(+), 18 deletions(-) diff --git a/dev/Boot/BootKit/BootKit.h b/dev/Boot/BootKit/BootKit.h index 09313830..86b6e4c5 100644 --- a/dev/Boot/BootKit/BootKit.h +++ b/dev/Boot/BootKit/BootKit.h @@ -353,8 +353,8 @@ namespace Boot BOOT_BLOCK_STRUCT epm_boot{0}; - constexpr auto kFsName = "NeFS"; - constexpr auto kBlockName = "ZKA:"; + const auto kFsName = "NeFS"; + const auto kBlockName = "OS"; CopyMem(epm_boot.Fs, reinterpret_cast(const_cast(kFsName)), StrLen(kFsName)); diff --git a/dev/Boot/Mod/SysChk/Module.cc b/dev/Boot/Mod/SysChk/Module.cc index 4073ec11..09a7a718 100644 --- a/dev/Boot/Mod/SysChk/Module.cc +++ b/dev/Boot/Mod/SysChk/Module.cc @@ -24,5 +24,9 @@ EXTERN_C Int32 ModuleMain(Kernel::HEL::BootInfoHeader* handover) { Boot::BDiskFormatFactory partition_factory; - return (!partition_factory.IsPartitionValid()) ? kEfiFail : kEfiOk; + + if (partition_factory.IsPartitionValid()) + return kEfiOk; + + return kEfiFail; } diff --git a/dev/Boot/src/HEL/AMD64/BootATA.cc b/dev/Boot/src/HEL/AMD64/BootATA.cc index cdf0d180..4222792f 100644 --- a/dev/Boot/src/HEL/AMD64/BootATA.cc +++ b/dev/Boot/src/HEL/AMD64/BootATA.cc @@ -169,6 +169,8 @@ Void boot_ata_write(UInt64 Lba, UInt16 IO, UInt8 Master, CharacterTypeUTF8* Buf, rt_out16(IO + ATA_REG_DATA, Buf[IndexOff]); boot_ata_wait_io(IO); } + + boot_ata_wait_io(IO); } /// @check is ATA detected? @@ -246,8 +248,11 @@ BootDeviceATA& BootDeviceATA::Write(CharacterTypeUTF8* Buf, const SizeT& SectorS Leak().mErr = false; - if (!Buf || SectorSz < 1) + if (!Buf || SectorSz < 1 || this->Leak().mSize < 1) + { + Leak().mErr = true; return *this; + } boot_ata_write(this->Leak().mBase, this->Leak().mBus, this->Leak().mMaster, Buf, SectorSz, this->Leak().mSize); diff --git a/dev/Boot/src/HEL/AMD64/BootMain.cc b/dev/Boot/src/HEL/AMD64/BootMain.cc index 6744438f..da618625 100644 --- a/dev/Boot/src/HEL/AMD64/BootMain.cc +++ b/dev/Boot/src/HEL/AMD64/BootMain.cc @@ -222,16 +222,21 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr image_handle, if (syschk_thread->Start(handover_hdr, NO) != kEfiOk) { - fb_init(); + if (partition_factory.IsPartitionValid() == NO) + { + Boot::BDiskFormatFactory::BFileDescriptor root{}; - Boot::BDiskFormatFactory::BFileDescriptor root{}; + root.fFileName[0] = kNeFSRoot[0]; + root.fFileName[1] = 0; - root.fFileName[0] = kNeFSRoot[0]; - root.fFileName[1] = 0; + root.fKind = kNeFSCatalogKindDir; - root.fKind = kNeFSCatalogKindDir; + const auto kFSName = "SSD"; - partition_factory.Format("HD", &root, 1); + partition_factory.Format(kFSName, &root, 1); + } + + fb_init(); UI::fb_clear_video(); diff --git a/dev/Kernel/FSKit/NeFS.h b/dev/Kernel/FSKit/NeFS.h index 2468fd16..78177e07 100644 --- a/dev/Kernel/FSKit/NeFS.h +++ b/dev/Kernel/FSKit/NeFS.h @@ -380,13 +380,37 @@ namespace Kernel return NO; } - Bool Commit(NeFileSystemParser* parser, + Bool ReleaseJournal() + { + if (mNode) + { + delete mNode; + mNode = nullptr; + return YES; + } + + return NO; + } + + Bool CommitJournal(NeFileSystemParser* parser, KString xml_data, KString journal_name) { - if (!parser) + if (!parser || + !mNode) return NO; + NFS_FORK_STRUCT new_fork{}; + + rt_copy_memory(mNode->Name, new_fork.CatalogName, rt_string_len(mNode->Name)); + rt_copy_memory(journal_name.Data(), new_fork.ForkName, rt_string_len(journal_name.Data())); + + new_fork.DataSize = xml_data.Length(); + + new_fork.Kind = kNeFSRsrcForkKind; + + parser->CreateFork(mNode, new_fork); + return parser->WriteCatalog(mNode, YES, xml_data.Data(), xml_data.Length(), journal_name.CData()); } diff --git a/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc b/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc index 55a3a4b9..081ce0b2 100644 --- a/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc +++ b/dev/Kernel/HALKit/AMD64/Storage/ATA-PIO.cc @@ -155,7 +155,7 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS rt_out8(IO + ATA_REG_SEC_COUNT0, ((Size + (SectorSz)) / SectorSz)); - rt_out8(IO + ATA_REG_LBA0, (Lba)&0xFF); + rt_out8(IO + ATA_REG_LBA0, (Lba) & 0xFF); rt_out8(IO + ATA_REG_LBA1, (Lba) >> 8); rt_out8(IO + ATA_REG_LBA2, (Lba) >> 16); rt_out8(IO + ATA_REG_LBA3, (Lba) >> 24); diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc index b5eb25e7..f188db43 100644 --- a/dev/Kernel/src/FS/NeFS.cc +++ b/dev/Kernel/src/FS/NeFS.cc @@ -85,11 +85,8 @@ _Output NFS_FORK_STRUCT* NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUC Lba lbaOfPreviousFork = lba; /// do not check for anything. Loop until we get what we want, that is a free fork zone. - while (true) + while (lba <= kNeFSCatalogStartAddress) { - if (lba <= kNeFSCatalogStartAddress) - break; - drv.fPacket.fPacketLba = lba; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv.fPacket.fPacketContent = &curFork; diff --git a/dev/Kernel/src/KernelMain.cc b/dev/Kernel/src/KernelMain.cc index 3a123e1b..58592a10 100644 --- a/dev/Kernel/src/KernelMain.cc +++ b/dev/Kernel/src/KernelMain.cc @@ -68,13 +68,15 @@ namespace Kernel::Detail } mJournal.CreateJournal(mNeFS); + KString xml; xml += "Formatted Filesystem"; KString name; name += "FORMAT"; - mJournal.Commit(mNeFS, xml, name); + mJournal.CommitJournal(mNeFS, xml, name); + mJournal.ReleaseJournal(); } } -- cgit v1.2.3