diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-01 00:17:26 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-05-01 00:17:26 +0200 |
| commit | 39252db4317b2e53eee59217ca7bb42a0b531443 (patch) | |
| tree | 5da3342e1d6431faa542a253010fffd0714b4119 | |
| parent | 32efe47d7ba51b6369baa3619b0a91591beeb1df (diff) | |
NewFS: Fix catalogs, fork must also have the catalog's owner name inside
of them.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
| -rw-r--r-- | Private/FSKit/NewFS.hxx | 12 | ||||
| -rw-r--r-- | Private/HALKit/AMD64/Storage/ATA-PIO.cxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/BootKit.hxx | 4 | ||||
| -rw-r--r-- | Private/Source/AppMain.cxx | 56 | ||||
| -rw-r--r-- | Private/Source/FS/NewFS.cxx | 47 |
5 files changed, 54 insertions, 67 deletions
diff --git a/Private/FSKit/NewFS.hxx b/Private/FSKit/NewFS.hxx index 2cc08cd6..b099a2c4 100644 --- a/Private/FSKit/NewFS.hxx +++ b/Private/FSKit/NewFS.hxx @@ -39,8 +39,8 @@ default. /// @brief Partition GUID on EPM and GPT disks. #define kNewFSUUID "@{DD997393-9CCE-4288-A8D5-C0FDE3908DBE}" -#define kNewFSVersionInteger 0x124 -#define kNewFSVerionString "1.24" +#define kNewFSVersionInteger 0x125 +#define kNewFSVerionString "1.25" /// @brief Standard fork types. #define kNewFSDataFork "data" @@ -132,12 +132,15 @@ struct PACKED NewCatalog final { NewOS::Lba PrevSibling; }; +#define kNewFSForkNameLen (200U) + /// @brief Fork type, contains a data page. /// @note The way we store is way different than how other filesystems do, specific chunk of code are /// written into either the data fork or resource fork, the resource fork is reserved for file metadata. /// whereas the data fork is reserved for file data. struct PACKED NewFork final { - NewCharType Name[kNewFSNodeNameLen]; + NewCharType ForkName[kNewFSForkNameLen]; + NewOS::Char CatalogName[kNewFSNodeNameLen]; NewOS::Int32 Flags; NewOS::Int32 Kind; @@ -151,9 +154,6 @@ struct PACKED NewFork final { NewOS::Lba NextSibling; NewOS::Lba PreviousSibling; - - /// To make a perfect sector. - NewOS::Char Padding[200]; }; /// @brief Partition block type diff --git a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx index 6dafb5e5..b9e69f52 100644 --- a/Private/HALKit/AMD64/Storage/ATA-PIO.cxx +++ b/Private/HALKit/AMD64/Storage/ATA-PIO.cxx @@ -112,7 +112,6 @@ Void drv_std_read(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, Out8(IO + ATA_REG_LBA0, (Lba)); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA3, (Lba) >> 24); Out8(IO + ATA_REG_COMMAND, ATA_CMD_READ_PIO); @@ -144,7 +143,6 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, Out8(IO + ATA_REG_LBA0, (Lba)); Out8(IO + ATA_REG_LBA1, (Lba) >> 8); Out8(IO + ATA_REG_LBA2, (Lba) >> 16); - Out8(IO + ATA_REG_LBA3, (Lba) >> 24); Out8(IO + ATA_REG_COMMAND, ATA_CMD_WRITE_PIO); diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 212e8914..03dddcb3 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -251,9 +251,11 @@ private: Char bufCatalog[sizeof(NewCatalog)] = { 0 }; + constexpr auto cNewFSCatalogPadding = 4; + NewCatalog* catalogKind = (NewCatalog*)bufCatalog; catalogKind->PrevSibling = startLba; - catalogKind->NextSibling = (startLba + sizeof(NewCatalog)); + catalogKind->NextSibling = (startLba + (sizeof(NewCatalog) * cNewFSCatalogPadding)); /// Fill catalog kind. catalogKind->Kind = blob->fKind; diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx index c4ceb55e..6dc2a3ff 100644 --- a/Private/Source/AppMain.cxx +++ b/Private/Source/AppMain.cxx @@ -45,57 +45,23 @@ class FilesystemAutomountProvider final { /// Sample AMD64 program, /// mov rax, 0x0 /// ret - /// @note there was a 0xc1 before, to delimit the program, but I removed it. We - /// don't need that now. + /// @note there was a 0xc1 before, to delimit the program, but I removed + /// it. We don't need that now. NewOS::UInt8 sanitizerBytes[sanitizerSize] = { "\x48\xC7\xC0\x00\x00\x00\x00\xC3"}; if (fNewFS->GetImpl()) { NewCatalog* sanitizerCatalog = nullptr; - if (!fNewFS->GetImpl()->GetCatalog("/System/%NKSYSSAN%")) { - NewFork sanitizerFork{0}; - - NewOS::rt_copy_memory( - (NewOS::VoidPtr) "/System/%NKSYSSAN%$RawExecutable", - (NewOS::VoidPtr)sanitizerFork.Name, - NewOS::rt_string_len("/System/%NKSYSSAN%$RawExecutable")); - - sanitizerFork.Kind = NewOS::kNewFSDataForkKind; - sanitizerFork.DataSize = kNewFSForkSize; - - delete fNewFS->GetImpl()->CreateCatalog("/System/", 0, kNewFSCatalogKindDir); - delete fNewFS->GetImpl()->CreateCatalog("/Boot/", 0, kNewFSCatalogKindDir); - delete fNewFS->GetImpl()->CreateCatalog("/Support/", 0, kNewFSCatalogKindDir); - delete fNewFS->GetImpl()->CreateCatalog("/Applications/", 0, kNewFSCatalogKindDir); - - sanitizerCatalog = - fNewFS->GetImpl()->CreateCatalog("/System/%NKSYSSAN%"); - - fNewFS->GetImpl()->CreateFork(sanitizerCatalog, sanitizerFork); - fNewFS->GetImpl()->WriteCatalog(sanitizerCatalog, sanitizerBytes, - sanitizerSize, - "/System/%NKSYSSAN%$RawExecutable"); - } - - NewOS::UInt8* buf = nullptr; - - buf = (NewOS::UInt8*)fNewFS->GetImpl()->ReadCatalog( - fNewFS->GetImpl()->GetCatalog("/System/%NKSYSSAN%"), 512, - "/System/%NKSYSSAN%$RawExecutable"); - - if (!buf) { - NewOS::kcout << "Bad-Ptr: " << NewOS::hex_number((NewOS::UIntPtr)buf) - << NewOS::endl; - NewOS::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR); - } - - for (NewOS::SizeT index = 0UL; index < sanitizerSize; ++index) { - if (buf[index] != sanitizerBytes[index]) { - NewOS::kcout << "Diff-Detected: " << NewOS::hex_number(buf[index]) - << NewOS::endl; - NewOS::ke_stop(RUNTIME_CHECK_BAD_BEHAVIOR); - } + if (!fNewFS->GetImpl()->GetCatalog("/System/")) { + delete fNewFS->GetImpl()->CreateCatalog("/System/", 0, + kNewFSCatalogKindDir); + delete fNewFS->GetImpl()->CreateCatalog("/Boot/", 0, + kNewFSCatalogKindDir); + delete fNewFS->GetImpl()->CreateCatalog("/Support/", 0, + kNewFSCatalogKindDir); + delete fNewFS->GetImpl()->CreateCatalog("/Applications/", 0, + kNewFSCatalogKindDir); } } } diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx index e96402e2..d3d75fb2 100644 --- a/Private/Source/FS/NewFS.cxx +++ b/Private/Source/FS/NewFS.cxx @@ -27,7 +27,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, _Input NewFork& theFork) { if (!sMountpointInterface.GetAddressOf(this->fDriveIndex)) return nullptr; - if (catalog && theFork.Name[0] != 0 && theFork.DataSize == kNewFSForkSize) { + if (catalog && theFork.ForkName[0] != 0 && theFork.DataSize == kNewFSForkSize) { Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork : catalog->ResourceFork; @@ -45,7 +45,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, NewFork prevFork{0}; Lba lbaOfPreviousFork = lba; - while (cpyFork.Name[0] == 0) { + while (cpyFork.ForkName[0] == 0) { if (lba <= kNewFSCatalogStartAddress) break; drv->fPacket.fLba = lba; @@ -58,7 +58,7 @@ _Output NewFork* NewFSParser::CreateFork(_Input NewCatalog* catalog, if (cpyFork.Flags == kNewFSFlagCreated) { kcout << "New OS: Fork already exists.\r"; - if (StringBuilder::Equals(cpyFork.Name, theFork.Name)) return nullptr; + if (StringBuilder::Equals(cpyFork.ForkName, theFork.ForkName)) return nullptr; lbaOfPreviousFork = lba; lba = cpyFork.NextSibling; @@ -140,7 +140,7 @@ _Output NewFork* NewFSParser::FindFork(_Input NewCatalog* catalog, return nullptr; } - if (StringBuilder::Equals(theFork->Name, name)) { + if (StringBuilder::Equals(theFork->ForkName, name)) { break; } @@ -219,7 +219,7 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, delete catalog; return nullptr; } else if (!catalog) { - outLba = kNewFSCatalogStartAddress; + outLba = kNewFSCatalogStartAddress; } constexpr SizeT cDefaultForkSize = kNewFSForkSize; @@ -281,13 +281,16 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fInput(&drive->fPacket); + constexpr auto cNewFSCatalogPadding = 4; + NewPartitionBlock* partBlock = (NewPartitionBlock*)sectorBufPartBlock; catalogChild->DataFork = partBlock->DiskSize - partBlock->StartCatalog; catalogChild->ResourceFork = catalogChild->DataFork; - catalogChild->NextSibling = startFree + sizeof(NewCatalog); + catalogChild->NextSibling = + startFree + (sizeof(NewCatalog) * cNewFSCatalogPadding); drive->fPacket.fPacketContent = catalogChild; drive->fPacket.fPacketSize = sizeof(NewCatalog); @@ -297,7 +300,8 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, drive->fPacket.fPacketContent = catalogBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = outLba; + drive->fPacket.fLba = + startFree - (sizeof(NewCatalog) * cNewFSCatalogPadding); drive->fInput(&drive->fPacket); @@ -307,7 +311,8 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, kcout << "New OS: Create new catalog, status: " << hex_number(catalogChild->Flags) << endl; - kcout << "New OS: Create new catalog, status: " << catalogChild->Name << endl; + kcout << "New OS: Create new catalog, status: " << catalogChild->Name + << endl; drive->fPacket.fPacketContent = sectorBufPartBlock; drive->fPacket.fPacketSize = kNewFSSectorSz; @@ -325,8 +330,10 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, return catalogChild; } + constexpr auto cNewFSCatalogPadding = 4; + //// @note that's how we find the next catalog in the partition block. - startFree = startFree + 1; + startFree = startFree + (sizeof(NewCatalog) * cNewFSCatalogPadding); drive->fPacket.fPacketContent = catalogBuf; drive->fPacket.fPacketSize = kNewFSSectorSz; @@ -440,6 +447,8 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, auto startFork = catalog->DataFork; + rt_copy_memory(catalog->Name, forkData->CatalogName, kNewFSNodeNameLen); + /// sanity check of the fork position as the condition to run the loop. while (startFork >= kNewFSCatalogStartAddress) { drive->fPacket.fPacketContent = forkData; @@ -447,7 +456,7 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, drive->fPacket.fLba = startFork; drive->fInput(&drive->fPacket); - kcout << "Fork-Name: " << forkData->Name << endl; + kcout << "Fork-Name: " << forkData->ForkName << endl; /// sanity check the fork. if (forkData->DataOffset <= kNewFSCatalogStartAddress) { @@ -461,7 +470,19 @@ bool NewFSParser::WriteCatalog(_Input _Output NewCatalog* catalog, voidPtr data, if (forkData->Flags != kNewFSFlagUnallocated && forkData->Flags != kNewFSFlagDeleted && - StringBuilder::Equals(forkData->Name, forkName)) { + StringBuilder::Equals(forkData->ForkName, forkName)) { + drive->fPacket.fPacketContent = data; + drive->fPacket.fPacketSize = sizeOfData; + drive->fPacket.fLba = forkData->DataOffset; + kcout << "Fork-Offset: " << hex_number(forkData->DataOffset) << endl; + + drive->fOutput(&drive->fPacket); + + delete forkData; + return true; + } else if (auto catalog = this->GetCatalog(forkData->CatalogName); + catalog == nullptr) { + delete catalog; drive->fPacket.fPacketContent = data; drive->fPacket.fPacketSize = sizeOfData; drive->fPacket.fLba = forkData->DataOffset; @@ -642,7 +663,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, forkData = (NewFork*)sectorBuf; - kcout << "Fork-Name: " << forkData->Name << endl; + kcout << "Fork-Name: " << forkData->ForkName << endl; if (forkData->DataOffset <= kNewFSCatalogStartAddress) { delete[] sectorBuf; @@ -652,7 +673,7 @@ VoidPtr NewFSParser::ReadCatalog(_Input _Output NewCatalog* catalog, return nullptr; } - if (StringBuilder::Equals(forkName, forkData->Name)) break; + if (StringBuilder::Equals(forkName, forkData->ForkName)) break; dataForkLba = forkData->NextSibling; } |
