diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-01-11 17:15:04 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-01-11 17:15:04 +0100 |
| commit | e5c86cd3463113096bab5b8170d224031ca4ad22 (patch) | |
| tree | 35a1082462623b2f6f8346e0364d1c81f7a3f341 /dev | |
| parent | bb790af9762e48812962c6d328fe90bb4ec91432 (diff) | |
ADD: Filesystem Tweaks.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Kernel/FSKit/NeFS.h | 19 | ||||
| -rw-r--r-- | dev/Kernel/src/BitMapMgr.cc | 5 | ||||
| -rw-r--r-- | dev/Kernel/src/FS/NeFS.cc | 135 | ||||
| -rw-r--r-- | dev/Kernel/src/KernelMain.cc | 3 |
4 files changed, 72 insertions, 90 deletions
diff --git a/dev/Kernel/FSKit/NeFS.h b/dev/Kernel/FSKit/NeFS.h index ba0b0afa..c3c9d549 100644 --- a/dev/Kernel/FSKit/NeFS.h +++ b/dev/Kernel/FSKit/NeFS.h @@ -33,7 +33,7 @@ default. #define kNeFSMinimumDiskSize (gib_cast(4)) -#define kNeFSSectorSz (512) +#define kNeFSSectorSz (512) #define kNeFSIdentLen (8) #define kNeFSIdent " NeFS" @@ -75,7 +75,7 @@ default. #define kNeFSCatalogKindTTF (13) #define kNeFSCatalogKindRIFF (14) #define kNeFSCatalogKindMPEG (15) -#define kNeFSCatalogKindDVX (16) +#define kNeFSCatalogKindMOFF (16) #define kNeFSSeparator '/' #define kNeFSSeparatorAlt '/' @@ -177,7 +177,7 @@ 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] = {0}; + Kernel::Char ForkName[kNeFSForkNameLen] = {0}; Kernel::Char CatalogName[kNeFSNodeNameLen] = {0}; Kernel::Int32 Flags; @@ -185,7 +185,7 @@ struct PACKED NFS_FORK_STRUCT final Kernel::Int64 ResourceId; Kernel::Int32 ResourceKind; - Kernel::Int32 ResourckMMFlags; + Kernel::Int32 ResourceFlags; Kernel::Lba DataOffset; // 8 Where to look for this data? Kernel::SizeT DataSize; /// Data size according using sector count. @@ -197,7 +197,7 @@ struct PACKED NFS_FORK_STRUCT final /// @brief Partition block type struct PACKED NFS_ROOT_PARTITION_BLOCK final { - Kernel::Char Ident[kNeFSIdentLen] = {0}; + Kernel::Char Ident[kNeFSIdentLen] = {0}; Kernel::Char PartitionName[kPartLen] = {0}; Kernel::Int32 Flags; @@ -264,7 +264,7 @@ namespace Kernel /// @param theFork the fork itself. /// @return the fork _Output BOOL CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& theFork); + _Input NFS_FORK_STRUCT& theFork); /// @brief Find fork inside New filesystem. /// @param catalog the catalog. @@ -407,8 +407,11 @@ namespace Kernel rt_copy_memory(mNode->Name, new_fork.CatalogName, rt_string_len(mNode->Name)); rt_copy_memory(journal_name, new_fork.ForkName, rt_string_len(journal_name)); - new_fork.DataSize = rt_string_len(xml_data); - new_fork.Kind = kNeFSRsrcForkKind; + new_fork.ResourceKind = kNeFSCatalogKindMetaFile; + new_fork.ResourceId = 0; + new_fork.ResourceFlags = 0; + new_fork.DataSize = rt_string_len(xml_data); + new_fork.Kind = kNeFSRsrcForkKind; parser->CreateFork(mNode, new_fork); diff --git a/dev/Kernel/src/BitMapMgr.cc b/dev/Kernel/src/BitMapMgr.cc index 63666f3e..72e27cbb 100644 --- a/dev/Kernel/src/BitMapMgr.cc +++ b/dev/Kernel/src/BitMapMgr.cc @@ -93,8 +93,7 @@ namespace Kernel UIntPtr* ptr_bit_set = reinterpret_cast<UIntPtr*>(base); if (ptr_bit_set[kBitMapMagIdx] == kBitMapMagic && - ptr_bit_set[kBitMapSizeIdx] <= size && - !ptr_bit_set[kBitMapUsedIdx]) + ptr_bit_set[kBitMapSizeIdx] <= size) { if (ptr_bit_set[kBitMapUsedIdx] == No) { @@ -108,6 +107,8 @@ namespace Kernel return (VoidPtr)ptr_bit_set; } + + kcout << "Missed potnetial bitmp!\r\n"; } else if (ptr_bit_set[kBitMapMagIdx] != kBitMapMagic) { diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc index ac1322f5..fc1afdd2 100644 --- a/dev/Kernel/src/FS/NeFS.cc +++ b/dev/Kernel/src/FS/NeFS.cc @@ -70,14 +70,24 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, auto drv = kDiskMountpoint.A(); - NFS_FORK_STRUCT cur_fork{}; + NFS_FORK_STRUCT cur_fork; Lba lba_prev_fork = lba; Lba lba_next_fork = lba; + if (the_fork.Kind == kNeFSDataForkKind) + catalog->DataForkSize += the_fork.DataSize; + else + catalog->ResourceForkSize += the_fork.DataSize; + + drv.fPacket.fPacketLba = catalog->NextSibling - sizeof(NFS_CATALOG_STRUCT); + drv.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); + drv.fPacket.fPacketContent = catalog; + + drv.fOutput(&drv.fPacket); + /// do not check for anything. Loop until we get what we want, that is a free fork zone. while (lba_next_fork >= kNeFSCatalogStartAddress) { - drv.fPacket.fPacketDrive = &drv; drv.fPacket.fPacketLba = lba_next_fork; drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); drv.fPacket.fPacketContent = &cur_fork; @@ -86,8 +96,6 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, 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, the_fork.CatalogName)) @@ -95,32 +103,31 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, kcout << "Fork already exists.\r"; return NO; } - } - - lba_next_fork = cur_fork.NextSibling; - } - while (1) - ; + lba_next_fork = cur_fork.NextSibling; + } + else + { + the_fork.Flags |= kNeFSFlagCreated; + the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT); + the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize; + the_fork.PreviousSibling = lba_prev_fork; - the_fork.Flags |= kNeFSFlagCreated; - the_fork.DataOffset = lba - sizeof(NFS_FORK_STRUCT); - the_fork.NextSibling = the_fork.DataOffset - the_fork.DataSize; - the_fork.PreviousSibling = lba_prev_fork; + drv.fPacket.fPacketLba = lba; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &the_fork; - drv.fPacket.fPacketLba = lba; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &the_fork; + drv.fOutput(&drv.fPacket); - drv.fOutput(&drv.fPacket); + /// log what we have now. + kcout << "Wrote fork data at: " << hex_number(the_fork.DataOffset) + << endl; - /// log what we have now. - kcout << "Wrote fork data at: " << hex_number(the_fork.DataOffset) - << endl; + kcout << "Wrote fork at: " << hex_number(lba) << endl; - kcout << "Wrote fork at: " << hex_number(lba) << endl; - - return YES; + return YES; + } + } } return NO; @@ -226,7 +233,10 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* kcout << "Catalog already exists: " << name << ".\r"; err_global_get() = kErrorFileExists; - return catalog_copy; + delete catalog_copy; + catalog_copy = nullptr; + + return nullptr; } Char parent_name[kNeFSNodeNameLen] = {0}; @@ -276,15 +286,18 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* return nullptr; } - constexpr SizeT kDefaultForkSize = kNeFSForkSize; + constexpr SizeT kDefaultForkSize = 0UL; + + if (!out_lba) + out_lba = kNeFSCatalogStartAddress; NFS_CATALOG_STRUCT* child_catalog = new NFS_CATALOG_STRUCT(); child_catalog->ResourceForkSize = kDefaultForkSize; child_catalog->DataForkSize = kDefaultForkSize; child_catalog->CatalogFlags = kNeFSStatusUnlocked; - child_catalog->NextSibling = out_lba; - child_catalog->PrevSibling = out_lba; + child_catalog->NextSibling = out_lba + sizeof(NFS_CATALOG_STRUCT); + child_catalog->PrevSibling = out_lba - sizeof(NFS_CATALOG_STRUCT); child_catalog->Kind = kind; child_catalog->Flags |= kNeFSFlagCreated; child_catalog->CatalogFlags = flags; @@ -305,65 +318,34 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* drive.fInput(&drive.fPacket); - start_free = temporary_catalog.NextSibling; - - if (start_free <= kNeFSRootCatalogStartAddress) - start_free = kNeFSCatalogStartAddress + sizeof(NFS_CATALOG_STRUCT); + Char buf_part_block[kNeFSSectorSz] = {0}; - child_catalog->PrevSibling = out_lba; + drive.fPacket.fPacketContent = buf_part_block; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - drive.fPacket.fPacketLba = start_free; drive.fInput(&drive.fPacket); - while (drive.fPacket.fPacketGood) - { - if (start_free <= kNeFSRootCatalogStartAddress) - { - delete child_catalog; - delete catalog; + NFS_ROOT_PARTITION_BLOCK* part_block = (NFS_ROOT_PARTITION_BLOCK*)buf_part_block; - catalog = nullptr; - child_catalog = nullptr; + if (part_block->FreeCatalog < 1) + { + delete child_catalog; + child_catalog = nullptr; - return nullptr; - } + return nullptr; + } + while (start_free >= kNeFSCatalogStartAddress) + { // ========================== // // Allocate catalog now... // ========================== // if ((temporary_catalog.Flags & kNeFSFlagCreated) == 0) { - Char buf_part_block[kNeFSSectorSz] = {0}; - - drive.fPacket.fPacketContent = buf_part_block; - drive.fPacket.fPacketSize = kNeFSSectorSz; - drive.fPacket.fPacketLba = kNeFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - constexpr auto kNeFSCatalogPadding = 4; - - NFS_ROOT_PARTITION_BLOCK* part_block = (NFS_ROOT_PARTITION_BLOCK*)buf_part_block; - - if (part_block->FreeCatalog < 1) - { - delete child_catalog; - child_catalog = nullptr; - - return nullptr; - } - 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. // - // This is necessary, so that we don't have to get another lba to allocate. // - if (!StringBuilder::Equals(parent_name, temporary_catalog.Name)) - { - child_catalog->NextSibling = - start_free + (sizeof(NFS_CATALOG_STRUCT) * kNeFSCatalogPadding); - } - drive.fPacket.fPacketContent = child_catalog; drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); drive.fPacket.fPacketLba = start_free; @@ -400,15 +382,12 @@ _Output NFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* else if ((temporary_catalog.Flags & kNeFSFlagCreated) && StringBuilder::Equals(temporary_catalog.Name, name)) { - NFS_CATALOG_STRUCT* found_catalog = new NFS_CATALOG_STRUCT(); - rt_copy_memory(&temporary_catalog, found_catalog, sizeof(NFS_CATALOG_STRUCT)); + rt_copy_memory(&temporary_catalog, child_catalog, sizeof(NFS_CATALOG_STRUCT)); return child_catalog; } - constexpr auto kNeFSCatalogPadding = 4; - - start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * kNeFSCatalogPadding); + start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * 4); drive.fPacket.fPacketContent = &temporary_catalog; drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); @@ -925,8 +904,6 @@ VoidPtr NeFileSystemParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catal return nullptr; } - constexpr auto kNeFSCatalogPadding = 4; - Lba dataForkLba = (!is_rsrc_fork) ? catalog->DataFork : catalog->ResourceFork; Size dataForkSize = (!is_rsrc_fork) ? catalog->DataForkSize : catalog->ResourceForkSize; diff --git a/dev/Kernel/src/KernelMain.cc b/dev/Kernel/src/KernelMain.cc index 2fefb318..41f4af81 100644 --- a/dev/Kernel/src/KernelMain.cc +++ b/dev/Kernel/src/KernelMain.cc @@ -69,7 +69,8 @@ namespace Kernel::Detail catalog_folder = nullptr; } - mJournal.CreateJournal(mNeFS); + if (!mJournal.GetJournal(mNeFS)) + mJournal.CreateJournal(mNeFS); mJournal.CommitJournal(mNeFS, "<LOG_XML>Format Filesystem NeFS for ZkaOS.</LOG_XML>", "NeFS Format System"); mJournal.ReleaseJournal(); |
