From 432e68391357423914547a7b34311258d7598808 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 5 Sep 2024 14:42:03 +0200 Subject: [ FIX ] Fixing shortcomings of scheduler, filesystem and kernel. Signed-off-by: Amlal El Mahrouss --- dev/DLL/EncryptFS/EncryptFS.hxx | 2 +- dev/HPFS/.gitignore | 3 + dev/HPFS/hpfs.json | 11 + dev/HPFS/hpfs_main.rs | 10 + dev/ZBA/BootKit/BootKit.hxx | 77 +- dev/ZBA/Modules/SysChk/build.json | 2 +- dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 58 +- dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx | 8 +- dev/ZKA/Docs/SPECIFICATION.md | 2 +- dev/ZKA/FSKit/NeFS.hxx | 326 ++++++++ dev/ZKA/FSKit/NewFS.hxx | 326 -------- dev/ZKA/FirmwareKit/EPM.hxx | 2 +- dev/ZKA/FirmwareKit/Handover.hxx | 12 +- dev/ZKA/KernelKit/FileMgr.hxx | 12 +- dev/ZKA/NewKit/Macros.hxx | 9 + dev/ZKA/Sources/DLLMain.cxx | 130 +++- dev/ZKA/Sources/FS/NeFS.cxx | 1045 +++++++++++++++++++++++++ dev/ZKA/Sources/FS/NewFS.cxx | 1048 -------------------------- dev/ZKA/Sources/FileMgr.cxx | 14 +- dev/ZKA/Sources/NewFS+FileMgr.cxx | 18 +- dev/ZKA/Sources/NewFS+IO.cxx | 18 +- dev/ZKA/Sources/NewFS+Journal.cxx | 4 +- 22 files changed, 1590 insertions(+), 1547 deletions(-) create mode 100644 dev/HPFS/.gitignore create mode 100644 dev/HPFS/hpfs.json create mode 100644 dev/HPFS/hpfs_main.rs create mode 100644 dev/ZKA/FSKit/NeFS.hxx delete mode 100644 dev/ZKA/FSKit/NewFS.hxx create mode 100644 dev/ZKA/Sources/FS/NeFS.cxx delete mode 100644 dev/ZKA/Sources/FS/NewFS.cxx (limited to 'dev') diff --git a/dev/DLL/EncryptFS/EncryptFS.hxx b/dev/DLL/EncryptFS/EncryptFS.hxx index 4dfafe7c..368df9ae 100644 --- a/dev/DLL/EncryptFS/EncryptFS.hxx +++ b/dev/DLL/EncryptFS/EncryptFS.hxx @@ -13,7 +13,7 @@ #pragma once -#include +#include namespace EncryptFS { diff --git a/dev/HPFS/.gitignore b/dev/HPFS/.gitignore new file mode 100644 index 00000000..6f675898 --- /dev/null +++ b/dev/HPFS/.gitignore @@ -0,0 +1,3 @@ +*.sys +*.exe +*.dll \ No newline at end of file diff --git a/dev/HPFS/hpfs.json b/dev/HPFS/hpfs.json new file mode 100644 index 00000000..1098dfd3 --- /dev/null +++ b/dev/HPFS/hpfs.json @@ -0,0 +1,11 @@ +{ + "compiler_path": "rustc", + "compiler_std": "", + "sources_path": ["*.rs"], + "output_name": "hpfs.sys", + "compiler_flags": [ + ], + "cpp_macros": [ + ] + } + \ No newline at end of file diff --git a/dev/HPFS/hpfs_main.rs b/dev/HPFS/hpfs_main.rs new file mode 100644 index 00000000..ed66d175 --- /dev/null +++ b/dev/HPFS/hpfs_main.rs @@ -0,0 +1,10 @@ +/* + * Created on Thu Sep 05 2024 + * + * Copyright (c) 2024 ZKA Technologies. + */ + +fn main() { + println!("ZKA High Performance File System Driver for ZKA/OS."); + println!("Copyright ZKA technologies, all rights reserved."); +} \ No newline at end of file diff --git a/dev/ZBA/BootKit/BootKit.hxx b/dev/ZBA/BootKit/BootKit.hxx index 6ac87b82..3732ea8d 100644 --- a/dev/ZBA/BootKit/BootKit.hxx +++ b/dev/ZBA/BootKit/BootKit.hxx @@ -15,10 +15,10 @@ #include #include -/// include NewFS header and Support header as well. +/// include NeFS header and Support header as well. #include -#include +#include #include /***********************************************************************************/ @@ -193,7 +193,7 @@ public: /// @brief File entry for **BDiskFormatFactory**. struct BFileDescriptor final { - Char fFileName[kNewFSNodeNameLen]; + Char fFileName[kNeFSNodeNameLen]; Int32 fKind; }; @@ -219,7 +219,7 @@ public: /// @brief check if partition is good. Bool IsPartitionValid() noexcept { - fDiskDev.Leak().mBase = (kNewFSRootCatalogStartAddress); + fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress); fDiskDev.Leak().mSize = BootDev::kSectorSize; Char buf[BootDev::kSectorSize] = {0}; @@ -230,9 +230,9 @@ public: BTextWriter writer; - for (SizeT indexMag = 0UL; indexMag < kNewFSIdentLen; ++indexMag) + for (SizeT indexMag = 0UL; indexMag < kNeFSIdentLen; ++indexMag) { - if (blockPart->Ident[indexMag] != kNewFSIdent[indexMag]) + if (blockPart->Ident[indexMag] != kNeFSIdent[indexMag]) return false; } @@ -241,7 +241,7 @@ public: if (blockPart->DiskSize != this->fDiskDev.GetDiskSize() || blockPart->DiskSize < 1 || blockPart->SectorSize != BootDev::kSectorSize || - blockPart->Version != kNewFSVersionInteger || + blockPart->Version != kNeFSVersionInteger || blockPart->StartCatalog == 0) { return false; @@ -260,7 +260,7 @@ private: /// @brief Write all of the requested catalogs into the filesystem. /// @param fileBlobs the blobs. /// @param blobCount the number of blobs to write. - /// @param partBlock the NewFS partition block. + /// @param partBlock the NeFS partition block. Boolean WriteRootCatalog(BFileDescriptor* fileBlobs, SizeT blobCount, NFS_ROOT_PARTITION_BLOCK& partBlock) { BFileDescriptor* blob = fileBlobs; @@ -269,14 +269,14 @@ private: NFS_CATALOG_STRUCT catalogKind{0}; - constexpr auto cNewFSCatalogPadding = 4; + constexpr auto cNeFSCatalogPadding = 4; catalogKind.PrevSibling = startLba; - catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); + catalogKind.NextSibling = (startLba + sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); /// Fill catalog kind. catalogKind.Kind = blob->fKind; - catalogKind.Flags = kNewFSFlagCreated; + catalogKind.Flags = kNeFSFlagCreated; --partBlock.FreeCatalog; --partBlock.FreeSectors; @@ -316,7 +316,7 @@ inline Boolean BDiskFormatFactory::Format(const Char* partName, /// @note A catalog roughly equal to a sector. - constexpr auto cMinimumDiskSize = 10; // at minimum. + constexpr auto cMinimumDiskSize = 4; // at minimum. /// @note also look at EPM headers, for free part blocks. @@ -325,70 +325,37 @@ inline Boolean BDiskFormatFactory::Format(const Char* partName, EFI::ThrowError(L"Disk-Too-Tiny", L"Can't format a New Filesystem partition here."); return false; } - - fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sectorSz; - + NFS_ROOT_PARTITION_BLOCK partBlock{0}; - fDiskDev.Read((Char*)&partBlock, sizeof(NFS_ROOT_PARTITION_BLOCK)); - - if (strncmp(kNewFSIdent, partBlock.Ident, kNewFSIdentLen) == 0 && - partBlock.Version != kNewFSVersionInteger) - { - if (partBlock.Version != 0) - { - BTextWriter writer; - writer.Write(L"newosldr: Disk partition updated.\r"); - - partBlock.Version = kNewFSVersionInteger; - - fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sectorSz; - - fDiskDev.Write((Char*)&partBlock, sectorSz); - - return true; - } - } - else if (strncmp(kNewFSIdent, partBlock.Ident, kNewFSIdentLen)) - { - BTextWriter writer; - writer.Write(L"newosldr: Disk partition error, not a valid one.\r"); - - // TODO: Find a way to use EFI::Stop. - while (1) - ; - } - - CopyMem(partBlock.Ident, kNewFSIdent, kNewFSIdentLen - 1); + CopyMem(partBlock.Ident, kNeFSIdent, kNeFSIdentLen - 1); CopyMem(partBlock.PartitionName, partName, strlen(partName)); - partBlock.Version = kNewFSVersionInteger; + partBlock.Version = kNeFSVersionInteger; partBlock.CatalogCount = blobCount; - partBlock.Kind = kNewFSHardDrive; + partBlock.Kind = kNeFSHardDrive; partBlock.SectorSize = sectorSz; partBlock.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NFS_CATALOG_STRUCT); partBlock.SectorCount = fDiskDev.GetSectorsCount(); partBlock.FreeSectors = fDiskDev.GetSectorsCount(); - partBlock.StartCatalog = kNewFSCatalogStartAddress; + partBlock.StartCatalog = kNeFSCatalogStartAddress; partBlock.DiskSize = fDiskDev.GetDiskSize(); - partBlock.Flags = kNewFSPartitionTypeBoot | kNewFSPartitionTypeStandard; + partBlock.Flags = kNeFSPartitionTypeBoot | kNeFSPartitionTypeStandard; - fDiskDev.Leak().mBase = kNewFSRootCatalogStartAddress; + fDiskDev.Leak().mBase = kNeFSRootCatalogStartAddress; fDiskDev.Leak().mSize = sectorSz; fDiskDev.Write((Char*)&partBlock, sectorSz); BOOT_BLOCK_STRUCT epmBoot{0}; - constexpr auto cFsName = "NewFS"; + constexpr auto cFsName = "NeFS"; constexpr auto cBlockName = "ZKA:"; CopyMem(epmBoot.Fs, reinterpret_cast(const_cast(cFsName)), StrLen(cFsName)); - epmBoot.FsVersion = kNewFSVersionInteger; - epmBoot.LbaStart = kNewFSRootCatalogStartAddress; + epmBoot.FsVersion = kNeFSVersionInteger; + epmBoot.LbaStart = kNeFSRootCatalogStartAddress; epmBoot.SectorSz = partBlock.SectorSize; epmBoot.NumBlocks = partBlock.CatalogCount; diff --git a/dev/ZBA/Modules/SysChk/build.json b/dev/ZBA/Modules/SysChk/build.json index dac413e0..67e22955 100644 --- a/dev/ZBA/Modules/SysChk/build.json +++ b/dev/ZBA/Modules/SysChk/build.json @@ -11,7 +11,7 @@ "-fPIC", "-fno-rtti", "-fno-exceptions", - "-Wl,--subsystem=17,--image-base,0x1000000,-e,ModuleMain" + "-Wl,--subsystem=17,--image-base,0x10000000,-e,ModuleMain" ], "cpp_macros": [ "__NEWOSKRNL__", diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index 55f10ea2..9cccc922 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -154,6 +154,27 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, handoverHdrPtr->f_HardwareTables.f_MultiProcessingEnabled = cnt_enabled > 1; // Fill handover header now. + BDiskFormatFactory checkPart; + + // ---------------------------------------------------- // + // The following checks for an exisiting partition + // inside the disk, if it doesn't have one, + // format the disk. + // ---------------------------------------------------- // + + if (!checkPart.IsPartitionValid()) + { + BDiskFormatFactory::BFileDescriptor root; + root.fFileName[0] = kNeFSRoot[0]; + root.fFileName[1] = 0; + + root.fKind = kNeFSCatalogKindDir; + + checkPart.Format("ZKA (A:)", &root, 1); + + rt_reset_hardware(); + } + BS->GetMemoryMap(&SizePtr, Descriptor, &MapKey, &SzDesc, &RevDesc); Descriptor = new EfiMemoryDescriptor[SzDesc]; @@ -193,15 +214,9 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &handoverHdrPtr->f_BitMapStart) != kEfiOk) ; - auto extended_heap = (VoidPtr)((UIntPtr)handoverHdrPtr->f_BitMapStart + kHandoverHeapSz); - - while (BS->AllocatePool(EfiRuntimeServicesData, kHandoverHeapSz, &extended_heap) != kEfiOk) - ; - handoverHdrPtr->f_VirtualSize = Descriptor[cDefaultMemoryMap].NumberOfPages; /* # of pages */ - handoverHdrPtr->f_FirmwareCustomTables[0] = (VoidPtr)BS; handoverHdrPtr->f_FirmwareCustomTables[1] = (VoidPtr)ST; @@ -241,27 +256,6 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, // Assign to global 'kHandoverHeader'. - BDiskFormatFactory checkPart; - - // ---------------------------------------------------- // - // The following checks for an exisiting partition - // inside the disk, if it doesn't have one, - // format the disk. - // ---------------------------------------------------- // - - if (!checkPart.IsPartitionValid()) - { - BDiskFormatFactory::BFileDescriptor root; - root.fFileName[0] = kNewFSRoot[0]; - root.fFileName[1] = 0; - - root.fKind = kNewFSCatalogKindDir; - - checkPart.Format("ZKA (A:)", &root, 1); - - rt_reset_hardware(); - } - BFileReader readerKernel(L"newoskrnl.exe", ImageHandle); readerKernel.ReadAll(0); @@ -293,11 +287,17 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, urbanistTTF.ReadAll(0); if (readerSysDrv.Blob() && - chimeWav.Blob()) + chimeWav.Blob() && + urbanistTTF.Blob()) { handoverHdrPtr->f_StartupChime = chimeWav.Blob(); - handoverHdrPtr->f_StartupImage = readerKernel.Blob(); + handoverHdrPtr->f_ChimeSz = chimeWav.Size(); + handoverHdrPtr->f_StartupImage = readerSysDrv.Blob(); + handoverHdrPtr->f_StartupSz = readerSysDrv.Size(); + handoverHdrPtr->f_KernelImage = readerKernel.Blob(); + handoverHdrPtr->f_KernelSz = readerKernel.Size(); handoverHdrPtr->f_TTFallbackFont = urbanistTTF.Blob(); + handoverHdrPtr->f_FontSz = urbanistTTF.Size(); } else { diff --git a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx index 65ea3d89..467f4303 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootTextWriter.cxx @@ -25,7 +25,7 @@ */ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ if (!str || *str == 0) return *this; @@ -57,7 +57,7 @@ BTextWriter& BTextWriter::Write(const CharacterTypeUTF16* str) /// @param str the input string. BTextWriter& BTextWriter::Write(const Char* str) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ if (!str || *str == 0) return *this; @@ -87,7 +87,7 @@ BTextWriter& BTextWriter::Write(const Char* str) BTextWriter& BTextWriter::Write(const UChar* str) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ if (!str || *str == 0) return *this; @@ -120,7 +120,7 @@ BTextWriter& BTextWriter::Write(const UChar* str) */ BTextWriter& BTextWriter::WriteCharacter(CharacterTypeUTF16 c) { -#ifdef __DEBUG_OUTPUT__ +#ifdef __DEBUG__ EfiCharType str[2]; str[0] = c; diff --git a/dev/ZKA/Docs/SPECIFICATION.md b/dev/ZKA/Docs/SPECIFICATION.md index d39a95d3..c38fa122 100644 --- a/dev/ZKA/Docs/SPECIFICATION.md +++ b/dev/ZKA/Docs/SPECIFICATION.md @@ -19,7 +19,7 @@ - Separation of Files/Devices. - Networking. - Hardware Abstraction Layer. -- Native Filesystem support (NewFS, FAT32 and ffs2). +- Native Filesystem support (NeFS, FAT32 and ffs2). - Program Loaders interfaces. - TLS (Thread Local Storage) support. - Semaphore, Locks, Timers. diff --git a/dev/ZKA/FSKit/NeFS.hxx b/dev/ZKA/FSKit/NeFS.hxx new file mode 100644 index 00000000..d1c0c9c7 --- /dev/null +++ b/dev/ZKA/FSKit/NeFS.hxx @@ -0,0 +1,326 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + FILE: NeFS.hxx + PURPOSE: NeFS (New FileSystem) kernel support. + + Revision History: + + ?/?/?: Added file (amlel) + 12/02/24: Add UUID macro for EPM and GPT partition schemes. + 3/16/24: Add mandatory sector size, kNeFSSectorSz is set to 2048 by +default. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +/** + @brief New File System specification. + @author Amlal EL Mahrouss +*/ + +#define kNeFSInvalidFork (-1) +#define kNeFSInvalidCatalog (-1) +#define kNeFSNodeNameLen (256) + +#define kNeFSSectorSz (512) +#define kNeFSForkDataSz (gib_cast(16)) + +#define kNeFSIdentLen (8) +#define kNeFSIdent " NewFS" +#define kNeFSPadLen (400) + +#define kNeFSMetaFilePrefix '$' + +#define kNeFSVersionInteger (0x0128) +#define kNeFSVerionString "1.28" + +/// @brief Standard fork types. +#define kNeFSDataFork "main_data" +#define kNeFSResourceFork "main_rsrc" + +#define kNeFSCatalogKindFile (1) +#define kNeFSCatalogKindDir (2) +#define kNeFSCatalogKindAlias (3) + +#define kNeFSForkSize (512) + +//! shared between network or +//! other filesystems. Export forks as .zip when copying. +#define kNeFSCatalogKindShared (4) + +#define kNeFSCatalogKindResource (5) +#define kNeFSCatalogKindExecutable (6) + +#define kNeFSCatalogKindPage (8) + +#define kNeFSPartitionTypeStandard (7) +#define kNeFSPartitionTypePage (8) +#define kNeFSPartitionTypeBoot (9) + +#define kNeFSCatalogKindDevice (9) +#define kNeFSCatalogKindLock (10) + +#define kNeFSCatalogKindRLE (11) + +#define kNeFSCatalogKindMetaFile (12) + +#define kNeFSSeparator '\\' +#define kNeFSSeparatorAlt '/' + +#define kNeFSUpDir ".." +#define kNeFSRoot "\\" +#define kNeFSRootAlt "/" + +#define kNeFSLF '\r' +#define kNeFSEOF (-1) + +#define kNeFSBitWidth (sizeof(Kernel::Char)) +#define kNeFSLbaType (Kernel::Lba) + +/// Start After the PM headers, pad 1024 bytes. +#define kNeFSRootCatalogStartAddress (1024) +#define kNeFSCatalogStartAddress ((2048) + sizeof(NFS_ROOT_PARTITION_BLOCK)) + +#define kResourceTypeDialog (10) +#define kResourceTypeString (11) +#define kResourceTypeMenu (12) + +#define kConfigLen (64) +#define kPartLen (32) + +#define kNeFSFlagDeleted (70) +#define kNeFSFlagUnallocated (0) +#define kNeFSFlagCreated (71) + +#define kNeFSMimeNameLen (200) + +#define kNeFSForkNameLen (200U) + +struct NFS_CATALOG_STRUCT; +struct NFS_FORK_STRUCT; +struct NFS_ROOT_PARTITION_BLOCK; + +enum +{ + kNeFSHardDrive = 0xC0, // Hard Drive + kNeFSSolidStateDrive = 0xC1, // Solid State Drive + kNeFSOpticalDrive = 0x0C, // Blu-Ray/DVD + kNeFSMassStorageDevice = 0xCC, // USB + kNeFSScsi = 0xC4, // SCSI Hard Drive + kNeFSFlashDrive = 0xC6, + kNeFSUnknown = 0xFF, // Unknown device. + kNeFSDriveCount = 7, +}; + +/// @brief Catalog type. +struct PACKED NFS_CATALOG_STRUCT final +{ + Kernel::Char Name[kNeFSNodeNameLen]; + Kernel::Char Mime[kNeFSMimeNameLen]; + + /// Catalog status flag. + Kernel::UInt16 Flags; + /// Custom catalog flags. + Kernel::UInt16 FileFlags; + /// Catalog kind. + Kernel::Int32 Kind; + + /// Size of the data fork. + Kernel::Lba DataForkSize; + + /// Size of all resource forks. + Kernel::Lba ResourceForkSize; + + Kernel::Lba DataFork; + Kernel::Lba ResourceFork; + + Kernel::Lba NextSibling; + Kernel::Lba PrevSibling; +}; + +/// @brief Fork type, contains a data page. +/// @note The way we store is way different than how other filesystems do, specific chunk of code are +/// written into either the data fork or resource fork, the resource fork is reserved for file metadata. +/// whereas the data fork is reserved for file data. +struct PACKED NFS_FORK_STRUCT final +{ + Kernel::Char ForkName[kNeFSForkNameLen]; + Kernel::Char CatalogName[kNeFSNodeNameLen]; + + Kernel::Int32 Flags; + Kernel::Int32 Kind; + + Kernel::Int64 ResourceId; + Kernel::Int32 ResourceKind; + Kernel::Int32 ResourceFlags; + + Kernel::Lba DataOffset; // 8 Where to look for this data? + Kernel::SizeT DataSize; /// Data size according using sector count. + + Kernel::Lba NextSibling; + Kernel::Lba PreviousSibling; +}; + +/// @brief Partition block type +struct PACKED NFS_ROOT_PARTITION_BLOCK final +{ + Kernel::Char Ident[kNeFSIdentLen]; + Kernel::Char PartitionName[kPartLen]; + + Kernel::Int32 Flags; + Kernel::Int32 Kind; + + Kernel::Lba StartCatalog; + Kernel::SizeT CatalogCount; + + Kernel::SizeT DiskSize; + + Kernel::SizeT FreeCatalog; + Kernel::SizeT FreeSectors; + + Kernel::SizeT SectorCount; + Kernel::SizeT SectorSize; + + Kernel::UInt64 Version; + + Kernel::Lba EpmBlock; + + Kernel::Char Pad[kNeFSPadLen - sizeof(Kernel::Lba)]; +}; + +namespace Kernel +{ + enum + { + kNeFSSubDriveA, + kNeFSSubDriveB, + kNeFSSubDriveC, + kNeFSSubDriveD, + kNeFSSubDriveInvalid, + kNeFSSubDriveCount, + }; + + /// \brief Resource fork kind. + enum + { + kNeFSRsrcForkKind = 0, + kNeFSDataForkKind = 1 + }; + + /// + /// \name NeFSParser + /// \brief NeFS parser class. (catalog creation, remove removal, root, + /// forks...) Designed like the DOM, detects the filesystem automatically. + /// + class NeFSParser final + { + public: + explicit NeFSParser() = default; + ~NeFSParser() = default; + + public: + ZKA_COPY_DEFAULT(NeFSParser); + + public: + /// @brief Creates a new fork inside the New filesystem partition. + /// @param catalog it's catalog + /// @param theFork the fork itself. + /// @return the fork + _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& theFork); + + /// @brief Find fork inside New filesystem. + /// @param catalog the catalog. + /// @param name the fork name. + /// @return the fork. + _Output NFS_FORK_STRUCT* FindFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input const Char* name, + Boolean dataOrRsrc); + + _Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork); + + _Output Void CloseFork(_Input NFS_FORK_STRUCT* fork); + + _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba); + + _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); + + _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, + _Input const Int32& flags, + _Input const Int32& kind); + + _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name); + + Bool WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, + _Input Bool isRsrcFork, + _Input VoidPtr data, + _Input SizeT sizeOfData, + _Input const Char* forkName); + + VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, + _Input Bool isRsrcFork, + _Input SizeT dataSz, + _Input const Char* forkName); + + bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off); + + SizeT Tell(_Input _Output NFS_CATALOG_STRUCT* catalog); + + bool RemoveCatalog(_Input const Char* catalog); + + bool CloseCatalog(_InOut NFS_CATALOG_STRUCT* catalog); + + /// @brief Make a EPM+NeFS drive out of the disk. + /// @param drive The drive to write on. + /// @return If it was sucessful, see ErrLocal(). + bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name); + + public: + Int32 fDriveIndex{kNeFSSubDriveA}; + }; + + /// + /// \name NewFilesystemHelper + /// \brief Filesystem helper and utils. + /// + + class NewFilesystemHelper final + { + public: + STATIC const Char* Root(); + STATIC const Char* UpDir(); + STATIC const Char Separator(); + STATIC const Char MetaFile(); + }; + + namespace Detail + { + Boolean fs_init_newfs(Void) noexcept; + } // namespace Detail +} // namespace Kernel + +/// @brief Write to newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt, + Kernel::DriveTrait& DrvTrait, + Kernel::Int32 DrvIndex); + +/// @brief Read from newfs disk. +/// @param Mnt mounted interface. +/// @param DrvTrait drive info +/// @param DrvIndex drive index. +/// @return +Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* Mnt, + Kernel::DriveTrait& DrvTrait, + Kernel::Int32 DrvIndex); diff --git a/dev/ZKA/FSKit/NewFS.hxx b/dev/ZKA/FSKit/NewFS.hxx deleted file mode 100644 index 4587b70f..00000000 --- a/dev/ZKA/FSKit/NewFS.hxx +++ /dev/null @@ -1,326 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: NewFS.hxx - Purpose: - - Revision History: - - ?/?/?: Added file (amlel) - 12/02/24: Add UUID macro for EPM and GPT partition schemes. - 3/16/24: Add mandatory sector size, kNewFSSectorSz is set to 2048 by -default. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include - -/** - @brief New File System specification. - @author Amlal EL Mahrouss -*/ - -#define kNewFSInvalidFork (-1) -#define kNewFSInvalidCatalog (-1) -#define kNewFSNodeNameLen (256) - -#define kNewFSSectorSz (512) -#define kNewFSForkSz (8192) - -#define kNewFSIdentLen (8) -#define kNewFSIdent " NewFS" -#define kNewFSPadLen (400) - -#define kNewFSMetaFilePrefix '$' - -#define kNewFSVersionInteger (0x0128) -#define kNewFSVerionString "1.28" - -/// @brief Standard fork types. -#define kNewFSDataFork "main_data" -#define kNewFSResourceFork "main_rsrc" - -#define kNewFSCatalogKindFile (1) -#define kNewFSCatalogKindDir (2) -#define kNewFSCatalogKindAlias (3) - -#define kNewFSForkSize (512) - -//! shared between network or -//! other filesystems. Export forks as .zip when copying. -#define kNewFSCatalogKindShared (4) - -#define kNewFSCatalogKindResource (5) -#define kNewFSCatalogKindExecutable (6) - -#define kNewFSCatalogKindPage (8) - -#define kNewFSPartitionTypeStandard (7) -#define kNewFSPartitionTypePage (8) -#define kNewFSPartitionTypeBoot (9) - -#define kNewFSCatalogKindDevice (9) -#define kNewFSCatalogKindLock (10) - -#define kNewFSCatalogKindRLE (11) - -#define kNewFSCatalogKindMetaFile (12) - -#define kNewFSSeparator '\\' -#define kNewFSSeparatorAlt '/' - -#define kNewFSUpDir ".." -#define kNewFSRoot "\\" -#define kNewFSRootAlt "/" - -#define kNewFSLF '\r' -#define kNewFSEOF (-1) - -#define kNewFSBitWidth (sizeof(Kernel::Char)) -#define kNewFSLbaType (Kernel::Lba) - -/// Start After the PM headers, pad 1024 bytes. -#define kNewFSRootCatalogStartAddress (1024) -#define kNewFSCatalogStartAddress ((2048) + sizeof(NFS_ROOT_PARTITION_BLOCK)) - -#define kResourceTypeDialog (10) -#define kResourceTypeString (11) -#define kResourceTypeMenu (12) - -#define kConfigLen (64) -#define kPartLen (32) - -#define kNewFSFlagDeleted (70) -#define kNewFSFlagUnallocated (0) -#define kNewFSFlagCreated (71) - -#define kNewFSMimeNameLen (200) - -#define kNewFSForkNameLen (200U) - -struct NFS_CATALOG_STRUCT; -struct NFS_FORK_STRUCT; -struct NFS_ROOT_PARTITION_BLOCK; - -enum -{ - kNewFSHardDrive = 0xC0, // Hard Drive - kNewFSSolidStateDrive = 0xC1, // Solid State Drive - kNewFSOpticalDrive = 0x0C, // Blu-Ray/DVD - kNewFSMassStorageDevice = 0xCC, // USB - kNewFSScsi = 0xC4, // SCSI Hard Drive - kNewFSFlashDrive = 0xC6, - kNewFSUnknown = 0xFF, // Unknown device. - kNewFSDriveCount = 7, -}; - -/// @brief Catalog type. -struct PACKED NFS_CATALOG_STRUCT final -{ - Kernel::Char Name[kNewFSNodeNameLen]; - Kernel::Char Mime[kNewFSMimeNameLen]; - - /// Catalog status flag. - Kernel::UInt16 Flags; - /// Custom catalog flags. - Kernel::UInt16 FileFlags; - /// Catalog kind. - Kernel::Int32 Kind; - - /// Size of the data fork. - Kernel::Lba DataForkSize; - - /// Size of all resource forks. - Kernel::Lba ResourceForkSize; - - Kernel::Lba DataFork; - Kernel::Lba ResourceFork; - - Kernel::Lba NextSibling; - Kernel::Lba PrevSibling; -}; - -/// @brief Fork type, contains a data page. -/// @note The way we store is way different than how other filesystems do, specific chunk of code are -/// written into either the data fork or resource fork, the resource fork is reserved for file metadata. -/// whereas the data fork is reserved for file data. -struct PACKED NFS_FORK_STRUCT final -{ - Kernel::Char ForkName[kNewFSForkNameLen]; - Kernel::Char CatalogName[kNewFSNodeNameLen]; - - Kernel::Int32 Flags; - Kernel::Int32 Kind; - - Kernel::Int64 ResourceId; - Kernel::Int32 ResourceKind; - Kernel::Int32 ResourceFlags; - - Kernel::Lba DataOffset; // 8 Where to look for this data? - Kernel::SizeT DataSize; /// Data size according using sector count. - - Kernel::Lba NextSibling; - Kernel::Lba PreviousSibling; -}; - -/// @brief Partition block type -struct PACKED NFS_ROOT_PARTITION_BLOCK final -{ - Kernel::Char Ident[kNewFSIdentLen]; - Kernel::Char PartitionName[kPartLen]; - - Kernel::Int32 Flags; - Kernel::Int32 Kind; - - Kernel::Lba StartCatalog; - Kernel::SizeT CatalogCount; - - Kernel::SizeT DiskSize; - - Kernel::SizeT FreeCatalog; - Kernel::SizeT FreeSectors; - - Kernel::SizeT SectorCount; - Kernel::SizeT SectorSize; - - Kernel::UInt64 Version; - - Kernel::Lba EpmBlock; - - Kernel::Char Pad[kNewFSPadLen - sizeof(Kernel::Lba)]; -}; - -namespace Kernel -{ - enum - { - kNewFSSubDriveA, - kNewFSSubDriveB, - kNewFSSubDriveC, - kNewFSSubDriveD, - kNewFSSubDriveInvalid, - kNewFSSubDriveCount, - }; - - /// \brief Resource fork kind. - enum - { - kNewFSRsrcForkKind = 0, - kNewFSDataForkKind = 1 - }; - - /// - /// \name NewFSParser - /// \brief NewFS parser class. (catalog creation, remove removal, root, - /// forks...) Designed like the DOM, detects the filesystem automatically. - /// - class NewFSParser final - { - public: - explicit NewFSParser() = default; - ~NewFSParser() = default; - - public: - ZKA_COPY_DEFAULT(NewFSParser); - - public: - /// @brief Creates a new fork inside the New filesystem partition. - /// @param catalog it's catalog - /// @param theFork the fork itself. - /// @return the fork - _Output NFS_FORK_STRUCT* CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& theFork); - - /// @brief Find fork inside New filesystem. - /// @param catalog the catalog. - /// @param name the fork name. - /// @return the fork. - _Output NFS_FORK_STRUCT* FindFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - Boolean dataOrRsrc); - - _Output Void RemoveFork(_Input NFS_FORK_STRUCT* fork); - - _Output Void CloseFork(_Input NFS_FORK_STRUCT* fork); - - _Output NFS_CATALOG_STRUCT* FindCatalog(_Input const Char* catalogName, Lba& outLba); - - _Output NFS_CATALOG_STRUCT* GetCatalog(_Input const Char* name); - - _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name, - _Input const Int32& flags, - _Input const Int32& kind); - - _Output NFS_CATALOG_STRUCT* CreateCatalog(_Input const Char* name); - - Bool WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, - _Input Bool isRsrcFork, - _Input VoidPtr data, - _Input SizeT sizeOfData, - _Input const Char* forkName); - - VoidPtr ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, - _Input Bool isRsrcFork, - _Input SizeT dataSz, - _Input const Char* forkName); - - bool Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off); - - SizeT Tell(_Input _Output NFS_CATALOG_STRUCT* catalog); - - bool RemoveCatalog(_Input const Char* catalog); - - bool CloseCatalog(_InOut NFS_CATALOG_STRUCT* catalog); - - /// @brief Make a EPM+NewFS drive out of the disk. - /// @param drive The drive to write on. - /// @return If it was sucessful, see ErrLocal(). - bool Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name); - - public: - Int32 fDriveIndex{kNewFSSubDriveA}; - }; - - /// - /// \name NewFilesystemHelper - /// \brief Filesystem helper and utils. - /// - - class NewFilesystemHelper final - { - public: - STATIC const Char* Root(); - STATIC const Char* UpDir(); - STATIC const Char Separator(); - STATIC const Char MetaFile(); - }; - - namespace Detail - { - Boolean fs_init_newfs(Void) noexcept; - } // namespace Detail -} // namespace Kernel - -/// @brief Write to newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Kernel::Int32 fs_newfs_write(Kernel::MountpointInterface* Mnt, - Kernel::DriveTrait& DrvTrait, - Kernel::Int32 DrvIndex); - -/// @brief Read from newfs disk. -/// @param Mnt mounted interface. -/// @param DrvTrait drive info -/// @param DrvIndex drive index. -/// @return -Kernel::Int32 fs_newfs_read(Kernel::MountpointInterface* Mnt, - Kernel::DriveTrait& DrvTrait, - Kernel::Int32 DrvIndex); diff --git a/dev/ZKA/FirmwareKit/EPM.hxx b/dev/ZKA/FirmwareKit/EPM.hxx index 0de288be..18f8558d 100644 --- a/dev/ZKA/FirmwareKit/EPM.hxx +++ b/dev/ZKA/FirmwareKit/EPM.hxx @@ -102,7 +102,7 @@ struct PACKED _BOOT_BLOCK_STRUCT Kernel::Int64 LbaEnd; // addition of lba_start to get the end of partition. Kernel::Int16 Kind; Kernel::Int32 FsVersion; - Kernel::Char Fs[kEPMFilesystemLength]; /* NewFS, ffs2... */ + Kernel::Char Fs[kEPMFilesystemLength]; /* NeFS, ffs2... */ Kernel::Char Reserved[401]; // to fill a full sector. }; diff --git a/dev/ZKA/FirmwareKit/Handover.hxx b/dev/ZKA/FirmwareKit/Handover.hxx index 80d68afa..b4558560 100644 --- a/dev/ZKA/FirmwareKit/Handover.hxx +++ b/dev/ZKA/FirmwareKit/Handover.hxx @@ -24,13 +24,7 @@ #define kHandoverMagic 0xBADCC #define kHandoverVersion 0x114 -#define kHandoverMaxCmdLine 8 - -#define kHandoverBetterEFI "ZKA_EFI" -#define kHandoverBetterEFI_U L"ZKA_EFI" - -#define kHandoverHeapSz gib_cast(2) - +#define kHandoverHeapSz gib_cast(3) #define kHandoverStructSz sizeof(HEL::HandoverInformationHeader) namespace Kernel::HEL @@ -67,9 +61,13 @@ namespace Kernel::HEL VoidPtr f_PhysicalStart; VoidPtr f_KernelImage; + SizeT f_KernelSz; VoidPtr f_StartupChime; + SizeT f_ChimeSz; VoidPtr f_StartupImage; + SizeT f_StartupSz; VoidPtr f_TTFallbackFont; + SizeT f_FontSz; WideChar f_FirmwareVendorName[32]; SizeT f_FirmwareVendorLen; diff --git a/dev/ZKA/KernelKit/FileMgr.hxx b/dev/ZKA/KernelKit/FileMgr.hxx index 86c40b69..a46216db 100644 --- a/dev/ZKA/KernelKit/FileMgr.hxx +++ b/dev/ZKA/KernelKit/FileMgr.hxx @@ -12,7 +12,7 @@ Revision History: 31/01/24: Update documentation (amlel) - 05/07/24: NewFS support, and fork support, updated constants and specs + 05/07/24: NeFS support, and fork support, updated constants and specs as well. ------------------------------------------- */ @@ -20,7 +20,7 @@ #pragma once #ifdef __FSKIT_USE_NEWFS__ -#include +#include #endif // __FSKIT_USE_NEWFS__ #include @@ -137,7 +137,7 @@ namespace Kernel #ifdef __FSKIT_USE_NEWFS__ /** - * @brief Based of FilesystemMgrInterface, takes care of managing NewFS + * @brief Based of FilesystemMgrInterface, takes care of managing NeFS * disks. */ class NewFilesystemMgr final : public FilesystemMgrInterface @@ -176,12 +176,12 @@ namespace Kernel _Input SizeT sz) override; public: - /// @brief Get NewFS parser class. + /// @brief Get NeFS parser class. /// @return The filesystem parser class. - NewFSParser* GetParser() noexcept; + NeFSParser* GetParser() noexcept; private: - NewFSParser* fImpl{nullptr}; + NeFSParser* fImpl{nullptr}; }; #endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/NewKit/Macros.hxx b/dev/ZKA/NewKit/Macros.hxx index b9242e79..0de25216 100644 --- a/dev/ZKA/NewKit/Macros.hxx +++ b/dev/ZKA/NewKit/Macros.hxx @@ -119,3 +119,12 @@ /// @brief The main system driver. #define kSysDrv "\\System\\startup.sys" + +/// @brief The main font file. +#define kSysTTF "\\System\\urbanist.ttf" + +/// @brief The main kernel file. +#define kSysChime "\\System\\startup.wav" + +/// @brief The main kernel file. +#define kSysKrnl "\\System\\newoskrnl.exe" diff --git a/dev/ZKA/Sources/DLLMain.cxx b/dev/ZKA/Sources/DLLMain.cxx index db1a80d1..0fa3a181 100644 --- a/dev/ZKA/Sources/DLLMain.cxx +++ b/dev/ZKA/Sources/DLLMain.cxx @@ -44,7 +44,7 @@ namespace Kernel::Detail /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { - Kernel::NewFilesystemMgr* fNewFS{nullptr}; + Kernel::NewFilesystemMgr* fNeFS{nullptr}; public: /// @brief wizard constructor. @@ -52,17 +52,17 @@ namespace Kernel::Detail { if (Kernel::FilesystemMgrInterface::GetMounted()) { - CG::CGDrawStringToWnd(cKernelWnd, "NewFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); - fNewFS = reinterpret_cast(Kernel::FilesystemMgrInterface::GetMounted()); + CG::CGDrawStringToWnd(cKernelWnd, "NeFS IFS already mounted by HAL (A:)", 10, 10, RGB(0, 0, 0)); + fNeFS = reinterpret_cast(Kernel::FilesystemMgrInterface::GetMounted()); } else { - // Mounts a NewFS from main drive. - fNewFS = new Kernel::NewFilesystemMgr(); + // Mounts a NeFS from main drive. + fNeFS = new Kernel::NewFilesystemMgr(); - Kernel::FilesystemMgrInterface::Mount(fNewFS); + Kernel::FilesystemMgrInterface::Mount(fNeFS); - CG::CGDrawStringToWnd(cKernelWnd, "Mounted NewFS IFS (A:)", 10, 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, "Mounted NeFS IFS (A:)", 10, 10, RGB(0, 0, 0)); } const Kernel::SizeT cDirCount = 7UL; @@ -71,11 +71,11 @@ namespace Kernel::Detail "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", "\\Users\\", "\\Library\\", "\\Mount\\"}; - if (fNewFS->GetParser()) + if (fNeFS->GetParser()) { for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { - auto catalogDir = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); + auto catalogDir = fNeFS->GetParser()->GetCatalog(cDirStr[dirIndx]); if (catalogDir) { @@ -86,8 +86,8 @@ namespace Kernel::Detail continue; } - catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, - kNewFSCatalogKindDir); + catalogDir = fNeFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, + kNeFSCatalogKindDir); CG::CGDrawStringToWnd(cKernelWnd, "Catalog directory has been created: ", 10 + (10 * (dirIndx + 1)), 10, RGB(0, 0, 0)); CG::CGDrawStringToWnd(cKernelWnd, catalogDir->Name, 10 + (10 * (dirIndx + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog directory has been created: ")), RGB(0, 0, 0)); @@ -96,44 +96,93 @@ namespace Kernel::Detail } } - NFS_CATALOG_STRUCT* catalogDisk = - this->fNewFS->GetParser()->GetCatalog(kSysPage); - const Kernel::Char* cSrcName = "8K_SYS_PAGE_KERNEL"; + constexpr auto cFileToFormatCnt = 5; - if (catalogDisk) + struct { - CG::CGDrawStringToWnd(cKernelWnd, "Catalog swap file already exists: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog swap file already exists: ")), RGB(0, 0, 0)); + VoidPtr fBlob; + Size fBlobSz; + Int32 fFlags; + Char fName[kNeFSNodeNameLen]; + } cFiles[cFileToFormatCnt] = { + { + .fBlob = kHandoverHeader->f_KernelImage, + .fBlobSz = kHandoverHeader->f_KernelSz, + .fFlags = kNeFSCatalogKindExecutable, + .fName = kSysKrnl, + }, + { + .fBlob = kHandoverHeader->f_StartupImage, + .fBlobSz = kHandoverHeader->f_StartupSz, + .fFlags = kNeFSCatalogKindExecutable, + .fName = kSysDrv, + }, + { + .fBlob = 0, + .fBlobSz = mib_cast(32), + .fFlags = kNeFSCatalogKindPage, + .fName = kSysPage, + }, + { + .fBlob = kHandoverHeader->f_TTFallbackFont, + .fBlobSz = kHandoverHeader->f_FontSz, + .fFlags = kNeFSCatalogKindResource, + .fName = kSysTTF, + }, + { + .fBlob = kHandoverHeader->f_StartupChime, + .fBlobSz = kHandoverHeader->f_ChimeSz, + .fFlags = kNeFSCatalogKindResource, + .fName = kSysChime, + } - delete catalogDisk; - } - else + }; + + for (size_t i = 0; i < cFileToFormatCnt; i++) { - CG::CGDrawStringToWnd(cKernelWnd, "Catalog swap file created: ", 10 + (10 * (cDirCount + 1)), 10, RGB(0, 0, 0)); - CG::CGDrawStringToWnd(cKernelWnd, kSysPage, 10 + (10 * (cDirCount + 1)), 10 + (FONT_SIZE_X * rt_string_len("Catalog swap file created: ")), RGB(0, 0, 0)); + NFS_CATALOG_STRUCT* catalogDisk = + this->fNeFS->GetParser()->GetCatalog(cFiles[i].fName); + + const Kernel::Char* cSrcName = cFiles[i].fName; - catalogDisk = - (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(kSysPage); + if (catalogDisk) + { + CG::CGDrawStringToWnd(cKernelWnd, "File already exists: ", 10 + (10 * (cDirCount + i + 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, cFiles[i].fName, 10 + (10 * (cDirCount + i+ 1)), 10 + (FONT_SIZE_X * rt_string_len("File already exists: ")), RGB(0, 0, 0)); + + delete catalogDisk; + } + else + { + CG::CGDrawStringToWnd(cKernelWnd, "File created: ", 10 + (10 * (cDirCount + i+ 1)), 10, RGB(0, 0, 0)); + CG::CGDrawStringToWnd(cKernelWnd, cFiles[i].fName, 10 + (10 * (cDirCount + i + 1)), 10 + (FONT_SIZE_X * rt_string_len("File created: ")), RGB(0, 0, 0)); + + catalogDisk = + (NFS_CATALOG_STRUCT*)this->Leak()->CreateSwapFile(cFiles[i].fName); - NFS_FORK_STRUCT theDiskFork{0}; + NFS_FORK_STRUCT theDiskFork{0}; - Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, - Kernel::rt_string_len(cSrcName)); + Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, + Kernel::rt_string_len(cSrcName)); - Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), - theDiskFork.CatalogName, - Kernel::rt_string_len(catalogDisk->Name)); + Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), + theDiskFork.CatalogName, + Kernel::rt_string_len(catalogDisk->Name)); - Kernel::Size sz_hdr = kNewFSForkSz; + theDiskFork.DataSize = cFiles[i].fBlobSz; + theDiskFork.ResourceId = cFiles[i].fFlags; + theDiskFork.ResourceKind = Kernel::kNeFSDataForkKind; + theDiskFork.Kind = Kernel::kNeFSDataForkKind; - theDiskFork.DataSize = sz_hdr; - theDiskFork.ResourceId = kNewFSCatalogKindExecutable | kNewFSCatalogKindPage; - theDiskFork.ResourceKind = Kernel::kNewFSDataForkKind; - theDiskFork.Kind = Kernel::kNewFSDataForkKind; + fNeFS->GetParser()->CreateFork(catalogDisk, theDiskFork); - fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); + if (theDiskFork.ResourceId != kNeFSCatalogKindPage) + { + fNeFS->GetParser()->WriteCatalog(catalogDisk, false, cFiles[i].fBlob, cFiles[i].fBlobSz, theDiskFork.ForkName); + } - delete catalogDisk; + delete catalogDisk; + } } } @@ -141,11 +190,11 @@ namespace Kernel::Detail ZKA_COPY_DEFAULT(FilesystemInstaller); - /// @brief Grab the disk's NewFS reference. + /// @brief Grab the disk's NeFS reference. /// @return NewFilesystemMgr the filesystem interface Kernel::NewFilesystemMgr* Leak() { - return fNewFS; + return fNeFS; } }; } // namespace Kernel::Detail @@ -154,7 +203,6 @@ EXTERN_C ATTRIBUTE(naked) Kernel::Void HangCPU(Kernel::Void) { while (Yes) { - } } @@ -190,7 +238,7 @@ EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) CG::CGDrawStringToWnd(cKernelWnd, "Starting ZKA System...", 20, 10, RGB(0, 0, 0)); Kernel::UserProcessHelper::Init(); - + Kernel::sched_execute_thread(HangCPU, "HANG TEST"); while (Yes) diff --git a/dev/ZKA/Sources/FS/NeFS.cxx b/dev/ZKA/Sources/FS/NeFS.cxx new file mode 100644 index 00000000..5bae8d4a --- /dev/null +++ b/dev/ZKA/Sources/FS/NeFS.cxx @@ -0,0 +1,1045 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifdef __FSKIT_USE_NEWFS__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace Kernel; + +#ifdef __ED__ +/***********************************************************************************/ +/** + Define those external symbols, to make the editor shutup +*/ +/***********************************************************************************/ + +/***********************************************************************************/ +/// @brief get sector count. +/***********************************************************************************/ +Kernel::SizeT drv_std_get_sector_count(); + +/***********************************************************************************/ +/// @brief get device size. +/***********************************************************************************/ +Kernel::SizeT drv_std_get_drv_size(); + +#endif + +///! BUGS: 0 + +/***********************************************************************************/ +/// This file implements the New File System. +/// New File System implements a B-Tree based algortihm. +/// \\ +/// \\Path1\\ \\ath2\\ +/// \\readme.rtf \\ListContents.pef \\readme.lnk <-- symlink. +/// \\Path1\\readme.rtf +/***********************************************************************************/ + +STATIC MountpointInterface sMountpointInterface; + +/***********************************************************************************/ +/// @brief Creates a new fork inside the New filesystem partition. +/// @param catalog it's catalog +/// @param theFork the fork itself. +/// @return the fork +/***********************************************************************************/ +_Output NFS_FORK_STRUCT* NeFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input NFS_FORK_STRUCT& theFork) +{ + if (catalog && theFork.ForkName[0] != 0 && + theFork.DataSize <= kNeFSForkDataSz) + { + Lba lba = (theFork.Kind == kNeFSDataForkKind) ? catalog->DataFork + : catalog->ResourceFork; + + kcout << "fork lba: " << hex_number(lba) << endl; + + if (lba <= kNeFSCatalogStartAddress) + return nullptr; + + auto drv = sMountpointInterface.A(); + + /// special treatment. + rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + NFS_FORK_STRUCT curFork{0}; + NFS_FORK_STRUCT prevFork{0}; + Lba lbaOfPreviousFork = lba; + + /// do not check for anything. Loop until we get what we want, that is a free fork zone. + while (true) + { + if (lba <= kNeFSCatalogStartAddress) + break; + + drv.fPacket.fLba = lba; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &curFork; + + drv.fInput(&drv.fPacket); + + if (curFork.NextSibling > kBadAddress) + { + kcout << "bad fork: " << hex_number(curFork.NextSibling) << endl; + break; + } + + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; + + if (curFork.Flags == kNeFSFlagCreated) + { + kcout << "fork already exists.\r"; + + /// sanity check. + if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && + StringBuilder::Equals(curFork.CatalogName, catalog->Name)) + return nullptr; + + kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; + + lbaOfPreviousFork = lba; + lba = curFork.NextSibling; + + prevFork = curFork; + } + else + { + /// This is a check that we have, in order to link the previous fork + /// entry. + if (lba >= kNeFSCatalogStartAddress) + { + drv.fPacket.fLba = lbaOfPreviousFork; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &prevFork; + + prevFork.NextSibling = lba; + + /// write to disk. + drv.fOutput(&drv.fPacket); + } + + break; + } + } + + constexpr auto cForkPadding = + 4; /// this value gives us space for the data offset. + + theFork.Flags = kNeFSFlagCreated; + theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) * cForkPadding; + theFork.PreviousSibling = lbaOfPreviousFork; + theFork.NextSibling = theFork.DataOffset - theFork.DataSize; + + drv.fPacket.fLba = lba; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = &theFork; + + drv.fOutput(&drv.fPacket); + + /// log what we have now. + kcout << "Wrote fork data at: " << hex_number(theFork.DataOffset) + << endl; + + kcout << "Wrote fork at: " << hex_number(lba) << endl; + + return &theFork; + } + + return nullptr; +} + +/***********************************************************************************/ +/// @brief Find fork inside New filesystem. +/// @param catalog the catalog. +/// @param name the fork name. +/// @return the fork. +/***********************************************************************************/ +_Output NFS_FORK_STRUCT* NeFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, + _Input const Char* name, + Boolean isDataFork) +{ + auto drv = sMountpointInterface.A(); + NFS_FORK_STRUCT* theFork = nullptr; + + Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; + + while (lba != 0) + { + drv.fPacket.fLba = lba; + drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drv.fPacket.fPacketContent = (VoidPtr)theFork; + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, 16); + + if (auto res = + fs_newfs_read(&sMountpointInterface, drv, this->fDriveIndex); + res) + { + switch (res) + { + case 1: + ErrLocal() = kErrorDiskReadOnly; + break; + case 2: + ErrLocal() = kErrorDiskIsFull; + break; + ErrLocal() = kErrorNoSuchDisk; + break; + + default: + break; + } + return nullptr; + } + + if (StringBuilder::Equals(theFork->ForkName, name)) + { + break; + } + + lba = theFork->NextSibling; + } + + return theFork; +} + +/***********************************************************************************/ +/// @brief Simpler factory to create a catalog (assumes you want to create a +/// file.) +/// @param name +/// @return catalog pointer. +/***********************************************************************************/ +_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name) +{ + return this->CreateCatalog(name, 0, kNeFSCatalogKindFile); +} + +/***********************************************************************************/ +/// @brief Creates a new catalog into the disk. +/// @param name the catalog name. +/// @param flags the flags of the catalog. +/// @param kind the catalog kind. +/// @return catalog pointer. +/***********************************************************************************/ +_Output NFS_CATALOG_STRUCT* NeFSParser::CreateCatalog(_Input const Char* name, + _Input const Int32& flags, + _Input const Int32& kind) +{ + kcout << "CreateCatalog(...)\r"; + + Lba out_lba = 0UL; + + kcout << "Checking for extension...\r"; + + /// a directory should have a slash in the end. + if (kind == kNeFSCatalogKindDir && + name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator()) + return nullptr; + + /// a file shouldn't have a slash in the end. + if (kind != kNeFSCatalogKindDir && + name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) + return nullptr; + + NFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba); + + if (catalog_copy) + { + kcout << "Catalog already exists: " << name << ".\r"; + ErrLocal() = kErrorFileExists; + + return catalog_copy; + } + + Char parentName[kNeFSNodeNameLen] = {0}; + + for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) + { + parentName[indexName] = name[indexName]; + } + + if (*parentName == 0) + { + kcout << "Parent name is NUL.\r"; + ErrLocal() = kErrorFileNotFound; + return nullptr; + } + + /// Locate parent catalog, to then allocate right after it. + + for (SizeT indexFill = 0; indexFill < rt_string_len(name); ++indexFill) + { + parentName[indexFill] = name[indexFill]; + } + + SizeT indexReverseCopy = rt_string_len(parentName); + + // zero character it. + parentName[--indexReverseCopy] = 0; + + // mandatory / character, zero it. + parentName[--indexReverseCopy] = 0; + + while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) + { + parentName[indexReverseCopy] = 0; + --indexReverseCopy; + } + + NFS_CATALOG_STRUCT* catalog = this->FindCatalog(parentName, out_lba); + + auto drive = sMountpointInterface.A(); + + if (catalog && catalog->Kind == kNeFSCatalogKindFile) + { + kcout << "Parent name is file.\r"; + delete catalog; + return nullptr; + } + else if (!catalog) + { + Char sectorBufPartBlock[kNeFSSectorSz] = {0}; + + drive.fPacket.fPacketContent = sectorBufPartBlock; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + constexpr auto cNeFSCatalogPadding = 4; + + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; + out_lba = partBlock->StartCatalog; + } + + constexpr SizeT cDefaultForkSize = kNeFSForkSize; + + NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); + + Int32 flagsList = flags; + + catalogChild->ResourceForkSize = cDefaultForkSize; + catalogChild->DataForkSize = cDefaultForkSize; + + catalogChild->NextSibling = out_lba; + catalogChild->PrevSibling = out_lba; + catalogChild->Kind = kind; + catalogChild->Flags = kNeFSFlagCreated | flagsList; + + rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name, + rt_string_len(name)); + + UInt16 catalogBuf[kNeFSSectorSz] = {0}; + + Lba start_free = out_lba; + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + drive.fPacket.fPacketContent = catalogBuf; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = start_free; + + drive.fInput(&drive.fPacket); + + NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; + + start_free = nextSibling->NextSibling; + + catalogChild->PrevSibling = out_lba; + + drive.fPacket.fLba = start_free; + drive.fInput(&drive.fPacket); + + while (drive.fPacket.fPacketGood) + { + nextSibling = reinterpret_cast(catalogBuf); + + if (start_free <= kNeFSRootCatalogStartAddress) + { + delete catalogChild; + delete catalog; + + return nullptr; + } + + // ========================== // + // Allocate catalog now... + // ========================== // + if ((nextSibling->Flags & kNeFSFlagCreated) == 0) + { + Char sectorBufPartBlock[kNeFSSectorSz] = {0}; + + drive.fPacket.fPacketContent = sectorBufPartBlock; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + constexpr auto cNeFSCatalogPadding = 4; + + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; + + if (partBlock->FreeCatalog < 1) + { + delete catalogChild; + return nullptr; + } + + catalogChild->DataFork = partBlock->DiskSize - start_free; + catalogChild->ResourceFork = catalogChild->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(parentName, nextSibling->Name)) + { + catalogChild->NextSibling = + start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); + } + + drive.fPacket.fPacketContent = catalogChild; + drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); + drive.fPacket.fLba = start_free; + + drive.fOutput(&drive.fPacket); + + // Get NeFS partition's block. + + drive.fPacket.fPacketContent = sectorBufPartBlock; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + partBlock->FreeSectors -= 1; + partBlock->CatalogCount += 1; + partBlock->FreeCatalog -= 1; + + drive.fOutput(&drive.fPacket); + + kcout << "Create new catalog, status: " + << hex_number(catalogChild->Flags) << endl; + kcout << "Create new catalog, name: " << catalogChild->Name + << endl; + + delete catalog; + return catalogChild; + } + else if ((nextSibling->Flags & kNeFSFlagCreated) && + StringBuilder::Equals(nextSibling->Name, name)) + { + return nextSibling; + } + + constexpr auto cNeFSCatalogPadding = 4; + + //// @note that's how we find the next catalog in the partition block. + start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNeFSCatalogPadding); + + drive.fPacket.fPacketContent = catalogBuf; + drive.fPacket.fPacketSize = kNeFSSectorSz; + drive.fPacket.fLba = start_free; + + drive.fInput(&drive.fPacket); + } + + delete catalog; + return nullptr; +} + +/// @brief Make a EPM+NeFS drive out of the disk. +/// @param drive The drive to write on. +/// @return If it was sucessful, see ErrLocal(). +bool NeFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) +{ + if (*part_name == 0 || + endLba == 0) + return false; + + // verify disk. + drive->fVerify(&drive->fPacket); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + // if disk isn't good, then error out. + if (false == drive->fPacket.fPacketGood) + { + ErrLocal() = kErrorDiskIsCorrupted; + return false; + } + + Char fs_buf[kNeFSSectorSz] = {0}; + + Lba start = kNeFSRootCatalogStartAddress; + + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = start; + + drive->fInput(&drive->fPacket); + + if (flags & kNeFSPartitionTypeBoot) + { + // make it bootable when needed. + Char bufEpmHdr[kNeFSSectorSz] = {0}; + + BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; + + // EPM header. + + constexpr auto cFsName = "NeFS"; + constexpr auto cBlockName = "ZKA:"; + + rt_copy_memory(reinterpret_cast(const_cast(cFsName)), epmBoot->Fs, rt_string_len(cFsName)); + + epmBoot->FsVersion = kNeFSVersionInteger; + epmBoot->LbaStart = start; + epmBoot->SectorSz = kNeFSSectorSz; + + rt_copy_memory(reinterpret_cast(const_cast(cBlockName)), epmBoot->Name, rt_string_len(cBlockName)); + rt_copy_memory(reinterpret_cast(const_cast(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic)); + + Lba outEpmLba = kEpmBase; + + Char buf[kNeFSSectorSz]; + + Lba prevStart = 0; + SizeT cnt = 0; + + while (drive->fPacket.fPacketGood) + { + drive->fPacket.fPacketContent = buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = outEpmLba; + + drive->fInput(&drive->fPacket); + + if (buf[0] == 0) + { + epmBoot->LbaStart = prevStart; + + if (epmBoot->LbaStart) + epmBoot->LbaStart = outEpmLba; + + epmBoot->LbaEnd = endLba; + epmBoot->NumBlocks = cnt; + + drive->fPacket.fPacketContent = bufEpmHdr; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = outEpmLba; + + drive->fOutput(&drive->fPacket); + + break; + } + else + { + prevStart = ((BOOT_BLOCK_STRUCT*)buf)->LbaStart + ((BOOT_BLOCK_STRUCT*)buf)->LbaEnd; + } + + outEpmLba += sizeof(BOOT_BLOCK_STRUCT); + ++cnt; + } + } + + // disk isnt faulty and data has been fetched. + while (drive->fPacket.fPacketGood) + { + NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)fs_buf; + + // check for an empty partition here. + if (partBlock->PartitionName[0] == 0 && + rt_string_cmp(partBlock->Ident, kNeFSIdent, kNeFSIdentLen)) + { + // partition is free and valid. + + partBlock->Version = kNeFSVersionInteger; + + const auto cUntitledHD = part_name; + + rt_copy_memory((VoidPtr)kNeFSIdent, (VoidPtr)partBlock->Ident, + kNeFSIdentLen); + + rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, + rt_string_len(cUntitledHD)); + + SizeT catalogCount = 0UL; + + SizeT sectorCount = drv_std_get_sector_count(); + SizeT diskSize = drv_std_get_drv_size(); + + partBlock->Kind = kNeFSPartitionTypeStandard; + partBlock->StartCatalog = kNeFSCatalogStartAddress; + partBlock->Flags = kNeFSPartitionTypeStandard; + partBlock->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT); + partBlock->SectorCount = sectorCount; + partBlock->DiskSize = diskSize; + partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); + + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive->fOutput(&drive->fPacket); + + kcout << "drive kind: " << drive->fDriveKind() << endl; + + kcout << "partition name: " << partBlock->PartitionName << endl; + kcout << "start: " << hex_number(partBlock->StartCatalog) << endl; + kcout << "number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; + kcout << "free catalog: " << hex_number(partBlock->FreeCatalog) << endl; + kcout << "free sectors: " << hex_number(partBlock->FreeSectors) << endl; + kcout << "sector size: " << hex_number(partBlock->SectorSize) << endl; + + // write the root catalog. + this->CreateCatalog(kNeFSRoot, 0, kNeFSCatalogKindDir); + + return true; + } + + kcout << "partition block already exists.\r"; + + start += partBlock->DiskSize; + + drive->fPacket.fPacketContent = fs_buf; + drive->fPacket.fPacketSize = kNeFSSectorSz; + drive->fPacket.fLba = start; + + drive->fInput(&drive->fPacket); + } + + return false; +} + +/// @brief Writes the data fork into a specific catalog. +/// @param catalog the catalog itself +/// @param data the data. +/// @return if the catalog w rote the contents successfully. +bool NeFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName) +{ + if (sizeOfData > kNeFSForkDataSz) + return No; + + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + auto startFork = (!isRsrcFork) ? catalog->DataFork + : catalog->ResourceFork; + + NFS_FORK_STRUCT* forkDataIn = new NFS_FORK_STRUCT(); + NFS_FORK_STRUCT prevFork{}; + + // sanity check of the fork position as the condition to run the loop. + while (startFork >= kNeFSCatalogStartAddress) + { + drive.fPacket.fPacketContent = forkDataIn; + drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drive.fPacket.fLba = startFork; + + drive.fInput(&drive.fPacket); + + // check the fork, if it's position is valid. + if (forkDataIn->DataOffset <= kNeFSCatalogStartAddress) + { + ErrLocal() = kErrorDiskIsCorrupted; + + kcout << "Invalid fork offset.\r"; + + return false; + } + + if (forkDataIn->Flags != kNeFSFlagUnallocated && + forkDataIn->Flags != kNeFSFlagDeleted && + StringBuilder::Equals(forkDataIn->ForkName, forkName) && + StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name)) + { + // ===================================================== // + // Store the blob now. + // ===================================================== // + + forkDataIn->Flags = kNeFSFlagCreated; + forkDataIn->DataOffset = startFork - sizeof(NFS_FORK_STRUCT); + forkDataIn->DataSize = sizeOfData; + + drive.fPacket.fPacketContent = data; + drive.fPacket.fPacketSize = sizeOfData; + drive.fPacket.fLba = forkDataIn->DataOffset; + + kcout << "data offset: " << hex_number(forkDataIn->DataOffset) << endl; + + drive.fOutput(&drive.fPacket); + + drive.fPacket.fPacketContent = &forkDataIn; + drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drive.fPacket.fLba = startFork; + + drive.fOutput(&drive.fPacket); + + kcout << "wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; + + delete catalog; + + return true; + } + + // stumble upon a fork, store it. + + prevFork = *forkDataIn; + + startFork = forkDataIn->NextSibling; + } + + return false; +} + +/// @brief +/// @param catalogName the catalog name. +/// @return the newly found catalog. +_Output NFS_CATALOG_STRUCT* NeFSParser::FindCatalog(_Input const Char* catalogName, + Lba& out_lba) +{ + kcout << "start finding catalog...\r"; + + NFS_ROOT_PARTITION_BLOCK fs_buf{0}; + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + drive.fPacket.fPacketContent = &fs_buf; + drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + + drive.fInput(&drive.fPacket); + + NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)&fs_buf; + + auto startCatalogList = part->StartCatalog; + const auto cCtartCatalogList = startCatalogList; + + auto localSearchFirst = false; + + NFS_CATALOG_STRUCT catalogBuf{0}; + + drive.fPacket.fLba = startCatalogList; + drive.fPacket.fPacketContent = &catalogBuf; + drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); + + drive.fInput(&drive.fPacket); + + if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) + { + Char parentName[kNeFSNodeNameLen] = {0}; + + for (SizeT indexFill = 0; indexFill < rt_string_len(catalogName); ++indexFill) + { + parentName[indexFill] = catalogName[indexFill]; + } + + SizeT indexReverseCopy = rt_string_len(parentName); + + // zero character. + parentName[--indexReverseCopy] = 0; + + // mandatory '/' character. + parentName[--indexReverseCopy] = 0; + + while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) + { + parentName[indexReverseCopy] = 0; + --indexReverseCopy; + } + + NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, out_lba); + + if (parentCatalog && + !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) + { + startCatalogList = parentCatalog->NextSibling; + delete parentCatalog; + + localSearchFirst = true; + } + else if (parentCatalog) + { + delete parentCatalog; + } + } + + kcout << "fetching catalog...\r"; + +NeFSSearchThroughCatalogList: + while (drive.fPacket.fPacketGood) + { + drive.fPacket.fLba = startCatalogList; + drive.fPacket.fPacketContent = &catalogBuf; + drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); + + drive.fInput(&drive.fPacket); + + NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)&catalogBuf; + + if (StringBuilder::Equals(catalogName, catalog->Name)) + { + /// ignore unallocated catalog, break + if (!(catalog->Flags & kNeFSFlagCreated)) + { + goto NeFSContinueSearch; + } + + 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: " << catalog->Name << endl; + + out_lba = startCatalogList; + return catalogPtr; + } + + NeFSContinueSearch: + startCatalogList = catalog->NextSibling; + + if (startCatalogList <= kNeFSRootCatalogStartAddress) + break; + } + + if (localSearchFirst) + { + localSearchFirst = false; + startCatalogList = cCtartCatalogList; + + goto NeFSSearchThroughCatalogList; + } + + out_lba = 0UL; + return nullptr; +} + +/// @brief Get catalog from filesystem. +/// @param name the catalog's name/ +/// @return +_Output NFS_CATALOG_STRUCT* NeFSParser::GetCatalog(_Input const Char* name) +{ + Lba unused = 0; + return this->FindCatalog(name, unused); +} + +/// @brief Closes a catalog, (frees it). +/// @param catalog the catalog to close. +/// @return +Boolean NeFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) +{ + if (!catalog) + return false; + + delete catalog; + catalog = nullptr; + + return true; +} + +/// @brief Mark catalog as removed. +/// @param catalog The catalog structure. +/// @return if the catalog was removed or not. +Boolean NeFSParser::RemoveCatalog(_Input const Char* catalogName) +{ + if (!catalogName || + StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) + { + ErrLocal() = kErrorInternal; + return false; + } + + Lba out_lba = 0; + auto catalog = this->FindCatalog(catalogName, out_lba); + + if (out_lba >= kNeFSCatalogStartAddress || + catalog->Flags == kNeFSFlagCreated) + { + catalog->Flags = kNeFSFlagDeleted; + + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + drive.fPacket.fLba = out_lba; // the catalog position. + drive.fPacket.fPacketSize = + sizeof(NFS_CATALOG_STRUCT); // size of catalog. roughly the sector size. + drive.fPacket.fPacketContent = catalog; // the catalog itself. + + drive.fOutput(&drive.fPacket); // send packet. + + Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; + + drive.fPacket.fLba = kNeFSRootCatalogStartAddress; + drive.fPacket.fPacketContent = partitionBlockBuf; + drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); + + drive.fInput(&drive.fPacket); + + NFS_ROOT_PARTITION_BLOCK* partBlock = + reinterpret_cast(partitionBlockBuf); + + --partBlock->CatalogCount; + ++partBlock->FreeSectors; + + drive.fOutput(&drive.fPacket); + + return true; + } + + delete catalog; + return false; +} + +/// ***************************************************************** /// +/// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead. +/// ***************************************************************** /// + +/***********************************************************************************/ +/// @brief Read the catalog data fork. +/// @param catalog +/// @param dataSz +/// @return +/***********************************************************************************/ + +VoidPtr NeFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, + _Input Bool isRsrcFork, + _Input SizeT dataSz, + _Input const Char* forkName) +{ + if (!catalog) + { + ErrLocal() = kErrorFileNotFound; + return nullptr; + } + + constexpr auto cNeFSCatalogPadding = 4; + + Lba dataForkLba = (!isRsrcFork) ? catalog->DataFork : catalog->ResourceFork; + Size dataForkSize = (!isRsrcFork) ? catalog->DataForkSize : catalog->ResourceForkSize; + + kcout << "catalog " << catalog->Name + << ", fork: " << hex_number(dataForkLba) << endl; + + NFS_FORK_STRUCT* fs_buf = new NFS_FORK_STRUCT(); + auto drive = sMountpointInterface.A(); + + rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, + rt_string_len("fs/newfs-packet")); + + NFS_FORK_STRUCT* fs_fork_data = nullptr; + + while (dataForkLba > kNeFSCatalogStartAddress) + { + drive.fPacket.fLba = dataForkLba; + drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); + drive.fPacket.fPacketContent = fs_buf; + + drive.fInput(&drive.fPacket); + + fs_fork_data = fs_buf; + + kcout << "ForkName: " << fs_fork_data->ForkName << endl; + kcout << "CatalogName: " << fs_fork_data->CatalogName << endl; + + if (StringBuilder::Equals(forkName, fs_fork_data->ForkName) && + StringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) + break; + + dataForkLba = fs_fork_data->NextSibling; + } + + if (dataForkLba < kNeFSCatalogStartAddress) + { + delete[] fs_buf; + return nullptr; + } + + return fs_fork_data; +} + +/***********************************************************************************/ +/// @brief Seek in the data fork. +/// @param catalog the catalog offset. +/// @param off where to seek. +/// @return if the seeking was successful. +/***********************************************************************************/ + +bool NeFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) +{ + if (!catalog) + { + ErrLocal() = kErrorFileNotFound; + return false; + } + + ErrLocal() = kErrorUnimplemented; + return false; +} + +/***********************************************************************************/ +/// @brief Tell where we are inside the data fork. +/// @param catalog +/// @return The position on the file. +/***********************************************************************************/ + +SizeT NeFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) +{ + if (!catalog) + { + ErrLocal() = kErrorFileNotFound; + return 0; + } + + ErrLocal() = kErrorUnimplemented; + return 0; +} + +namespace Kernel::Detail +{ + /***********************************************************************************/ + /// @brief Construct NeFS drives. + /***********************************************************************************/ + Boolean fs_init_newfs(Void) noexcept + { + kcout << "Creating drives...\r"; + + sMountpointInterface.A() = io_construct_main_drive(); + sMountpointInterface.B() = io_construct_drive(); + sMountpointInterface.C() = io_construct_drive(); + sMountpointInterface.D() = io_construct_drive(); + + kcout << "Testing A:\r"; + + sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); + + kcout << "Testing A: [ OK ]\r"; + + return true; + } +} // namespace Kernel::Detail + +#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/FS/NewFS.cxx b/dev/ZKA/Sources/FS/NewFS.cxx deleted file mode 100644 index 37b2a44c..00000000 --- a/dev/ZKA/Sources/FS/NewFS.cxx +++ /dev/null @@ -1,1048 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifdef __FSKIT_USE_NEWFS__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Kernel; - -#ifdef __ED__ -/***********************************************************************************/ -/** - Define those external symbols, to make the editor shutup -*/ -/***********************************************************************************/ - -/***********************************************************************************/ -/// @brief get sector count. -/***********************************************************************************/ -Kernel::SizeT drv_std_get_sector_count(); - -/***********************************************************************************/ -/// @brief get device size. -/***********************************************************************************/ -Kernel::SizeT drv_std_get_drv_size(); - -#endif - -///! BUGS: 0 - -/***********************************************************************************/ -/// This file implements the New File System. -/// New File System implements a B-Tree based algortihm. -/// \\ -/// \\Path1\\ \\ath2\\ -/// \\readme.rtf \\ListContents.pef \\readme.lnk <-- symlink. -/// \\Path1\\readme.rtf -/***********************************************************************************/ - -STATIC MountpointInterface sMountpointInterface; - -/***********************************************************************************/ -/// @brief Creates a new fork inside the New filesystem partition. -/// @param catalog it's catalog -/// @param theFork the fork itself. -/// @return the fork -/***********************************************************************************/ -_Output NFS_FORK_STRUCT* NewFSParser::CreateFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input NFS_FORK_STRUCT& theFork) -{ - if (catalog && theFork.ForkName[0] != 0) - { - Lba lba = (theFork.Kind == kNewFSDataForkKind) ? catalog->DataFork - : catalog->ResourceFork; - - kcout << "fork lba: " << hex_number(lba) << endl; - - if (lba <= kNewFSCatalogStartAddress) - return nullptr; - - auto drv = sMountpointInterface.A(); - - /// special treatment. - rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - NFS_FORK_STRUCT curFork{0}; - NFS_FORK_STRUCT prevFork{0}; - Lba lbaOfPreviousFork = lba; - - /// do not check for anything. Loop until we get what we want, that is a free fork zone. - while (true) - { - if (lba <= kNewFSCatalogStartAddress) - break; - - drv.fPacket.fLba = lba; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &curFork; - - drv.fInput(&drv.fPacket); - - if (curFork.NextSibling > kBadAddress) - { - kcout << "bad fork: " << hex_number(curFork.NextSibling) << endl; - break; - } - - kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; - - if (curFork.Flags == kNewFSFlagCreated) - { - kcout << "fork already exists.\r"; - - /// sanity check. - if (StringBuilder::Equals(curFork.ForkName, theFork.ForkName) && - StringBuilder::Equals(curFork.CatalogName, catalog->Name)) - return nullptr; - - kcout << "next fork: " << hex_number(curFork.NextSibling) << endl; - - lbaOfPreviousFork = lba; - lba = curFork.NextSibling; - - prevFork = curFork; - } - else - { - /// This is a check that we have, in order to link the previous fork - /// entry. - if (lba >= kNewFSCatalogStartAddress) - { - drv.fPacket.fLba = lbaOfPreviousFork; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &prevFork; - - prevFork.NextSibling = lba; - - /// write to disk. - drv.fOutput(&drv.fPacket); - } - - break; - } - } - - constexpr auto cForkPadding = - 4; /// this value gives us space for the data offset. - - theFork.Flags = kNewFSFlagCreated; - theFork.DataOffset = lba - sizeof(NFS_FORK_STRUCT) * cForkPadding; - theFork.PreviousSibling = lbaOfPreviousFork; - theFork.NextSibling = theFork.DataOffset - theFork.DataSize; - - drv.fPacket.fLba = lba; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = &theFork; - - drv.fOutput(&drv.fPacket); - - /// log what we have now. - kcout << "Wrote fork data at: " << hex_number(theFork.DataOffset) - << endl; - - kcout << "Wrote fork at: " << hex_number(lba) << endl; - - return &theFork; - } - - return nullptr; -} - -/***********************************************************************************/ -/// @brief Find fork inside New filesystem. -/// @param catalog the catalog. -/// @param name the fork name. -/// @return the fork. -/***********************************************************************************/ -_Output NFS_FORK_STRUCT* NewFSParser::FindFork(_Input NFS_CATALOG_STRUCT* catalog, - _Input const Char* name, - Boolean isDataFork) -{ - auto drv = sMountpointInterface.A(); - NFS_FORK_STRUCT* theFork = nullptr; - - Lba lba = isDataFork ? catalog->DataFork : catalog->ResourceFork; - - while (lba != 0) - { - drv.fPacket.fLba = lba; - drv.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drv.fPacket.fPacketContent = (VoidPtr)theFork; - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drv.fPacket.fPacketMime, 16); - - if (auto res = - fs_newfs_read(&sMountpointInterface, drv, this->fDriveIndex); - res) - { - switch (res) - { - case 1: - ErrLocal() = kErrorDiskReadOnly; - break; - case 2: - ErrLocal() = kErrorDiskIsFull; - break; - ErrLocal() = kErrorNoSuchDisk; - break; - - default: - break; - } - return nullptr; - } - - if (StringBuilder::Equals(theFork->ForkName, name)) - { - break; - } - - lba = theFork->NextSibling; - } - - return theFork; -} - -/***********************************************************************************/ -/// @brief Simpler factory to create a catalog (assumes you want to create a -/// file.) -/// @param name -/// @return catalog pointer. -/***********************************************************************************/ -_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name) -{ - return this->CreateCatalog(name, 0, kNewFSCatalogKindFile); -} - -/***********************************************************************************/ -/// @brief Creates a new catalog into the disk. -/// @param name the catalog name. -/// @param flags the flags of the catalog. -/// @param kind the catalog kind. -/// @return catalog pointer. -/***********************************************************************************/ -_Output NFS_CATALOG_STRUCT* NewFSParser::CreateCatalog(_Input const Char* name, - _Input const Int32& flags, - _Input const Int32& kind) -{ - kcout << "CreateCatalog(...)\r"; - - Lba out_lba = 0UL; - - kcout << "Checking for extension...\r"; - - /// a directory should have a slash in the end. - if (kind == kNewFSCatalogKindDir && - name[rt_string_len(name) - 1] != NewFilesystemHelper::Separator()) - return nullptr; - - /// a file shouldn't have a slash in the end. - if (kind != kNewFSCatalogKindDir && - name[rt_string_len(name) - 1] == NewFilesystemHelper::Separator()) - return nullptr; - - NFS_CATALOG_STRUCT* catalog_copy = this->FindCatalog(name, out_lba); - - if (catalog_copy) - { - kcout << "Catalog already exists: " << name << ".\r"; - ErrLocal() = kErrorFileExists; - - return catalog_copy; - } - - Char parentName[kNewFSNodeNameLen] = {0}; - - for (SizeT indexName = 0UL; indexName < rt_string_len(name); ++indexName) - { - parentName[indexName] = name[indexName]; - } - - if (*parentName == 0) - { - kcout << "Parent name is NUL.\r"; - ErrLocal() = kErrorFileNotFound; - return nullptr; - } - - /// Locate parent catalog, to then allocate right after it. - - for (SizeT indexFill = 0; indexFill < rt_string_len(name); ++indexFill) - { - parentName[indexFill] = name[indexFill]; - } - - SizeT indexReverseCopy = rt_string_len(parentName); - - // zero character it. - parentName[--indexReverseCopy] = 0; - - // mandatory / character, zero it. - parentName[--indexReverseCopy] = 0; - - while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) - { - parentName[indexReverseCopy] = 0; - --indexReverseCopy; - } - - NFS_CATALOG_STRUCT* catalog = this->FindCatalog(parentName, out_lba); - - auto drive = sMountpointInterface.A(); - - if (catalog && catalog->Kind == kNewFSCatalogKindFile) - { - kcout << "Parent name is file.\r"; - delete catalog; - return nullptr; - } - else if (!catalog) - { - Char sectorBufPartBlock[kNewFSSectorSz] = {0}; - - drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - constexpr auto cNewFSCatalogPadding = 4; - - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; - out_lba = partBlock->StartCatalog; - } - - constexpr SizeT cDefaultForkSize = kNewFSForkSize; - - NFS_CATALOG_STRUCT* catalogChild = new NFS_CATALOG_STRUCT(); - - Int32 flagsList = flags; - - catalogChild->ResourceForkSize = cDefaultForkSize; - catalogChild->DataForkSize = cDefaultForkSize; - - catalogChild->NextSibling = out_lba; - catalogChild->PrevSibling = out_lba; - catalogChild->Kind = kind; - catalogChild->Flags = kNewFSFlagCreated | flagsList; - - rt_copy_memory((VoidPtr)name, (VoidPtr)catalogChild->Name, - rt_string_len(name)); - - UInt16 catalogBuf[kNewFSSectorSz] = {0}; - - Lba start_free = out_lba; - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - drive.fPacket.fPacketContent = catalogBuf; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = start_free; - - drive.fInput(&drive.fPacket); - - NFS_CATALOG_STRUCT* nextSibling = (NFS_CATALOG_STRUCT*)catalogBuf; - - start_free = nextSibling->NextSibling; - - catalogChild->PrevSibling = out_lba; - - drive.fPacket.fLba = start_free; - drive.fInput(&drive.fPacket); - - while (drive.fPacket.fPacketGood) - { - nextSibling = reinterpret_cast(catalogBuf); - - if (start_free <= kNewFSRootCatalogStartAddress) - { - delete catalogChild; - delete catalog; - - return nullptr; - } - - // ========================== // - // Allocate catalog now... - // ========================== // - if ((nextSibling->Flags & kNewFSFlagCreated) == 0) - { - Char sectorBufPartBlock[kNewFSSectorSz] = {0}; - - drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - constexpr auto cNewFSCatalogPadding = 4; - - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)sectorBufPartBlock; - - if (partBlock->FreeCatalog < 1) - { - delete catalogChild; - return nullptr; - } - - catalogChild->DataFork = partBlock->DiskSize - start_free; - catalogChild->ResourceFork = catalogChild->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(parentName, nextSibling->Name)) - { - catalogChild->NextSibling = - start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); - } - - drive.fPacket.fPacketContent = catalogChild; - drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); - drive.fPacket.fLba = start_free; - - drive.fOutput(&drive.fPacket); - - // Get NewFS partition's block. - - drive.fPacket.fPacketContent = sectorBufPartBlock; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - partBlock->FreeSectors -= 1; - partBlock->CatalogCount += 1; - partBlock->FreeCatalog -= 1; - - drive.fOutput(&drive.fPacket); - - kcout << "Create new catalog, status: " - << hex_number(catalogChild->Flags) << endl; - kcout << "Create new catalog, name: " << catalogChild->Name - << endl; - - delete catalog; - return catalogChild; - } - else if ((nextSibling->Flags & kNewFSFlagCreated) && - StringBuilder::Equals(nextSibling->Name, name)) - { - return nextSibling; - } - - constexpr auto cNewFSCatalogPadding = 4; - - //// @note that's how we find the next catalog in the partition block. - start_free = start_free + (sizeof(NFS_CATALOG_STRUCT) * cNewFSCatalogPadding); - - drive.fPacket.fPacketContent = catalogBuf; - drive.fPacket.fPacketSize = kNewFSSectorSz; - drive.fPacket.fLba = start_free; - - drive.fInput(&drive.fPacket); - } - - delete catalog; - return nullptr; -} - -/// @brief Make a EPM+NewFS drive out of the disk. -/// @param drive The drive to write on. -/// @return If it was sucessful, see ErrLocal(). -bool NewFSParser::Format(_Input _Output DriveTrait* drive, _Input const Lba endLba, _Input const Int32 flags, const Char* part_name) -{ - if (*part_name == 0 || - endLba == 0) - return false; - - // verify disk. - drive->fVerify(&drive->fPacket); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive->fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - // if disk isn't good, then error out. - if (false == drive->fPacket.fPacketGood) - { - ErrLocal() = kErrorDiskIsCorrupted; - return false; - } - - Char fs_buf[kNewFSSectorSz] = {0}; - - Lba start = kNewFSRootCatalogStartAddress; - - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = start; - - drive->fInput(&drive->fPacket); - - if (flags & kNewFSPartitionTypeBoot) - { - // make it bootable when needed. - Char bufEpmHdr[kNewFSSectorSz] = {0}; - - BOOT_BLOCK_STRUCT* epmBoot = (BOOT_BLOCK_STRUCT*)bufEpmHdr; - - // EPM header. - - constexpr auto cFsName = "NewFS"; - constexpr auto cBlockName = "ZKA:"; - - rt_copy_memory(reinterpret_cast(const_cast(cFsName)), epmBoot->Fs, rt_string_len(cFsName)); - - epmBoot->FsVersion = kNewFSVersionInteger; - epmBoot->LbaStart = start; - epmBoot->SectorSz = kNewFSSectorSz; - - rt_copy_memory(reinterpret_cast(const_cast(cBlockName)), epmBoot->Name, rt_string_len(cBlockName)); - rt_copy_memory(reinterpret_cast(const_cast(kEPMMagic)), epmBoot->Magic, rt_string_len(kEPMMagic)); - - Lba outEpmLba = kEpmBase; - - Char buf[kNewFSSectorSz]; - - Lba prevStart = 0; - SizeT cnt = 0; - - while (drive->fPacket.fPacketGood) - { - drive->fPacket.fPacketContent = buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = outEpmLba; - - drive->fInput(&drive->fPacket); - - if (buf[0] == 0) - { - epmBoot->LbaStart = prevStart; - - if (epmBoot->LbaStart) - epmBoot->LbaStart = outEpmLba; - - epmBoot->LbaEnd = endLba; - epmBoot->NumBlocks = cnt; - - drive->fPacket.fPacketContent = bufEpmHdr; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = outEpmLba; - - drive->fOutput(&drive->fPacket); - - break; - } - else - { - prevStart = ((BOOT_BLOCK_STRUCT*)buf)->LbaStart + ((BOOT_BLOCK_STRUCT*)buf)->LbaEnd; - } - - outEpmLba += sizeof(BOOT_BLOCK_STRUCT); - ++cnt; - } - } - - // disk isnt faulty and data has been fetched. - while (drive->fPacket.fPacketGood) - { - NFS_ROOT_PARTITION_BLOCK* partBlock = (NFS_ROOT_PARTITION_BLOCK*)fs_buf; - - // check for an empty partition here. - if (partBlock->PartitionName[0] == 0 && - rt_string_cmp(partBlock->Ident, kNewFSIdent, kNewFSIdentLen)) - { - // partition is free and valid. - - partBlock->Version = kNewFSVersionInteger; - - const auto cUntitledHD = part_name; - - rt_copy_memory((VoidPtr)kNewFSIdent, (VoidPtr)partBlock->Ident, - kNewFSIdentLen); - - rt_copy_memory((VoidPtr)cUntitledHD, (VoidPtr)partBlock->PartitionName, - rt_string_len(cUntitledHD)); - - SizeT catalogCount = 0UL; - - SizeT sectorCount = drv_std_get_sector_count(); - SizeT diskSize = drv_std_get_drv_size(); - - partBlock->Kind = kNewFSPartitionTypeStandard; - partBlock->StartCatalog = kNewFSCatalogStartAddress; - partBlock->Flags = kNewFSPartitionTypeStandard; - partBlock->CatalogCount = sectorCount / sizeof(NFS_CATALOG_STRUCT); - partBlock->SectorCount = sectorCount; - partBlock->DiskSize = diskSize; - partBlock->FreeCatalog = sectorCount / sizeof(NFS_CATALOG_STRUCT); - - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive->fOutput(&drive->fPacket); - - kcout << "drive kind: " << drive->fDriveKind() << endl; - - kcout << "partition name: " << partBlock->PartitionName << endl; - kcout << "start: " << hex_number(partBlock->StartCatalog) << endl; - kcout << "number of catalogs: " << hex_number(partBlock->CatalogCount) << endl; - kcout << "free catalog: " << hex_number(partBlock->FreeCatalog) << endl; - kcout << "free sectors: " << hex_number(partBlock->FreeSectors) << endl; - kcout << "sector size: " << hex_number(partBlock->SectorSize) << endl; - - // write the root catalog. - this->CreateCatalog(kNewFSRoot, 0, kNewFSCatalogKindDir); - - return true; - } - - kcout << "partition block already exists.\r"; - - start += partBlock->DiskSize; - - drive->fPacket.fPacketContent = fs_buf; - drive->fPacket.fPacketSize = kNewFSSectorSz; - drive->fPacket.fLba = start; - - drive->fInput(&drive->fPacket); - } - - return false; -} - -/// @brief Writes the data fork into a specific catalog. -/// @param catalog the catalog itself -/// @param data the data. -/// @return if the catalog w rote the contents successfully. -bool NewFSParser::WriteCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, Bool isRsrcFork, _Input VoidPtr data, _Input SizeT sizeOfData, _Input const Char* forkName) -{ - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - auto startFork = (!isRsrcFork) ? catalog->DataFork - : catalog->ResourceFork; - - NFS_FORK_STRUCT* forkDataIn = new NFS_FORK_STRUCT(); - NFS_FORK_STRUCT prevFork{}; - - // sanity check of the fork position as the condition to run the loop. - while (startFork >= kNewFSCatalogStartAddress) - { - drive.fPacket.fPacketContent = forkDataIn; - drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fLba = startFork; - - drive.fInput(&drive.fPacket); - - // check the fork, if it's position is valid. - if (forkDataIn->DataOffset <= kNewFSCatalogStartAddress) - { - ErrLocal() = kErrorDiskIsCorrupted; - - kcout << "Invalid fork offset.\r"; - - return false; - } - - if (forkDataIn->Flags != kNewFSFlagUnallocated && - forkDataIn->Flags != kNewFSFlagDeleted && - StringBuilder::Equals(forkDataIn->ForkName, forkName) && - StringBuilder::Equals(forkDataIn->CatalogName, catalog->Name)) - { - // ===================================================== // - // Store size of blob now. - // ===================================================== // - - if (forkDataIn->DataSize < sizeOfData && - forkDataIn->DataSize < 1) - { - startFork = forkDataIn->NextSibling; - continue; - } - - forkDataIn->Flags = kNewFSFlagCreated; - forkDataIn->DataOffset = startFork + sizeof(NFS_FORK_STRUCT); - forkDataIn->DataSize = sizeOfData; - - drive.fPacket.fPacketContent = data; - drive.fPacket.fPacketSize = sizeOfData; - drive.fPacket.fLba = startFork + sizeof(NFS_FORK_STRUCT); - - kcout << "data offset: " << hex_number(forkDataIn->DataOffset) << endl; - - drive.fOutput(&drive.fPacket); - - drive.fPacket.fPacketContent = &forkDataIn; - drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fLba = startFork; - - drive.fOutput(&drive.fPacket); - - kcout << "wrote fork at offset: " << hex_number(forkDataIn->DataOffset) << endl; - - delete catalog; - - return true; - } - - // stumble upon a fork, store it. - - prevFork = *forkDataIn; - - startFork = forkDataIn->NextSibling; - } - - return false; -} - -/// @brief -/// @param catalogName the catalog name. -/// @return the newly found catalog. -_Output NFS_CATALOG_STRUCT* NewFSParser::FindCatalog(_Input const Char* catalogName, - Lba& out_lba) -{ - kcout << "start finding catalog...\r"; - - NFS_ROOT_PARTITION_BLOCK fs_buf{0}; - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - drive.fPacket.fPacketContent = &fs_buf; - drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - - drive.fInput(&drive.fPacket); - - NFS_ROOT_PARTITION_BLOCK* part = (NFS_ROOT_PARTITION_BLOCK*)&fs_buf; - - auto startCatalogList = part->StartCatalog; - const auto cCtartCatalogList = startCatalogList; - - auto localSearchFirst = false; - - NFS_CATALOG_STRUCT catalogBuf{0}; - - drive.fPacket.fLba = startCatalogList; - drive.fPacket.fPacketContent = &catalogBuf; - drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); - - drive.fInput(&drive.fPacket); - - if (!StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) - { - Char parentName[kNewFSNodeNameLen] = {0}; - - for (SizeT indexFill = 0; indexFill < rt_string_len(catalogName); ++indexFill) - { - parentName[indexFill] = catalogName[indexFill]; - } - - SizeT indexReverseCopy = rt_string_len(parentName); - - // zero character. - parentName[--indexReverseCopy] = 0; - - // mandatory '/' character. - parentName[--indexReverseCopy] = 0; - - while (parentName[indexReverseCopy] != NewFilesystemHelper::Separator()) - { - parentName[indexReverseCopy] = 0; - --indexReverseCopy; - } - - NFS_CATALOG_STRUCT* parentCatalog = this->FindCatalog(parentName, out_lba); - - if (parentCatalog && - !StringBuilder::Equals(parentName, NewFilesystemHelper::Root())) - { - startCatalogList = parentCatalog->NextSibling; - delete parentCatalog; - - localSearchFirst = true; - } - else if (parentCatalog) - { - delete parentCatalog; - } - } - - kcout << "fetching catalog...\r"; - -NewFSSearchThroughCatalogList: - while (drive.fPacket.fPacketGood) - { - drive.fPacket.fLba = startCatalogList; - drive.fPacket.fPacketContent = &catalogBuf; - drive.fPacket.fPacketSize = sizeof(NFS_CATALOG_STRUCT); - - drive.fInput(&drive.fPacket); - - NFS_CATALOG_STRUCT* catalog = (NFS_CATALOG_STRUCT*)&catalogBuf; - - if (StringBuilder::Equals(catalogName, catalog->Name)) - { - /// ignore unallocated catalog, break - if (!(catalog->Flags & kNewFSFlagCreated)) - { - goto NewFSContinueSearch; - } - - 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: " << catalog->Name << endl; - - out_lba = startCatalogList; - return catalogPtr; - } - - NewFSContinueSearch: - startCatalogList = catalog->NextSibling; - - if (startCatalogList <= kNewFSRootCatalogStartAddress) - break; - } - - if (localSearchFirst) - { - localSearchFirst = false; - startCatalogList = cCtartCatalogList; - - goto NewFSSearchThroughCatalogList; - } - - out_lba = 0UL; - return nullptr; -} - -/// @brief Get catalog from filesystem. -/// @param name the catalog's name/ -/// @return -_Output NFS_CATALOG_STRUCT* NewFSParser::GetCatalog(_Input const Char* name) -{ - Lba unused = 0; - return this->FindCatalog(name, unused); -} - -/// @brief Closes a catalog, (frees it). -/// @param catalog the catalog to close. -/// @return -Boolean NewFSParser::CloseCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog) -{ - if (!catalog) - return false; - - delete catalog; - catalog = nullptr; - - return true; -} - -/// @brief Mark catalog as removed. -/// @param catalog The catalog structure. -/// @return if the catalog was removed or not. -Boolean NewFSParser::RemoveCatalog(_Input const Char* catalogName) -{ - if (!catalogName || - StringBuilder::Equals(catalogName, NewFilesystemHelper::Root())) - { - ErrLocal() = kErrorInternal; - return false; - } - - Lba out_lba = 0; - auto catalog = this->FindCatalog(catalogName, out_lba); - - if (out_lba >= kNewFSCatalogStartAddress || - catalog->Flags == kNewFSFlagCreated) - { - catalog->Flags = kNewFSFlagDeleted; - - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - drive.fPacket.fLba = out_lba; // the catalog position. - drive.fPacket.fPacketSize = - sizeof(NFS_CATALOG_STRUCT); // size of catalog. roughly the sector size. - drive.fPacket.fPacketContent = catalog; // the catalog itself. - - drive.fOutput(&drive.fPacket); // send packet. - - Char partitionBlockBuf[sizeof(NFS_ROOT_PARTITION_BLOCK)] = {0}; - - drive.fPacket.fLba = kNewFSRootCatalogStartAddress; - drive.fPacket.fPacketContent = partitionBlockBuf; - drive.fPacket.fPacketSize = sizeof(NFS_ROOT_PARTITION_BLOCK); - - drive.fInput(&drive.fPacket); - - NFS_ROOT_PARTITION_BLOCK* partBlock = - reinterpret_cast(partitionBlockBuf); - - --partBlock->CatalogCount; - ++partBlock->FreeSectors; - - drive.fOutput(&drive.fPacket); - - return true; - } - - delete catalog; - return false; -} - -/// ***************************************************************** /// -/// Reading,Seek,Tell are unimplemented on catalogs, refer to forks I/O instead. -/// ***************************************************************** /// - -/***********************************************************************************/ -/// @brief Read the catalog data fork. -/// @param catalog -/// @param dataSz -/// @return -/***********************************************************************************/ - -VoidPtr NewFSParser::ReadCatalog(_Input _Output NFS_CATALOG_STRUCT* catalog, - _Input Bool isRsrcFork, - _Input SizeT dataSz, - _Input const Char* forkName) -{ - if (!catalog) - { - ErrLocal() = kErrorFileNotFound; - return nullptr; - } - - constexpr auto cNewFSCatalogPadding = 4; - - Lba dataForkLba = (!isRsrcFork) ? catalog->DataFork : catalog->ResourceFork; - Size dataForkSize = (!isRsrcFork) ? catalog->DataForkSize : catalog->ResourceForkSize; - - kcout << "catalog " << catalog->Name - << ", fork: " << hex_number(dataForkLba) << endl; - - NFS_FORK_STRUCT* fs_buf = new NFS_FORK_STRUCT(); - auto drive = sMountpointInterface.A(); - - rt_copy_memory((VoidPtr) "fs/newfs-packet", drive.fPacket.fPacketMime, - rt_string_len("fs/newfs-packet")); - - NFS_FORK_STRUCT* fs_fork_data = nullptr; - - while (dataForkLba > kNewFSCatalogStartAddress) - { - drive.fPacket.fLba = dataForkLba; - drive.fPacket.fPacketSize = sizeof(NFS_FORK_STRUCT); - drive.fPacket.fPacketContent = fs_buf; - - drive.fInput(&drive.fPacket); - - fs_fork_data = fs_buf; - - kcout << "ForkName: " << fs_fork_data->ForkName << endl; - kcout << "CatalogName: " << fs_fork_data->CatalogName << endl; - - if (StringBuilder::Equals(forkName, fs_fork_data->ForkName) && - StringBuilder::Equals(catalog->Name, fs_fork_data->CatalogName)) - break; - - dataForkLba = fs_fork_data->NextSibling; - } - - if (dataForkLba < kNewFSCatalogStartAddress) - { - delete[] fs_buf; - return nullptr; - } - - return fs_fork_data; -} - -/***********************************************************************************/ -/// @brief Seek in the data fork. -/// @param catalog the catalog offset. -/// @param off where to seek. -/// @return if the seeking was successful. -/***********************************************************************************/ - -bool NewFSParser::Seek(_Input _Output NFS_CATALOG_STRUCT* catalog, SizeT off) -{ - if (!catalog) - { - ErrLocal() = kErrorFileNotFound; - return false; - } - - ErrLocal() = kErrorUnimplemented; - return false; -} - -/***********************************************************************************/ -/// @brief Tell where we are inside the data fork. -/// @param catalog -/// @return The position on the file. -/***********************************************************************************/ - -SizeT NewFSParser::Tell(_Input _Output NFS_CATALOG_STRUCT* catalog) -{ - if (!catalog) - { - ErrLocal() = kErrorFileNotFound; - return 0; - } - - ErrLocal() = kErrorUnimplemented; - return 0; -} - -namespace Kernel::Detail -{ - /***********************************************************************************/ - /// @brief Construct NewFS drives. - /***********************************************************************************/ - Boolean fs_init_newfs(Void) noexcept - { - kcout << "Creating drives...\r"; - - sMountpointInterface.A() = io_construct_main_drive(); - sMountpointInterface.B() = io_construct_drive(); - sMountpointInterface.C() = io_construct_drive(); - sMountpointInterface.D() = io_construct_drive(); - - kcout << "Testing A:\r"; - - sMountpointInterface.A().fVerify(&sMountpointInterface.A().fPacket); - - kcout << "Testing A: [ OK ]\r"; - - return true; - } -} // namespace Kernel::Detail - -#endif // ifdef __FSKIT_USE_NEWFS__ diff --git a/dev/ZKA/Sources/FileMgr.cxx b/dev/ZKA/Sources/FileMgr.cxx index 270c13f2..cbd2a4f4 100644 --- a/dev/ZKA/Sources/FileMgr.cxx +++ b/dev/ZKA/Sources/FileMgr.cxx @@ -80,7 +80,7 @@ namespace Kernel if (!size) return; - constexpr auto cDataForkName = kNewFSDataFork; + constexpr auto cDataForkName = kNeFSDataFork; this->Write(cDataForkName, node, data, flags, size); } @@ -96,7 +96,7 @@ namespace Kernel if (!size) return nullptr; - constexpr auto cDataForkName = kNewFSDataFork; + constexpr auto cDataForkName = kNeFSDataFork; return this->Read(cDataForkName, node, flags, size); } @@ -107,7 +107,7 @@ namespace Kernel _Input SizeT size) { if (!size || - size > kNewFSForkSize) + size > kNeFSForkSize) return; if (!data) @@ -115,7 +115,7 @@ namespace Kernel ZKA_UNUSED(flags); - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) fImpl->WriteCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), data, size, name); } @@ -125,7 +125,7 @@ namespace Kernel _Input Int32 flags, _Input SizeT sz) { - if (sz > kNewFSForkSize) + if (sz > kNeFSForkSize) return nullptr; if (!sz) @@ -133,7 +133,7 @@ namespace Kernel ZKA_UNUSED(flags); - if ((reinterpret_cast(node))->Kind == kNewFSCatalogKindFile) + if ((reinterpret_cast(node))->Kind == kNeFSCatalogKindFile) return fImpl->ReadCatalog(reinterpret_cast(node), (flags & cFileFlagRsrc ? true : false), sz, name); @@ -182,7 +182,7 @@ namespace Kernel /// @brief Returns the filesystem parser. /// @return the Filesystem parser class. - _Output NewFSParser* NewFilesystemMgr::GetParser() noexcept + _Output NeFSParser* NewFilesystemMgr::GetParser() noexcept { return fImpl; } diff --git a/dev/ZKA/Sources/NewFS+FileMgr.cxx b/dev/ZKA/Sources/NewFS+FileMgr.cxx index 1ffa774a..29beda45 100644 --- a/dev/ZKA/Sources/NewFS+FileMgr.cxx +++ b/dev/ZKA/Sources/NewFS+FileMgr.cxx @@ -9,7 +9,7 @@ #ifdef __FSKIT_USE_NEWFS__ -/// @brief NewFS File manager. +/// @brief NeFS File manager. /// BUGS: 0 namespace Kernel @@ -18,7 +18,7 @@ namespace Kernel NewFilesystemMgr::NewFilesystemMgr() { MUST_PASS(Detail::fs_init_newfs()); - fImpl = new NewFSParser(); + fImpl = new NeFSParser(); MUST_PASS(fImpl); kcout << "We are done here... (NewFilesystemMgr).\r"; @@ -58,7 +58,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NewFilesystemMgr::CreateDirectory(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindDir)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } /// @brief Creates a node with is a alias. @@ -66,7 +66,7 @@ namespace Kernel /// @return The Node pointer. NodePtr NewFilesystemMgr::CreateAlias(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindAlias)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } /// @brief Creates a node with is a page file. @@ -74,35 +74,35 @@ namespace Kernel /// @return The Node pointer. NodePtr NewFilesystemMgr::CreateSwapFile(const Char* path) { - return node_cast(fImpl->CreateCatalog(path, 0, kNewFSCatalogKindPage)); + return node_cast(fImpl->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. /// @return const Char* NewFilesystemHelper::Root() { - return kNewFSRoot; + return kNeFSRoot; } /// @brief Gets the up-dir directory. /// @return const Char* NewFilesystemHelper::UpDir() { - return kNewFSUpDir; + return kNeFSUpDir; } /// @brief Gets the separator character. /// @return const Char NewFilesystemHelper::Separator() { - return kNewFSSeparator; + return kNeFSSeparator; } /// @brief Gets the metafile character. /// @return const Char NewFilesystemHelper::MetaFile() { - return kNewFSMetaFilePrefix; + return kNeFSMetaFilePrefix; } } // namespace Kernel diff --git a/dev/ZKA/Sources/NewFS+IO.cxx b/dev/ZKA/Sources/NewFS+IO.cxx index e1a6ac95..7917c1bb 100644 --- a/dev/ZKA/Sources/NewFS+IO.cxx +++ b/dev/ZKA/Sources/NewFS+IO.cxx @@ -9,7 +9,7 @@ /************************************************************* * - * File: NewFS+IO.cxx + * File: NeFS+IO.cxx * Purpose: Filesystem to mountpoint interface. * Date: 3/26/24 * @@ -42,19 +42,19 @@ Int32 fs_newfs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvInd switch (DrvIndex) { - case kNewFSSubDriveA: { + case kNeFSSubDriveA: { NEWFS_READ(A, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveB: { + case kNeFSSubDriveB: { NEWFS_READ(B, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveC: { + case kNeFSSubDriveC: { NEWFS_READ(C, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveD: { + case kNeFSSubDriveD: { NEWFS_READ(D, DrvTrait.fPacket, Mnt); break; } @@ -77,19 +77,19 @@ Int32 fs_newfs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIn switch (DrvIndex) { - case kNewFSSubDriveA: { + case kNeFSSubDriveA: { NEWFS_WRITE(A, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveB: { + case kNeFSSubDriveB: { NEWFS_WRITE(B, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveC: { + case kNeFSSubDriveC: { NEWFS_WRITE(C, DrvTrait.fPacket, Mnt); break; } - case kNewFSSubDriveD: { + case kNeFSSubDriveD: { NEWFS_WRITE(D, DrvTrait.fPacket, Mnt); break; } diff --git a/dev/ZKA/Sources/NewFS+Journal.cxx b/dev/ZKA/Sources/NewFS+Journal.cxx index 2f63cc9a..f8d82fcd 100644 --- a/dev/ZKA/Sources/NewFS+Journal.cxx +++ b/dev/ZKA/Sources/NewFS+Journal.cxx @@ -10,8 +10,8 @@ #ifdef __FSKIT_USE_NEWFS__ ///! BUGS: 0 -///! @file NewFS+Journal.cxx -///! @brief Journaling for NewFS. +///! @file NeFS+Journal.cxx +///! @brief Journaling for NeFS. namespace Kernel::Journal { -- cgit v1.2.3