diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-01-11 16:30:07 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-01-11 16:30:07 +0100 |
| commit | bb790af9762e48812962c6d328fe90bb4ec91432 (patch) | |
| tree | 9dd2562015da8a900826222f3691d1c3a8591dc3 /dev | |
| parent | 8360742fdf9f1964ae016e99a47ddaf2c770e908 (diff) | |
ADD: Better memory management, filesystem lookup and tweaks.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Kernel/FSKit/NeFS.h | 34 | ||||
| -rw-r--r-- | dev/Kernel/src/BitMapMgr.cc | 10 | ||||
| -rw-r--r-- | dev/Kernel/src/FS/NeFS.cc | 60 | ||||
| -rw-r--r-- | dev/Kernel/src/KernelMain.cc | 8 |
4 files changed, 49 insertions, 63 deletions
diff --git a/dev/Kernel/FSKit/NeFS.h b/dev/Kernel/FSKit/NeFS.h index 8afdfdc3..ba0b0afa 100644 --- a/dev/Kernel/FSKit/NeFS.h +++ b/dev/Kernel/FSKit/NeFS.h @@ -142,8 +142,8 @@ enum /// @brief Catalog type. struct PACKED NFS_CATALOG_STRUCT final { - Kernel::Char Name[kNeFSNodeNameLen]; - Kernel::Char Mime[kNeFSMimeNameLen]; + Kernel::Char Name[kNeFSNodeNameLen] = {0}; + Kernel::Char Mime[kNeFSMimeNameLen] = {0}; /// Catalog flags. Kernel::UInt16 Flags; @@ -177,8 +177,8 @@ struct PACKED NFS_CATALOG_STRUCT final /// whereas the data fork is reserved for file data. struct PACKED NFS_FORK_STRUCT final { - Kernel::Char ForkName[kNeFSForkNameLen]; - Kernel::Char CatalogName[kNeFSNodeNameLen]; + Kernel::Char ForkName[kNeFSForkNameLen] = {0}; + Kernel::Char CatalogName[kNeFSNodeNameLen] = {0}; Kernel::Int32 Flags; Kernel::Int32 Kind; @@ -197,8 +197,8 @@ struct PACKED NFS_FORK_STRUCT final /// @brief Partition block type struct PACKED NFS_ROOT_PARTITION_BLOCK final { - Kernel::Char Ident[kNeFSIdentLen]; - Kernel::Char PartitionName[kPartLen]; + Kernel::Char Ident[kNeFSIdentLen] = {0}; + Kernel::Char PartitionName[kPartLen] = {0}; Kernel::Int32 Flags; Kernel::Int32 Kind; @@ -263,7 +263,7 @@ namespace Kernel /// @param catalog it's catalog /// @param theFork the fork itself. /// @return the fork - _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Output BOOL CreateFork(_Input NFS_CATALOG_STRUCT* catalog, _Input NFS_FORK_STRUCT& theFork); /// @brief Find fork inside New filesystem. @@ -278,7 +278,7 @@ namespace Kernel _Output Void CloseFork(_Input NFS_FORK_STRUCT* fork); - _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba, Bool searchHidden = YES); + _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba, Bool searchHidden = YES, Bool local_search = NO); _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); @@ -371,9 +371,11 @@ namespace Kernel if (!parser) return NO; - if (mNode = parser->GetCatalog(mStamp); - mNode) + auto node = parser->GetCatalog(mStamp); + + if (node) { + mNode = node; return YES; } @@ -393,8 +395,8 @@ namespace Kernel } Bool CommitJournal(NeFileSystemParser* parser, - KString xml_data, - KString journal_name) + Char* xml_data, + Char* journal_name) { if (!parser || !mNode) @@ -403,16 +405,16 @@ namespace Kernel NFS_FORK_STRUCT new_fork{}; rt_copy_memory(mNode->Name, new_fork.CatalogName, rt_string_len(mNode->Name)); - rt_copy_memory(journal_name.Data(), new_fork.ForkName, rt_string_len(journal_name.Data())); + rt_copy_memory(journal_name, new_fork.ForkName, rt_string_len(journal_name)); - new_fork.DataSize = xml_data.Length(); + new_fork.DataSize = rt_string_len(xml_data); new_fork.Kind = kNeFSRsrcForkKind; parser->CreateFork(mNode, new_fork); - kcout << "Commit: " << xml_data.Data() << "\r\nTo: " << journal_name.Data() << endl; + kcout << "Commit: " << xml_data << "\r\nTo: " << journal_name << endl; - auto ret = parser->WriteCatalog(mNode, YES, xml_data.Data(), xml_data.Length(), journal_name.CData()); + auto ret = parser->WriteCatalog(mNode, YES, xml_data, rt_string_len(xml_data), new_fork.ForkName); return ret; } diff --git a/dev/Kernel/src/BitMapMgr.cc b/dev/Kernel/src/BitMapMgr.cc index aa32cb93..63666f3e 100644 --- a/dev/Kernel/src/BitMapMgr.cc +++ b/dev/Kernel/src/BitMapMgr.cc @@ -15,7 +15,8 @@ #include <NewKit/Defines.h> #include <NewKit/KernelPanic.h> -#define kBitMapMagic (0x10210U) +#define kBitMapMagic (0x10210U) +#define kBitMapPadSize (mib_cast(16)) #define kBitMapMagIdx (0U) #define kBitMapSizeIdx (1U) @@ -87,12 +88,13 @@ namespace Kernel VoidPtr base = reinterpret_cast<VoidPtr>(((UIntPtr)base_ptr) + kPageSize); - while (((UIntPtr)base) < (reinterpret_cast<UIntPtr>(base) + kHandoverHeader->f_BitMapSize)) + while (YES) { UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base); if (ptr_bit_set[kBitMapMagIdx] == kBitMapMagic && - ptr_bit_set[kBitMapSizeIdx] <= size) + ptr_bit_set[kBitMapSizeIdx] <= size && + !ptr_bit_set[kBitMapUsedIdx]) { if (ptr_bit_set[kBitMapUsedIdx] == No) { @@ -121,7 +123,7 @@ namespace Kernel return (VoidPtr)ptr_bit_set; } - base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base) + ((ptr_bit_set[kBitMapMagIdx] != kBitMapMagic) ? size : ptr_bit_set[kBitMapSizeIdx])); + base = reinterpret_cast<VoidPtr>(reinterpret_cast<UIntPtr>(base) + ((ptr_bit_set[kBitMapMagIdx] != kBitMapMagic) ? (size) : ptr_bit_set[kBitMapSizeIdx])); } return nullptr; diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc index ff5a5dc8..ac1322f5 100644 --- a/dev/Kernel/src/FS/NeFS.cc +++ b/dev/Kernel/src/FS/NeFS.cc @@ -60,58 +60,49 @@ STATIC MountpointInterface kDiskMountpoint; /// @param the_fork the fork itself. /// @return the fork /***********************************************************************************/ -_Output NFS_FORK_STRUCT* NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& the_fork) +_Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& the_fork) { - if (catalog && the_fork.ForkName[0] != 0 && - the_fork.DataSize > 0) + if (catalog && the_fork.DataSize > 0) { Lba lba = (the_fork.Kind == kNeFSDataForkKind) ? catalog->DataFork : catalog->ResourceFork; auto drv = kDiskMountpoint.A(); - /// special treatment. - rt_copy_memory((VoidPtr) "fs/nefs-packet", drv.fPacket.fPacketMime, - rt_string_len("fs/nefs-packet")); - - NFS_FORK_STRUCT cur_fork{0}; - NFS_FORK_STRUCT prev_fork{0}; + NFS_FORK_STRUCT cur_fork{}; Lba lba_prev_fork = lba; + Lba lba_next_fork = lba; /// do not check for anything. Loop until we get what we want, that is a free fork zone. - while (lba <= kNeFSCatalogStartAddress) + while (lba_next_fork >= kNeFSCatalogStartAddress) { - drv.fPacket.fPacketLba = lba; + drv.fPacket.fPacketDrive = &drv; + drv.fPacket.fPacketLba = lba_next_fork; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv.fPacket.fPacketContent = &cur_fork; drv.fInput(&drv.fPacket); - lba_prev_fork = lba; - prev_fork = cur_fork; - - if (cur_fork.PreviousSibling <= kNeFSCatalogStartAddress) - break; - - lba = cur_fork.PreviousSibling; - if (cur_fork.Flags & kNeFSFlagCreated) { + lba = cur_fork.NextSibling; + /// sanity check. if (StringBuilder::Equals(cur_fork.ForkName, the_fork.ForkName) && - StringBuilder::Equals(cur_fork.CatalogName, catalog->Name)) + StringBuilder::Equals(cur_fork.CatalogName, the_fork.CatalogName)) { kcout << "Fork already exists.\r"; - return nullptr; + return NO; } } - else - { - break; - } + + lba_next_fork = cur_fork.NextSibling; } + while (1) + ; + the_fork.Flags |= kNeFSFlagCreated; the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT); the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize; @@ -129,10 +120,10 @@ _Output NFS_FORK_STRUCT* NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUC kcout << "Wrote fork at: " << hex_number(lba) << endl; - return &the_fork; + return YES; } - return nullptr; + return NO; } /***********************************************************************************/ @@ -362,7 +353,7 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* return nullptr; } - child_catalog->DataFork = part_block->DiskSize - kNeFSRootCatalogStartAddress; + child_catalog->DataFork = part_block->DiskSize - start_free; child_catalog->ResourceFork = child_catalog->DataFork; // Write the new catalog next sibling, if we don't know this parent. // @@ -690,7 +681,8 @@ bool NeFileSystemParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog /// @return the newly found catalog. _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* catalog_name, Lba& out_lba, - Bool search_hidden) + Bool search_hidden, + Bool local_search) { if (!catalog_name || *catalog_name == 0) @@ -725,7 +717,7 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* c drive.fInput(&drive.fPacket); - if (!StringBuilder::Equals(catalog_name, NeFileSystemHelper::Root())) + if (!StringBuilder::Equals(catalog_name, NeFileSystemHelper::Root()) && !local_search) { Char parent_name[kNeFSNodeNameLen] = {0}; @@ -748,7 +740,7 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* c --index_reverse_copy; } - NFS_CATALOG_STRUCT* parent_catalog = this->FindCatalog(parent_name, out_lba); + NFS_CATALOG_STRUCT* parent_catalog = this->FindCatalog(parent_name, out_lba, YES); if (parent_catalog && !StringBuilder::Equals(parent_name, NeFileSystemHelper::Root())) @@ -765,10 +757,6 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::FindCatalog(_Input const Char* c delete parent_catalog; parent_catalog = nullptr; } - else - { - return nullptr; - } } kcout << "Finding catalog...\r"; diff --git a/dev/Kernel/src/KernelMain.cc b/dev/Kernel/src/KernelMain.cc index fea439ca..2fefb318 100644 --- a/dev/Kernel/src/KernelMain.cc +++ b/dev/Kernel/src/KernelMain.cc @@ -71,13 +71,7 @@ namespace Kernel::Detail mJournal.CreateJournal(mNeFS); - KString xml; - xml += "<LOG_XML>Format Filesystem NeFS for ZkaOS.</LOG_XML>"; - - KString name; - name += "NeFS Format System"; - - mJournal.CommitJournal(mNeFS, xml, name); + mJournal.CommitJournal(mNeFS, "<LOG_XML>Format Filesystem NeFS for ZkaOS.</LOG_XML>", "NeFS Format System"); mJournal.ReleaseJournal(); } } |
