From fb790b07aeba8e22e4190cf3e1834d11ecde6c96 Mon Sep 17 00:00:00 2001 From: Amlal Date: Fri, 25 Apr 2025 13:08:33 +0200 Subject: dev: better .clang-format, ran format command. Signed-off-by: Amlal --- dev/kernel/src/FS/HeFS+FileMgr.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dev/kernel/src/FS/HeFS+FileMgr.cc') diff --git a/dev/kernel/src/FS/HeFS+FileMgr.cc b/dev/kernel/src/FS/HeFS+FileMgr.cc index e6719e1b..e0b92a8d 100644 --- a/dev/kernel/src/FS/HeFS+FileMgr.cc +++ b/dev/kernel/src/FS/HeFS+FileMgr.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -10,5 +10,5 @@ #include #include -#endif // ifdef __FSKIT_INCLUDES_HEFS__ -#endif // ifndef __NE_MINIMAL_OS__ +#endif // ifdef __FSKIT_INCLUDES_HEFS__ +#endif // ifndef __NE_MINIMAL_OS__ -- cgit v1.2.3 From 11dd858e1d9da71a182bc707ca3a481dafbccbe4 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sun, 27 Apr 2025 19:51:43 +0200 Subject: dev, kernel: refactor and improve parts of the kernel, related to I/O Signed-off-by: Amlal --- dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 10 ++-- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 4 +- dev/kernel/KernelKit/FileMgr.h | 10 ++-- dev/kernel/StorageKit/ATA.h | 4 +- dev/kernel/StorageKit/DMA.h | 71 ---------------------- dev/kernel/StorageKit/DmaPool.h | 80 +++++++++++++++++++++++++ dev/kernel/StorageKit/StorageKit.h | 2 +- dev/kernel/SwapKit/DiskSwap.h | 2 +- dev/kernel/src/FS/HeFS+FileMgr.cc | 4 +- dev/kernel/src/FS/NeFS+FileMgr.cc | 14 ++--- 10 files changed, 106 insertions(+), 95 deletions(-) delete mode 100644 dev/kernel/StorageKit/DMA.h create mode 100644 dev/kernel/StorageKit/DmaPool.h (limited to 'dev/kernel/src/FS/HeFS+FileMgr.cc') diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 1591fa56..deea30e1 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -151,10 +151,10 @@ STATIC Void drv_std_input_output_ahci(UInt64 lba, UInt8* buffer, SizeT sector_sz (volatile HbaCmdTbl*) (((UInt64) command_header->Ctbau << 32) | command_header->Ctba); rt_set_memory((VoidPtr) command_table, 0, sizeof(HbaCmdTbl)); - VoidPtr ptr = Kernel::rtl_dma_alloc(size_buffer, 4096); + VoidPtr ptr = rtl_dma_alloc(size_buffer, 4096); if (Write) { - Kernel::rt_copy_memory(buffer, ptr, size_buffer); + rt_copy_memory(buffer, ptr, size_buffer); } // Build the PRDT @@ -293,7 +293,7 @@ STATIC BOOL ahci_enable_and_probe() { STATIC Bool drv_init_command_structures_ahci() { // Allocate 4KiB for Command List (32 headers) - VoidPtr clb_mem = Kernel::rtl_dma_alloc(4096, 1024); + VoidPtr clb_mem = rtl_dma_alloc(4096, 1024); if (!clb_mem) { kout << "Failed to allocate CLB memory!\r"; return NO; @@ -312,7 +312,7 @@ STATIC Bool drv_init_command_structures_ahci() { for (Int32 i = 0; i < 32; ++i) { // Allocate 4KiB for Command Table - VoidPtr ct_mem = Kernel::rtl_dma_alloc(4096, 128); + VoidPtr ct_mem = rtl_dma_alloc(4096, 128); if (!ct_mem) { (Void)(kout << "Failed to allocate CTB memory for slot " << hex_number(i)); kout << "!\r"; diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index db9a1747..a024d2fe 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -173,7 +173,7 @@ namespace Kernel { /// @brief Initialize an PIO device (StorageKit function) /// @param is_master is the current PIO master? /// @return [io:master] for PIO device. -BOOL sk_init_pio_device(BOOL is_master, UInt16& io, UInt8& master) { +BOOL sk_init_ata_device(BOOL is_master, UInt16& io, UInt8& master) { return drv_pio_std_init(ATA_SECONDARY_IO, is_master, io, master); } @@ -225,7 +225,7 @@ namespace Detail { /// @brief Acquires a new PIO device with drv_index in mind. /// @param drv_index The drive index to assign. /// @return A wrapped device interface if successful, or error code. -ErrorOr sk_acquire_pio_device(Int32 drv_index) { +ErrorOr sk_acquire_ata_device(Int32 drv_index) { /// here we don't check if we probed ATA, since we'd need to grab IO after that. ATADeviceInterface device(Detail::sk_io_read_pio, Detail::sk_io_write_pio); diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 465d0afb..3dff61b0 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -21,6 +21,7 @@ #ifndef INC_FILEMGR_H #define INC_FILEMGR_H +//! Include filesystems that neoskrnl supports. #include #include #include @@ -35,7 +36,7 @@ #include /// @brief Filesystem manager, abstraction over mounted filesystem. -/// Works like the VFS or IFS. +/// Works like the VFS or IFS subsystem. #define kRestrictR "r" #define kRestrictRB "rb" @@ -45,7 +46,7 @@ #define kRestrictMax (5U) -#define node_cast(PTR) reinterpret_cast(PTR) +#define rtl_node_cast(PTR) reinterpret_cast(PTR) /** @note Refer to first enum. @@ -54,16 +55,17 @@ #define kFileMimeGeneric "ne-application-kind/all" /** @brief invalid position. (n-pos) */ -#define kNPos (SizeT)(-1); +#define kFileMgrNPos (~0UL) namespace Kernel { enum { + kFileIOInvalid = 0, kFileWriteAll = 100, kFileReadAll = 101, kFileReadChunk = 102, kFileWriteChunk = 103, kFileIOCnt = (kFileWriteChunk - kFileWriteAll) + 1, - // file flags + // File flags (HFS+, NeFS specific) kFileFlagRsrc = 104, kFileFlagData = 105, }; diff --git a/dev/kernel/StorageKit/ATA.h b/dev/kernel/StorageKit/ATA.h index d2950228..5887c579 100644 --- a/dev/kernel/StorageKit/ATA.h +++ b/dev/kernel/StorageKit/ATA.h @@ -47,10 +47,10 @@ class ATADeviceInterface : public IDeviceObject { /// @brief Initialize an PIO device (StorageKit function) /// @param is_master is the current PIO master? /// @return [io:master] for PIO device. -BOOL sk_init_pio_device(BOOL is_master, UInt16& io, UInt8& master); +BOOL sk_init_ata_device(BOOL is_master, UInt16& io, UInt8& master); /// @brief Acquires a new PIO device with drv_index in mind. /// @param drv_index The drive index to assign. /// @return A wrapped device interface if successful, or error code. -ErrorOr sk_acquire_pio_device(Int32 drv_index); +ErrorOr sk_acquire_ata_device(Int32 drv_index); } // namespace Kernel diff --git a/dev/kernel/StorageKit/DMA.h b/dev/kernel/StorageKit/DMA.h deleted file mode 100644 index c572ffa3..00000000 --- a/dev/kernel/StorageKit/DMA.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2025 Amlal El Mahrouss. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#pragma once - -#include -#include - -#ifdef __NE_AMD64__ -#define DMA_POOL_START (0x1000000) -#define DMA_POOL_SIZE (0x1000000) - -namespace Kernel { -inline UInt8* kDmaPoolPtr = (UInt8*) DMA_POOL_START; - -inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { - if (!size) { - return nullptr; - } - - UIntPtr addr = (UIntPtr) kDmaPoolPtr; - - addr = (addr + (align - 1)) & ~(align - 1); // Align up - - if (addr + size >= DMA_POOL_START + DMA_POOL_SIZE) { - kout << "DMA Pool exhausted!\r"; - - return nullptr; - } - - kDmaPoolPtr = (UInt8*) (addr + size); - return (VoidPtr) addr; -} - -inline Void rtl_dma_free(SizeT size) { - if (!size) return; - - kDmaPoolPtr = (UInt8*) (kDmaPoolPtr - size); -} - -inline Void rtl_dma_flush(Void* ptr, SizeT size_buffer) { - if (ptr > (Void*) (DMA_POOL_START + DMA_POOL_SIZE)) { - return; - } - - for (SizeT i = 0; i < size_buffer; ++i) { - asm volatile("clflush (%0)" : : "r"((UInt8*) ptr + i) : "memory"); - } - asm volatile("mfence" ::: "memory"); -} -} // namespace Kernel -#endif \ No newline at end of file diff --git a/dev/kernel/StorageKit/DmaPool.h b/dev/kernel/StorageKit/DmaPool.h new file mode 100644 index 00000000..9e59910a --- /dev/null +++ b/dev/kernel/StorageKit/DmaPool.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 Amlal El Mahrouss. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#include + +#ifdef __NE_AMD64__ +#define NE_DMA_POOL_START (0x1000000) +#define NE_DMA_POOL_SIZE (0x1000000) + +namespace Kernel { +/// @brief DMA pool base pointer, here we're sure that AHCI or whatever tricky standard sees it. +inline UInt8* kDmaPoolPtr = (UInt8*) NE_DMA_POOL_START; + +/// @brief allocate from the rtl_dma_alloc system. +/// @param size the size of the chunk to allocate. +/// @param align alignement of pointer. +inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { + if (!size) { + return nullptr; + } + + UIntPtr addr = (UIntPtr) kDmaPoolPtr; + + /// here we just align the address according to a `align` variable, i'd rather be a power of two really. + addr = (addr + (align - 1)) & ~(align - 1); + + if ((addr + size) >= (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) { + kout << "DMA Pool exhausted!\r"; + + return nullptr; + } + + kDmaPoolPtr = (UInt8*) (addr + size); + return (VoidPtr) addr; +} + +inline Void rtl_dma_free(SizeT size) { + if (!size) return; + + kDmaPoolPtr = (UInt8*) (kDmaPoolPtr - size); +} + +inline Void rtl_dma_flush(VoidPtr ptr, SizeT size_buffer) { + if (ptr > (Void*) (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) { + return; + } + + if (!ptr) { + return; + } + + for (SizeT i = 0; i < size_buffer; ++i) { + asm volatile("clflush (%0)" : : "r"((UInt8*) ptr + i) : "memory"); + } + + asm volatile("mfence" ::: "memory"); +} +} // namespace Kernel +#endif \ No newline at end of file diff --git a/dev/kernel/StorageKit/StorageKit.h b/dev/kernel/StorageKit/StorageKit.h index 9dbb014d..adb9f5dc 100644 --- a/dev/kernel/StorageKit/StorageKit.h +++ b/dev/kernel/StorageKit/StorageKit.h @@ -8,7 +8,7 @@ #define kDriveSectorSizeHDD (512U) #define kDriveSectorSizeSSD (512U) -#define kDriveSectorSizeOptical (2048) +#define kDriveSectorSizeOptical (2048U) namespace Kernel { template diff --git a/dev/kernel/SwapKit/DiskSwap.h b/dev/kernel/SwapKit/DiskSwap.h index b7e403aa..1832923f 100644 --- a/dev/kernel/SwapKit/DiskSwap.h +++ b/dev/kernel/SwapKit/DiskSwap.h @@ -68,5 +68,5 @@ typedef struct SWAP_DISK_HEADER { UInt64 fVirtualAddress; SizeT fBlobSz; UInt8 fBlob[1]; -} PACKED SWAP_DISK_HEADER; +} PACKED ALIGN(8) SWAP_DISK_HEADER; } // namespace Kernel diff --git a/dev/kernel/src/FS/HeFS+FileMgr.cc b/dev/kernel/src/FS/HeFS+FileMgr.cc index e0b92a8d..d7530d8f 100644 --- a/dev/kernel/src/FS/HeFS+FileMgr.cc +++ b/dev/kernel/src/FS/HeFS+FileMgr.cc @@ -10,5 +10,5 @@ #include #include -#endif // ifdef __FSKIT_INCLUDES_HEFS__ -#endif // ifndef __NE_MINIMAL_OS__ +#endif // ifdef __FSKIT_INCLUDES_HEFS__ +#endif // ifndef __NE_MINIMAL_OS__ diff --git a/dev/kernel/src/FS/NeFS+FileMgr.cc b/dev/kernel/src/FS/NeFS+FileMgr.cc index 56fc2dbb..c92d6727 100644 --- a/dev/kernel/src/FS/NeFS+FileMgr.cc +++ b/dev/kernel/src/FS/NeFS+FileMgr.cc @@ -10,7 +10,7 @@ #include #include -/// @brief NeFS File manager. +/// @brief NeFS File System Manager. /// BUGS: 0 namespace Kernel { @@ -42,28 +42,28 @@ bool NeFileSystemMgr::Remove(_Input const Char* path) { /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::Create(_Input const Char* path) { - return node_cast(mParser->CreateCatalog(path)); + return rtl_node_cast(mParser->CreateCatalog(path)); } /// @brief Creates a node with is a directory. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateDirectory(const Char* path) { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindDir)); } /// @brief Creates a node with is a alias. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateAlias(const Char* path) { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindAlias)); } /// @brief Creates a node with is a page file. /// @param path The filename path. /// @return The Node pointer. NodePtr NeFileSystemMgr::CreateSwapFile(const Char* path) { - return node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); + return rtl_node_cast(mParser->CreateCatalog(path, 0, kNeFSCatalogKindPage)); } /// @brief Gets the root directory. @@ -101,7 +101,7 @@ _Output NodePtr NeFileSystemMgr::Open(_Input const Char* path, _Input const Char auto catalog = mParser->GetCatalog(path); - return node_cast(catalog); + return rtl_node_cast(catalog); } /// @brief Writes to a catalog's fork. @@ -177,7 +177,7 @@ _Output Bool NeFileSystemMgr::Seek(NodePtr node, SizeT off) { /// @retval false always returns this, it is unimplemented. _Output SizeT NeFileSystemMgr::Tell(NodePtr node) { - if (!node) return kNPos; + if (!node) return kFileMgrNPos; return mParser->Tell(reinterpret_cast(node)); } -- cgit v1.2.3 From 2ead335ccc7afd8e1b2a6533e966c10f49fbdfe9 Mon Sep 17 00:00:00 2001 From: Amlal Date: Mon, 28 Apr 2025 09:06:35 +0200 Subject: dev, kernel: HeFS, Tooling: reworked the mkfs.hefs tool for the new filesystem. other/related: - Add new KPC codes. - Final refactors for HeFS's Format method. - Dma pool improvements. - Better standard disk I/O names. - Add mm_memory_fence function inside HalPagingMgrAMD64.cc Signed-off-by: Amlal --- dev/boot/BootKit/HW/SATA.h | 2 +- dev/kernel/FSKit/HeFS.h | 36 ++++++------- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 2 +- dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc | 16 ++++-- dev/kernel/HALKit/AMD64/Processor.h | 2 + dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 14 +++--- dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc | 6 +-- dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 4 +- dev/kernel/KernelKit/FileMgr.h | 2 +- dev/kernel/KernelKit/KPC.h | 6 ++- dev/kernel/NewKit/KString.h | 2 +- dev/kernel/StorageKit/DmaPool.h | 21 ++++++-- dev/kernel/src/DriveMgr.cc | 2 +- dev/kernel/src/FS/HeFS+FileMgr.cc | 4 +- dev/kernel/src/FS/HeFS.cc | 67 ++++++++++++++----------- dev/kernel/src/FS/NeFS.cc | 8 +-- dev/kernel/src/Utils.cc | 1 - dev/modules/AHCI/AHCI.h | 4 +- dev/modules/ATA/ATA.h | 4 +- dev/user/ProcessCodes.h | 1 + docs/tex/hefs.tex | 2 +- tooling/hefs.h | 67 +++++++++++-------------- tooling/mkfs.hefs.cc | 24 ++++----- 23 files changed, 161 insertions(+), 136 deletions(-) (limited to 'dev/kernel/src/FS/HeFS+FileMgr.cc') diff --git a/dev/boot/BootKit/HW/SATA.h b/dev/boot/BootKit/HW/SATA.h index 5c70c18c..8cf48ec7 100644 --- a/dev/boot/BootKit/HW/SATA.h +++ b/dev/boot/BootKit/HW/SATA.h @@ -28,7 +28,7 @@ class BootDeviceSATA final { operator bool() { return this->Leak().mDetected; } - SizeT GetDiskSize() { return drv_get_size(); } + SizeT GetDiskSize() { return drv_std_get_size(); } constexpr static auto kSectorSize = kAHCISectorSize; diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h index 90a2e274..515034fc 100644 --- a/dev/kernel/FSKit/HeFS.h +++ b/dev/kernel/FSKit/HeFS.h @@ -28,12 +28,6 @@ #define kHeFSDefaultVoluneName u8"HeFS Volume" -#define kHeFSDIMBootDir u8"boot-x/dir" -#define kHeFSMIMEBootFile u8"boot-x/file" - -#define kHeFSDIMSystemDir u8"system-x/dir" -#define kHeFSMIMESystemFile u8"system-x/file" - #define kHeFSSearchAllStr u8"*" struct HEFS_BOOT_NODE; @@ -101,19 +95,19 @@ typedef UInt64 ATime; /// @details Acts like a superblock, it contains the information about the filesystem. /// @note The boot node is the first block of the filesystem. struct PACKED HEFS_BOOT_NODE final { - Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. + Kernel::Char fMagic[kHeFSMagicLen]; /// @brief Magic number of the filesystem. Kernel::Utf8Char fVolName[kHeFSPartNameLen]; /// @brief Volume name. - Kernel::UInt32 fVersion; /// @brief Version of the filesystem. - Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem. - Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem. - Kernel::UInt64 fSectorSize; /// @brief Size of the sector. - Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node. - Kernel::UInt8 fDiskKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical - /// Drive, etc). - Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc). - Kernel::UInt64 fStartIND; /// @brief Start of the INode tree. - Kernel::UInt64 fEndIND; /// @brief End of the INode tree. - Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree. + Kernel::UInt32 fVersion; /// @brief Version of the filesystem. + Kernel::UInt64 fBadSectors; /// @brief Number of bad sectors in the filesystem. + Kernel::UInt64 fSectorCount; /// @brief Number of sectors in the filesystem. + Kernel::UInt64 fSectorSize; /// @brief Size of the sector. + Kernel::UInt32 fChecksum; /// @brief Checksum of the boot node. + Kernel::UInt8 fDiskKind; /// @brief Kind of the drive. (Hard Drive, Solid State Drive, Optical + /// Drive, etc). + Kernel::UInt8 fEncoding; /// @brief Encoding of the filesystem. (UTF-8, UTF-16, etc). + Kernel::UInt64 fStartIND; /// @brief Start of the INode tree. + Kernel::UInt64 fEndIND; /// @brief End of the INode tree. + Kernel::UInt64 fINDCount; /// @brief Number of leafs in the INode tree. Kernel::UInt64 fDiskSize; /// @brief Size of the disk. (Could be a virtual size, that is not the /// real size of the disk.) Kernel::UInt16 fDiskStatus; /// @brief Status of the disk. (locked, unlocked, error, invalid). @@ -124,7 +118,7 @@ struct PACKED HEFS_BOOT_NODE final { Kernel::UInt64 fReserved2; /// @brief Reserved for future use. Kernel::UInt64 fReserved3; /// @brief Reserved for future use. Kernel::UInt64 fReserved4; /// @brief Reserved for future use. - Kernel::Char fPad[272]; + Kernel::Char fPad[272]; }; inline constexpr Kernel::ATime kHeFSTimeInvalid = 0x0000000000000000; @@ -136,11 +130,11 @@ inline constexpr Kernel::ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF - 1; /// @note The index node is used to store the file information of a file. struct PACKED ALIGN(8) HEFS_INDEX_NODE final { Kernel::Utf8Char fName[kHeFSFileNameLen]; /// @brief File name. - Kernel::UInt32 fFlags; /// @brief File flags. + Kernel::UInt32 fFlags; /// @brief File flags. Kernel::UInt16 fKind; /// @brief File kind. (Regular, Directory, Block, Character, FIFO, Socket, /// Symbolic Link, Unknown). Kernel::UInt32 fSize; /// @brief File size. - Kernel::UInt32 fChecksum; /// @brief Checksum. + Kernel::UInt32 fChecksum; /// @brief Checksum. Kernel::Boolean fSymLink; /// @brief Is this a symbolic link? (if yes, the fName is the path to /// the file and blocklinkstart and end contains it's inodes.) diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index 66793aa6..a6bf09c7 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -142,4 +142,4 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) noexcept { ++team_index; } } -#endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ \ No newline at end of file +#endif // ifndef __NE_MODULAR_KERNEL_COMPONENTS__ \ No newline at end of file diff --git a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc index d7a8baf6..b6176e39 100644 --- a/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc +++ b/dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc @@ -93,6 +93,18 @@ UIntPtr hal_get_phys_address(VoidPtr virt) { return (pte->PhysicalAddress << 12) | (kVMAddr & 0xFFF); } +/***********************************************************************************/ +/// @brief clflush+mfence helper function. +/***********************************************************************************/ +EXTERN_C Int32 mm_memory_fence(VoidPtr virtual_address) { + if (!virtual_address || !hal_get_phys_address(virtual_address)) return kErrorInvalidData; + + asm volatile("clflush (%0)" : : "r"(virtual_address) : "memory"); + asm volatile("mfence" ::: "memory"); + + return kErrorSuccess; +} + /***********************************************************************************/ /// @brief Maps or allocates a page from virtual_address. /// @param virtual_address a valid virtual address. @@ -136,9 +148,7 @@ EXTERN_C Int32 mm_map_page(VoidPtr virtual_address, VoidPtr physical_address, UI hal_invl_tlb(virtual_address); - asm volatile("clflush (%0)" : : "r"(virtual_address) : "memory"); - - asm volatile("mfence" ::: "memory"); + mm_memory_fence(virtual_address); mmi_page_status(pte); diff --git a/dev/kernel/HALKit/AMD64/Processor.h b/dev/kernel/HALKit/AMD64/Processor.h index 1319277f..b57e9abf 100644 --- a/dev/kernel/HALKit/AMD64/Processor.h +++ b/dev/kernel/HALKit/AMD64/Processor.h @@ -272,6 +272,8 @@ EXTERN_C Void rt_cli(); EXTERN_C Void rt_sti(); EXTERN_C Void rt_cld(); EXTERN_C Void rt_std(); + +EXTERN_C Int32 mm_memory_fence(VoidPtr virtual_address); } // namespace Kernel::HAL EXTERN_C Kernel::Void idt_handle_generic(Kernel::UIntPtr rsp); diff --git a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc index 06c7781c..050826e3 100644 --- a/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc @@ -257,7 +257,7 @@ SizeT drv_get_sector_count_ahci() { /// @brief Get the drive size. /// @return Disk size in bytes. SizeT drv_get_size_ahci() { - return drv_get_sector_count() * kAHCISectorSize; + return drv_std_get_sector_count() * kAHCISectorSize; } /// @brief Enable Host and probe using the IDENTIFY command. @@ -426,16 +426,16 @@ Bool drv_std_detected_ahci() { /// //////////////////////////////////////////////////// Void drv_std_write(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) { - drv_std_input_output_ahci(lba / sector_sz, reinterpret_cast(buffer), sector_sz, - size_buffer); + drv_std_input_output_ahci(lba / sector_sz, reinterpret_cast(buffer), + sector_sz, size_buffer); } //////////////////////////////////////////////////// /// //////////////////////////////////////////////////// Void drv_std_read(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) { - drv_std_input_output_ahci(lba / sector_sz, reinterpret_cast(buffer), sector_sz, - size_buffer); + drv_std_input_output_ahci(lba / sector_sz, reinterpret_cast(buffer), + sector_sz, size_buffer); } //////////////////////////////////////////////////// @@ -459,7 +459,7 @@ Bool drv_std_detected(Void) { @return Sector size in bytes. */ //////////////////////////////////////////////////// -SizeT drv_get_sector_count() { +SizeT drv_std_get_sector_count() { return drv_get_sector_count_ahci(); } @@ -467,7 +467,7 @@ SizeT drv_get_sector_count() { /// @brief Get the drive size. /// @return Disk size in bytes. //////////////////////////////////////////////////// -SizeT drv_get_size() { +SizeT drv_std_get_size() { return drv_get_size_ahci(); } diff --git a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc index ca3e9ee4..4688203f 100644 --- a/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc @@ -183,15 +183,15 @@ Boolean drv_std_detected(Void) { @return Number of sectors, or zero. */ /***********************************************************************************/ -Kernel::SizeT drv_get_sector_count() { +Kernel::SizeT drv_std_get_sector_count() { return (kATAIdentifyData[61] << 16) | kATAIdentifyData[60]; } /***********************************************************************************/ /// @brief Get the size of the current drive. /***********************************************************************************/ -Kernel::SizeT drv_get_size() { - return (drv_get_sector_count()) * kATASectorSize; +Kernel::SizeT drv_std_get_size() { + return (drv_std_get_sector_count()) * kATASectorSize; } #endif /* ifdef __ATA_DMA__ */ diff --git a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc index a024d2fe..e57494a7 100644 --- a/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc +++ b/dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc @@ -245,11 +245,11 @@ Void drv_std_write(UInt64 Lba, UInt16 IO, UInt8 Master, Char* Buf, SizeT SectorS drv_pio_std_write(Lba, IO, Master, Buf, SectorSz, Size); } -SizeT drv_get_size() { +SizeT drv_std_get_size() { return drv_pio_get_size(); } -SizeT drv_get_sector_count() { +SizeT drv_std_get_sector_count() { return drv_pio_get_sector_count(); } diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h index 3dff61b0..2c4b2055 100644 --- a/dev/kernel/KernelKit/FileMgr.h +++ b/dev/kernel/KernelKit/FileMgr.h @@ -59,7 +59,7 @@ namespace Kernel { enum { - kFileIOInvalid = 0, + kFileIOInvalid = 0, kFileWriteAll = 100, kFileReadAll = 101, kFileReadChunk = 102, diff --git a/dev/kernel/KernelKit/KPC.h b/dev/kernel/KernelKit/KPC.h index e195d5ad..9de1f70f 100644 --- a/dev/kernel/KernelKit/KPC.h +++ b/dev/kernel/KernelKit/KPC.h @@ -61,7 +61,11 @@ inline constexpr KPCError kErrorInvalidCreds = 61; inline constexpr KPCError kErrorCDTrayBroken = 62; inline constexpr KPCError kErrorUnrecoverableDisk = 63; inline constexpr KPCError kErrorFileLocked = 64; -inline constexpr KPCError kErrorUnimplemented = -1; +inline constexpr KPCError kErrorDiskIsTooTiny = 65; +/// Kernel errors. +inline constexpr KPCError kErrorDmaExhausted = 101; +/// Generic errors. +inline constexpr KPCError kErrorUnimplemented = -1; /// @brief Does a system wide bug check. /// @param void no params are needed. diff --git a/dev/kernel/NewKit/KString.h b/dev/kernel/NewKit/KString.h index a9a58b7e..08f783c0 100644 --- a/dev/kernel/NewKit/KString.h +++ b/dev/kernel/NewKit/KString.h @@ -71,7 +71,7 @@ class KString final { }; class KStringBuilder final { -public: + public: static ErrorOr Construct(const Char* data); static const Char* FromBool(const Char* fmt, bool n); static const Char* Format(const Char* fmt, const Char* from); diff --git a/dev/kernel/StorageKit/DmaPool.h b/dev/kernel/StorageKit/DmaPool.h index 9e59910a..09851a0c 100644 --- a/dev/kernel/StorageKit/DmaPool.h +++ b/dev/kernel/StorageKit/DmaPool.h @@ -23,6 +23,7 @@ #pragma once #include +#include "NewKit/Defines.h" #ifdef __NE_AMD64__ #define NE_DMA_POOL_START (0x1000000) @@ -30,11 +31,14 @@ namespace Kernel { /// @brief DMA pool base pointer, here we're sure that AHCI or whatever tricky standard sees it. -inline UInt8* kDmaPoolPtr = (UInt8*) NE_DMA_POOL_START; +inline UInt8* kDmaPoolPtr = (UInt8*) NE_DMA_POOL_START; +inline const UInt8* kDmaPoolEnd = (UInt8*) (NE_DMA_POOL_START + NE_DMA_POOL_SIZE); +/***********************************************************************************/ /// @brief allocate from the rtl_dma_alloc system. /// @param size the size of the chunk to allocate. /// @param align alignement of pointer. +/***********************************************************************************/ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { if (!size) { return nullptr; @@ -42,11 +46,14 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { UIntPtr addr = (UIntPtr) kDmaPoolPtr; - /// here we just align the address according to a `align` variable, i'd rather be a power of two really. + /// here we just align the address according to a `align` variable, i'd rather be a power of two + /// really. addr = (addr + (align - 1)) & ~(align - 1); - if ((addr + size) >= (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) { - kout << "DMA Pool exhausted!\r"; + if ((addr + size) >= reinterpret_cast(kDmaPoolEnd)) { + kout << "DMA Pool is exhausted!\r"; + + err_global_get() = kErrorDmaExhausted; return nullptr; } @@ -55,12 +62,18 @@ inline VoidPtr rtl_dma_alloc(SizeT size, SizeT align) { return (VoidPtr) addr; } +/***********************************************************************************/ +/// @brief Free DMA pointer. +/***********************************************************************************/ inline Void rtl_dma_free(SizeT size) { if (!size) return; kDmaPoolPtr = (UInt8*) (kDmaPoolPtr - size); } +/***********************************************************************************/ +/// @brief Flush DMA pointer. +/***********************************************************************************/ inline Void rtl_dma_flush(VoidPtr ptr, SizeT size_buffer) { if (ptr > (Void*) (NE_DMA_POOL_START + NE_DMA_POOL_SIZE)) { return; diff --git a/dev/kernel/src/DriveMgr.cc b/dev/kernel/src/DriveMgr.cc index 46a5c588..b0f78ae4 100644 --- a/dev/kernel/src/DriveMgr.cc +++ b/dev/kernel/src/DriveMgr.cc @@ -193,7 +193,7 @@ namespace Detail { trait.fKind = kMassStorageDrive | kUnformattedDrive | kReadOnlyDrive; trait.fSectorSz = 512; - trait.fLbaEnd = drv_get_sector_count() - 1; + trait.fLbaEnd = drv_std_get_sector_count() - 1; trait.fLbaStart = 0x400; } } diff --git a/dev/kernel/src/FS/HeFS+FileMgr.cc b/dev/kernel/src/FS/HeFS+FileMgr.cc index d7530d8f..e0b92a8d 100644 --- a/dev/kernel/src/FS/HeFS+FileMgr.cc +++ b/dev/kernel/src/FS/HeFS+FileMgr.cc @@ -10,5 +10,5 @@ #include #include -#endif // ifdef __FSKIT_INCLUDES_HEFS__ -#endif // ifndef __NE_MINIMAL_OS__ +#endif // ifdef __FSKIT_INCLUDES_HEFS__ +#endif // ifndef __NE_MINIMAL_OS__ diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 37c2f8fb..f4776686 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -756,7 +756,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input NE_UNUSED(flags); NE_UNUSED(part_name); - // verify disk. + // Verify Disk. drive->fVerify(drive->fPacket); // if disk isn't good, then error out. @@ -765,6 +765,12 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input return false; } + if (drv_std_get_size() < kHeFSMinimumDiskSize) { + err_global_get() = kErrorDiskIsTooTiny; + kout << "Error: Failed to allocate memory for boot node.\r"; + return NO; + } + HEFS_BOOT_NODE* root = new HEFS_BOOT_NODE(); if (!root) { @@ -806,11 +812,11 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input rt_string_len("fs/hefs-packet")); urt_copy_memory((VoidPtr) part_name, root->fVolName, urt_string_len(part_name)); - rt_copy_memory((VoidPtr) kHeFSMagic, root->fMagic, sizeof(kHeFSMagic)); + rt_copy_memory((VoidPtr) kHeFSMagic, root->fMagic, kHeFSMagicLen - 1); root->fBadSectors = 0; - root->fSectorCount = drv_get_sector_count(); + root->fSectorCount = drv_std_get_sector_count(); root->fSectorSize = drive->fSectorSz; @@ -821,7 +827,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input root->fINDCount = 0; - root->fDiskSize = drv_get_size(); + root->fDiskSize = drv_std_get_size(); root->fDiskStatus = kHeFSStatusUnlocked; root->fDiskFlags = flags; @@ -844,6 +850,8 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input root->fVID = kHeFSInvalidVID; + root->fChecksum = ke_calculate_crc32((Char*) root, sizeof(HEFS_BOOT_NODE)); + drive->fPacket.fPacketLba = start; drive->fPacket.fPacketSize = sizeof(HEFS_BOOT_NODE); drive->fPacket.fPacketContent = root; @@ -861,52 +869,55 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input start = root->fStartIND; - constexpr SizeT kHeFSPreallocateCount = 16UL; + constexpr SizeT kHeFSPreallocateCount = 0x10UL; - HEFS_INDEX_NODE_DIRECTORY* index_node = new HEFS_INDEX_NODE_DIRECTORY(); + HEFS_INDEX_NODE_DIRECTORY* dir = new HEFS_INDEX_NODE_DIRECTORY(); // Pre-allocate index node directory tree for (SizeT i = 0; i < kHeFSPreallocateCount; ++i) { - rt_set_memory(index_node, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); - urt_copy_memory((VoidPtr) u8"?", index_node->fName, urt_string_len(u8"?")); + rt_set_memory(dir, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); + urt_copy_memory((VoidPtr) u8".deleted", dir->fName, urt_string_len(u8".deleted")); + + dir->fFlags = flags; + dir->fKind = kHeFSFileKindDirectory; - index_node->fFlags = flags; - index_node->fKind = kHeFSFileKindDirectory; + dir->fDeleted = kHeFSTimeMax; /// TODO: Add current time. - index_node->fDeleted = kHeFSTimeMax; + dir->fEntryCount = 0; - index_node->fEntryCount = 1; + dir->fIndexNodeChecksum = 0; - index_node->fChecksum = 0; - index_node->fIndexNodeChecksum = 0; + dir->fUID = 0; + dir->fGID = 0; + dir->fMode = 0; - index_node->fUID = 0; - index_node->fGID = 0; - index_node->fMode = 0; + dir->fColor = kHeFSBlack; + dir->fChild = 0; + dir->fParent = 0; + dir->fNext = 0; + dir->fPrev = 0; - index_node->fColor = kHeFSBlack; - index_node->fChild = 0; - index_node->fParent = 0; - index_node->fNext = 0; - index_node->fPrev = 0; + dir->fChecksum = ke_calculate_crc32((Char*) dir, sizeof(HEFS_INDEX_NODE_DIRECTORY)); drive->fPacket.fPacketLba = start; drive->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY); - drive->fPacket.fPacketContent = index_node; + drive->fPacket.fPacketContent = dir; start += sizeof(HEFS_INDEX_NODE_DIRECTORY); drive->fOutput(drive->fPacket); } - delete index_node; - index_node = nullptr; + delete dir; + dir = nullptr; delete root; root = nullptr; Detail::hefsi_balance_filesystem(root, drive); + err_global_get() = kErrorSuccess; + if (drive->fPacket.fPacketGood) return YES; err_global_get() = kErrorDiskIsCorrupted; @@ -953,7 +964,7 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu Detail::hefsi_balance_filesystem(root, drive); - auto dirent = new HEFS_INDEX_NODE_DIRECTORY(); + HEFS_INDEX_NODE_DIRECTORY* dirent = new HEFS_INDEX_NODE_DIRECTORY(); rt_set_memory(dirent, 0, sizeof(HEFS_INDEX_NODE_DIRECTORY)); @@ -969,7 +980,7 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu dirent->fFlags = flags; dirent->fChecksum = 0; - dirent->fEntryCount = 1; + dirent->fEntryCount = 0; if (Detail::hefs_allocate_index_directory_node(root, drive, dirent)) { delete dirent; @@ -1093,7 +1104,7 @@ Boolean fs_init_hefs(Void) noexcept { HeFileSystemParser parser; - parser.Format(&drv, kHeFSEncodingUTF16, kHeFSDefaultVoluneName); + parser.Format(&drv, kHeFSEncodingUTF8, kHeFSDefaultVoluneName); return YES; } diff --git a/dev/kernel/src/FS/NeFS.cc b/dev/kernel/src/FS/NeFS.cc index e68a4035..d572bffc 100644 --- a/dev/kernel/src/FS/NeFS.cc +++ b/dev/kernel/src/FS/NeFS.cc @@ -32,12 +32,12 @@ using namespace Kernel; /***********************************************************************************/ /// @brief get sector count. /***********************************************************************************/ -Kernel::SizeT drv_get_sector_count(); +Kernel::SizeT drv_std_get_sector_count(); /***********************************************************************************/ /// @brief get device size. /***********************************************************************************/ -Kernel::SizeT drv_get_size(); +Kernel::SizeT drv_std_get_size(); #endif @@ -455,8 +455,8 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const I rt_copy_memory((VoidPtr) kNeFSUntitledHD, (VoidPtr) part_block->PartitionName, rt_string_len(kNeFSUntitledHD)); - SizeT sectorCount = drv_get_sector_count(); - SizeT diskSize = drv_get_size(); + SizeT sectorCount = drv_std_get_sector_count(); + SizeT diskSize = drv_std_get_size(); part_block->Version = kNeFSVersionInteger; diff --git a/dev/kernel/src/Utils.cc b/dev/kernel/src/Utils.cc index ea0ff7a7..4f47849b 100644 --- a/dev/kernel/src/Utils.cc +++ b/dev/kernel/src/Utils.cc @@ -193,4 +193,3 @@ EXTERN_C void* memcpy(void* dst, const void* src, long long unsigned int len) { EXTERN_C Kernel::Int32 strcmp(const char* dst, const char* src) { return Kernel::rt_string_cmp(dst, src, Kernel::rt_string_len(dst)); } - diff --git a/dev/modules/AHCI/AHCI.h b/dev/modules/AHCI/AHCI.h index 98fb3d60..7303e8c5 100644 --- a/dev/modules/AHCI/AHCI.h +++ b/dev/modules/AHCI/AHCI.h @@ -349,10 +349,10 @@ Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::Char* buf, Kernel::SizeT Kernel::SizeT buf_sz); /// @brief Gets the sector count from AHCI disk. -Kernel::SizeT drv_get_sector_count(); +Kernel::SizeT drv_std_get_sector_count(); /// @brief Gets the AHCI disk size. -Kernel::SizeT drv_get_size(); +Kernel::SizeT drv_std_get_size(); /// @brief Checks if the drive has completed the command. Kernel::Bool drv_is_ready(void); diff --git a/dev/modules/ATA/ATA.h b/dev/modules/ATA/ATA.h index bd21d106..e7cf200f 100644 --- a/dev/modules/ATA/ATA.h +++ b/dev/modules/ATA/ATA.h @@ -149,9 +149,9 @@ Kernel::Void drv_std_write(Kernel::UInt64 lba, Kernel::UInt16 io, Kernel::UInt8 Kernel::Char* buf, Kernel::SizeT sec_sz, Kernel::SizeT buf_sz); /// @brief get sector count. -Kernel::SizeT drv_get_sector_count(); +Kernel::SizeT drv_std_get_sector_count(); /// @brief get device size. -Kernel::SizeT drv_get_size(); +Kernel::SizeT drv_std_get_size(); #endif // ifdef __NEOSKRNL__ \ No newline at end of file diff --git a/dev/user/ProcessCodes.h b/dev/user/ProcessCodes.h index 74b50c68..90457944 100644 --- a/dev/user/ProcessCodes.h +++ b/dev/user/ProcessCodes.h @@ -51,6 +51,7 @@ inline constexpr ErrRef kErrorInvalidCreds = 61; inline constexpr ErrRef kErrorCDTrayBroken = 62; inline constexpr ErrRef kErrorUnrecoverableDisk = 63; inline constexpr ErrRef kErrorFileLocked = 64; +inline constexpr ErrRef kErrorDiskIsTooTiny = 65; inline constexpr ErrRef kErrorUnimplemented = -1; /// @brief The last error reported by the system to the process. diff --git a/docs/tex/hefs.tex b/docs/tex/hefs.tex index 75f98bcc..f3c2d6bf 100644 --- a/docs/tex/hefs.tex +++ b/docs/tex/hefs.tex @@ -26,7 +26,7 @@ \title{HeFS (High-Throughput Extended File System) Specification} \author{Amlal El Mahrouss} -\date{2024--2025} +\date{2024-2025} \begin{document} diff --git a/tooling/hefs.h b/tooling/hefs.h index d0ad823b..2a04a1c3 100644 --- a/tooling/hefs.h +++ b/tooling/hefs.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -16,17 +16,11 @@ #define kHeFSFileNameLen (256U) #define kHeFSPartNameLen (128U) -#define kHeFSMinimumDiskSize (gib_cast(4)) - -#define kHeFSDefaultVoluneName u"HeFS Volume" - -#define kHeFSDIMBootDir u"boot-x/dir" -#define kHeFSMIMEBootFile u"boot-x/file" - -#define kHeFSDIMSystemDir u"system-x/dir" -#define kHeFSMIMESystemFile u"system-x/file" +#define kHeFSDefaultVoluneName u8"HeFS Volume" namespace mkfs::hefs { + +// Drive kinds enum { kHeFSHardDrive = 0xC0, // Hard Drive kHeFSSolidStateDrive = 0xC1, // Solid State Drive @@ -38,6 +32,7 @@ enum { kHeFSDriveCount = 7, }; +// Disk status enum { kHeFSStatusUnlocked = 0x18, kHeFSStatusLocked, @@ -46,6 +41,7 @@ enum { kHeFSStatusCount, }; +// Encodings enum { kHeFSEncodingUTF8 = 0x00, kHeFSEncodingUTF16, @@ -60,18 +56,13 @@ enum { kHeFSEncodingCount, }; -// Constants +// Block constants constexpr std::size_t kHeFSBlockCount = 16; -// Types +// Time type using ATime = std::uint64_t; -enum { - kHeFSRed = 100, - kHeFSBlack, - kHeFSColorCount, -}; - +// File kinds inline constexpr uint16_t kHeFSFileKindRegular = 0x00; inline constexpr uint16_t kHeFSFileKindDirectory = 0x01; inline constexpr uint16_t kHeFSFileKindBlock = 0x02; @@ -82,14 +73,22 @@ inline constexpr uint16_t kHeFSFileKindSymbolicLink = 0x06; inline constexpr uint16_t kHeFSFileKindUnknown = 0x07; inline constexpr uint16_t kHeFSFileKindCount = 0x08; -// Basic Time Constants +// Red-black tree colors +enum { + kHeFSInvalidColor = 0, + kHeFSRed = 100, + kHeFSBlack, + kHeFSColorCount, +}; + +// Time constants inline constexpr ATime kHeFSTimeInvalid = 0x0000000000000000; inline constexpr ATime kHeFSTimeMax = 0xFFFFFFFFFFFFFFFF - 1; -// Boot Node (Superblock Equivalent) +// Boot Node struct alignas(8) BootNode { char magic[kHeFSMagicLen]{}; - char16_t volumeName[kHeFSPartNameLen]{}; + char8_t volumeName[kHeFSPartNameLen]{}; std::uint32_t version{}; std::uint64_t badSectors{}; std::uint64_t sectorCount{}; @@ -108,19 +107,16 @@ struct alignas(8) BootNode { std::uint64_t reserved2{}; std::uint64_t reserved3{}; std::uint64_t reserved4{}; + char pad[272]{}; }; -// File Node (Index Node) +// Index Node struct alignas(8) IndexNode { - char16_t name[kHeFSFileNameLen]{}; + char8_t name[kHeFSFileNameLen]{}; std::uint32_t flags{}; std::uint16_t kind{}; std::uint32_t size{}; std::uint32_t checksum{}; - std::uint32_t recoverChecksum{}; - std::uint32_t blockChecksum{}; - std::uint32_t linkChecksum{}; - char16_t mime[kHeFSFileNameLen]{}; bool symbolicLink{false}; ATime created{}; ATime accessed{}; @@ -129,23 +125,18 @@ struct alignas(8) IndexNode { std::uint32_t uid{}; std::uint32_t gid{}; std::uint32_t mode{}; - std::uint64_t blockLinkStart[kHeFSBlockCount]{}; - std::uint64_t blockLinkEnd[kHeFSBlockCount]{}; - std::uint64_t blockStart[kHeFSBlockCount]{}; - std::uint64_t blockEnd[kHeFSBlockCount]{}; - std::uint64_t blockRecoveryStart[kHeFSBlockCount]{}; - std::uint64_t blockRecoveryEnd[kHeFSBlockCount]{}; + std::uint64_t block[kHeFSBlockCount]{}; + char pad[62]{}; }; -// Directory Node (Red-Black Tree Node) +// Index Node Directory (Red-Black Tree Node) struct alignas(8) IndexNodeDirectory { - char16_t name[kHeFSFileNameLen]{}; + char8_t name[kHeFSFileNameLen]{}; std::uint32_t flags{}; std::uint16_t kind{}; std::uint32_t entryCount{}; std::uint32_t checksum{}; std::uint32_t indexNodeChecksum{}; - char16_t dim[kHeFSFileNameLen]{}; ATime created{}; ATime accessed{}; ATime modified{}; @@ -153,13 +144,13 @@ struct alignas(8) IndexNodeDirectory { std::uint32_t uid{}; std::uint32_t gid{}; std::uint32_t mode{}; - std::uint64_t indexNodeStart[kHeFSBlockCount]{}; - std::uint64_t indexNodeEnd[kHeFSBlockCount]{}; + std::uint64_t indexNode[kHeFSBlockCount]{}; std::uint8_t color{}; std::uint64_t next{}; std::uint64_t prev{}; std::uint64_t child{}; std::uint64_t parent{}; + char pad[32]{}; }; } // namespace mkfs::hefs diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc index 542ae175..3147a6e6 100644 --- a/tooling/mkfs.hefs.cc +++ b/tooling/mkfs.hefs.cc @@ -28,10 +28,10 @@ static std::basic_string get_option(const std::basic_string& } } // namespace mkfs::detail -static size_t kDiskSize = 1024 * 1024 * 1024 * 4UL; -static uint16_t kVersion = kHeFSVersion; -static std::u16string kLabel = kHeFSDefaultVoluneName; -static size_t kSectorSize = 512; +static size_t kDiskSize = 1024 * 1024 * 1024 * 4UL; +static uint16_t kVersion = kHeFSVersion; +static std::u8string kLabel = kHeFSDefaultVoluneName; +static size_t kSectorSize = 512; int main(int argc, char** argv) { if (argc < 2) { @@ -42,8 +42,8 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - std::string args; - std::u16string args_wide; + std::string args; + std::u8string args_wide; for (int i = 1; i < argc; ++i) { args += argv[i]; @@ -55,13 +55,13 @@ int main(int argc, char** argv) { args_wide.push_back(ch); } - args_wide += u" "; + args_wide += u8" "; } auto output_device = mkfs::detail::get_option(args, "-o"); kSectorSize = std::strtol(mkfs::detail::get_option(args, "-s").data(), nullptr, 10); - kLabel = mkfs::detail::get_option(args_wide, u"-L"); + kLabel = mkfs::detail::get_option(args_wide, u8"-L"); if (kLabel.empty()) kLabel = kHeFSDefaultVoluneName; @@ -91,14 +91,14 @@ int main(int argc, char** argv) { bootNode.version = kVersion; bootNode.diskKind = mkfs::hefs::kHeFSHardDrive; - bootNode.encoding = mkfs::hefs::kHeFSEncodingUTF16; + bootNode.encoding = mkfs::hefs::kHeFSEncodingUTF8; bootNode.diskSize = kDiskSize; bootNode.sectorSize = kSectorSize; bootNode.startIND = start_ind; bootNode.endIND = end_ind; bootNode.diskStatus = mkfs::hefs::kHeFSStatusUnlocked; - std::memcpy(bootNode.magic, kHeFSMagic, kHeFSMagicLen); + std::memcpy(bootNode.magic, kHeFSMagic, kHeFSMagicLen - 1); std::memcpy(bootNode.volumeName, kLabel.data(), kLabel.size() * sizeof(char16_t)); filesystem.seekp(std::strtol(mkfs::detail::get_option(args, "-p").data(), nullptr, 10)); @@ -121,9 +121,9 @@ int main(int argc, char** argv) { for (size_t i = 0; i < cnt; ++i) { mkfs::hefs::IndexNodeDirectory indexNode{}; - std::memcpy(indexNode.name, u"/", std::u16string(u"/").size() * sizeof(char16_t)); + std::memcpy(indexNode.name, u8"/", std::u8string(u8"/").size() * sizeof(char16_t)); - indexNode.flags = mkfs::hefs::kHeFSEncodingUTF16; + indexNode.flags = mkfs::hefs::kHeFSEncodingUTF8; indexNode.kind = mkfs::hefs::kHeFSFileKindDirectory; indexNode.deleted = mkfs::hefs::kHeFSTimeMax; -- cgit v1.2.3