diff options
Diffstat (limited to 'Private')
| -rw-r--r-- | Private/FirmwareKit/EPM.hxx | 4 | ||||
| -rw-r--r-- | Private/Root/Assistants/.gitkeep | 0 | ||||
| -rw-r--r-- | Private/Source/AppMain.cxx | 78 | ||||
| -rw-r--r-- | Private/Source/FS/NewFS.cxx | 63 |
4 files changed, 123 insertions, 22 deletions
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 --- /dev/null +++ b/Private/Root/Assistants/.gitkeep 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 <ArchKit/ArchKit.hpp> #include <Builtins/Toolbox/Toolbox.hxx> +#include <CompilerKit/Detail.hxx> #include <FirmwareKit/Handover.hxx> #include <KernelKit/FileManager.hpp> #include <KernelKit/Framebuffer.hpp> @@ -19,8 +20,8 @@ #include <KernelKit/UserHeap.hpp> #include <NewKit/Json.hpp> #include <NewKit/KernelCheck.hpp> -#include <NewKit/Utils.hpp> #include <NewKit/String.hpp> +#include <NewKit/Utils.hpp> 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 += "<p>Kind: folder</p>\r<p>Created by: system</p>\r<p>Edited by: " - "system</p>\r<p>Volume Type: New OS Standard</p>\r"; + "system</p>\r<p>Volume Type: New OS Standard</p>\r"; metadataFolder += "<p>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 += + "<p>Kind: alias to disk</p>\r<p>Created by: system</p>\r<p>Edited " + "by: " + "system</p>\r<p>Volume Type: New OS Standard</p>\r"; + + diskFolder += "<p>Original Path: "; + diskFolder += NewOS::NewFilesystemHelper::Root(); + diskFolder += "</p>\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; |
