From 7d1c053177ff178d86a17f3b19f92cf308bd0d2e Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 2 May 2025 16:11:51 +0200 Subject: kernel, FS: Mostly patches regarding NeFS's formating and disk write implementation. Signed-off-by: Amlal --- dev/kernel/FSKit/HeFS.h | 17 +++++------ dev/kernel/HALKit/AMD64/HalKernelMain.cc | 4 +-- dev/kernel/src/FS/HeFS.cc | 4 +-- dev/kernel/src/FS/NeFS.cc | 51 ++++++++++++++++++++++++-------- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 50b8e259..8723cd86 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -358,21 +358,20 @@ class HeFileSystemParser final { /// @return If it was sucessful, see err_local_get(). _Output Bool Format(_Input _Output DriveTrait* drive, _Input const Int32 flags, const Utf8Char* part_name); - + _Output Bool CreateDirectory(_Input DriveTrait* drive, _Input const Int32 flags, - const Utf8Char* dir, const Utf8Char* parent_dir); + const Utf8Char* dir, const Utf8Char* parent_dir); - _Output Bool RemoveDirectory(_Input DriveTrait* drive, _Input const Int32 flags, - const Utf8Char* dir, const Utf8Char* parent_dir); + const Utf8Char* dir, const Utf8Char* parent_dir); - _Output Bool CreateFile(_Input DriveTrait* drive, _Input const Int32 flags, const Utf8Char* dir, const Utf8Char* namespase, - const Utf8Char* name); + _Output Bool CreateFile(_Input DriveTrait* drive, _Input const Int32 flags, const Utf8Char* dir, + const Utf8Char* namespase, const Utf8Char* name); private: - - _Output Bool DirectoryCtl_(_Input DriveTrait* drive, _Input const Int32 flags, - const Utf8Char* dir, const Utf8Char* parent, const BOOL delete_or_create); + _Output Bool DirectoryCtl_(_Input DriveTrait* drive, _Input const Int32 flags, + const Utf8Char* dir, const Utf8Char* parent, + const BOOL delete_or_create); UInt32 mDriveIndex{MountpointInterface::kDriveIndexA}; /// @brief The drive index which this /// filesystem is mounted on. diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 5de1b8e4..f41979bb 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -135,7 +135,7 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { STATIC Kernel::Array kTeams; - SizeT team_index = 0U; + static SizeT team_index = 0U; /// @brief This just loops over the teams and switches between them. /// @details Not even round-robin, just a simple loop in this boot core we're at. @@ -153,4 +153,4 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { ++team_index; } } -#endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ \ No newline at end of file +#endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index d2cb403e..2ae41331 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -397,7 +397,7 @@ namespace Detail { hefsi_traverse_tree(tmpend, mnt, root->fStartIND, child_first, YES); } } - + dirent->fNext = tmpdir->fNext; dirent->fPrev = tmpdir->fPrev; dirent->fParent = tmpdir->fParent; @@ -915,7 +915,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input drive->fOutput(drive->fPacket); (Void)(kout << "Drive kind: " << drive->fProtocol() << kendl); - (Void)(kout8 << u8"Partition name: " << root->fVolName << kendl8); + (Void)(kout8 << u8"Volume name: " << root->fVolName << kendl8); (Void)(kout << "Start IND: " << hex_number(root->fStartIND) << kendl); (Void)(kout << "Number of IND: " << hex_number(root->fINDCount) << kendl); (Void)(kout << "Sector size: " << hex_number(root->fSectorSize) << kendl); diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc index e61a7c8a..4d9a2be1 100644 --- a/dev/kernel/src/FS/NeFS.cc +++ b/dev/kernel/src/FS/NeFS.cc @@ -462,10 +462,10 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I part_block->StartCatalog = start + sizeof(NEFS_CATALOG_STRUCT); part_block->Flags = 0UL; part_block->CatalogCount = sectorCount / sizeof(NEFS_CATALOG_STRUCT); - part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT) - 1; part_block->SectorCount = sectorCount; part_block->DiskSize = diskSize; - part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT); + part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT) - 1; drive->fPacket.fPacketContent = fs_buf; drive->fPacket.fPacketSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); @@ -474,16 +474,32 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I drive->fOutput(drive->fPacket); (Void)(kout << "Drive kind: " << drive->fProtocol() << kendl); - (Void)(kout << "Partition name: " << part_block->PartitionName << kendl); - (Void)(kout << "Start: " << hex_number(part_block->StartCatalog) << kendl); + (Void)(kout << "Start catalog: " << hex_number(part_block->StartCatalog) << kendl); (Void)(kout << "Number of catalogs: " << hex_number(part_block->CatalogCount) << kendl); (Void)(kout << "Free catalog: " << hex_number(part_block->FreeCatalog) << kendl); (Void)(kout << "Free sectors: " << hex_number(part_block->FreeSectors) << kendl); (Void)(kout << "Sector size: " << hex_number(part_block->SectorSize) << kendl); - // write the root catalog. - this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); + NEFS_CATALOG_STRUCT root{}; + + rt_set_memory(&root, 0, sizeof(NEFS_CATALOG_STRUCT)); + + root.PrevSibling = part_block->StartCatalog; + root.NextSibling = 0UL; + + root.Kind = kNeFSCatalogKindDir; + root.Flags |= kNeFSFlagCreated; + root.CatalogFlags |= kNeFSStatusUnlocked; + + root.Name[0] = '/'; + root.Name[1] = 0; + + drive->fPacket.fPacketLba = part_block->StartCatalog; + drive->fPacket.fPacketSize = sizeof(NEFS_CATALOG_STRUCT); + drive->fPacket.fPacketContent = &root; + + drive->fOutput(drive->fPacket); return true; } @@ -546,16 +562,27 @@ bool NeFileSystemParser::WriteCatalog(_Input const Char* catalog_name, Bool is_r KStringBuilder::Equals(fork_data_input->CatalogName, catalog_name) && fork_data_input->DataSize == size_of_data) { // ===================================================== // - // Store the blob now. + // Store the blob now, into chunks. // ===================================================== // - drive.fPacket.fPacketContent = buf; - drive.fPacket.fPacketSize = size_of_data; - drive.fPacket.fPacketLba = fork_data_input->DataOffset; + auto cnt = size_of_data / kNeFSSectorSz; + auto cnter = 0UL; + auto compute_sz = kNeFSSectorSz; - (Void)(kout << "data offset: " << hex_number(fork_data_input->DataOffset) << kendl); + if (cnt < 1) break; - drive.fOutput(drive.fPacket); + while (compute_sz) { + drive.fPacket.fPacketContent = buf + (cnter * kNeFSSectorSz); + drive.fPacket.fPacketSize = compute_sz; + drive.fPacket.fPacketLba = fork_data_input->DataOffset; + + (Void)(kout << "data offset: " << hex_number(cnt * kNeFSSectorSz) << kendl); + + drive.fOutput(drive.fPacket); + + compute_sz /= (size_of_data / cnt); + ++cnter; + } (Void)(kout << "wrote data at offset: " << hex_number(fork_data_input->DataOffset) << kendl); -- cgit v1.2.3