summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/src
diff options
context:
space:
mode:
Diffstat (limited to 'dev/kernel/src')
-rw-r--r--dev/kernel/src/AsciiUtils.cc3
-rw-r--r--dev/kernel/src/Atom.cc2
-rw-r--r--dev/kernel/src/Crc32.cc4
-rw-r--r--dev/kernel/src/FS/Ext2+FileSystemParser.cc21
-rw-r--r--dev/kernel/src/FS/Ext2+IFS.cc (renamed from dev/kernel/src/FS/Ext2+FileMgr.cc)158
-rw-r--r--dev/kernel/src/FS/HeFS+FileMgr.cc14
-rw-r--r--dev/kernel/src/FS/NeFS+FileSystemParser.cc6
-rw-r--r--dev/kernel/src/FS/OpenHeFS+FileMgr.cc191
-rw-r--r--dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc (renamed from dev/kernel/src/FS/HeFS+FileSystemParser.cc)18
-rw-r--r--dev/kernel/src/GUIDWizard.cc8
-rw-r--r--dev/kernel/src/GUIDWrapper.cc2
-rw-r--r--dev/kernel/src/HardwareThreadScheduler.cc3
-rw-r--r--dev/kernel/src/IFS.cc20
-rw-r--r--dev/kernel/src/IPEFDylibObject.cc4
-rw-r--r--dev/kernel/src/IndexableProperty.cc3
-rw-r--r--dev/kernel/src/Json.cc2
-rw-r--r--dev/kernel/src/KernelTaskScheduler.cc15
-rw-r--r--dev/kernel/src/Network/IPAddress.cc4
-rw-r--r--dev/kernel/src/Network/NetworkDevice.cc2
-rw-r--r--dev/kernel/src/PEFCodeMgr.cc54
-rw-r--r--dev/kernel/src/Property.cc8
-rw-r--r--dev/kernel/src/Storage/AHCIDeviceInterface.cc14
-rw-r--r--dev/kernel/src/Storage/ATADeviceInterface.cc14
-rw-r--r--dev/kernel/src/Storage/NVMEDeviceInterface.cc4
-rw-r--r--dev/kernel/src/Swap/DiskSwap.cc9
-rw-r--r--dev/kernel/src/UserMgr.cc12
-rw-r--r--dev/kernel/src/UserProcessScheduler.cc23
-rw-r--r--dev/kernel/src/UtfUtils.cc9
28 files changed, 423 insertions, 204 deletions
diff --git a/dev/kernel/src/AsciiUtils.cc b/dev/kernel/src/AsciiUtils.cc
index cca3a368..8d2f9dc5 100644
--- a/dev/kernel/src/AsciiUtils.cc
+++ b/dev/kernel/src/AsciiUtils.cc
@@ -52,9 +52,12 @@ Int32 rt_copy_memory_safe(const voidPtr src, voidPtr dst, Size len, Size dst_siz
}
return -1;
}
+
auto s = reinterpret_cast<const UInt8*>(src);
auto d = reinterpret_cast<UInt8*>(dst);
+
for (Size i = 0; i < len; ++i) d[i] = s[i];
+
return static_cast<Int>(len);
}
diff --git a/dev/kernel/src/Atom.cc b/dev/kernel/src/Atom.cc
index 6e84d7d5..a0e45468 100644
--- a/dev/kernel/src/Atom.cc
+++ b/dev/kernel/src/Atom.cc
@@ -6,5 +6,5 @@
#include <NeKit/Atom.h>
-// @file Atom.cpp
+// @file Atom.cc
// @brief Atomic primitives
diff --git a/dev/kernel/src/Crc32.cc b/dev/kernel/src/Crc32.cc
index 46a1d940..df0b34e3 100644
--- a/dev/kernel/src/Crc32.cc
+++ b/dev/kernel/src/Crc32.cc
@@ -6,7 +6,9 @@
#include <NeKit/Crc32.h>
-// @file CRC32.cpp
+#define kCrcCnt (256)
+
+// @file CRC32.cc
// @brief Check sequence implementation.
namespace Kernel {
diff --git a/dev/kernel/src/FS/Ext2+FileSystemParser.cc b/dev/kernel/src/FS/Ext2+FileSystemParser.cc
deleted file mode 100644
index 318f83d6..00000000
--- a/dev/kernel/src/FS/Ext2+FileSystemParser.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-/* -------------------------------------------
-
- Copyright (C) 2025, Amlal El Mahrouss, all rights reserved.
-
-------------------------------------------- */
-
-#ifdef __FSKIT_INCLUDES_EXT2__
-
-#include <FSKit/Ext2+IFS.h>
-#include <FirmwareKit/EPM.h>
-#include <KernelKit/KPC.h>
-#include <KernelKit/ProcessScheduler.h>
-#include <KernelKit/UserMgr.h>
-#include <NeKit/Crc32.h>
-#include <NeKit/KString.h>
-#include <NeKit/KernelPanic.h>
-#include <NeKit/Utils.h>
-#include <modules/AHCI/AHCI.h>
-#include <modules/ATA/ATA.h>
-
-#endif // ifdef __FSKIT_INCLUDES_EXT2__
diff --git a/dev/kernel/src/FS/Ext2+FileMgr.cc b/dev/kernel/src/FS/Ext2+IFS.cc
index 7c28c0c9..2c359197 100644
--- a/dev/kernel/src/FS/Ext2+FileMgr.cc
+++ b/dev/kernel/src/FS/Ext2+IFS.cc
@@ -17,14 +17,14 @@
#include <NeKit/KernelPanic.h>
#include <NeKit/Utils.h>
-constexpr UInt32 EXT2_DIRECT_BLOCKS = 12;
-constexpr UInt32 EXT2_SINGLE_INDIRECT_INDEX = 12;
-constexpr UInt32 EXT2_DOUBLE_INDIRECT_INDEX = 13;
-constexpr UInt32 EXT2_TRIPLE_INDIRECT_INDEX = 14;
-constexpr UInt32 EXT2_ROOT_INODE = 2;
-constexpr UInt32 EXT2_SUPERBLOCK_BLOCK = 1;
-constexpr UInt32 EXT2_GROUP_DESC_BLOCK_SMALL = 2;
-constexpr UInt32 EXT2_GROUP_DESC_BLOCK_LARGE = 1;
+constexpr static UInt32 EXT2_DIRECT_BLOCKS = 12;
+constexpr static UInt32 EXT2_SINGLE_INDIRECT_INDEX = 12;
+constexpr static UInt32 EXT2_DOUBLE_INDIRECT_INDEX = 13;
+constexpr ATTRIBUTE(unused) static UInt32 EXT2_TRIPLE_INDIRECT_INDEX = 14;
+constexpr static UInt32 EXT2_ROOT_INODE = 2;
+constexpr ATTRIBUTE(unused) static UInt32 EXT2_SUPERBLOCK_BLOCK = 1;
+constexpr static UInt32 EXT2_GROUP_DESC_BLOCK_SMALL = 2;
+constexpr static UInt32 EXT2_GROUP_DESC_BLOCK_LARGE = 1;
static inline SizeT ext2_min(SizeT a, SizeT b) {
return a < b ? a : b;
@@ -38,8 +38,7 @@ struct Ext2GroupInfo {
};
// Convert EXT2 block number -> LBA (sector index) for Drive I/O.
-static inline UInt32 ext2_block_to_lba(Ext2Context* ctx,
- UInt32 blockNumber) {
+static inline UInt32 ext2_block_to_lba(Ext2Context* ctx, UInt32 blockNumber) {
if (!ctx || !ctx->drive) return 0;
UInt32 blockSize = ctx->BlockSize();
UInt32 sectorSize = ctx->drive->fSectorSz;
@@ -48,13 +47,11 @@ static inline UInt32 ext2_block_to_lba(Ext2Context* ctx,
}
// Read a block and return a pointer to its content
-static ErrorOr<UInt32*> ext2_read_block_ptr(Ext2Context* ctx,
- UInt32 blockNumber) {
- if (!ctx || !ctx->drive || !ctx->superblock)
- return ErrorOr<UInt32*>(kErrorInvalidData);
+static ErrorOr<UInt32*> ext2_read_block_ptr(Ext2Context* ctx, UInt32 blockNumber) {
+ if (!ctx || !ctx->drive || !ctx->superblock) return ErrorOr<UInt32*>(kErrorInvalidData);
UInt32 blockSize = ctx->BlockSize();
- auto buf = (UInt32*) mm_alloc_ptr(blockSize, true, false);
+ auto buf = (UInt32*) mm_alloc_ptr(blockSize, true, false);
if (!buf) return ErrorOr<UInt32*>(kErrorHeapOutOfMemory);
UInt32 lba = ext2_block_to_lba(ctx, blockNumber);
@@ -67,7 +64,7 @@ static ErrorOr<UInt32*> ext2_read_block_ptr(Ext2Context* ctx,
// Get the block address for a given logical block index
static ErrorOr<UInt32> ext2_get_block_address(Ext2Context* ctx, Ext2Node* node,
- UInt32 logicalIndex) {
+ UInt32 logicalIndex) {
if (!ctx || !node || !ctx->drive) return ErrorOr<UInt32>(kErrorInvalidData);
UInt32 blockSize = ctx->BlockSize();
@@ -132,8 +129,7 @@ static ErrorOr<UInt32> ext2_get_block_address(Ext2Context* ctx, Ext2Node* node,
return ErrorOr<UInt32>(kErrorUnimplemented);
}
-static ErrorOr<voidPtr> ext2_read_inode_data(Ext2Context* ctx, Ext2Node* node,
- SizeT size) {
+static ErrorOr<voidPtr> ext2_read_inode_data(Ext2Context* ctx, Ext2Node* node, SizeT size) {
if (!ctx || !ctx->drive || !node || size == 0) return ErrorOr<voidPtr>(1);
auto blockSize = ctx->BlockSize();
@@ -190,7 +186,7 @@ static ErrorOr<voidPtr> ext2_read_inode_data(Ext2Context* ctx, Ext2Node* node,
// Get group descriptor information for a given block/inode number
static ErrorOr<Ext2GroupInfo*> ext2_get_group_descriptor_info(Ext2Context* ctx,
- UInt32 targetBlockOrInode) {
+ UInt32 targetBlockOrInode) {
if (!ctx || !ctx->superblock || !ctx->drive) return ErrorOr<Ext2GroupInfo*>(kErrorInvalidData);
UInt32 blockSize = ctx->BlockSize();
@@ -260,8 +256,7 @@ static ErrorOr<Ext2GroupInfo*> ext2_get_group_descriptor_info(Ext2Context* ctx,
}
// Allocate a new block
-inline ErrorOr<UInt32> ext2_alloc_block(Ext2Context* ctx,
- EXT2_GROUP_DESCRIPTOR* groupDesc) {
+inline ErrorOr<UInt32> ext2_alloc_block(Ext2Context* ctx, EXT2_GROUP_DESCRIPTOR* groupDesc) {
if (!ctx || !ctx->superblock || !groupDesc) return ErrorOr<UInt32>(kErrorInvalidData);
UInt32 blockSize = ctx->BlockSize();
@@ -308,10 +303,8 @@ inline ErrorOr<UInt32> ext2_alloc_block(Ext2Context* ctx,
}
// Indirect blocks
-static ErrorOr<Void*> ext2_set_block_address(Ext2Context* ctx,
- Ext2Node* node,
- UInt32 logicalBlockIndex,
- UInt32 physicalBlockNumber) {
+static ErrorOr<Void*> ext2_set_block_address(Ext2Context* ctx, Ext2Node* node,
+ UInt32 logicalBlockIndex, UInt32 physicalBlockNumber) {
using namespace Kernel;
if (!ctx || !ctx->drive || !node) return ErrorOr<Void*>(kErrorInvalidData);
@@ -518,15 +511,14 @@ static ErrorOr<Void*> ext2_set_block_address(Ext2Context* ctx,
// Find a directory entry by name within a directory inode
static ErrorOr<EXT2_DIR_ENTRY*> ext2_find_dir_entry(Ext2Context* ctx, Ext2Node* dirNode,
const char* name) {
- if (!ctx || !ctx->drive || !dirNode || !name)
- return ErrorOr<EXT2_DIR_ENTRY*>(kErrorInvalidData);
+ if (!ctx || !ctx->drive || !dirNode || !name) return ErrorOr<EXT2_DIR_ENTRY*>(kErrorInvalidData);
// Check directory type
auto type = (dirNode->inode.fMode >> 12) & 0xF;
if (type != kExt2FileTypeDirectory) return ErrorOr<EXT2_DIR_ENTRY*>(kErrorInvalidData);
UInt32 blockSize = ctx->BlockSize();
- auto blockBuf = mm_alloc_ptr(blockSize, true, false);
+ auto blockBuf = mm_alloc_ptr(blockSize, true, false);
if (!blockBuf) return ErrorOr<EXT2_DIR_ENTRY*>(kErrorHeapOutOfMemory);
SizeT nameLen = rt_string_len(name);
@@ -578,8 +570,7 @@ static inline UInt16 ext2_dir_entry_ideal_len(UInt8 nameLen) {
}
static ErrorOr<Void*> ext2_add_dir_entry(Ext2Context* ctx, Ext2Node* parentDirNode,
- const char* name, UInt32 inodeNumber,
- UInt8 fileType) {
+ const char* name, UInt32 inodeNumber, UInt8 fileType) {
using namespace Kernel;
if (!ctx || !ctx->drive || !parentDirNode || !name) return ErrorOr<Void*>(kErrorInvalidData);
@@ -763,8 +754,7 @@ static ErrorOr<Void*> ext2_add_dir_entry(Ext2Context* ctx, Ext2Node* parentDirNo
}
// Soon
-static ErrorOr<UInt32> ext2_alloc_inode(Ext2Context* ctx,
- EXT2_GROUP_DESCRIPTOR* groupDesc) {
+static ErrorOr<UInt32> ext2_alloc_inode(Ext2Context* ctx, EXT2_GROUP_DESCRIPTOR* groupDesc) {
if (!ctx || !ctx->superblock || !groupDesc) return ErrorOr<UInt32>(kErrorInvalidData);
UInt32 blockSize = ctx->BlockSize();
@@ -902,8 +892,8 @@ struct PathComponents {
return;
}
- UInt32 compCount = 0;
- Char* p = buffer;
+ UInt32 compCount = 0;
+ Char* p = buffer;
while (*p != '\0') {
// skip slashes
@@ -952,16 +942,19 @@ struct PathComponents {
} // anonymous namespace
// The Ext2FileSystemParser (not manager!)
-Ext2FileSystemParser::Ext2FileSystemParser(DriveTrait* drive) : ctx(drive) {}
+Ext2FileSystemParser::Ext2FileSystemParser(DriveTrait* drive) : fCtx(drive) {
+ MUST_PASS(fCtx);
+}
+
NodePtr Ext2FileSystemParser::Open(const char* path, const char* restrict_type) {
NE_UNUSED(restrict_type);
- if (!path || *path == '\0' || !this->ctx.drive) {
+ if (!path || *path == '\0' || !this->fCtx.drive) {
return nullptr;
}
// Root ("/")
if (rt_string_len(path) == 1 && rt_string_cmp(path, "/", 1) == 0) {
- auto inodeResult = ext2_load_inode(&this->ctx, EXT2_ROOT_INODE);
+ auto inodeResult = ext2_load_inode(&this->fCtx, EXT2_ROOT_INODE);
if (!inodeResult) {
return nullptr;
}
@@ -982,8 +975,8 @@ NodePtr Ext2FileSystemParser::Open(const char* path, const char* restrict_type)
UInt32 currentInodeNumber = EXT2_ROOT_INODE;
Ext2Node* currentDirNode = nullptr;
- for (UInt32 i = 0; i < (UInt32)pathComponents.count; ++i) {
- auto inodeResult = ext2_load_inode(&this->ctx, currentInodeNumber);
+ for (UInt32 i = 0; i < (UInt32) pathComponents.count; ++i) {
+ auto inodeResult = ext2_load_inode(&this->fCtx, currentInodeNumber);
if (!inodeResult) {
if (currentDirNode) mm_free_ptr(currentDirNode);
return nullptr;
@@ -1011,7 +1004,7 @@ NodePtr Ext2FileSystemParser::Open(const char* path, const char* restrict_type)
}
auto dirEntryResult =
- ext2_find_dir_entry(&this->ctx, currentDirNode, pathComponents.components[i]);
+ ext2_find_dir_entry(&this->fCtx, currentDirNode, pathComponents.components[i]);
if (!dirEntryResult) {
mm_free_ptr(currentDirNode);
return nullptr;
@@ -1022,7 +1015,7 @@ NodePtr Ext2FileSystemParser::Open(const char* path, const char* restrict_type)
mm_free_ptr(entryPtr);
}
- auto finalInodeResult = ext2_load_inode(&this->ctx, currentInodeNumber);
+ auto finalInodeResult = ext2_load_inode(&this->fCtx, currentInodeNumber);
if (!finalInodeResult) {
if (currentDirNode) mm_free_ptr(currentDirNode);
return nullptr;
@@ -1048,7 +1041,7 @@ void* Ext2FileSystemParser::Read(NodePtr node, Int32 flags, SizeT size) {
NE_UNUSED(flags);
auto extNode = reinterpret_cast<Ext2Node*>(node);
- auto dataResult = ext2_read_inode_data(&this->ctx, extNode, size);
+ auto dataResult = ext2_read_inode_data(&this->fCtx, extNode, size);
if (!dataResult) {
return nullptr; // error, nothing to return
@@ -1068,7 +1061,7 @@ void Ext2FileSystemParser::Write(NodePtr node, void* data, Int32 flags, SizeT si
NE_UNUSED(flags);
auto extNode = reinterpret_cast<Ext2Node*>(node);
- auto blockSize = this->ctx.BlockSize();
+ auto blockSize = this->fCtx.BlockSize();
SizeT bytesWritten = 0;
UInt32 currentOffset = extNode->cursor;
@@ -1078,19 +1071,19 @@ void Ext2FileSystemParser::Write(NodePtr node, void* data, Int32 flags, SizeT si
UInt32 logicalBlockIndex = currentOffset / blockSize;
UInt32 offsetInBlock = currentOffset % blockSize;
- auto physBlockResult = ext2_get_block_address(&this->ctx, extNode, logicalBlockIndex);
+ auto physBlockResult = ext2_get_block_address(&this->fCtx, extNode, logicalBlockIndex);
UInt32 physicalBlock = 0;
if (!physBlockResult) {
auto err = physBlockResult.Error();
if (err == kErrorInvalidData || err == kErrorUnimplemented) {
- auto groupInfoResult = ext2_get_group_descriptor_info(&this->ctx, extNode->inodeNumber);
+ auto groupInfoResult = ext2_get_group_descriptor_info(&this->fCtx, extNode->inodeNumber);
if (!groupInfoResult) {
return;
}
auto groupInfo = *groupInfoResult.Leak();
- auto allocResult = ext2_alloc_block(&this->ctx, groupInfo->groupDesc);
+ auto allocResult = ext2_alloc_block(&this->fCtx, groupInfo->groupDesc);
if (!allocResult) {
mm_free_ptr(reinterpret_cast<void*>(groupInfo->blockBuffer));
mm_free_ptr(groupInfo);
@@ -1099,15 +1092,16 @@ void Ext2FileSystemParser::Write(NodePtr node, void* data, Int32 flags, SizeT si
physicalBlock = *allocResult.Leak();
- auto setRes = ext2_set_block_address(&this->ctx, extNode, logicalBlockIndex, physicalBlock);
+ auto setRes =
+ ext2_set_block_address(&this->fCtx, extNode, logicalBlockIndex, physicalBlock);
if (!setRes) {
mm_free_ptr(reinterpret_cast<void*>(groupInfo->blockBuffer));
mm_free_ptr(groupInfo);
return;
}
- UInt32 gdtLba = ext2_block_to_lba(&this->ctx, groupInfo->groupDescriptorBlock);
- if (!ext2_write_block(this->ctx.drive, gdtLba, groupInfo->blockBuffer, blockSize)) {
+ UInt32 gdtLba = ext2_block_to_lba(&this->fCtx, groupInfo->groupDescriptorBlock);
+ if (!ext2_write_block(this->fCtx.drive, gdtLba, groupInfo->blockBuffer, blockSize)) {
mm_free_ptr(reinterpret_cast<void*>(groupInfo->blockBuffer));
mm_free_ptr(groupInfo);
return;
@@ -1122,13 +1116,13 @@ void Ext2FileSystemParser::Write(NodePtr node, void* data, Int32 flags, SizeT si
physicalBlock = physBlockResult.Value();
}
- UInt32 physicalLba = ext2_block_to_lba(&this->ctx, physicalBlock);
+ UInt32 physicalLba = ext2_block_to_lba(&this->fCtx, physicalBlock);
auto blockBuf = mm_alloc_ptr(blockSize, true, false);
if (!blockBuf) return;
if (offsetInBlock > 0 || (size - bytesWritten) < blockSize) {
- if (!ext2_read_block(this->ctx.drive, physicalLba, blockBuf, blockSize)) {
+ if (!ext2_read_block(this->fCtx.drive, physicalLba, blockBuf, blockSize)) {
mm_free_ptr(blockBuf);
return;
}
@@ -1141,7 +1135,7 @@ void Ext2FileSystemParser::Write(NodePtr node, void* data, Int32 flags, SizeT si
rt_copy_memory_safe(src, static_cast<void*>((UInt8*) blockBuf + offsetInBlock),
bytesInCurrentBlock, blockSize - offsetInBlock);
- if (!ext2_write_block(this->ctx.drive, physicalLba, blockBuf, blockSize)) {
+ if (!ext2_write_block(this->fCtx.drive, physicalLba, blockBuf, blockSize)) {
mm_free_ptr(blockBuf);
return;
}
@@ -1160,7 +1154,7 @@ void Ext2FileSystemParser::Write(NodePtr node, void* data, Int32 flags, SizeT si
extNode->inode.fBlocks = (extNode->inode.fSize + blockSize - 1) / blockSize;
extNode->inode.fModifyTime = 0;
- auto writeInodeRes = ext2_write_inode(&this->ctx, extNode);
+ auto writeInodeRes = ext2_write_inode(&this->fCtx, extNode);
if (!writeInodeRes) {
// Failed to persist inode
}
@@ -1226,7 +1220,7 @@ NodePtr Ext2FileSystemParser::Create(const char* path) {
NodePtr parentDirNodePtr = nullptr;
if (currentPathLen == 0) {
// root
- auto inodeRes = ext2_load_inode(&this->ctx, EXT2_ROOT_INODE);
+ auto inodeRes = ext2_load_inode(&this->fCtx, EXT2_ROOT_INODE);
if (!inodeRes) return nullptr;
parentDirNodePtr = mm_alloc_ptr(sizeof(Ext2Node), true, false);
if (!parentDirNodePtr) return nullptr;
@@ -1248,7 +1242,7 @@ NodePtr Ext2FileSystemParser::Create(const char* path) {
}
// Get group info for allocation
- auto groupInfoResult = ext2_get_group_descriptor_info(&this->ctx, parentDirNode->inodeNumber);
+ auto groupInfoResult = ext2_get_group_descriptor_info(&this->fCtx, parentDirNode->inodeNumber);
if (!groupInfoResult) {
mm_free_ptr(parentDirNode);
return nullptr;
@@ -1256,7 +1250,7 @@ NodePtr Ext2FileSystemParser::Create(const char* path) {
auto groupInfo = *groupInfoResult.Leak();
// Allocate new inode
- auto newInodeRes = ext2_alloc_inode(&this->ctx, groupInfo->groupDesc);
+ auto newInodeRes = ext2_alloc_inode(&this->fCtx, groupInfo->groupDesc);
if (!newInodeRes) {
mm_free_ptr(reinterpret_cast<void*>(groupInfo->blockBuffer));
mm_free_ptr(groupInfo); // so this works
@@ -1265,8 +1259,8 @@ NodePtr Ext2FileSystemParser::Create(const char* path) {
}
UInt32 newInodeNumber = newInodeRes.Value();
- UInt32 gdtLba = ext2_block_to_lba(&this->ctx, groupInfo->groupDescriptorBlock);
- if (!ext2_write_block(this->ctx.drive, gdtLba, groupInfo->blockBuffer, this->ctx.BlockSize())) {
+ UInt32 gdtLba = ext2_block_to_lba(&this->fCtx, groupInfo->groupDescriptorBlock);
+ if (!ext2_write_block(this->fCtx.drive, gdtLba, groupInfo->blockBuffer, this->fCtx.BlockSize())) {
mm_free_ptr(reinterpret_cast<void*>(groupInfo->blockBuffer));
mm_free_ptr(groupInfo);
mm_free_ptr(parentDirNode);
@@ -1296,7 +1290,7 @@ NodePtr Ext2FileSystemParser::Create(const char* path) {
newFileNode->inode.fModifyTime = 0;
// Persist new inode
- auto writeInodeRes = ext2_write_inode(&this->ctx, newFileNode);
+ auto writeInodeRes = ext2_write_inode(&this->fCtx, newFileNode);
if (!writeInodeRes) {
mm_free_ptr(parentDirNode);
mm_free_ptr(newFileNode);
@@ -1304,8 +1298,8 @@ NodePtr Ext2FileSystemParser::Create(const char* path) {
}
// Add directory entry
- auto addRes =
- ext2_add_dir_entry(&this->ctx, parentDirNode, filename, newInodeNumber, kExt2FileTypeRegular);
+ auto addRes = ext2_add_dir_entry(&this->fCtx, parentDirNode, filename, newInodeNumber,
+ kExt2FileTypeRegular);
if (!addRes) {
mm_free_ptr(parentDirNode);
mm_free_ptr(newFileNode);
@@ -1313,7 +1307,7 @@ NodePtr Ext2FileSystemParser::Create(const char* path) {
}
// Update parent inode
- auto parentWriteRes = ext2_write_inode(&this->ctx, parentDirNode);
+ auto parentWriteRes = ext2_write_inode(&this->fCtx, parentDirNode);
// ignore failure
NE_UNUSED(parentWriteRes);
@@ -1360,7 +1354,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
// Open parent directory node
NodePtr parentDirNodePtr = nullptr;
if (currentPathLen == 0) {
- auto inodeRes = ext2_load_inode(&this->ctx, EXT2_ROOT_INODE);
+ auto inodeRes = ext2_load_inode(&this->fCtx, EXT2_ROOT_INODE);
if (!inodeRes) {
return nullptr;
}
@@ -1390,7 +1384,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
}
// Allocate inode
- auto groupInfoResult = ext2_get_group_descriptor_info(&this->ctx, parentDirNode->inodeNumber);
+ auto groupInfoResult = ext2_get_group_descriptor_info(&this->fCtx, parentDirNode->inodeNumber);
if (!groupInfoResult) {
kout << "EXT2: Failed to get group descriptor info for new dir inode.\n";
mm_free_ptr(parentDirNode);
@@ -1398,7 +1392,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
}
auto groupInfo = *groupInfoResult.Leak();
- auto newInodeRes = ext2_alloc_inode(&this->ctx, groupInfo->groupDesc);
+ auto newInodeRes = ext2_alloc_inode(&this->fCtx, groupInfo->groupDesc);
if (!newInodeRes) {
kout << "EXT2: Failed to allocate inode for new directory.\n";
mm_free_ptr(reinterpret_cast<void*>(groupInfo->blockBuffer));
@@ -1410,8 +1404,8 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
UInt32 newInodeNumber = *newInodeRes.Leak();
// Write back group descriptor block
- UInt32 gdtLba = ext2_block_to_lba(&this->ctx, groupInfo->groupDescriptorBlock);
- if (!ext2_write_block(this->ctx.drive, gdtLba, groupInfo->blockBuffer, this->ctx.BlockSize())) {
+ UInt32 gdtLba = ext2_block_to_lba(&this->fCtx, groupInfo->groupDescriptorBlock);
+ if (!ext2_write_block(this->fCtx.drive, gdtLba, groupInfo->blockBuffer, this->fCtx.BlockSize())) {
kout << "EXT2: Failed to write group descriptor after inode allocation.\n";
mm_free_ptr(reinterpret_cast<void*>(groupInfo->blockBuffer));
mm_free_ptr(groupInfo);
@@ -1436,13 +1430,13 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
newDirNode->inode.fUID = 0;
newDirNode->inode.fGID = 0;
newDirNode->inode.fLinksCount = 2; // . and ..
- newDirNode->inode.fSize = this->ctx.BlockSize();
+ newDirNode->inode.fSize = this->fCtx.BlockSize();
newDirNode->inode.fBlocks = 1;
newDirNode->inode.fCreateTime = 0;
newDirNode->inode.fModifyTime = 0;
// Allocate a data block for the new directory
- auto groupForBlockRes = ext2_get_group_descriptor_info(&this->ctx, newDirNode->inodeNumber);
+ auto groupForBlockRes = ext2_get_group_descriptor_info(&this->fCtx, newDirNode->inodeNumber);
if (!groupForBlockRes) {
kout << "EXT2: Failed to get group info for directory block allocation.\n";
mm_free_ptr(parentDirNode);
@@ -1451,7 +1445,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
}
auto groupForBlock = *groupForBlockRes.Leak();
- auto newBlockRes = ext2_alloc_block(&this->ctx, groupForBlock->groupDesc);
+ auto newBlockRes = ext2_alloc_block(&this->fCtx, groupForBlock->groupDesc);
if (!newBlockRes) {
kout << "EXT2: Failed to allocate block for new directory contents.\n";
mm_free_ptr(reinterpret_cast<void*>(groupForBlock->blockBuffer));
@@ -1464,9 +1458,9 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
UInt32 newDirBlockNum = *newBlockRes.Leak();
// Write back GDT
- UInt32 gdtLba2 = ext2_block_to_lba(&this->ctx, groupForBlock->groupDescriptorBlock);
- if (!ext2_write_block(this->ctx.drive, gdtLba2, groupForBlock->blockBuffer,
- this->ctx.BlockSize())) {
+ UInt32 gdtLba2 = ext2_block_to_lba(&this->fCtx, groupForBlock->groupDescriptorBlock);
+ if (!ext2_write_block(this->fCtx.drive, gdtLba2, groupForBlock->blockBuffer,
+ this->fCtx.BlockSize())) {
kout << "EXT2: Failed to write GDT after directory block allocation.\n";
mm_free_ptr(reinterpret_cast<void*>(groupForBlock->blockBuffer));
mm_free_ptr(groupForBlock);
@@ -1479,7 +1473,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
mm_free_ptr(groupForBlock);
// Set the block in newDirNode
- auto setBlkRes = ext2_set_block_address(&this->ctx, newDirNode, 0, newDirBlockNum);
+ auto setBlkRes = ext2_set_block_address(&this->fCtx, newDirNode, 0, newDirBlockNum);
if (!setBlkRes) {
kout << "EXT2: Failed to set data block for new directory.\n";
mm_free_ptr(parentDirNode);
@@ -1488,7 +1482,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
}
// Prepare block with '.' and '..'
- auto dirBlockBuf = mm_alloc_ptr(this->ctx.BlockSize(), true, false);
+ auto dirBlockBuf = mm_alloc_ptr(this->fCtx.BlockSize(), true, false);
if (!dirBlockBuf) {
kout << "EXT2: Out of memory preparing directory block.\n";
mm_free_ptr(parentDirNode);
@@ -1496,7 +1490,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
return nullptr;
}
- rt_zero_memory(dirBlockBuf, this->ctx.BlockSize());
+ rt_zero_memory(dirBlockBuf, this->fCtx.BlockSize());
// '.' entry
auto dot = reinterpret_cast<EXT2_DIR_ENTRY*>(dirBlockBuf);
@@ -1511,13 +1505,13 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
dotdot->fInode = parentDirNode->inodeNumber;
dotdot->fNameLength = 2;
dotdot->fFileType = kExt2FileTypeDirectory;
- dotdot->fRecordLength = static_cast<UInt16>(this->ctx.BlockSize() - dot->fRecordLength);
+ dotdot->fRecordLength = static_cast<UInt16>(this->fCtx.BlockSize() - dot->fRecordLength);
dotdot->fName[0] = '.';
dotdot->fName[1] = '.';
// Write dir block to disk
- UInt32 newDirBlockLba = ext2_block_to_lba(&this->ctx, newDirBlockNum);
- if (!ext2_write_block(this->ctx.drive, newDirBlockLba, dirBlockBuf, this->ctx.BlockSize())) {
+ UInt32 newDirBlockLba = ext2_block_to_lba(&this->fCtx, newDirBlockNum);
+ if (!ext2_write_block(this->fCtx.drive, newDirBlockLba, dirBlockBuf, this->fCtx.BlockSize())) {
kout << "EXT2: Failed to write directory block to disk.\n";
mm_free_ptr(dirBlockBuf);
mm_free_ptr(parentDirNode);
@@ -1528,7 +1522,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
mm_free_ptr(dirBlockBuf);
// Persist new directory inode
- auto writeInodeRes = ext2_write_inode(&this->ctx, newDirNode);
+ auto writeInodeRes = ext2_write_inode(&this->fCtx, newDirNode);
if (!writeInodeRes) {
kout << "EXT2: Failed to write new directory inode to disk.\n";
mm_free_ptr(parentDirNode);
@@ -1537,7 +1531,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
}
// Add directory entry into parent
- auto addRes = ext2_add_dir_entry(&this->ctx, parentDirNode, dirname, newInodeNumber,
+ auto addRes = ext2_add_dir_entry(&this->fCtx, parentDirNode, dirname, newInodeNumber,
kExt2FileTypeDirectory);
if (!addRes) {
kout << "EXT2: Failed to add directory entry for '" << dirname << "' to parent.\n";
@@ -1548,7 +1542,7 @@ NodePtr Ext2FileSystemParser::CreateDirectory(const char* path) {
// Increment parent link count and persist parent inode
parentDirNode->inode.fLinksCount += 1;
- auto parentWriteRes = ext2_write_inode(&this->ctx, parentDirNode);
+ auto parentWriteRes = ext2_write_inode(&this->fCtx, parentDirNode);
if (!parentWriteRes) {
kout << "EXT2: Warning: failed to update parent inode after directory creation.\n";
}
diff --git a/dev/kernel/src/FS/HeFS+FileMgr.cc b/dev/kernel/src/FS/HeFS+FileMgr.cc
deleted file mode 100644
index e4985a3b..00000000
--- a/dev/kernel/src/FS/HeFS+FileMgr.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-/* -------------------------------------------
-
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
-
-------------------------------------------- */
-
-#ifndef __NE_MINIMAL_OS__
-#ifdef __FSKIT_INCLUDES_HEFS__
-
-#include <KernelKit/FileMgr.h>
-#include <KernelKit/HeapMgr.h>
-
-#endif // ifdef __FSKIT_INCLUDES_HEFS__
-#endif // ifndef __NE_MINIMAL_OS__
diff --git a/dev/kernel/src/FS/NeFS+FileSystemParser.cc b/dev/kernel/src/FS/NeFS+FileSystemParser.cc
index 14e0b974..b50841a4 100644
--- a/dev/kernel/src/FS/NeFS+FileSystemParser.cc
+++ b/dev/kernel/src/FS/NeFS+FileSystemParser.cc
@@ -74,7 +74,7 @@ static inline bool is_valid_lba(Lba lba, DriveTrait& drive) {
return (lba >= part_block.StartCatalog) && (lba < maxLba);
}
-STATIC MountpointInterface kMountpoint;
+STATIC IMountpoint kMountpoint;
/***********************************************************************************/
/// @brief Creates a new fork inside the New filesystem partition.
/// @param catalog it's catalog
@@ -141,7 +141,7 @@ _Output BOOL NeFileSystemParser::CreateFork(_Input NEFS_FORK_STRUCT& the_fork) {
drv.fPacket.fPacketContent = reinterpret_cast<VoidPtr>(&the_fork);
drv.fOutput(drv.fPacket);
- fs_ifs_write(&kMountpoint, drv, MountpointInterface::kDriveIndexA);
+ fs_ifs_write(&kMountpoint, drv, IMountpoint::kDriveIndexA);
delete catalog;
return YES;
@@ -858,7 +858,7 @@ namespace Kernel::NeFS {
/// @brief Construct NeFS drives.
/***********************************************************************************/
Boolean fs_init_nefs(Void) noexcept {
- kout << "Creating HeFS disk...\r";
+ kout << "Creating OpenHeFS disk...\r";
kMountpoint.A() = io_construct_main_drive();
if (kMountpoint.A().fPacket.fPacketReadOnly == YES)
ke_panic(RUNTIME_CHECK_FILESYSTEM, "Main disk cannot be mounted.");
diff --git a/dev/kernel/src/FS/OpenHeFS+FileMgr.cc b/dev/kernel/src/FS/OpenHeFS+FileMgr.cc
new file mode 100644
index 00000000..bb87fd67
--- /dev/null
+++ b/dev/kernel/src/FS/OpenHeFS+FileMgr.cc
@@ -0,0 +1,191 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#ifndef __NE_MINIMAL_OS__
+#ifdef __FSKIT_INCLUDES_HEFS__
+
+#include <KernelKit/FileMgr.h>
+#include <KernelKit/HeapMgr.h>
+
+/// @brief OpenHeFS File System Manager.
+/// BUGS: 0
+
+namespace Kernel {
+/// @brief C++ constructor
+HeFileSystemMgr::HeFileSystemMgr() {
+ mParser = new HeFileSystemParser();
+ MUST_PASS(mParser);
+
+ kout << "We are done allocating HeFileSystemParser...\n";
+}
+
+HeFileSystemMgr::~HeFileSystemMgr() {
+ if (mParser) {
+ kout << "Destroying HeFileSystemParser...\n";
+ delete mParser;
+ mParser = nullptr;
+ }
+}
+
+/// @brief Removes a node from the filesystem.
+/// @param path The filename
+/// @return If it was deleted or not.
+bool HeFileSystemMgr::Remove(_Input const Char* path) {
+ if (path == nullptr || *path == 0) {
+ kout << "OpenHeFS: Remove called with null or empty path\n";
+ return false;
+ }
+
+ return NO;
+}
+
+/// @brief Creates a node with the specified.
+/// @param path The filename path.
+/// @return The Node pointer.
+NodePtr HeFileSystemMgr::Create(_Input const Char* path) {
+ if (!path || *path == 0) {
+ kout << "OpenHeFS: Create called with null or empty path\n";
+ return nullptr;
+ }
+ return nullptr;
+}
+
+/// @brief Creates a node which is a directory.
+/// @param path The filename path.
+/// @return The Node pointer.
+NodePtr HeFileSystemMgr::CreateDirectory(const Char* path) {
+ if (!path || *path == 0) {
+ kout << "OpenHeFS: CreateDirectory called with null or empty path\n";
+ return nullptr;
+ }
+ return nullptr;
+}
+
+/// @brief Creates a node which is an alias.
+/// @param path The filename path.
+/// @return The Node pointer.
+NodePtr HeFileSystemMgr::CreateAlias(const Char* path) {
+ if (!path || *path == 0) {
+ kout << "OpenHeFS: CreateAlias called with null or empty path\n";
+ return nullptr;
+ }
+ return nullptr;
+}
+
+NodePtr HeFileSystemMgr::CreateSwapFile(const Char* path) {
+ if (!path || *path == 0) {
+ kout << "OpenHeFS: CreateSwapFile called with null or empty path\n";
+ return nullptr;
+ }
+ return nullptr;
+}
+
+/// @brief Gets the root directory.
+/// @return
+const Char* NeFileSystemHelper::Root() {
+ return kHeFSRootDirectory;
+}
+
+/// @brief Gets the up-dir directory.
+/// @return
+const Char* NeFileSystemHelper::UpDir() {
+ return kHeFSUpDir;
+}
+
+/// @brief Gets the separator character.
+/// @return
+Char NeFileSystemHelper::Separator() {
+ return kHeFSSeparator;
+}
+
+/// @brief Gets the metafile character.
+/// @return
+Char NeFileSystemHelper::MetaFile() {
+ return '\0';
+}
+
+/// @brief Opens a new file.
+/// @param path
+/// @param r
+/// @return
+_Output NodePtr HeFileSystemMgr::Open(_Input const Char* path, _Input const Char* r) {
+ if (!path || *path == 0) {
+ kout << "OpenHeFS: Open called with null or empty path\n";
+ return nullptr;
+ }
+ if (!r || *r == 0) {
+ kout << "OpenHeFS: Open called with null or empty mode string\n";
+ return nullptr;
+ }
+ return nullptr;
+}
+
+Void HeFileSystemMgr::Write(_Input NodePtr node, _Input VoidPtr data, _Input Int32 flags,
+ _Input SizeT size) {
+ NE_UNUSED(node);
+ NE_UNUSED(flags);
+ NE_UNUSED(size);
+ NE_UNUSED(data);
+}
+
+_Output VoidPtr HeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) {
+ NE_UNUSED(node);
+ NE_UNUSED(flags);
+ NE_UNUSED(size);
+
+ return nullptr;
+}
+
+Void HeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data,
+ _Input Int32 flags, _Input SizeT size) {
+ NE_UNUSED(node);
+ NE_UNUSED(flags);
+ NE_UNUSED(size);
+ NE_UNUSED(name);
+ NE_UNUSED(data);
+}
+
+_Output VoidPtr HeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node,
+ _Input Int32 flags, _Input SizeT sz) {
+ NE_UNUSED(node);
+ NE_UNUSED(flags);
+ NE_UNUSED(sz);
+ NE_UNUSED(name);
+
+ return nullptr;
+}
+
+_Output Bool HeFileSystemMgr::Seek(NodePtr node, SizeT off) {
+ NE_UNUSED(node);
+ NE_UNUSED(off);
+
+ return false;
+}
+
+/// @brief Tell current offset within catalog.
+/// @param node
+/// @return kFileMgrNPos if invalid, else current offset.
+_Output SizeT HeFileSystemMgr::Tell(NodePtr node) {
+ NE_UNUSED(node);
+ return kFileMgrNPos;
+}
+
+/// @brief Rewinds the catalog
+/// @param node
+/// @return False if invalid, nah? calls Seek(node, 0).
+_Output Bool HeFileSystemMgr::Rewind(NodePtr node) {
+ NE_UNUSED(node);
+ return kFileMgrNPos;
+}
+
+/// @brief Returns the parser of OpenHeFS.
+_Output HeFileSystemParser* HeFileSystemMgr::GetParser() noexcept {
+ return mParser;
+}
+} // namespace Kernel
+
+#endif // ifdef __FSKIT_INCLUDES_HEFS__
+#endif // ifndef __NE_MINIMAL_OS__
diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc
index 86f929c0..3746ebc1 100644
--- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc
+++ b/dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc
@@ -6,7 +6,7 @@
#ifdef __FSKIT_INCLUDES_HEFS__
-#include <FSKit/HeFS.h>
+#include <FSKit/OpenHeFS.h>
#include <FirmwareKit/EPM.h>
#include <FirmwareKit/GPT.h>
#include <KernelKit/KPC.h>
@@ -79,12 +79,14 @@ namespace Detail {
const Utf8Char* dir_name, UInt16 flags,
const BOOL delete_or_create);
+ /// @brief This helper makes it easier for other machines to understand OpenHeFS encoded hashes.
STATIC UInt64 hefsi_to_big_endian_64(UInt64 val) {
return ((val >> 56) & 0x00000000000000FFULL) | ((val >> 40) & 0x000000000000FF00ULL) |
((val >> 24) & 0x0000000000FF0000ULL) | ((val >> 8) & 0x00000000FF000000ULL) |
((val << 8) & 0x000000FF00000000ULL) | ((val << 24) & 0x0000FF0000000000ULL) |
((val << 40) & 0x00FF000000000000ULL) | ((val << 56) & 0xFF00000000000000ULL);
}
+
/// @brief Simple algorithm to hash directory entries for INDs.
/// @param path the directory path.
/// @return The hashed path.
@@ -741,12 +743,12 @@ namespace Detail {
} // namespace Detail
} // namespace Kernel
-/// @note HeFS will allocate inodes and ind in advance, to avoid having to allocate them in
+/// @note OpenHeFS will allocate inodes and ind in advance, to avoid having to allocate them in
/// real-time.
/// @note This is certainly take longer to format a disk with it, but worth-it in the long run.
namespace Kernel {
-/// @brief Make a EPM+HeFS mnt out of the disk.
+/// @brief Make a EPM+OpenHeFS mnt out of the disk.
/// @param mnt The mnt to write on.
/// @return If it was sucessful, see err_local_get().
_Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input const Int32 flags,
@@ -764,7 +766,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c
(Void)(kout << "OpenHeFS recommends at least 128 GiB of free space." << kendl);
(Void)(
kout
- << "The OS will still try to format a HeFS disk here anyway, don't expect perfect geometry."
+ << "The OS will still try to format a OpenHeFS disk here anyway, don't expect perfect geometry."
<< kendl);
}
@@ -820,7 +822,7 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c
MUST_PASS(boot->fSectorSize);
- /// @note all HeFS strucutres are equal to 512, so here it's fine, unless fSectoSize is 2048.
+ /// @note all OpenHeFS strucutres are equal to 512, so here it's fine, unless fSectoSize is 2048.
const SizeT max_lba = (drv_std_get_size()) / boot->fSectorSize;
const SizeT dir_max = max_lba / 300; // 5% for directory inodes
@@ -1005,7 +1007,7 @@ _Output Bool HeFileSystemParser::INodeManip(_Input DriveTrait* mnt, VoidPtr bloc
mnt->fInput(mnt->fPacket);
if (!KStringBuilder::Equals(boot->fMagic, kHeFSMagic) || boot->fVersion != kHeFSVersion) {
- (Void)(kout << "Invalid Boot Node, HeFS partition is invalid." << kendl);
+ (Void)(kout << "Invalid Boot Node, OpenHeFS partition is invalid." << kendl);
mm_free_ptr((VoidPtr) boot);
err_global_get() = kErrorDisk;
return NO;
@@ -1145,9 +1147,9 @@ _Output Bool HeFileSystemParser::INodeCtlManip(_Input DriveTrait* mnt, _Input co
STATIC DriveTrait kMountPoint;
-/// @brief Initialize the HeFS filesystem.
+/// @brief Initialize the OpenHeFS filesystem.
/// @return To check its status, see err_local_get().
-Boolean HeFS::fs_init_hefs(Void) noexcept {
+Boolean OpenHeFS::fs_init_hefs(Void) noexcept {
kout << "Verifying disk...\r";
kMountPoint = io_construct_main_drive();
diff --git a/dev/kernel/src/GUIDWizard.cc b/dev/kernel/src/GUIDWizard.cc
index 46915ace..b36fffc2 100644
--- a/dev/kernel/src/GUIDWizard.cc
+++ b/dev/kernel/src/GUIDWizard.cc
@@ -17,13 +17,15 @@
// @brief Size of UUID.
#define kUUIDSize 37
-namespace CF::XRN::Version1 {
+namespace Kernel::CF::XRN::Version1 {
auto cf_make_sequence(const ArrayList<UInt32>& uuidSeq) -> Ref<GUIDSequence*> {
GUIDSequence* seq = new GUIDSequence();
MUST_PASS(seq);
Ref<GUIDSequence*> seq_ref{seq};
+ if (!seq) return seq_ref;
+
seq_ref.Leak()->fUuid.fMs1 = uuidSeq[0];
seq_ref.Leak()->fUuid.fMs2 = uuidSeq[1];
seq_ref.Leak()->fUuid.fMs3 = uuidSeq[2];
@@ -60,6 +62,6 @@ auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<KString>> {
if (view) return ErrorOr<Ref<KString>>{view.Leak()};
- return ErrorOr<Ref<KString>>{-1};
+ return ErrorOr<Ref<KString>>{kErrorInvalidData};
}
-} // namespace CF::XRN::Version1
+} // namespace Kernel::CF::XRN::Version1
diff --git a/dev/kernel/src/GUIDWrapper.cc b/dev/kernel/src/GUIDWrapper.cc
index f87a1bdd..d5ab6bb8 100644
--- a/dev/kernel/src/GUIDWrapper.cc
+++ b/dev/kernel/src/GUIDWrapper.cc
@@ -6,4 +6,4 @@
#include <CFKit/GUIDWrapper.h>
-namespace CF::XRN {}
+namespace Kernel::CF::XRN {}
diff --git a/dev/kernel/src/HardwareThreadScheduler.cc b/dev/kernel/src/HardwareThreadScheduler.cc
index 86f46718..a4b6b4b8 100644
--- a/dev/kernel/src/HardwareThreadScheduler.cc
+++ b/dev/kernel/src/HardwareThreadScheduler.cc
@@ -134,7 +134,7 @@ HardwareThreadScheduler& HardwareThreadScheduler::The() {
/// @brief Get Stack Frame of AP.
/***********************************************************************************/
HAL::StackFramePtr HardwareThreadScheduler::Leak() noexcept {
- return fThreadList[fCurrentThread].fStack;
+ return fThreadList[fCurrentThreadIdx].fStack;
}
/***********************************************************************************/
@@ -150,6 +150,7 @@ Ref<HardwareThread*> HardwareThreadScheduler::operator[](SizeT idx) {
return {kFakeThread};
}
+ fCurrentThreadIdx = idx;
return &fThreadList[idx];
}
diff --git a/dev/kernel/src/IFS.cc b/dev/kernel/src/IFS.cc
index ba2ec8c0..ffb8ef8e 100644
--- a/dev/kernel/src/IFS.cc
+++ b/dev/kernel/src/IFS.cc
@@ -28,25 +28,25 @@ namespace Kernel {
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
+Int32 fs_ifs_read(IMountpoint* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
if (!Mnt) return kErrorDisk;
DrvTrait.fPacket.fPacketGood = false;
switch (DrvIndex) {
- case MountpointInterface::kDriveIndexA: {
+ case IMountpoint::kDriveIndexA: {
fsi_ifs_read(A, DrvTrait.fPacket, Mnt);
break;
}
- case MountpointInterface::kDriveIndexB: {
+ case IMountpoint::kDriveIndexB: {
fsi_ifs_read(B, DrvTrait.fPacket, Mnt);
break;
}
- case MountpointInterface::kDriveIndexC: {
+ case IMountpoint::kDriveIndexC: {
fsi_ifs_read(C, DrvTrait.fPacket, Mnt);
break;
}
- case MountpointInterface::kDriveIndexD: {
+ case IMountpoint::kDriveIndexD: {
fsi_ifs_read(D, DrvTrait.fPacket, Mnt);
break;
}
@@ -60,25 +60,25 @@ Int32 fs_ifs_read(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex
/// @param DrvTrait drive info
/// @param DrvIndex drive index.
/// @return
-Int32 fs_ifs_write(MountpointInterface* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
+Int32 fs_ifs_write(IMountpoint* Mnt, DriveTrait& DrvTrait, Int32 DrvIndex) {
if (!Mnt) return kErrorDisk;
DrvTrait.fPacket.fPacketGood = false;
switch (DrvIndex) {
- case MountpointInterface::kDriveIndexA: {
+ case IMountpoint::kDriveIndexA: {
fsi_ifs_write(A, DrvTrait.fPacket, Mnt);
break;
}
- case MountpointInterface::kDriveIndexB: {
+ case IMountpoint::kDriveIndexB: {
fsi_ifs_write(B, DrvTrait.fPacket, Mnt);
break;
}
- case MountpointInterface::kDriveIndexC: {
+ case IMountpoint::kDriveIndexC: {
fsi_ifs_write(C, DrvTrait.fPacket, Mnt);
break;
}
- case MountpointInterface::kDriveIndexD: {
+ case IMountpoint::kDriveIndexD: {
fsi_ifs_write(D, DrvTrait.fPacket, Mnt);
break;
}
diff --git a/dev/kernel/src/IPEFDylibObject.cc b/dev/kernel/src/IPEFDylibObject.cc
index a24fba72..91f8c88a 100644
--- a/dev/kernel/src/IPEFDylibObject.cc
+++ b/dev/kernel/src/IPEFDylibObject.cc
@@ -90,6 +90,10 @@ EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& process) {
EXTERN_C Void rtl_fini_dylib_pef(USER_PROCESS& process, IDylibRef dll_obj, BOOL* successful) {
MUST_PASS(successful);
+ if (!successful) {
+ return;
+ }
+
// sanity check (will also trigger a bug check if this fails)
if (dll_obj == nullptr) {
*successful = false;
diff --git a/dev/kernel/src/IndexableProperty.cc b/dev/kernel/src/IndexableProperty.cc
index c11e328d..56143607 100644
--- a/dev/kernel/src/IndexableProperty.cc
+++ b/dev/kernel/src/IndexableProperty.cc
@@ -22,7 +22,7 @@ namespace Indexer {
Void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; }
- Void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; }
+ Void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= ~(flag); }
Int16 IndexableProperty::HasFlag(Int16 flag) { return fFlags & flag; }
@@ -33,6 +33,7 @@ namespace Indexer {
/// @return none, check before if indexer can be claimed (using indexer.HasFlag(kIndexerClaimed)).
Void fs_index_file(const Char* filename, SizeT filenameLen, IndexableProperty& indexer) {
if (!indexer.HasFlag(kIndexerClaimed)) {
+ indexer.RemoveFlag(kIndexerUnclaimed);
indexer.AddFlag(kIndexerClaimed);
rt_copy_memory_safe(reinterpret_cast<VoidPtr>(const_cast<Char*>(filename)),
(VoidPtr) indexer.Leak().Path, filenameLen, kIndexerCatalogNameLength);
diff --git a/dev/kernel/src/Json.cc b/dev/kernel/src/Json.cc
index 68ab55fc..d156c0ce 100644
--- a/dev/kernel/src/Json.cc
+++ b/dev/kernel/src/Json.cc
@@ -7,4 +7,4 @@
#include <NeKit/Json.h>
/// @brief Undefined object, is null in length.
-RTL_INIT_OBJECT(Kernel::Json::kNull, Kernel::Json);
+RTL_INIT_OBJECT(Kernel::JsonObject::kNull, Kernel::JsonObject);
diff --git a/dev/kernel/src/KernelTaskScheduler.cc b/dev/kernel/src/KernelTaskScheduler.cc
index 1997c175..8bbe5601 100644
--- a/dev/kernel/src/KernelTaskScheduler.cc
+++ b/dev/kernel/src/KernelTaskScheduler.cc
@@ -15,4 +15,17 @@
/// @author Amlal El Mahrouss (amlal@nekernel.org)
/***********************************************************************************/
-namespace Kernel {} // namespace Kernel \ No newline at end of file
+namespace Kernel {
+EXTERN_C Void hal_switch_kernel_task(HAL::StackFramePtr frame, ProcessID kid);
+
+Bool KernelTaskHelper::Switch(HAL::StackFramePtr frame_ptr, ProcessID new_kid) {
+ NE_UNUSED(frame_ptr);
+ NE_UNUSED(new_kid);
+
+ return NO;
+}
+
+Bool KernelTaskHelper::CanBeScheduled(const KERNEL_TASK& task) {
+ return task.Kid > 0 && task.Image.HasCode();
+}
+} // namespace Kernel \ No newline at end of file
diff --git a/dev/kernel/src/Network/IPAddress.cc b/dev/kernel/src/Network/IPAddress.cc
index b02eae08..bc46292b 100644
--- a/dev/kernel/src/Network/IPAddress.cc
+++ b/dev/kernel/src/Network/IPAddress.cc
@@ -73,14 +73,14 @@ bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6) {
/// @todo
ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress6>& ipv6) {
NE_UNUSED(ipv6);
- auto str = KStringBuilder::Construct(0);
+ auto str = KStringBuilder::Construct("");
return str;
}
/// @todo
ErrorOr<KString> IPFactory::ToKString(Ref<RawIPAddress>& ipv4) {
NE_UNUSED(ipv4);
- auto str = KStringBuilder::Construct(0);
+ auto str = KStringBuilder::Construct("");
return str;
}
diff --git a/dev/kernel/src/Network/NetworkDevice.cc b/dev/kernel/src/Network/NetworkDevice.cc
index 7f93fa1b..ffdfa53b 100644
--- a/dev/kernel/src/Network/NetworkDevice.cc
+++ b/dev/kernel/src/Network/NetworkDevice.cc
@@ -11,7 +11,7 @@ namespace Kernel {
/// \brief Getter for fNetworkName.
/// \return Network device name.
const Char* NetworkDevice::Name() const {
- return "/devices/net{}";
+ return "/devices/net/net{}";
}
/// \brief Setter for fNetworkName.
diff --git a/dev/kernel/src/PEFCodeMgr.cc b/dev/kernel/src/PEFCodeMgr.cc
index c0caeb5b..a0d0a6af 100644
--- a/dev/kernel/src/PEFCodeMgr.cc
+++ b/dev/kernel/src/PEFCodeMgr.cc
@@ -53,7 +53,37 @@ namespace Detail {
/***********************************************************************************/
PEFLoader::PEFLoader(const VoidPtr blob) : fCachedBlob(blob) {
MUST_PASS(fCachedBlob);
- fBad = false;
+
+ if (!fCachedBlob) {
+ this->fBad = YES;
+ return;
+ }
+
+ PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob);
+
+ if (container->Abi == kPefAbi &&
+ container->Count >=
+ 3) { /* if same ABI, AND: .text, .bss, .data (or at least similar) exists */
+ if (container->Cpu == Detail::ldr_get_platform() && container->Magic[0] == kPefMagic[0] &&
+ container->Magic[1] == kPefMagic[1] && container->Magic[2] == kPefMagic[2] &&
+ container->Magic[3] == kPefMagic[3] && container->Magic[4] == kPefMagic[4]) {
+ return;
+ } else if (container->Magic[0] == kPefMagicFat[0] && container->Magic[1] == kPefMagicFat[1] &&
+ container->Magic[2] == kPefMagicFat[2] && container->Magic[3] == kPefMagicFat[3] &&
+ container->Magic[4] == kPefMagicFat[4]) {
+ /// This is a fat binary. Treat it as such.
+ this->fFatBinary = YES;
+ return;
+ }
+ }
+
+ kout << "PEFLoader: warning: Binary format error!\r";
+
+ this->fFatBinary = NO;
+ this->fBad = YES;
+
+ if (this->fCachedBlob) mm_free_ptr(this->fCachedBlob);
+ this->fCachedBlob = nullptr;
}
/***********************************************************************************/
@@ -69,6 +99,11 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false)
/// @note zero here means that the FileMgr will read every container header inside the file.
fCachedBlob = fFile->Read(kPefHeader, 0UL);
+ if (!fCachedBlob) {
+ this->fBad = YES;
+ return;
+ }
+
PEFContainer* container = reinterpret_cast<PEFContainer*>(fCachedBlob);
if (container->Abi == kPefAbi &&
@@ -82,18 +117,18 @@ PEFLoader::PEFLoader(const Char* path) : fCachedBlob(nullptr), fFatBinary(false)
container->Magic[2] == kPefMagicFat[2] && container->Magic[3] == kPefMagicFat[3] &&
container->Magic[4] == kPefMagicFat[4]) {
/// This is a fat binary, treat it as such.
- this->fFatBinary = true;
+ this->fFatBinary = YES;
return;
}
}
- fBad = true;
+ kout << "PEFLoader: warning: Binary format error!\r";
- if (fCachedBlob) mm_free_ptr(fCachedBlob);
-
- kout << "PEFLoader: warning: exec format error!\r";
+ this->fFatBinary = NO;
+ this->fBad = YES;
- fCachedBlob = nullptr;
+ if (this->fCachedBlob) mm_free_ptr(this->fCachedBlob);
+ this->fCachedBlob = nullptr;
}
/***********************************************************************************/
@@ -127,9 +162,8 @@ ErrorOr<VoidPtr> PEFLoader::FindSymbol(const Char* name, Int32 kind) {
return ErrorOr<VoidPtr>{kErrorInvalidData};
/// fat binary check.
- if (command_header->Cpu != container->Cpu && !this->fFatBinary) {
+ if (command_header->Cpu != container->Cpu && !this->fFatBinary)
return ErrorOr<VoidPtr>{kErrorInvalidData};
- }
const auto kMangleCharacter = '$';
const Char* kContainerKinds[] = {".code64", ".data64", ".zero64", nullptr};
@@ -183,7 +217,7 @@ ErrorOr<VoidPtr> PEFLoader::FindSymbol(const Char* name, Int32 kind) {
mm_free_ptr(blob);
- kout << "PEFLoader: info: Loaded stub: " << command_header->Name << "!\r";
+ kout << "PEFLoader: info: Load stub: " << command_header->Name << "!\r";
Int32 ret = 0;
SizeT pages_count = (command_header->VMSize + kPageSize - 1) / kPageSize;
diff --git a/dev/kernel/src/Property.cc b/dev/kernel/src/Property.cc
index 581da501..714fb2a4 100644
--- a/dev/kernel/src/Property.cc
+++ b/dev/kernel/src/Property.cc
@@ -6,7 +6,7 @@
#include <CFKit/Property.h>
-namespace CF {
+namespace Kernel::CF {
/***********************************************************************************/
/// @brief Destructor.
/***********************************************************************************/
@@ -21,14 +21,14 @@ Property::Property() = default;
/// @brief Check if property's name equals to name.
/// @param name string to check.
/***********************************************************************************/
-Bool Property::StringEquals(BasicKString<>& name) {
+Bool Property::StringEquals(KBasicString<>& name) {
return this->fName && this->fName == name;
}
/***********************************************************************************/
/// @brief Gets the key (name) of property.
/***********************************************************************************/
-BasicKString<>& Property::GetKey() {
+KBasicString<>& Property::GetKey() {
return this->fName;
}
@@ -38,4 +38,4 @@ BasicKString<>& Property::GetKey() {
PropertyId& Property::GetValue() {
return fValue;
}
-} // namespace CF
+} // namespace Kernel::CF
diff --git a/dev/kernel/src/Storage/AHCIDeviceInterface.cc b/dev/kernel/src/Storage/AHCIDeviceInterface.cc
index 39570665..6dcfed69 100644
--- a/dev/kernel/src/Storage/AHCIDeviceInterface.cc
+++ b/dev/kernel/src/Storage/AHCIDeviceInterface.cc
@@ -13,9 +13,9 @@ using namespace Kernel;
/// @param In Drive input
/// @param Cleanup Drive cleanup.
AHCIDeviceInterface::AHCIDeviceInterface(void (*out)(DeviceInterface* self,
- MountpointInterface* outpacket),
+ IMountpoint* outpacket),
void (*in)(DeviceInterface* self,
- MountpointInterface* inpacket))
+ IMountpoint* inpacket))
: DeviceInterface(out, in) {}
/// @brief Class desctructor
@@ -30,7 +30,7 @@ const Char* AHCIDeviceInterface::Name() const {
/// @brief Output operator.
/// @param mnt the disk mountpoint.
/// @return the class itself after operation.
-AHCIDeviceInterface& AHCIDeviceInterface::operator<<(MountpointInterface* mnt) {
+AHCIDeviceInterface& AHCIDeviceInterface::operator<<(IMountpoint* mnt) {
if (!mnt) return *this;
for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) {
@@ -45,13 +45,13 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator<<(MountpointInterface* mnt) {
}
}
- return (AHCIDeviceInterface&) DeviceInterface<MountpointInterface*>::operator<<(mnt);
+ return (AHCIDeviceInterface&) DeviceInterface<IMountpoint*>::operator<<(mnt);
}
/// @brief Input operator.
/// @param mnt the disk mountpoint.
/// @return the class itself after operation.
-AHCIDeviceInterface& AHCIDeviceInterface::operator>>(MountpointInterface* mnt) {
+AHCIDeviceInterface& AHCIDeviceInterface::operator>>(IMountpoint* mnt) {
if (!mnt) return *this;
for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) {
@@ -67,7 +67,7 @@ AHCIDeviceInterface& AHCIDeviceInterface::operator>>(MountpointInterface* mnt) {
}
}
- return (AHCIDeviceInterface&) DeviceInterface<MountpointInterface*>::operator>>(mnt);
+ return (AHCIDeviceInterface&) DeviceInterface<IMountpoint*>::operator>>(mnt);
}
const UInt16& AHCIDeviceInterface::GetPortsImplemented() {
@@ -84,6 +84,6 @@ const UInt32& AHCIDeviceInterface::GetIndex() {
}
Void AHCIDeviceInterface::SetIndex(const UInt32& drv) {
- MUST_PASS(MountpointInterface::kDriveIndexInvalid != drv);
+ MUST_PASS(IMountpoint::kDriveIndexInvalid < drv);
this->fDriveIndex = drv;
} \ No newline at end of file
diff --git a/dev/kernel/src/Storage/ATADeviceInterface.cc b/dev/kernel/src/Storage/ATADeviceInterface.cc
index 609837af..70d6e9ae 100644
--- a/dev/kernel/src/Storage/ATADeviceInterface.cc
+++ b/dev/kernel/src/Storage/ATADeviceInterface.cc
@@ -13,8 +13,8 @@ using namespace Kernel;
/// @param In Drive input
/// @param Cleanup Drive cleanup.
ATADeviceInterface::ATADeviceInterface(void (*Out)(DeviceInterface*,
- MountpointInterface* outpacket),
- void (*In)(DeviceInterface*, MountpointInterface* inpacket))
+ IMountpoint* outpacket),
+ void (*In)(DeviceInterface*, IMountpoint* inpacket))
: DeviceInterface(Out, In) {}
/// @brief Class desctructor
@@ -29,7 +29,7 @@ const Char* ATADeviceInterface::Name() const {
/// @brief Output operator.
/// @param Data the disk mountpoint.
/// @return the class itself after operation.
-ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) {
+ATADeviceInterface& ATADeviceInterface::operator<<(IMountpoint* Data) {
if (!Data) return *this;
for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) {
@@ -44,13 +44,13 @@ ATADeviceInterface& ATADeviceInterface::operator<<(MountpointInterface* Data) {
}
}
- return (ATADeviceInterface&) DeviceInterface<MountpointInterface*>::operator<<(Data);
+ return (ATADeviceInterface&) DeviceInterface<IMountpoint*>::operator<<(Data);
}
/// @brief Input operator.
/// @param Data the disk mountpoint.
/// @return the class itself after operation.
-ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) {
+ATADeviceInterface& ATADeviceInterface::operator>>(IMountpoint* Data) {
if (!Data) return *this;
for (SizeT driveCount = 0; driveCount < kDriveMaxCount; ++driveCount) {
@@ -66,7 +66,7 @@ ATADeviceInterface& ATADeviceInterface::operator>>(MountpointInterface* Data) {
}
}
- return (ATADeviceInterface&) DeviceInterface<MountpointInterface*>::operator>>(Data);
+ return (ATADeviceInterface&) DeviceInterface<IMountpoint*>::operator>>(Data);
}
const UInt32& ATADeviceInterface::GetIndex() {
@@ -74,7 +74,7 @@ const UInt32& ATADeviceInterface::GetIndex() {
}
Void ATADeviceInterface::SetIndex(const UInt32& drv) {
- MUST_PASS(MountpointInterface::kDriveIndexInvalid != drv);
+ MUST_PASS(IMountpoint::kDriveIndexInvalid < drv);
this->fDriveIndex = drv;
}
diff --git a/dev/kernel/src/Storage/NVMEDeviceInterface.cc b/dev/kernel/src/Storage/NVMEDeviceInterface.cc
index 077595cf..0b8043b7 100644
--- a/dev/kernel/src/Storage/NVMEDeviceInterface.cc
+++ b/dev/kernel/src/Storage/NVMEDeviceInterface.cc
@@ -8,8 +8,8 @@
namespace Kernel {
NVMEDeviceInterface::NVMEDeviceInterface(
- void (*out)(DeviceInterface*, MountpointInterface* outpacket),
- void (*in)(DeviceInterface*, MountpointInterface* inpacket), void (*cleanup)(void))
+ void (*out)(DeviceInterface*, IMountpoint* outpacket),
+ void (*in)(DeviceInterface*, IMountpoint* inpacket), void (*cleanup)(void))
: DeviceInterface(out, in), fCleanup(cleanup) {}
NVMEDeviceInterface::~NVMEDeviceInterface() {
diff --git a/dev/kernel/src/Swap/DiskSwap.cc b/dev/kernel/src/Swap/DiskSwap.cc
index 8578450c..99efb2c0 100644
--- a/dev/kernel/src/Swap/DiskSwap.cc
+++ b/dev/kernel/src/Swap/DiskSwap.cc
@@ -8,6 +8,8 @@
#include <SwapKit/DiskSwap.h>
namespace Kernel {
+static constexpr UInt32 kSwapDiskHeaderMagic = 0x44535750; // 'DSWP'
+
/***********************************************************************************/
/// @brief Write memory chunk onto disk.
/// @param fork_name The swap name to recognize this memory region.
@@ -20,7 +22,7 @@ BOOL DiskSwapInterface::Write(const Char* fork_name, SizeT fork_name_len, SWAP_D
if (*fork_name == 0) return NO;
- if (!data) return NO;
+ if (!data || data->fMagic != kSwapDiskHeaderMagic) return NO;
FileStream file(kSwapPageFilePath, kRestrictWRB);
@@ -52,6 +54,11 @@ SWAP_DISK_HEADER* DiskSwapInterface::Read(const Char* fork_name, SizeT fork_name
VoidPtr blob = file.Read(fork_name, sizeof(SWAP_DISK_HEADER) + data_len);
+ if (!blob || ((SWAP_DISK_HEADER*) blob)->fMagic != kSwapDiskHeaderMagic) {
+ if (blob) mm_free_ptr(blob);
+ return nullptr;
+ }
+
return reinterpret_cast<SWAP_DISK_HEADER*>(blob);
}
} // namespace Kernel
diff --git a/dev/kernel/src/UserMgr.cc b/dev/kernel/src/UserMgr.cc
index 8e4ba540..5ee2aa33 100644
--- a/dev/kernel/src/UserMgr.cc
+++ b/dev/kernel/src/UserMgr.cc
@@ -22,7 +22,7 @@
#define kStdUserType (0xEE)
#define kSuperUserType (0xEF)
-/// @file User.cc
+/// @file UserMgr.cc
/// @brief Multi-user support.
namespace Kernel {
@@ -38,14 +38,14 @@ namespace Detail {
kout << "user_fnv_generator: Hashing user password...\r";
- const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL;
- const UInt64 FNV_PRIME = 0x100000001b3ULL;
+ const UInt64 kFnvOffsetBasis = 0xcbf29ce484222325ULL;
+ const UInt64 fFnvPrime = 0x100000001b3ULL;
- UInt64 hash = FNV_OFFSET_BASIS;
+ UInt64 hash = kFnvOffsetBasis;
while (*password) {
- hash ^= (Utf8Char) (*password++);
- hash *= FNV_PRIME;
+ hash ^= (Char) (*password++);
+ hash *= fFnvPrime;
}
kout << "user_fnv_generator: Hashed user password.\r";
diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc
index 07c4a572..ac25c3d8 100644
--- a/dev/kernel/src/UserProcessScheduler.cc
+++ b/dev/kernel/src/UserProcessScheduler.cc
@@ -21,7 +21,7 @@
#include <KernelKit/ProcessScheduler.h>
#include <NeKit/KString.h>
#include <NeKit/Utils.h>
-#include <SignalKit/SignalGen.h>
+#include <SignalKit/Signals.h>
///! BUGS: 0
@@ -462,15 +462,10 @@ UserProcessScheduler& UserProcessScheduler::The() {
/***********************************************************************************/
Void UserProcessScheduler::Remove(ProcessID process_id) {
- if (process_id < 0 || process_id > kSchedProcessLimitPerTeam) {
- return;
- }
-
- if (this->mTeam.mProcessList[process_id].Status == ProcessStatusKind::kInvalid) {
- return;
- }
+ if (process_id < 0 || process_id > kSchedProcessLimitPerTeam) return;
+ if (this->mTeam.mProcessList[process_id].Status == ProcessStatusKind::kInvalid) return;
- mTeam.mProcessList[process_id].Exit(0);
+ mTeam.mProcessList[process_id].Exit(kErrorSuccess);
}
/// @brief Is it a user scheduler?
@@ -586,17 +581,13 @@ ErrorOr<ProcessID> UserProcessHelper::TheCurrentPID() {
/// @retval true can be schedulded.
/// @retval false cannot be schedulded.
Bool UserProcessHelper::CanBeScheduled(const USER_PROCESS& process) {
+ if (process.Affinity == AffinityKind::kRealTime) return Yes;
+
if (process.Status != ProcessStatusKind::kRunning) return No;
if (process.Affinity == AffinityKind::kInvalid) return No;
if (process.StackSize > kSchedMaxStackSz) return No;
if (!process.Name[0]) return No;
-
- // real time processes shouldn't wait that much.
- if (process.Affinity == AffinityKind::kRealTime) return Yes;
-
- if (process.Signal.SignalID == sig_generate_unique<SIGTRAP>()) {
- return No;
- }
+ if (process.Signal.SignalID == sig_generate_unique<SIGTRAP>()) return No;
return process.PTime < 1;
}
diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc
index e98b8306..d0523b96 100644
--- a/dev/kernel/src/UtfUtils.cc
+++ b/dev/kernel/src/UtfUtils.cc
@@ -10,6 +10,8 @@
namespace Kernel {
Size urt_string_len(const Utf8Char* str) {
+ if (!str) return 0;
+
SizeT len{0};
while (str[len] != u8'\0') ++len;
@@ -18,6 +20,8 @@ Size urt_string_len(const Utf8Char* str) {
}
Void urt_set_memory(const voidPtr src, UInt32 dst, Size len) {
+ if (!src) return;
+
Utf8Char* srcChr = reinterpret_cast<Utf8Char*>(src);
Size index = 0;
@@ -28,6 +32,8 @@ Void urt_set_memory(const voidPtr src, UInt32 dst, Size len) {
}
Int32 urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) {
+ if (!src) return 0;
+
Int32 counter = 0;
for (Size index = 0; index < size; ++index) {
@@ -38,6 +44,9 @@ Int32 urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) {
}
Int32 urt_copy_memory(const VoidPtr src, VoidPtr dst, Size len) {
+ if (!src) return 0;
+ if (!dst) return 0;
+
Utf8Char* srcChr = reinterpret_cast<Utf8Char*>(src);
Utf8Char* dstChar = reinterpret_cast<Utf8Char*>(dst);