diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-05-12 13:44:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-12 13:44:45 +0200 |
| commit | d608230b1350b064ceb01e6572519b108f6139b0 (patch) | |
| tree | 438052f9e51890099d1d20f10b7e3b5ffa7bf1a6 /dev/kernel/src | |
| parent | 57d040e3e6b6d0257c0ba5a914396520b18d9d87 (diff) | |
| parent | ab617428ecd00ec15960ba92e12a1a2252f28e45 (diff) | |
Merge pull request #31 from nekernel-org/dev
0.0.2e2 - Amend
Diffstat (limited to 'dev/kernel/src')
| -rw-r--r-- | dev/kernel/src/FS/HeFS+FileSystemParser.cc | 74 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS+FileSystemParser.cc | 6 | ||||
| -rw-r--r-- | dev/kernel/src/IndexableProperty.cc | 16 |
3 files changed, 42 insertions, 54 deletions
diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index e91040b2..a285593e 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -470,6 +470,16 @@ namespace Detail { (HEFS_INDEX_NODE_DIRECTORY*) mm_new_heap(sizeof(HEFS_INDEX_NODE_DIRECTORY), Yes, No); while (YES) { + if (err_global_get() == kErrorDiskIsCorrupted) { + delete dir; + dir = nullptr; + + delete node; + node = nullptr; + + return nullptr; + } + mnt->fPacket.fPacketLba = start; mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); mnt->fPacket.fPacketContent = dir; @@ -479,6 +489,8 @@ namespace Detail { (Void)(kout << hex_number(hefsi_hash_64(dir_name)) << kendl); (Void)(kout << hex_number(dir->fHashPath) << kendl); + if (dir->fHashPath == 0) break; + if (hefsi_hash_64(dir_name) == dir->fHashPath) { for (SizeT inode_index = 0UL; inode_index < kHeFSSliceCount; ++inode_index) { mnt->fPacket.fPacketLba = dir->fINSlices[inode_index]; @@ -491,12 +503,16 @@ namespace Detail { (Void)(kout << hex_number(node->fHashPath) << kendl); if (hefsi_hash_64(file_name) == node->fHashPath && node->fKind == kind) { + delete dir; + dir = nullptr; + return node; } } } hefsi_traverse_tree(dir, mnt, root->fStartIND, start); + if (start == root->fStartIND || start == root->fStartIND) break; } delete node; @@ -522,6 +538,8 @@ namespace Detail { if (start > root->fEndIND) return NO; if (root->fStartIN > root->fEndIN) return NO; + ; + if (root->fStartBlock > root->fEndBlock) return NO; if (mnt) { HEFS_INDEX_NODE_DIRECTORY* dir = @@ -740,8 +758,8 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c } if (drv_std_get_size() < kHeFSMinimumDiskSize) { - err_global_get() = kErrorDiskIsTooTiny; - kout << "Error: Failed to allocate memory for boot node->\r"; + kout << "HeFS requires at least 128 GiB." << kendl; + err_global_get() = kErrorDisk; return NO; } @@ -798,10 +816,10 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c MUST_PASS(root->fSectorSize); /// @note all HeFS strucutres are equal to 512, so here it's fine, unless fSectoSize is 2048. - const SizeT max_lba = drv_std_get_size() / root->fSectorSize; + const SizeT max_lba = (drv_std_get_size()) / root->fSectorSize; - const SizeT dir_max = max_lba / 20; // 20% for directory inodes - const SizeT inode_max = max_lba / 30; // 30% for inodes + const SizeT dir_max = max_lba / 300; // 5% for directory inodes + const SizeT inode_max = max_lba / 400; // 5% for inodes root->fStartIND = mnt->fLbaStart + kHeFSINDStartOffset; root->fEndIND = root->fStartIND + dir_max; @@ -994,14 +1012,23 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc (Void)(kout << hex_number(start->fHashPath) << kendl); (Void)(kout << hex_number(start->fOffsetSliceLow) << kendl); - if (start->fOffsetSliceLow) { - mnt->fPacket.fPacketLba = start->fOffsetSliceLow | (UInt64) start->fOffsetSliceHigh << 32; - mnt->fPacket.fPacketSize = block_sz; + if (start->fOffsetSliceLow && start->fHashPath) { + mnt->fPacket.fPacketLba = ((UInt64) start->fOffsetSliceHigh << 32) | start->fOffsetSliceLow; + mnt->fPacket.fPacketSize = block_sz; mnt->fPacket.fPacketContent = block; if (is_input) { mnt->fInput(mnt->fPacket); } else { + if (start->fFlags & kHeFSFlagsReadOnly) { + mm_delete_heap((VoidPtr) root); + delete start; + + kout << "Error: File is read-only\r"; + + return NO; + } + mnt->fOutput(mnt->fPacket); } } @@ -1127,37 +1154,6 @@ Boolean fs_init_hefs(Void) { parser.Format(&kMountPoint, kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName); - MUST_PASS(parser.CreateINode(&kMountPoint, kHeFSEncodingFlagsBinary | kHeFSFlagsReadOnly, - u8"/boot", u8"bootinfo.cfg", kHeFSFileKindRegular)); - - Utf8Char contents_1[kHeFSBlockLen] = {0}; - - urt_set_memory(contents_1, 0, kHeFSBlockLen); - - MUST_PASS(parser.INodeManip(&kMountPoint, contents_1, kHeFSBlockLen, u8"/boot", u8"bootinfo.cfg", - kHeFSFileKindRegular, YES)); - - if (*contents_1 != u'\0') { - (Void)(kout << "/boot/bootinfo.cfg:" << kendl); - (Void)(kout8 << contents_1 << kendl8); - } else { - auto src = - u8"[boot]\r" - u8"path=bootz.efi\r" - u8"name=BootZ\r" - u8"[kernel]\r" - u8"path=krnl.efi\r" - u8"name=NeKernel\r" - u8"[chk]\r" - u8"path=chk.efi\r" - u8"name=SysChk\r"; - - urt_copy_memory((VoidPtr) src, contents_1, urt_string_len(src)); - - MUST_PASS(parser.INodeManip(&kMountPoint, contents_1, kHeFSBlockLen, u8"/boot", - u8"bootinfo.cfg", kHeFSFileKindRegular, NO)); - } - return YES; } } // namespace Kernel::HeFS diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc index 683adc7a..0b818bbb 100644 --- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc @@ -150,8 +150,8 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) { /// @return the newly found fork. /***********************************************************************************/ _Output NEFS_FORK_STRUCT* NeFileSystemParser::FindFork(_Input NEFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - _Input Boolean is_data) { + _Input const Char* name, + _Input Boolean is_data) { auto& drive = kMountpoint.A(); NEFS_FORK_STRUCT* the_fork = nullptr; @@ -209,7 +209,7 @@ _Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char /// @param kind the catalog kind. /// @return catalog pointer. /***********************************************************************************/ -_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, +_Output NEFS_CATALOG_STRUCT* NeFileSystemParser::CreateCatalog(_Input const Char* name, _Input const Int32& flags, _Input const Int32& kind) { kout << "CreateCatalog(*...*)\r"; diff --git a/dev/kernel/src/IndexableProperty.cc b/dev/kernel/src/IndexableProperty.cc index 8dd216c8..a89ea92d 100644 --- a/dev/kernel/src/IndexableProperty.cc +++ b/dev/kernel/src/IndexableProperty.cc @@ -16,21 +16,13 @@ namespace Kernel { namespace Indexer { - Index& IndexableProperty::Leak() noexcept { - return fIndex; - } + Index& IndexableProperty::Leak() noexcept { return fIndex; } - Void IndexableProperty::AddFlag(Int16 flag) { - fFlags |= flag; - } + Void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; } - Void IndexableProperty::RemoveFlag(Int16 flag) { - fFlags &= flag; - } + Void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; } - Int16 IndexableProperty::HasFlag(Int16 flag) { - return fFlags & flag; - } + Int16 IndexableProperty::HasFlag(Int16 flag) { return fFlags & flag; } /// @brief Index a file into the indexer instance. /// @param filename filesystem path to access. |
