From 2b4a4792abf51487ab4a16106f9376f43acf381a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 2 May 2024 15:51:31 +0200 Subject: unstable: lots of filesystem improvements. Signed-off-by: Amlal El Mahrouss --- Private/FirmwareKit/EPM.hxx | 4 +-- Private/Root/Assistants/.gitkeep | 0 Private/Source/AppMain.cxx | 78 +++++++++++++++++++++++++++++++++------- Private/Source/FS/NewFS.cxx | 63 +++++++++++++++++++++++++++----- 4 files changed, 123 insertions(+), 22 deletions(-) create mode 100644 Private/Root/Assistants/.gitkeep diff --git a/Private/FirmwareKit/EPM.hxx b/Private/FirmwareKit/EPM.hxx index 3b3585be..5c7ad548 100644 --- a/Private/FirmwareKit/EPM.hxx +++ b/Private/FirmwareKit/EPM.hxx @@ -111,7 +111,7 @@ typedef struct PartitionBlock PartitionBlockType; ///! @brief partition must start at this address. ///! Anything below is reserved for Data backup by the Main OS. -#define kEPMStartPartitionBlk (0) +#define kEPMStartPartitionBlk (sizeof(BootBlock)) ///! @brief Current EPM revision (2) #define kEPMRevision (2) @@ -119,6 +119,6 @@ typedef struct PartitionBlock PartitionBlockType; ///! @brief Current EPM revision (2) #define kEPMRevisionUEFI (0xF) -/// END SPECS +/// END OF SPECS #endif // ifndef __PARTITION_MAP__ diff --git a/Private/Root/Assistants/.gitkeep b/Private/Root/Assistants/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/Private/Source/AppMain.cxx b/Private/Source/AppMain.cxx index 663a6775..5ada91a1 100644 --- a/Private/Source/AppMain.cxx +++ b/Private/Source/AppMain.cxx @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -19,8 +20,8 @@ #include #include #include -#include #include +#include namespace Detail { /// @brief Filesystem auto mounter, additional checks are also done by the @@ -43,21 +44,21 @@ class FilesystemWizard final { if (fNewFS->GetImpl()) { constexpr auto cFolderInfo = "Metadata"; - const auto cDirCount = 7; + const auto cDirCount = 8; const char* cDirStr[cDirCount] = { "/Boot/", "/System/", "/Support/", "/Applications/", - "/Users/", "/Library/", "/Mount/"}; + "/Users/", "/Library/", "/Mount/", "/Assistants/"}; for (NewOS::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { auto catalogDir = fNewFS->GetImpl()->GetCatalog(cDirStr[dirIndx]); if (catalogDir) { - delete catalogDir; - continue; + delete catalogDir; + continue; } - catalogDir = fNewFS->GetImpl()->CreateCatalog( - cDirStr[dirIndx], 0, kNewFSCatalogKindDir); + catalogDir = fNewFS->GetImpl()->CreateCatalog(cDirStr[dirIndx], 0, + kNewFSCatalogKindDir); NewFork theFork{0}; @@ -81,7 +82,7 @@ class FilesystemWizard final { metadataFolder += "

Kind: folder

\r

Created by: system

\r

Edited by: " - "system

\r

Volume Type: New OS Standard

\r"; + "system

\r

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

\r

Created by: system

\r

Edited " + "by: " + "system

\r

Volume 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