diff options
Diffstat (limited to 'Private/Source')
| -rw-r--r-- | Private/Source/AppMain.cxx | 56 | ||||
| -rw-r--r-- | Private/Source/FS/NewFS.cxx | 47 |
2 files changed, 45 insertions, 58 deletions
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; } |
