summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-10-07 09:24:56 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-10-07 09:24:56 +0200
commit3b6a7e8c87f94391f92b55f20b9ba3e560ef280e (patch)
tree15fc04bff2ab6b07683dc1ea570aaf65dbce9fbb /dev/kernel
parentabff64f38c988a5350cbeb243896c0ee30401058 (diff)
feat: kernel & libSystem: improvements and tweaks.
feat: docs: wip design of Launch. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel')
-rw-r--r--dev/kernel/CFKit/GUIDWizard.h10
-rw-r--r--dev/kernel/CFKit/GUIDWrapper.h6
-rw-r--r--dev/kernel/CFKit/Property.h8
-rw-r--r--dev/kernel/CFKit/Utils.h6
-rw-r--r--dev/kernel/FSKit/Ext2+IFS.h2
-rw-r--r--dev/kernel/FSKit/HeFS.h8
-rw-r--r--dev/kernel/KernelKit/FileMgr.h4
-rw-r--r--dev/kernel/KernelKit/KernelTaskScheduler.h2
-rw-r--r--dev/kernel/KernelKit/UserProcessScheduler.h4
-rw-r--r--dev/kernel/NeKit/ErrorOr.h2
-rw-r--r--dev/kernel/NeKit/Pair.h38
-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.cc152
-rw-r--r--dev/kernel/src/GUIDWizard.cc4
-rw-r--r--dev/kernel/src/GUIDWrapper.cc2
-rw-r--r--dev/kernel/src/PEFCodeMgr.cc54
-rw-r--r--dev/kernel/src/Property.cc4
18 files changed, 341 insertions, 144 deletions
diff --git a/dev/kernel/CFKit/GUIDWizard.h b/dev/kernel/CFKit/GUIDWizard.h
index c7cb18ac..e2d9bcb1 100644
--- a/dev/kernel/CFKit/GUIDWizard.h
+++ b/dev/kernel/CFKit/GUIDWizard.h
@@ -15,9 +15,7 @@
#include <NeKit/Ref.h>
#include <NeKit/Stream.h>
-namespace CF::XRN::Version1 {
-using namespace Kernel;
-
-Ref<GUIDSequence*> cf_make_sequence(const ArrayList<UInt32>& seq);
-ErrorOr<Ref<Kernel::KString>> cf_try_guid_to_string(Ref<GUIDSequence*>& guid);
-} // namespace CF::XRN::Version1
+namespace Kernel::CF::XRN::Version1 {
+Ref<GUIDSequence*> cf_make_sequence(const ArrayList<UInt32>& seq);
+ErrorOr<Ref<KString>> cf_try_guid_to_string(Ref<GUIDSequence*>& guid);
+} // namespace Kernel::CF::XRN::Version1
diff --git a/dev/kernel/CFKit/GUIDWrapper.h b/dev/kernel/CFKit/GUIDWrapper.h
index a3920357..05cb4754 100644
--- a/dev/kernel/CFKit/GUIDWrapper.h
+++ b/dev/kernel/CFKit/GUIDWrapper.h
@@ -15,9 +15,7 @@
#define kXRNNil "@{........-....-M...-N...-............}"
/// @brief eXtended Resource Namespace
-namespace CF::XRN {
-using namespace Kernel;
-
+namespace Kernel::CF::XRN {
union GUIDSequence {
alignas(8) UShort fU8[16];
alignas(8) UShort fU16[8];
@@ -48,4 +46,4 @@ class GUID final {
private:
GUIDSequence fUUID;
};
-} // namespace CF::XRN
+} // namespace Kernel::CF::XRN
diff --git a/dev/kernel/CFKit/Property.h b/dev/kernel/CFKit/Property.h
index 7fc9bf07..17246a63 100644
--- a/dev/kernel/CFKit/Property.h
+++ b/dev/kernel/CFKit/Property.h
@@ -15,9 +15,7 @@
#define kMaxPropLen (256U)
-namespace CF {
-using namespace Kernel;
-
+namespace Kernel::CF {
/// @brief handle to anything (number, ptr, string...)
using PropertyId = UIntPtr;
@@ -44,10 +42,10 @@ class Property {
template <SizeT N>
using PropertyArray = Array<Property, N>;
-} // namespace CF
+} // namespace Kernel::CF
namespace Kernel {
-using namespace CF;
+using namespace Kernel::CF;
}
#endif // !CFKIT_PROPS_H
diff --git a/dev/kernel/CFKit/Utils.h b/dev/kernel/CFKit/Utils.h
index 97b0ee53..247ad5fb 100644
--- a/dev/kernel/CFKit/Utils.h
+++ b/dev/kernel/CFKit/Utils.h
@@ -5,9 +5,7 @@
#include <KernelKit/PE.h>
/// @brief CFKit
-namespace CF {
-using namespace Kernel;
-
+namespace Kernel::CF {
/// @brief Finds the PE header inside the blob.
inline auto ldr_find_exec_header(DosHeaderPtr ptrDos) -> LDR_EXEC_HEADER_PTR {
if (!ptrDos) return nullptr;
@@ -45,6 +43,6 @@ inline auto ldr_find_exec_header(const Char* ptrDos) -> LDR_EXEC_HEADER_PTR {
inline auto ldr_find_opt_exec_header(const Char* ptrDos) -> LDR_OPTIONAL_HEADER_PTR {
return ldr_find_opt_exec_header((DosHeaderPtr) ptrDos);
}
-} // namespace CF
+} // namespace Kernel::CF
#endif // ifndef CFKIT_UTILS_H
diff --git a/dev/kernel/FSKit/Ext2+IFS.h b/dev/kernel/FSKit/Ext2+IFS.h
index 72e01ecd..44435a29 100644
--- a/dev/kernel/FSKit/Ext2+IFS.h
+++ b/dev/kernel/FSKit/Ext2+IFS.h
@@ -146,7 +146,7 @@ inline Kernel::ErrorOr<Ext2Node*> ext2_load_inode(Ext2Context* ctx, Kernel::UInt
*/
class Ext2FileSystemParser final {
private:
- Ext2Context ctx; // Internal EXT2 context
+ Ext2Context fCtx; // Internal EXT2 context
public:
/*
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h
index 845ef467..51ec7648 100644
--- a/dev/kernel/FSKit/HeFS.h
+++ b/dev/kernel/FSKit/HeFS.h
@@ -32,6 +32,14 @@
#define kHeFSINDStartOffset (sizeof(HEFS_BOOT_NODE))
#define kHeFSINStartOffset (sizeof(HEFS_INDEX_NODE_DIRECTORY))
+#define kHeFSRootDirectory "/"
+#define kHeFSRootDirectoryU8 u8"/"
+
+#define kHeFSSeparator '/'
+#define kHeFSUpDir ".."
+
+#define kHeFSRootDirectoryLen (2U)
+
#define kHeFSSearchAllStr u8"*"
struct HEFS_BOOT_NODE;
diff --git a/dev/kernel/KernelKit/FileMgr.h b/dev/kernel/KernelKit/FileMgr.h
index bad6cf85..cc2feeb8 100644
--- a/dev/kernel/KernelKit/FileMgr.h
+++ b/dev/kernel/KernelKit/FileMgr.h
@@ -298,7 +298,7 @@ class FileStream final {
if (man) {
man->Write(offset, fFile, data, len);
- return ErrorOr<Int64>(0);
+ return ErrorOr<Int64>(kErrorSuccess);
}
return ErrorOr<Int64>(kErrorInvalidData);
@@ -317,7 +317,7 @@ class FileStream final {
if (man) {
man->Write(name, fFile, data, 0, len);
- return ErrorOr<Int64>(0);
+ return ErrorOr<Int64>(kErrorSuccess);
}
return ErrorOr<Int64>(kErrorInvalidData);
diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h
index 1bc8975a..2029ae7b 100644
--- a/dev/kernel/KernelKit/KernelTaskScheduler.h
+++ b/dev/kernel/KernelKit/KernelTaskScheduler.h
@@ -41,6 +41,6 @@ class KernelTaskHelper final {
STATIC Bool Switch(HAL::StackFramePtr frame_ptr, ProcessID new_kid);
STATIC Bool CanBeScheduled(const KERNEL_TASK& process);
STATIC ErrorOr<KID> TheCurrentKID();
- STATIC SizeT StartScheduling();
+ STATIC SizeT StartScheduling();
};
} // namespace Kernel \ No newline at end of file
diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h
index d106e511..2cf65fe0 100644
--- a/dev/kernel/KernelKit/UserProcessScheduler.h
+++ b/dev/kernel/KernelKit/UserProcessScheduler.h
@@ -192,8 +192,8 @@ class UserProcessScheduler final : public ISchedulable {
NE_MOVE_DELETE(UserProcessScheduler)
public:
- explicit operator bool();
- bool operator!();
+ explicit operator bool();
+ bool operator!();
public:
UserProcessTeam& TheCurrentTeam();
diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h
index 09f0cad5..3351c65d 100644
--- a/dev/kernel/NeKit/ErrorOr.h
+++ b/dev/kernel/NeKit/ErrorOr.h
@@ -50,7 +50,7 @@ class ErrorOr final {
private:
Ref<T> mRef;
- ErrorT mId{0};
+ ErrorT mId{0};
};
using ErrorOrAny = ErrorOr<voidPtr>;
diff --git a/dev/kernel/NeKit/Pair.h b/dev/kernel/NeKit/Pair.h
index aeeeb8a2..61668f5a 100644
--- a/dev/kernel/NeKit/Pair.h
+++ b/dev/kernel/NeKit/Pair.h
@@ -6,8 +6,46 @@
#pragma once
+#include <CompilerKit/CompilerKit.h>
#include <NeKit/Defines.h>
+#include <NeKit/ErrorOr.h>
namespace Kernel {
+template <typename T1, typename T2>
class Pair;
+
+class PairBuilder;
+
+template <typename T1, typename T2>
+class Pair final {
+ T1 fFirst{nullptr};
+ T2 fSecond{nullptr};
+
+ friend PairBuilder;
+
+ public:
+ explicit Pair() = default;
+ ~Pair() = default;
+
+ NE_COPY_DEFAULT(Pair)
+
+ T1& First() { return fFirst; }
+ T2& Second() { return fSecond; }
+
+ const T1& First() const { return *fFirst; }
+ const T2& Second() const { return *fSecond; }
+
+ private:
+ Pair(T1 first, T2 second) : fFirst(first), fSecond(second) {}
+};
+
+class PairBuilder final {
+ template <typename T1, typename T2>
+ STATIC Pair<T1, T2> Construct(T1 first, T2 second) {
+ return Pair(first, second);
+ }
+};
+
+template <typename T1, typename T2>
+using PairOr = ErrorOr<Pair<T1, T2>>;
} // 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 c0c9c84e..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 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;
+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
index e4985a3b..6b559cf4 100644
--- a/dev/kernel/src/FS/HeFS+FileMgr.cc
+++ b/dev/kernel/src/FS/HeFS+FileMgr.cc
@@ -10,5 +10,157 @@
#include <KernelKit/FileMgr.h>
#include <KernelKit/HeapMgr.h>
+/// @brief HeFS File System Manager.
+/// BUGS: 0
+
+namespace Kernel {
+/// @brief C++ constructor
+HeFileSystemMgr::HeFileSystemMgr() {
+ mParser = new HeFileSystemParser();
+ MUST_PASS(mParser);
+
+ kout << "We are done allocating NeFileSystemParser...\n";
+}
+
+HeFileSystemMgr::~HeFileSystemMgr() {
+ if (mParser) {
+ kout << "Destroying NeFileSystemParser...\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 << "HeFS: 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 << "HeFS: 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 << "HeFS: 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 << "HeFS: CreateAlias called with null or empty path\n";
+ return nullptr;
+ }
+ return nullptr;
+}
+
+NodePtr HeFileSystemMgr::CreateSwapFile(const Char* path) {
+ if (!path || *path == 0) {
+ kout << "HeFS: 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 << "HeFS: Open called with null or empty path\n";
+ return nullptr;
+ }
+ if (!r || *r == 0) {
+ kout << "HeFS: 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) {}
+
+_Output VoidPtr HeFileSystemMgr::Read(_Input NodePtr node, _Input Int32 flags, _Input SizeT size) {
+ return nullptr;
+}
+
+Void HeFileSystemMgr::Write(_Input const Char* name, _Input NodePtr node, _Input VoidPtr data,
+ _Input Int32 flags, _Input SizeT size) {}
+
+_Output VoidPtr HeFileSystemMgr::Read(_Input const Char* name, _Input NodePtr node,
+ _Input Int32 flags, _Input SizeT sz) {
+ return nullptr;
+}
+
+_Output Bool HeFileSystemMgr::Seek(NodePtr node, SizeT off) {
+ return false;
+}
+
+/// @brief Tell current offset within catalog.
+/// @param node
+/// @return kFileMgrNPos if invalid, else current offset.
+_Output SizeT HeFileSystemMgr::Tell(NodePtr node) {
+ return kFileMgrNPos;
+}
+
+/// @brief Rewinds the catalog
+/// @param node
+/// @return False if invalid, nah? calls Seek(node, 0).
+_Output Bool HeFileSystemMgr::Rewind(NodePtr node) {
+ return kFileMgrNPos;
+}
+
+/// @brief Returns the parser of HeFS.
+_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/GUIDWizard.cc b/dev/kernel/src/GUIDWizard.cc
index 46915ace..b3120179 100644
--- a/dev/kernel/src/GUIDWizard.cc
+++ b/dev/kernel/src/GUIDWizard.cc
@@ -17,7 +17,7 @@
// @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);
@@ -62,4 +62,4 @@ auto cf_try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<KString>> {
return ErrorOr<Ref<KString>>{-1};
}
-} // 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/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..1d01293f 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.
/***********************************************************************************/
@@ -38,4 +38,4 @@ BasicKString<>& Property::GetKey() {
PropertyId& Property::GetValue() {
return fValue;
}
-} // namespace CF
+} // namespace Kernel::CF