summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-28 09:06:35 +0200
committerAmlal <amlal@nekernel.org>2025-04-28 09:06:35 +0200
commit2ead335ccc7afd8e1b2a6533e966c10f49fbdfe9 (patch)
treeca447cda4307a2e51990d901be29a72829b2ea4c /dev
parent8a7396493c3effb356d2dc4484b993b4698bc422 (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>
Diffstat (limited to 'dev')
-rw-r--r--dev/boot/BootKit/HW/SATA.h2
-rw-r--r--dev/kernel/FSKit/HeFS.h36
-rw-r--r--dev/kernel/HALKit/AMD64/HalKernelMain.cc2
-rw-r--r--dev/kernel/HALKit/AMD64/HalPagingMgrAMD64.cc16
-rw-r--r--dev/kernel/HALKit/AMD64/Processor.h2
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/AHCI+Generic.cc14
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/DMA+Generic.cc6
-rw-r--r--dev/kernel/HALKit/AMD64/Storage/PIO+Generic.cc4
-rw-r--r--dev/kernel/KernelKit/FileMgr.h2
-rw-r--r--dev/kernel/KernelKit/KPC.h6
-rw-r--r--dev/kernel/NewKit/KString.h2
-rw-r--r--dev/kernel/StorageKit/DmaPool.h21
-rw-r--r--dev/kernel/src/DriveMgr.cc2
-rw-r--r--dev/kernel/src/FS/HeFS+FileMgr.cc4
-rw-r--r--dev/kernel/src/FS/HeFS.cc67
-rw-r--r--dev/kernel/src/FS/NeFS.cc8
-rw-r--r--dev/kernel/src/Utils.cc1
-rw-r--r--dev/modules/AHCI/AHCI.h4
-rw-r--r--dev/modules/ATA/ATA.h4
-rw-r--r--dev/user/ProcessCodes.h1
20 files changed, 119 insertions, 85 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.