diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-28 09:06:35 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-28 09:06:35 +0200 |
| commit | 2ead335ccc7afd8e1b2a6533e966c10f49fbdfe9 (patch) | |
| tree | ca447cda4307a2e51990d901be29a72829b2ea4c | |
| parent | 8a7396493c3effb356d2dc4484b993b4698bc422 (diff) | |
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 <amlal@nekernel.org>
| -rw-r--r-- | dev/boot/BootKit/HW/SATA.h | 2 | ||||
| -rw-r--r-- | dev/kernel/FSKit/HeFS.h | 36 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalKernelMain.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc | 16 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Processor.h | 2 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc | 14 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc | 6 | ||||
| -rw-r--r-- | dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc | 4 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/FileMgr.h | 2 | ||||
| -rw-r--r-- | dev/kernel/KernelKit/KPC.h | 6 | ||||
| -rw-r--r-- | dev/kernel/NewKit/KString.h | 2 | ||||
| -rw-r--r-- | dev/kernel/StorageKit/DmaPool.h | 21 | ||||
| -rw-r--r-- | dev/kernel/src/DriveMgr.cc | 2 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS+FileMgr.cc | 4 | ||||
| -rw-r--r-- | dev/kernel/src/FS/HeFS.cc | 67 | ||||
| -rw-r--r-- | dev/kernel/src/FS/NeFS.cc | 8 | ||||
| -rw-r--r-- | dev/kernel/src/Utils.cc | 1 | ||||
| -rw-r--r-- | dev/modules/AHCI/AHCI.h | 4 | ||||
| -rw-r--r-- | dev/modules/ATA/ATA.h | 4 | ||||
| -rw-r--r-- | dev/user/ProcessCodes.h | 1 | ||||
| -rw-r--r-- | docs/tex/hefs.tex | 2 | ||||
| -rw-r--r-- | tooling/hefs.h | 67 | ||||
| -rw-r--r-- | tooling/mkfs.hefs.cc | 24 |
23 files changed, 161 insertions, 136 deletions
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 @@ -94,6 +94,18 @@ UIntPtr hal_get_phys_address(VoidPtr virt) { } /***********************************************************************************/ +/// @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. /// @param phys_addr point to physical 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<YES, YES, NO>(lba / sector_sz, reinterpret_cast<UInt8*>(buffer), sector_sz, - size_buffer); + drv_std_input_output_ahci<YES, YES, NO>(lba / sector_sz, reinterpret_cast<UInt8*>(buffer), + sector_sz, size_buffer); } //////////////////////////////////////////////////// /// //////////////////////////////////////////////////// Void drv_std_read(UInt64 lba, Char* buffer, SizeT sector_sz, SizeT size_buffer) { - drv_std_input_output_ahci<NO, YES, NO>(lba / sector_sz, reinterpret_cast<UInt8*>(buffer), sector_sz, - size_buffer); + drv_std_input_output_ahci<NO, YES, NO>(lba / sector_sz, reinterpret_cast<UInt8*>(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<KString> 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 <KernelKit/DebugOutput.h> +#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<UIntPtr>(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 <KernelKit/FileMgr.h> #include <KernelKit/MemoryMgr.h> -#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<CharType> get_option(const std::basic_string<CharType>& } } // 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<char>(args, "-o"); kSectorSize = std::strtol(mkfs::detail::get_option<char>(args, "-s").data(), nullptr, 10); - kLabel = mkfs::detail::get_option<char16_t>(args_wide, u"-L"); + kLabel = mkfs::detail::get_option<char8_t>(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<char>(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; |
