diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-21 03:30:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-21 03:30:40 -0500 |
| commit | e3fa27827e7647a0ecc466f4d92097fe48fbbb43 (patch) | |
| tree | 33ba30655f555d37e3c970707b27413936e5a9ad | |
| parent | c739255b48b3a5b2e184ca1a637f9f1f95c978ff (diff) | |
| parent | efefa7221a3fea3636a64f2bf067e2af75626f34 (diff) | |
Merge pull request #79 from nekernel-org/devv0.0.61
Kernel: OpenHeFS fixes and new components.
26 files changed, 299 insertions, 137 deletions
diff --git a/dev/kernel/FSKit/OpenHeFS.h b/dev/kernel/FSKit/OpenHeFS.h index 4e44b948..04f07b8e 100644 --- a/dev/kernel/FSKit/OpenHeFS.h +++ b/dev/kernel/FSKit/OpenHeFS.h @@ -17,9 +17,9 @@ /// @file OpenHeFS.h
/// @brief OpenHeFS filesystem support.
-#define kHeFSVersion (0x0103)
-#define kHeFSMagic " HeFS"
-#define kHeFSMagicLen (8)
+#define kHeFSVersion (0x0104)
+#define kHeFSMagic "OpenHeFS"
+#define kHeFSMagicLen (9U)
#define kHeFSBlockLen (512U)
#define kHeFSFileNameLen (256U)
diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index bd7c207d..dfd71777 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -148,8 +148,6 @@ EXTERN_C Kernel::Void hal_real_init(Kernel::Void) { HAL::IDTLoader idt_loader; idt_loader.Load(idt_reg); - HAL::mp_init_cores(kHandoverHeader->f_HardwareTables.f_VendorPtr); - while (YES) ; } diff --git a/dev/kernel/HALKit/AMD64/HalTimer.cc b/dev/kernel/HALKit/AMD64/HalTimer.cc index 1f500ac9..f6488b05 100644 --- a/dev/kernel/HALKit/AMD64/HalTimer.cc +++ b/dev/kernel/HALKit/AMD64/HalTimer.cc @@ -15,7 +15,9 @@ #include <KernelKit/Timer.h>
#include <modules/ACPI/ACPIFactoryInterface.h>
-// timer slot 0
+/// ================================================================================
+/// @note timer slot 0
+/// ================================================================================
#define kHPETSignature ("HPET")
@@ -24,9 +26,11 @@ #define kHPETCompRegValue (0x24)
#define kHPETInterruptRegValue (0x2C)
+/// ================================================================================
///! BUGS: 0
///! @file HalTimer.cc
///! @brief Hardware Timer (HPET)
+/// ================================================================================
namespace Kernel::Detail {
struct HPET_BLOCK : public Kernel::SDT {
diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h index 2e3afb46..4c924957 100644 --- a/dev/kernel/NeKit/ErrorOr.h +++ b/dev/kernel/NeKit/ErrorOr.h @@ -15,6 +15,9 @@ namespace Kernel { using ErrorT = Int32; +/// ================================================================================ +/// @brief ErrorOr class for error handling. +/// ================================================================================ template <typename T> class ErrorOr final { public: diff --git a/dev/kernel/NeKit/Function.h b/dev/kernel/NeKit/Function.h index 45b1a5af..70242bc3 100644 --- a/dev/kernel/NeKit/Function.h +++ b/dev/kernel/NeKit/Function.h @@ -4,13 +4,15 @@ ======================================== */ -#ifndef _INC_FUNCTION_H_ -#define _INC_FUNCTION_H_ +#pragma once #include <NeKit/Defines.h> #include <NeKit/ErrorOr.h> namespace Kernel { +/// ================================================================================ +/// @brief Function wrapper class. +/// ================================================================================ template <typename T, typename... Args> class Function final { public: @@ -40,11 +42,10 @@ class Function final { private: T(*fFn) - (Args... args); + (Args... args){nullptr}; }; template <typename T, typename... Args> using FunctionOr = ErrorOr<Function<T, Args...>>; } // namespace Kernel -#endif // !_INC_FUNCTION_H__ diff --git a/dev/kernel/NeKit/Json.h b/dev/kernel/NeKit/Json.h index 836a0995..1e804354 100644 --- a/dev/kernel/NeKit/Json.h +++ b/dev/kernel/NeKit/Json.h @@ -19,54 +19,68 @@ #define kNeJsonLen (256) #define kNeJsonNullArr "[]" #define kNeJsonNullObj "{}" +#define kNeJsonNullKey "null" +#define kNeJsonNullValue kNeJsonNullKey namespace Kernel { -/// @brief JavaScript object class +/// ================================================================================ +/// @brief JSON object representation. +/// ================================================================================ +template <typename CharKind = Char> class JsonObject final { public: explicit JsonObject() { - auto len = kNeJsonMaxLen; - KBasicString<> key = KString(len); - key += kNeJsonNullObj; + KBasicString<CharKind> key = KString(kNeJsonMaxLen); + key += kNeJsonNullValue; this->AsKey() = key; - this->AsValue() = key; + this->AsValue() = key; } - explicit JsonObject(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) {} + explicit JsonObject(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) { + + KBasicString<CharKind> key = KString(lhsLen); + this->AsKey() = key; + + KBasicString<CharKind> value = KString(rhsLen); + this->AsValue() = value; + } ~JsonObject() = default; NE_COPY_DEFAULT(JsonObject) + NE_MOVE_DEFAULT(JsonObject) Bool& IsUndefined() { return fUndefined; } private: Bool fUndefined; // is this instance undefined? - KBasicString<> fKey; - KBasicString<> fValue; + KBasicString<CharKind> fKey; + KBasicString<CharKind> fValue; public: /// @brief returns the key of the json /// @return the key as string view. - KBasicString<>& AsKey() { return fKey; } + KBasicString<CharKind>& AsKey() { return fKey; } /// @brief returns the value of the json. /// @return the key as string view. - KBasicString<>& AsValue() { return fValue; } + KBasicString<CharKind>& AsValue() { return fValue; } - static JsonObject kNull; + STATIC JsonObject<CharKind> kNull; }; -/// @brief JsonObject stream reader helper. -struct JsonStreamReader final { - STATIC JsonObject In(const Char* full_array) { +/// ================================================================================ +/// @brief JsonObject stream reader helper for ASCII. +/// ================================================================================ +struct AsciiJsonStreamReader final { + STATIC JsonObject<Char> In(const Char* full_array) { auto start_val = '{'; auto end_val = '}'; Boolean probe_value = false; if (full_array[0] != start_val) { - if (full_array[0] != '[') return JsonObject::kNull; + if (full_array[0] != '[') return JsonObject<Char>{0, 0}; start_val = '['; end_val = ']'; @@ -79,7 +93,7 @@ struct JsonStreamReader final { SizeT key_len = 0; SizeT value_len = 0; - JsonObject type(kNeJsonMaxLen, kNeJsonMaxLen); + JsonObject<Char> type(kNeJsonMaxLen, kNeJsonMaxLen); for (SizeT i = 1; i < len; ++i) { if (full_array[i] == '\r' || full_array[i] == '\n') continue; @@ -125,5 +139,8 @@ struct JsonStreamReader final { } }; -using JsonStream = Stream<JsonStreamReader, JsonObject>; +/// ================================================================================ +/// @brief AsciiJsonStream type definition. +/// ================================================================================ +using AsciiJsonStream = Stream<AsciiJsonStreamReader, JsonObject<Char>>; } // namespace Kernel diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h index 9c244be5..dac701e0 100644 --- a/dev/kernel/NeKit/Ref.h +++ b/dev/kernel/NeKit/Ref.h @@ -56,6 +56,7 @@ class NonNullRef final { NonNullRef(nullPtr) = delete; NonNullRef(T* ref) : fRef(ref) { MUST_PASS(ref); } + NonNullRef(Ref<T> ref) : fRef(ref) { MUST_PASS(ref); } Ref<T>& operator->() { MUST_PASS(fRef); diff --git a/dev/kernel/NeKit/TOML.h b/dev/kernel/NeKit/TOML.h new file mode 100644 index 00000000..dee273ad --- /dev/null +++ b/dev/kernel/NeKit/TOML.h @@ -0,0 +1,15 @@ +/* ======================================== + + Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +namespace Kernel { +class TOMLObject final { + public: + explicit TOMLObject() = delete; + ~TOMLObject() = default; +}; +} // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/NeKit/Variant.h b/dev/kernel/NeKit/Variant.h index 42a47bc0..7bcd0dff 100644 --- a/dev/kernel/NeKit/Variant.h +++ b/dev/kernel/NeKit/Variant.h @@ -8,6 +8,7 @@ #include <NeKit/Defines.h> #include <NeKit/Json.h> +#include <NeKit/TOML.h> #include <NeKit/KString.h> #include <SwapKit/DiskSwap.h> @@ -15,13 +16,13 @@ namespace Kernel { class Variant final { public: enum class VariantKind { - kString, + kInvalid = 0, + kString = 200, kBlob, kNull, kJson, - kXML, + kTOML, kSwap, - kInvalid, }; public: @@ -37,7 +38,9 @@ class Variant final { explicit Variant(KBasicString<CharKind>* stringView) : fPtr((VoidPtr) stringView), fKind(VariantKind::kString) {} - explicit Variant(JsonObject* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} + explicit Variant(JsonObject<>* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} + + explicit Variant(TOMLObject* toml) : fPtr((VoidPtr) toml), fKind(VariantKind::kTOML) {} explicit Variant(nullPtr ptr) : fPtr(ptr), fKind(VariantKind::kNull) {} @@ -47,10 +50,15 @@ class Variant final { public: const Char* ToString(); + + /// ======================================================================== + /// @brief Returns the underlying pointer. + /// @return the underlying pointer. + /// ======================================================================== VoidPtr Leak(); template <typename T> - T* As() { + T* As() noexcept { return reinterpret_cast<T*>(fPtr); } diff --git a/dev/kernel/src/BitMapMgr.cc b/dev/kernel/src/BitMapMgr.cc index 2039e1c9..d7ecb810 100644 --- a/dev/kernel/src/BitMapMgr.cc +++ b/dev/kernel/src/BitMapMgr.cc @@ -88,9 +88,10 @@ namespace HAL { } VoidPtr base = reinterpret_cast<VoidPtr>((UIntPtr) base_ptr); - MUST_PASS(base); + if (!base) return nullptr; + STATIC SizeT biggest = 0UL; while (YES) { @@ -105,7 +106,7 @@ namespace HAL { this->GetBitMapStatus(ptr_bit_set); UInt32 flags = this->MakeMMFlags(wr, user); - mm_map_page(ptr_bit_set, ptr_bit_set, flags); + mm_map_page(ptr_bit_set, (VoidPtr)mm_get_page_addr(ptr_bit_set), flags); if (biggest < (size + pad)) biggest = size + pad; @@ -121,7 +122,7 @@ namespace HAL { this->GetBitMapStatus(ptr_bit_set); UInt32 flags = this->MakeMMFlags(wr, user); - mm_map_page(ptr_bit_set, ptr_bit_set, flags); + mm_map_page(ptr_bit_set, (VoidPtr)mm_get_page_addr(ptr_bit_set), flags); if (biggest < (size + pad)) biggest = (size + pad); @@ -136,7 +137,6 @@ namespace HAL { : ptr_bit_set[kBitMapSizeIdx]; base = reinterpret_cast<VoidPtr>(raw_base + offset); - if (base == nullptr) return nullptr; } @@ -166,9 +166,10 @@ namespace HAL { }; } // namespace Detail + STATIC Detail::IBitMapProxy kBitMapMgr; + auto mm_is_bitmap(VoidPtr ptr) -> BOOL { - Detail::IBitMapProxy bitmp; - return bitmp.IsBitMap(ptr); + return kBitMapMgr.IsBitMap(ptr); } /***********************************************************************************/ @@ -178,12 +179,10 @@ namespace HAL { /// @return a new bitmap allocated pointer. /***********************************************************************************/ auto mm_alloc_bitmap(Boolean wr, Boolean user, SizeT size, Bool is_page, SizeT pad) -> VoidPtr { - VoidPtr ptr_new = nullptr; - Detail::IBitMapProxy bitmp; - + VoidPtr ptr_new = nullptr; if (is_page) return nullptr; - ptr_new = bitmp.FindBitMap(kKernelBitMpStart, size, wr, user, pad); + ptr_new = kBitMapMgr.FindBitMap(kKernelBitMpStart, size, wr, user, pad); if (!ptr_new) { ke_panic(RUNTIME_CHECK_VIRTUAL_OUT_OF_MEM, "Out of memory bitmap"); @@ -200,9 +199,7 @@ namespace HAL { auto mm_free_bitmap(VoidPtr ptr) -> Bool { if (!ptr) return No; - Detail::IBitMapProxy bitmp; - Bool ret = bitmp.FreeBitMap(ptr); - + Bool ret = kBitMapMgr.FreeBitMap(ptr); return ret; } } // namespace HAL diff --git a/dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc b/dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc index c79b6323..d8e22f18 100644 --- a/dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/OpenHeFS+FileSystemParser.cc @@ -764,9 +764,6 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c if (drv_std_get_size() < kHeFSMinimumDiskSize) { (Void)(kout << "OpenHeFS recommends at least 128 GiB of free space." << kendl); - (Void)(kout << "The OS will still try to format a OpenHeFS disk here anyway, don't expect " - "perfect geometry." - << kendl); } HEFS_BOOT_NODE* boot = (HEFS_BOOT_NODE*) RTL_ALLOCA(sizeof(HEFS_BOOT_NODE)); @@ -880,12 +877,12 @@ _Output Bool HeFileSystemParser::Format(_Input _Output DriveTrait* mnt, _Input c return NO; } - constexpr const SizeT kHeFSPreallocateCount = 0x6UL; + /// AMLALE: Better way to create default directories than before. + const Utf8Char* kFileMap[] = {u8"/", u8"/boot", u8"/system", u8"/network", + u8"/devices", u8"/media", u8"/dev", (Utf8Char*) nullptr}; - const Utf8Char* kFileMap[kHeFSPreallocateCount] = {u8"/", u8"/boot", u8"/system", - u8"/network", u8"/devices", u8"/media"}; - - for (SizeT i = 0; i < kHeFSPreallocateCount; ++i) { + SizeT i = 0; + while (kFileMap[++i] != nullptr) { this->CreateINodeDirectory(mnt, kHeFSEncodingFlagsUTF8, kFileMap[i]); } @@ -1153,19 +1150,10 @@ Boolean OpenHeFS::fs_init_openhefs(Void) noexcept { if (kMountpoint.A().fPacket.fPacketReadOnly == YES) { kout << "Main disk cannot be mounted (read-only media).\r"; - return NO; - } - - HeFileSystemParser parser; - - if (!parser.Format(&kMountpoint.A(), kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName)) { - kout << "Failed to format OpenHeFS partition!\r"; - return NO; + return YES; } - kout << "Valid OpenHeFS disk...\r"; - - return YES; + return HeFileSystemParser{}.Format(&kMountpoint.A(), kHeFSEncodingFlagsUTF8, kHeFSDefaultVolumeName); } } // namespace Kernel diff --git a/dev/kernel/src/Json.cc b/dev/kernel/src/Json.cc index 8f073da8..198aed99 100644 --- a/dev/kernel/src/Json.cc +++ b/dev/kernel/src/Json.cc @@ -6,5 +6,4 @@ #include <NeKit/Json.h> -/// @brief Undefined object, is null in length. -RTL_INIT_OBJECT(Kernel::JsonObject::kNull, Kernel::JsonObject); +namespace Kernel {}
\ No newline at end of file diff --git a/dev/kernel/src/SoftwareTimer.cc b/dev/kernel/src/SoftwareTimer.cc index 167fc630..eafe8db6 100644 --- a/dev/kernel/src/SoftwareTimer.cc +++ b/dev/kernel/src/SoftwareTimer.cc @@ -6,8 +6,10 @@ #include <KernelKit/Timer.h> +/// ================================================================================ /// @brief SoftwareTimer class, meant to be generic. ///! @author Amlal El Mahrouss (amlal@nekernel.org) +/// ================================================================================ using namespace Kernel; diff --git a/dev/kernel/src/Variant.cc b/dev/kernel/src/Variant.cc index 732dabd2..fcf2f443 100644 --- a/dev/kernel/src/Variant.cc +++ b/dev/kernel/src/Variant.cc @@ -9,8 +9,8 @@ namespace Kernel { const Char* Variant::ToString() { switch (fKind) { - case VariantKind::kXML: - return ("Class:{XML}"); + case VariantKind::kTOML: + return ("Class:{TOML}"); case VariantKind::kJson: return ("Class:{Json}"); case VariantKind::kString: diff --git a/docs/tex/hefs.tex b/docs/tex/hefs.tex index 9ec68020..1ce387a0 100644 --- a/docs/tex/hefs.tex +++ b/docs/tex/hefs.tex @@ -21,8 +21,8 @@ The High-throughput Extended File System (OpenHeFS) is a custom filesystem tailo \textbf{Name} & \textbf{Value / Description} \\ \hline \texttt{kHeFSVersion} & 0x0103 \\ -\texttt{kHeFSMagic} & " OpenHeFS" (8-byte magic identifier) \\ -\texttt{kHeFSMagicLen} & 8 \\ +\texttt{kHeFSMagic} & "OpenHeFS" (8-byte magic identifier) \\ +\texttt{kHeFSMagicLen} & 9 \\ \texttt{kHeFSBlockLen} & 512 bytes \\ \texttt{kHeFSFileNameLen} & 256 characters \\ \texttt{kHeFSPartNameLen} & 128 characters \\ diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h index e195c572..68b00264 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h @@ -14,7 +14,7 @@ namespace CF { class CFString; -class CFGUID; +union CFGUID; class CFProperty; class CFObject; @@ -72,4 +72,20 @@ struct CFRect final { BOOL SizeMatches(CFRect& rect) noexcept; BOOL PositionMatches(CFRect& rect) noexcept; }; + +union CFGUID final { + alignas(8) UInt16 fU8[16]; + alignas(8) UInt16 fU16[8]; + alignas(8) UInt32 fU32[4]; + alignas(8) UInt64 fU64[2]; + + struct { + alignas(8) UInt32 fMs1; + UInt16 fMs2; + UInt16 fMs3; + UInt8 fMs4[8]; + } fUuid; +}; + +using CF_GUID_TYPE = union CFGUID; } // namespace CF
\ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Property.h b/public/frameworks/CoreFoundation.fwrk/headers/Property.h index f3c4a937..b8784f68 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Property.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Property.h @@ -4,31 +4,34 @@ ======================================== */ -#ifndef _PROPS_H -#define _PROPS_H +#pragma once +#include <CoreFoundation.fwrk/headers/Foundation.h> #include <CoreFoundation.fwrk/headers/Ref.h> #include <libSystem/SystemKit/System.h> -#define kMaxPropLen (256U) +#define kCFMaxPropLen (256U) namespace CF { class CFString; class CFProperty; -class CFGUID; template <typename Cls, SizeT N> class CFArray; +/// ================================================================================ /// @brief handle to anything (number, ptr, string...) +/// ================================================================================ using CFPropertyId = UIntPtr; +/// ================================================================================ /// @brief User property class. /// @example /prop/foo or /prop/bar +/// ================================================================================ class CFProperty final CF_OBJECT { public: - CFProperty(); - virtual ~CFProperty(); + CFProperty(CFRef<CFGUID> guid, CFString& name, CFPropertyId value); + ~CFProperty() override = default; public: CFProperty& operator=(const CFProperty&) = default; @@ -41,11 +44,10 @@ class CFProperty final CF_OBJECT { private: CFString* fName{nullptr}; CFPropertyId fValue{0UL}; - Ref<CFGUID> fGUID{}; + CFRef<CFGUID> fGUID{}; }; template <SizeT N> using CFPropertyArray = CFArray<CFProperty, N>; } // namespace CF -#endif // !CFKIT_PROPS_H diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h index c1d5aec7..6757daac 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h @@ -5,8 +5,7 @@ ======================================== */ -#ifndef _REF_H_ -#define _REF_H_ +#pragma once #include <CoreFoundation.fwrk/headers/Object.h> #include <libSystem/SystemKit/System.h> @@ -15,6 +14,9 @@ namespace CF { template <typename T> class CFRef; +/// ================================================================================ +/// @brief CFRef class for reference counting. +/// ================================================================================ template <typename T> class CFRef final CF_OBJECT { public: @@ -57,6 +59,9 @@ class CFRef final CF_OBJECT { T* fClass{nullptr}; }; +/// ================================================================================ +/// @brief CFNonNullRef class for non-null reference counting. +/// ================================================================================ template <typename T> class CFNonNullRef final { public: @@ -64,6 +69,7 @@ class CFNonNullRef final { CFNonNullRef(nullPtr) = delete; CFNonNullRef(T* ref) : fRef(ref) { MUST_PASS(ref); } + CFNonNullRef(CFRef<T> ref) : fRef(ref) { MUST_PASS(ref); } CFRef<T>& operator->() { MUST_PASS(fRef); @@ -78,4 +84,3 @@ class CFNonNullRef final { }; } // namespace CF -#endif // ifndef _NEKIT_REF_H_ diff --git a/public/frameworks/CoreFoundation.fwrk/headers/String.h b/public/frameworks/CoreFoundation.fwrk/headers/String.h index 6fb2f817..247d3894 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/String.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/String.h @@ -1,4 +1,3 @@ - /* ======================================== Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. @@ -8,16 +7,42 @@ #pragma once #include <CoreFoundation.fwrk/headers/Object.h> +#include <CoreFoundation.fwrk/headers/Ref.h> namespace CF { class CFString; +class CFStringBuilder; +/// ================================================================================ +/// @brief CFString class for string manipulations. +/// ================================================================================ class CFString final CF_OBJECT { public: - CFString() = default; - ~CFString() = default; + CFString() = delete; + + explicit CFString(const SizeT sz); + explicit CFString(const Char* str); + + ~CFString(); + + const char* asBytes() const; + + LIBSYS_COPY_DELETE(CFString); + + private: + Char* mStr{nullptr}; +}; + +/// ================================================================================ +/// @brief CFStringBuilder class for string manipulations. +/// ================================================================================ +class CFStringBuilder final { + public: + static CFRef<CFString> Construct(const Char*); + static const Char* FromBool(const Char*, BOOL); + static const Char* Format(const Char*, const Char*); - CFString(const CFString&) = delete; - CFString& operator=(const CFString&) = delete; + static BOOL Equals(const Char, const Char*); + static BOOL Equals(const Char*, const Char*); }; } // namespace CF
\ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/headers/Foundation.h b/public/frameworks/KernelTest.fwrk/headers/Foundation.h new file mode 100644 index 00000000..4329af6b --- /dev/null +++ b/public/frameworks/KernelTest.fwrk/headers/Foundation.h @@ -0,0 +1,16 @@ +/* ======================================== + + Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include <KernelKit/DebugOutput.h> +#include <NeKit/KernelPanic.h> + +#define KT_TEST_VERSION_BCD (0x0001) +#define KT_TEST_VERSION "dev-nekernel-test" + +#define KT_TEST_SUCCESS (kErrorSuccess) +#define KT_TEST_FAILURE (kErrorSuccess + 1) diff --git a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h b/public/frameworks/KernelTest.fwrk/headers/KernelTest.h deleted file mode 100644 index 7b25c8a4..00000000 --- a/public/frameworks/KernelTest.fwrk/headers/KernelTest.h +++ /dev/null @@ -1,31 +0,0 @@ -/* ======================================== - - Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. - -======================================== */ - -#pragma once - -#include <NeKit/KernelPanic.h> - -/// @brief Kernel Test Framework. -/// @file KernelTest.h - -#define KT_TEST_VERSION_BCD (0x0002) -#define KT_TEST_VERSION "v0.0.2-kerneltest" - -#define KT_TEST_FAILURE (1) - -#define KT_TEST_SUCCESS (0) - -#define KT_DECL_TEST(NAME, FN) \ - class KT_##NAME final { \ - public: \ - Kernel::Void Run(); \ - const Kernel::Char* ToString(); \ - }; \ - inline Kernel::Void KT_##NAME::Run() { MUST_PASS(FN() == true); } \ - inline const Kernel::Char* KT_##NAME::ToString() { return #FN; } - -KT_DECL_TEST(ALWAYS_BREAK, []() -> bool { return false; }); -KT_DECL_TEST(ALWAYS_GOOD, []() -> bool { return true; });
\ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/headers/SourceLocation.h b/public/frameworks/KernelTest.fwrk/headers/SourceLocation.h new file mode 100644 index 00000000..6507864b --- /dev/null +++ b/public/frameworks/KernelTest.fwrk/headers/SourceLocation.h @@ -0,0 +1,36 @@ +/* ======================================== + + Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include <CoreFoundation.fwrk/headers/Object.h> +#include <CoreFoundation.fwrk/headers/String.h> +#include <KernelTest.fwrk/headers/Foundation.h> + +class KTSourceLocation; + +/// ================================================================================ +/// @brief SourceLocation class for Kernel Test Framework. +/// ================================================================================ +class KTSourceLocation final CF_OBJECT { + public: + explicit KTSourceLocation() = delete; + ~KTSourceLocation() override = default; + + LIBSYS_COPY_DELETE(KTSourceLocation); + + public: + KTSourceLocation(const Char*, const SInt32 = 0UL); + + CF::CFString File(); + SInt32 Line(); + + CF::CFString operator()(); + + private: + CF::CFString mFile{4096}; + SInt32 mLine{0U}; +};
\ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/headers/TestCase.h b/public/frameworks/KernelTest.fwrk/headers/TestCase.h new file mode 100644 index 00000000..c040ca0f --- /dev/null +++ b/public/frameworks/KernelTest.fwrk/headers/TestCase.h @@ -0,0 +1,56 @@ +/* ======================================== + + Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include <KernelTest.fwrk/headers/SourceLocation.h> + +/// ================================================================================ +/// @brief Kernel Test Framework main header. +/// @file TestCase.h +/// ================================================================================ + +#define KT_RUN_TEST(OBJECT) {KTTestCase##OBJECT{}.Run();} + +#define KT_MUST_PASS(MSG, LEFT_COND, RIGHT_COND) \ + if (LEFT_COND != RIGHT_COND) { \ + (Kernel::Void)(Kernel::kout << "[KERNEL-TEST] BREAK: LEFT_COND: " << #LEFT_COND \ + << " RIGHT_COND: " << #RIGHT_COND << Kernel::kendl); \ + (Kernel::Void)(Kernel::kout << "[KERNEL-TEST] BREAK: MSG: " << MSG << Kernel::kendl); \ + MUST_PASS(NO); \ + } else { \ + (Kernel::Void)(Kernel::kout << "[KERNEL-TEST] PASS: MSG: " << MSG << Kernel::kendl); \ + } + +#define KT_DECL_TEST(NAME, FN) \ + class KTTestCase##NAME final { \ + public: \ + explicit KTTestCase##NAME() = default; \ + ~KTTestCase##NAME() = default; \ + LIBSYS_COPY_DELETE(KTTestCase##NAME); \ + Kernel::Void Run(); \ + const Kernel::Char* ToString(); \ + }; \ + inline Kernel::Void KTTestCase##NAME::Run() { \ + auto ret = FN() == YES; \ + if (!ret) { \ + Kernel::kout << "[KERNEL-TEST] TEST FAILED!" << Kernel::kendl; \ + MUST_PASS(ret); \ + } \ + } \ + inline const Kernel::Char* KTTestCase##NAME::ToString() { \ + return #FN; \ + } + +KT_DECL_TEST(AlwaysBreak, []() -> bool { + KT_MUST_PASS("AlwaysBreak", YES, NO); + return NO; +}); + +KT_DECL_TEST(AlwaysPass, []() -> bool { + KT_MUST_PASS("AlwaysPass", YES, YES); + return YES; +});
\ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/src/CSymbols.cc b/public/frameworks/KernelTest.fwrk/src/CSymbols.cc new file mode 100644 index 00000000..575525f0 --- /dev/null +++ b/public/frameworks/KernelTest.fwrk/src/CSymbols.cc @@ -0,0 +1,21 @@ +/* ======================================== + + Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#include <public/frameworks/KernelTest.fwrk/headers/TestCase.h> + +/// ================================================================================ +/// @brief Function to run breaking test. +/// ================================================================================ +EXTERN_C Kernel::Void KT_TestBreak() { + KT_RUN_TEST(AlwaysBreak); +} + +/// ================================================================================ +/// @brief Function to run passing test. +/// ================================================================================ +EXTERN_C Kernel::Void KT_TestPass() { + KT_RUN_TEST(AlwaysPass); +}
\ No newline at end of file diff --git a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc b/public/frameworks/KernelTest.fwrk/src/UnitTests.cc deleted file mode 100644 index ab6effa9..00000000 --- a/public/frameworks/KernelTest.fwrk/src/UnitTests.cc +++ /dev/null @@ -1,17 +0,0 @@ -/* ======================================== - - Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. - -======================================== */ - -#include <public/frameworks/KernelTest.fwrk/headers/KernelTest.h> - -EXTERN_C Kernel::Void KT_TestBreak() { - KT_ALWAYS_BREAK brk; - brk.Run(); -} - -EXTERN_C Kernel::Void KT_TestGood() { - KT_ALWAYS_GOOD good; - good.Run(); -}
\ No newline at end of file diff --git a/tools/libmkfs/openhefs.h b/tools/libmkfs/openhefs.h index d90fda32..36d300f3 100644 --- a/tools/libmkfs/openhefs.h +++ b/tools/libmkfs/openhefs.h @@ -10,8 +10,8 @@ #include <cstring> #define kHeFSVersion (0x0101) -#define kHeFSMagic " HeFS" -#define kHeFSMagicLen (8) +#define kHeFSMagic "OpenHeFS" +#define kHeFSMagicLen (9U) #define kHeFSFileNameLen (256U) #define kHeFSPartNameLen (128U) |
