From 2b4a4792abf51487ab4a16106f9376f43acf381a Mon Sep 17 00:00:00 2001
From: Amlal El Mahrouss Kind: folder Created by: system Edited by: "
- "system Volume Type: New OS Standard
Volume Type: New OS Standard
\r"; metadataFolder += "File name: "; metadataFolder += cDirStr[dirIndx]; @@ -93,17 +94,70 @@ class FilesystemWizard final { fNewFS->GetImpl()->CreateFork(catalogSystem, theFork); - fNewFS->GetImpl()->WriteCatalog(catalogSystem, - (NewOS::VoidPtr)(metadataFolder.CData()), - metadataSz, cFolderInfo); + fNewFS->GetImpl()->WriteCatalog( + catalogSystem, (NewOS::VoidPtr)(metadataFolder.CData()), + metadataSz, cFolderInfo); delete catalogSystem; } } + + NewCatalog* catalogDisk = + this->fNewFS->GetImpl()->GetCatalog("/Mount/This Disk"); + + const NewOS::Char* cSrcName = "DiskInfo"; + + if (catalogDisk) { + auto bufferInfoDisk = (NewOS::Char*)this->fNewFS->GetImpl()->ReadCatalog(catalogDisk, kNewFSSectorSz, cSrcName); + NewOS::kcout << bufferInfoDisk << NewOS::end_line(); + + delete bufferInfoDisk; + delete catalogDisk; + } else { + catalogDisk = + (NewCatalog*)this->Leak()->CreateAlias("/Mount/This Disk"); + + NewOS::StringView diskFolder(kNewFSSectorSz); + + diskFolder += + "
Kind: alias to disk
\rCreated by: system
\rEdited " + "by: " + "system
\rVolume Type: New OS Standard
\r"; + + diskFolder += "Original Path: "; + diskFolder += NewOS::NewFilesystemHelper::Root(); + diskFolder += "
\r"; + + NewFork theDiskFork{0}; + + NewOS::rt_copy_memory((NewOS::VoidPtr)(cSrcName), theDiskFork.ForkName, + NewOS::rt_string_len(cSrcName)); + + NewOS::rt_copy_memory((NewOS::VoidPtr)(catalogDisk->Name), + theDiskFork.CatalogName, + NewOS::rt_string_len(catalogDisk->Name)); + + theDiskFork.DataSize = kNewFSForkSize; + theDiskFork.ResourceId = 0; + theDiskFork.ResourceKind = NewOS::kNewFSRsrcForkKind; + theDiskFork.Kind = NewOS::kNewFSDataForkKind; + + fNewFS->GetImpl()->CreateFork(catalogDisk, theDiskFork); + fNewFS->GetImpl()->WriteCatalog(catalogDisk, + (NewOS::VoidPtr)diskFolder.CData(), + kNewFSSectorSz, cSrcName); + + delete catalogDisk; + } } } ~FilesystemWizard() { delete fNewFS; } + + NEWOS_COPY_DEFAULT(FilesystemWizard); + + /// Grab the disk's NewFS reference. + NewOS::NewFilesystemManager* Leak() { return fNewFS; } }; } // namespace Detail @@ -111,7 +165,7 @@ class FilesystemWizard final { EXTERN_C NewOS::Void AppMain(NewOS::Void) { /// Now run kernel loop, until no process are running. - Detail::FilesystemWizard mounter; + Detail::FilesystemWizard wizard; // automatic. while (NewOS::ProcessScheduler::Shared().Leak().Run() > 0) { ; diff --git a/Private/Source/FS/NewFS.cxx b/Private/Source/FS/NewFS.cxx index 870c1b69..c3d5283e 100644 --- a/Private/Source/FS/NewFS.cxx +++ b/Private/Source/FS/NewFS.cxx @@ -190,11 +190,12 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, Lba outLba = 0UL; + /// a directory should have a slash in the end. if (kind == kNewFSCatalogKindDir && name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator()) return nullptr; - /// as well as this, we don't want that. + /// a file shouldn't have a slash in the end. if (kind != kNewFSCatalogKindDir && name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) return nullptr; @@ -216,6 +217,8 @@ _Output NewCatalog* NewFSParser::CreateCatalog(_Input const char* name, return nullptr; } + /// Locate parent catalog, to then allocate right after it. + for (SizeT indexFill = 0; indexFill < rt_string_len(name); ++indexFill) { parentName[indexFill] = name[indexFill]; } @@ -550,14 +553,51 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, NewPartitionBlock* part = (NewPartitionBlock*)sectorBuf; - auto start = part->StartCatalog; + auto startCatalogList = part->StartCatalog; + const auto cCtartCatalogList = part->StartCatalog; + + auto localSearchFirst = false; - drive->fPacket.fLba = start; + drive->fPacket.fLba = startCatalogList; drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = sizeof(NewCatalog); drive->fInput(&drive->fPacket); + if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) { + Char parentName[kNewFSNodeNameLen] = { 0 }; + + for (SizeT indexFill = 0; indexFill < rt_string_len(catalogName); ++indexFill) { + parentName[indexFill] = catalogName[indexFill]; + } + + SizeT indexReverseCopy = rt_string_len(parentName); + + // zero character. + parentName[--indexReverseCopy] = 0; + + // mandatory / character. + parentName[--indexReverseCopy] = 0; + + while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) { + parentName[indexReverseCopy] = 0; + --indexReverseCopy; + } + + NewCatalog* parentCatalog = this->FindCatalog(parentName, outLba); + + if (parentCatalog && + !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) { + startCatalogList = outLba; + delete parentCatalog; + + localSearchFirst = true; + } else if (parentCatalog) { + delete parentCatalog; + } + } + +_NewFSSearchThroughCatalogList: while (drive->fPacket.fPacketGood) { NewCatalog* catalog = (NewCatalog*)sectorBuf; @@ -570,25 +610,32 @@ _Output NewCatalog* NewFSParser::FindCatalog(_Input const char* catalogName, NewCatalog* catalogPtr = new NewCatalog(); rt_copy_memory(catalog, catalogPtr, sizeof(NewCatalog)); - kcout << "New OS: Found catalog at: " << hex_number(start) << endl; + kcout << "New OS: Found catalog at: " << hex_number(startCatalogList) << endl; - outLba = start; + outLba = startCatalogList; delete[] sectorBuf; return catalogPtr; } _NewFSContinueSearch: - start = catalog->NextSibling; + startCatalogList = catalog->NextSibling; - if (start <= kNewFSAddressAsLba) break; + if (startCatalogList <= kNewFSAddressAsLba) break; - drive->fPacket.fLba = start; + drive->fPacket.fLba = startCatalogList; drive->fPacket.fPacketContent = sectorBuf; drive->fPacket.fPacketSize = sizeof(NewCatalog); drive->fInput(&drive->fPacket); } + if (localSearchFirst) { + localSearchFirst = false; + startCatalogList = cCtartCatalogList; + + goto _NewFSSearchThroughCatalogList; + } + outLba = 0UL; delete[] sectorBuf; -- cgit v1.2.3