diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-12-22 09:59:02 +0100 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-12-22 09:59:02 +0100 |
| commit | 81183c95e955a416a5b401b05a903945687b1fad (patch) | |
| tree | 35565ce5593630709a803b04b8fcad06759d12d7 | |
| parent | bddaafedff871716a0169e9ebf1ada5851970365 (diff) | |
#3 : NeFilesystemInstaller WiP Issue on it.
| -rw-r--r-- | dev/BootLoader/BootKit/BootKit.h | 28 | ||||
| -rw-r--r-- | dev/BootLoader/src/HEL/AMD64/BootMain.cc | 2 | ||||
| -rw-r--r-- | dev/Kernel/FSKit/NeFS.h | 33 | ||||
| -rw-r--r-- | dev/Kernel/HALKit/AMD64/HalKernelMain.cc | 1 | ||||
| -rw-r--r-- | dev/Kernel/KernelKit/FileMgr.h | 2 | ||||
| -rw-r--r-- | dev/Kernel/src/FS/NeFS.cc | 20 | ||||
| -rw-r--r-- | dev/Kernel/src/KernelMain.cc | 54 | ||||
| -rw-r--r-- | dev/Kernel/src/NeFS+FileMgr.cc | 34 | ||||
| -rw-r--r-- | dev/Kernel/src/UserProcessScheduler.cc | 2 |
9 files changed, 97 insertions, 79 deletions
diff --git a/dev/BootLoader/BootKit/BootKit.h b/dev/BootLoader/BootKit/BootKit.h index 395ac2d7..a3d6a026 100644 --- a/dev/BootLoader/BootKit/BootKit.h +++ b/dev/BootLoader/BootKit/BootKit.h @@ -315,9 +315,6 @@ namespace Boot if (!fileBlobs || !blobCount) return false; /// sanity check - /// convert the sector into something that the disk understands. - SizeT sectorSz = sizeof(NFS_ROOT_PARTITION_BLOCK); - /// @note A catalog roughly equal to a sector. constexpr auto kMinimumDiskSize = kNeFSMinimumDiskSize; // at minimum. @@ -341,7 +338,7 @@ namespace Boot partBlock.Version = kNeFSVersionInteger; partBlock.CatalogCount = blobCount; partBlock.Kind = kNeFSHardDrive; - partBlock.SectorSize = sectorSz; + partBlock.SectorSize = sizeof(NFS_ROOT_PARTITION_BLOCK); partBlock.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT); partBlock.SectorCount = fDiskDev.GetSectorsCount(); partBlock.FreeSectors = fDiskDev.GetSectorsCount(); @@ -350,16 +347,16 @@ namespace Boot partBlock.Flags = kNeFSPartitionTypeBoot | kNeFSPartitionTypeStandard; fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sectorSz; + fDiskDev.Leak().mSize = sizeof(NFS_ROOT_PARTITION_BLOCK); - fDiskDev.Write((Char*)&partBlock, sectorSz); + fDiskDev.Write((Char*)&partBlock, sizeof(NFS_ROOT_PARTITION_BLOCK)); BOOT_BLOCK_STRUCT epm_boot{0}; - constexpr auto cFsName = "NeFS"; - constexpr auto cBlockName = "ZKA:"; + constexpr auto kFsName = "NeFS"; + constexpr auto kBlockName = "ZKA:"; - CopyMem(epm_boot.Fs, reinterpret_cast<VoidPtr>(const_cast<Char*>(cFsName)), StrLen(cFsName)); + CopyMem(epm_boot.Fs, reinterpret_cast<VoidPtr>(const_cast<Char*>(kFsName)), StrLen(kFsName)); epm_boot.FsVersion = kNeFSVersionInteger; epm_boot.LbaStart = kNeFSRootCatalogStartAddress; @@ -367,24 +364,27 @@ namespace Boot epm_boot.Kind = kEPMZkaOS; epm_boot.NumBlocks = partBlock.CatalogCount; - CopyMem(epm_boot.Name, reinterpret_cast<VoidPtr>(const_cast<Char*>(cBlockName)), StrLen(cBlockName)); + CopyMem(epm_boot.Name, reinterpret_cast<VoidPtr>(const_cast<Char*>(kBlockName)), StrLen(kBlockName)); CopyMem(epm_boot.Magic, reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), StrLen(kEPMMagic)); - fDiskDev.Leak().mBase = 1; // always always resies at zero block. - fDiskDev.Leak().mSize = BootDev::kSectorSize; + fDiskDev.Leak().mBase = kEPMBootBlockLba; // always always resies at zero block. + fDiskDev.Leak().mSize = sizeof(BOOT_BLOCK_STRUCT); - fDiskDev.Write((Char*)&epm_boot, sectorSz); + fDiskDev.Write((Char*)&epm_boot, sizeof(BOOT_BLOCK_STRUCT)); /// if we can write a root catalog, then write the partition block. if (this->WriteRootCatalog(fileBlobs, blobCount, partBlock)) { BTextWriter writer; - writer.Write(L"BootZ: Drive formatted.\r"); + writer.Write(L"BootZ: Drive Formatted Successfully.\r"); return true; } else { + cg_init(); + CGDrawBitMapInRegion(zka_no_disk, ZKA_NO_DISK_HEIGHT, ZKA_NO_DISK_WIDTH, (kHandoverHeader->f_GOP.f_Width - ZKA_NO_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - ZKA_NO_DISK_HEIGHT) / 2); + EFI::ThrowError(L"Filesystem-Failure-Part", L"Filesystem couldn't be partitioned, this drive cannot be formatted as an explicit partition map."); } diff --git a/dev/BootLoader/src/HEL/AMD64/BootMain.cc b/dev/BootLoader/src/HEL/AMD64/BootMain.cc index dd8fb345..64c2c983 100644 --- a/dev/BootLoader/src/HEL/AMD64/BootMain.cc +++ b/dev/BootLoader/src/HEL/AMD64/BootMain.cc @@ -174,7 +174,7 @@ EFI_EXTERN_C EFI_API Int32 Main(EfiHandlePtr ImageHandle, cg_fini(); - Boot::BDiskFormatFactory<BootDeviceATA>::BFileDescriptor root; + Boot::BDiskFormatFactory<BootDeviceATA>::BFileDescriptor root{}; root.fFileName[0] = kNeFSRoot[0]; root.fFileName[1] = 0; diff --git a/dev/Kernel/FSKit/NeFS.h b/dev/Kernel/FSKit/NeFS.h index 2a8bac2a..c80bc1c7 100644 --- a/dev/Kernel/FSKit/NeFS.h +++ b/dev/Kernel/FSKit/NeFS.h @@ -20,6 +20,7 @@ default. #include <HintKit/CompilerHint.h> #include <KernelKit/DriveMgr.h> #include <NewKit/Defines.h> +#include <NewKit/KString.h> /** @brief New File System specification. @@ -318,8 +319,11 @@ namespace Kernel /// @brief Journal class for NeFS. class NeFileSystemJournal final { + private: + NFS_CATALOG_STRUCT* mNode{nullptr}; + public: - explicit NeFileSystemJournal(const char* stamp) + explicit NeFileSystemJournal(const char* stamp = "/System" kNeFSJournalExt) { if (!stamp) { @@ -340,37 +344,36 @@ namespace Kernel if (!parser) return NO; - auto node = parser->CreateCatalog(mStamp); + mNode = parser->CreateCatalog(mStamp); - if (!node) + if (!mNode) return NO; - delete node; - node = nullptr; - return YES; } - Bool IsJournalValid(NeFileSystemParser* parser) + Bool GetJournal(NeFileSystemParser* parser) { if (!parser) return NO; - if (auto node = parser->GetCatalog(mStamp); - node) + if (mNode = parser->GetCatalog(mStamp); + mNode) { - delete node; - node = nullptr; - return YES; } return NO; } - Void Commit() {} - - Void Start() {} + Bool Commit(NeFileSystemParser* parser, + KString xml_data, KString journal_name) + { + if (!parser) + return NO; + + return parser->WriteCatalog(mNode, YES, xml_data.Data(), xml_data.Length(), journal_name.CData()); + } private: Char mStamp[255] = { "/System/FileSystemStamp.jrnl" }; diff --git a/dev/Kernel/HALKit/AMD64/HalKernelMain.cc b/dev/Kernel/HALKit/AMD64/HalKernelMain.cc index d6fe8a14..9333d3c5 100644 --- a/dev/Kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/Kernel/HALKit/AMD64/HalKernelMain.cc @@ -99,5 +99,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept while (YES) { + continue; } } diff --git a/dev/Kernel/KernelKit/FileMgr.h b/dev/Kernel/KernelKit/FileMgr.h index ac94d86b..10aef681 100644 --- a/dev/Kernel/KernelKit/FileMgr.h +++ b/dev/Kernel/KernelKit/FileMgr.h @@ -186,7 +186,7 @@ namespace Kernel NeFileSystemParser* GetParser() noexcept; private: - NeFileSystemParser* fImpl{nullptr}; + NeFileSystemParser* mParser{nullptr}; }; #endif // ifdef __FSKIT_INCLUDES_NEFS__ diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc index fe6fbe0c..1dd08e4f 100644 --- a/dev/Kernel/src/FS/NeFS.cc +++ b/dev/Kernel/src/FS/NeFS.cc @@ -742,14 +742,14 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* c NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)&fs_buf; - auto startCatalogList = part->StartCatalog; - const auto cCtartCatalogList = startCatalogList; + auto start_catalog_lba = part->StartCatalog; + const auto kStartCatalogList = start_catalog_lba; auto localSearchFirst = false; NFS_CATALOG_STRUCT temporary_catalog{0}; - drive.fPacket.fPacketLba = startCatalogList; + drive.fPacket.fPacketLba = start_catalog_lba; drive.fPacket.fPacketContent = &temporary_catalog; drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); @@ -783,7 +783,7 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* c if (parentCatalog && !StringBuilder::Equals(parentName, NeFileSystemHelper::Root())) { - startCatalogList = parentCatalog->NextSibling; + start_catalog_lba = parentCatalog->NextSibling; delete parentCatalog; localSearchFirst = true; @@ -803,7 +803,7 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* c NeFSSearchThroughCatalogList: while (drive.fPacket.fPacketGood) { - drive.fPacket.fPacketLba = startCatalogList; + drive.fPacket.fPacketLba = start_catalog_lba; drive.fPacket.fPacketContent = &temporary_catalog; drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); @@ -822,24 +822,24 @@ NeFSSearchThroughCatalogList: NFS_CATALOG_STRUCT* catalogPtr = new NFS_CATALOG_STRUCT(); rt_copy_memory(catalog, catalogPtr, sizeof(NFS_CATALOG_STRUCT)); - kcout << "Found catalog at: " << hex_number(startCatalogList) << endl; + kcout << "Found catalog at: " << hex_number(start_catalog_lba) << endl; kcout << "Found catalog at: " << catalog->Name << endl; - out_lba = startCatalogList; + out_lba = start_catalog_lba; return catalogPtr; } NeFSContinueSearch: - startCatalogList = catalog->NextSibling; + start_catalog_lba = catalog->NextSibling; - if (startCatalogList <= kNeFSRootCatalogStartAddress) + if (start_catalog_lba <= kNeFSRootCatalogStartAddress) break; } if (localSearchFirst) { localSearchFirst = false; - startCatalogList = cCtartCatalogList; + start_catalog_lba = kStartCatalogList; goto NeFSSearchThroughCatalogList; } diff --git a/dev/Kernel/src/KernelMain.cc b/dev/Kernel/src/KernelMain.cc index 6907deea..8895814d 100644 --- a/dev/Kernel/src/KernelMain.cc +++ b/dev/Kernel/src/KernelMain.cc @@ -25,32 +25,37 @@ #include <Modules/FB/KWindow.h> #include <KernelKit/Timer.h> +#define kKeCachedName "/System/CacheKernel" + STATIC CG::ML_WINDOW_STRUCT* kKernelWnd = nullptr; namespace Kernel::Detail { /// @brief Filesystem auto formatter, additional checks are also done by the class. - class FilesystemInstaller final + class NeFilesystemInstaller final { - Kernel::NeFileSystemMgr* fNeFS{nullptr}; + Kernel::NeFileSystemMgr* mNeFS{nullptr}; + Kernel::NeFileSystemJournal mJournal; public: /// @brief wizard constructor. - FilesystemInstaller() + explicit NeFilesystemInstaller() { - fNeFS = (Kernel::NeFileSystemMgr*)Kernel::IFilesystemMgr::GetMounted(); + mNeFS = new Kernel::NeFileSystemMgr(); - if (fNeFS && fNeFS->GetParser()) + if (mNeFS) { + mJournal.CreateJournal(mNeFS->GetParser()); + constexpr auto kFolderInfo = "META-XML"; - const auto kFolderCount = 7; - const char* kFolderStr[kFolderCount] = { + const SizeT kFolderCount = 7; + const Char* kFolderStr[kFolderCount] = { "/Boot/", "/System/", "/Support/", "/Applications/", "/Users/", "/Library/", "/Mount/"}; for (Kernel::SizeT dir_index = 0UL; dir_index < kFolderCount; ++dir_index) { - auto catalog_folder = fNeFS->GetParser()->GetCatalog(kFolderStr[dir_index]); + auto catalog_folder = mNeFS->GetParser()->GetCatalog(kFolderStr[dir_index]); if (catalog_folder) { @@ -60,7 +65,7 @@ namespace Kernel::Detail continue; } - catalog_folder = fNeFS->GetParser()->CreateCatalog(kFolderStr[dir_index], 0, + catalog_folder = mNeFS->GetParser()->CreateCatalog(kFolderStr[dir_index], 0, kNeFSCatalogKindDir); NFS_FORK_STRUCT fork_folder{0}; @@ -87,11 +92,16 @@ namespace Kernel::Detail folder_metadata += kFolderStr[dir_index]; folder_metadata += "</p>\r"; + Kernel::KString folder_name(2048); + folder_name += catalog_folder->Name; + + mJournal.Commit(mNeFS->GetParser(), folder_metadata,folder_name); + const Kernel::SizeT kMetaDataSz = kNeFSSectorSz; - fNeFS->GetParser()->CreateFork(catalog_folder, fork_folder); + mNeFS->GetParser()->CreateFork(catalog_folder, fork_folder); - fNeFS->GetParser()->WriteCatalog( + mNeFS->GetParser()->WriteCatalog( catalog_folder, true, (Kernel::VoidPtr)(folder_metadata.CData()), kMetaDataSz, kFolderInfo); @@ -99,17 +109,26 @@ namespace Kernel::Detail catalog_folder = nullptr; } } + + while (1); } - ~FilesystemInstaller() = default; + ~NeFilesystemInstaller() + { + if (mNeFS) + delete mNeFS; + + mNeFS = nullptr; + } - ZKA_COPY_DEFAULT(FilesystemInstaller); + ZKA_COPY_DEFAULT(NeFilesystemInstaller); /// @brief Grab the disk's NewFS reference. /// @return NeFileSystemMgr the filesystem interface - Kernel::NeFileSystemMgr* Leak() + Kernel::NeFileSystemMgr* Leak() noexcept { - return fNeFS; + MUST_PASS(mNeFS); + return mNeFS; } }; } // namespace Kernel::Detail @@ -119,8 +138,7 @@ namespace Kernel::Detail /// @return Void EXTERN_C Kernel::Void rtl_kernel_main(Kernel::SizeT argc, char** argv, char** envp, Kernel::SizeT envp_len) { - Kernel::IFilesystemMgr::Mount(new Kernel::NeFileSystemMgr()); - Kernel::Detail::FilesystemInstaller installer; - + Kernel::Detail::fs_init_newfs(); + Kernel::Detail::NeFilesystemInstaller installer{}; } diff --git a/dev/Kernel/src/NeFS+FileMgr.cc b/dev/Kernel/src/NeFS+FileMgr.cc index c57785dc..d47a900a 100644 --- a/dev/Kernel/src/NeFS+FileMgr.cc +++ b/dev/Kernel/src/NeFS+FileMgr.cc @@ -18,22 +18,18 @@ namespace Kernel /// @brief C++ constructor NeFileSystemMgr::NeFileSystemMgr() { - MUST_PASS(Detail::fs_init_newfs()); - - NeFileSystemParser* fImpl; - mm_new_class<NeFileSystemParser>(&fImpl); - MUST_PASS(fImpl); + NeFileSystemParser* mParser = new NeFileSystemParser(); + MUST_PASS(mParser); kcout << "We are done allocating NeFileSystemParser...\r"; } NeFileSystemMgr::~NeFileSystemMgr() { - if (fImpl) + if (mParser) { kcout << "Destroying NeFileSystemParser...\r"; - - mm_delete_class(&fImpl); + mm_delete_class(&mParser); } } @@ -45,7 +41,7 @@ namespace Kernel if (path == nullptr || *path == 0) return false; - return fImpl->RemoveCatalog(path); + return mParser->RemoveCatalog(path); } /// @brief Creates a node with the specified. @@ -53,7 +49,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NeFileSystemMgr::Create(_Input const Char* path) { - return node_cast(fImpl->CreateCatalog(path)); + return node_cast(mParser->CreateCatalog(path)); } /// @brief Creates a node with is a directory. @@ -61,7 +57,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir)); + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } /// @brief Creates a node with is a alias. @@ -69,7 +65,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateAlias(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } /// @brief Creates a node with is a page file. @@ -77,7 +73,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage)); + return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. @@ -120,7 +116,7 @@ namespace Kernel if (!r || *r == 0) return nullptr; - auto catalog = fImpl->GetCatalog(path); + auto catalog = mParser->GetCatalog(path); return node_cast(catalog); } @@ -173,7 +169,7 @@ namespace Kernel ZKA_UNUSED(flags); if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) - fImpl->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & kFileFlagRsrc ? true : false), data, size, + mParser->WriteCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & kFileFlagRsrc ? true : false), data, size, name); } @@ -191,7 +187,7 @@ namespace Kernel ZKA_UNUSED(flags); if ((reinterpret_cast<NFS_CATALOG_STRUCT*>(node))->Kind == kNeFSCatalogKindFile) - return fImpl->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & kFileFlagRsrc ? true : false), sz, + return mParser->ReadCatalog(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), (flags & kFileFlagRsrc ? true : false), sz, name); return nullptr; @@ -208,7 +204,7 @@ namespace Kernel if (!node || off == 0) return false; - return fImpl->Seek(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), off); + return mParser->Seek(reinterpret_cast<NFS_CATALOG_STRUCT*>(node), off); } /// @brief Tell where the catalog is. @@ -221,7 +217,7 @@ namespace Kernel if (!node) return kNPos; - return fImpl->Tell(reinterpret_cast<NFS_CATALOG_STRUCT*>(node)); + return mParser->Tell(reinterpret_cast<NFS_CATALOG_STRUCT*>(node)); } /// @brief Rewinds the catalog. @@ -241,7 +237,7 @@ namespace Kernel /// @return the Filesystem parser class. _Output NeFileSystemParser* NeFileSystemMgr::GetParser() noexcept { - return fImpl; + return mParser; } } // namespace Kernel diff --git a/dev/Kernel/src/UserProcessScheduler.cc b/dev/Kernel/src/UserProcessScheduler.cc index 637eb151..d6e27bd6 100644 --- a/dev/Kernel/src/UserProcessScheduler.cc +++ b/dev/Kernel/src/UserProcessScheduler.cc @@ -9,7 +9,7 @@ /***********************************************************************************/ /// @file UserProcessScheduler.cc -/// @brief EL0/Ring-3 process scheduler. +/// @brief Low level/Ring-3 process scheduler. /***********************************************************************************/ #include <KernelKit/UserProcessScheduler.h> |
