From b2c4d9a8ebebf87be33dcc357af86102d31dac47 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 15 Nov 2025 06:07:15 +0100 Subject: feat: DDK: compiler improvements and working on fwrk standard and launch design. Signed-off-by: Amlal El Mahrouss --- docs/drawio/LAUNCH_DESIGN.drawio | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docs/drawio') diff --git a/docs/drawio/LAUNCH_DESIGN.drawio b/docs/drawio/LAUNCH_DESIGN.drawio index e69de29b..a1cfc8cc 100644 --- a/docs/drawio/LAUNCH_DESIGN.drawio +++ b/docs/drawio/LAUNCH_DESIGN.drawio @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 86e5bd89ecbe6e3a204ab816b9f7e48eb9a7fee7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 16 Nov 2025 14:37:12 +0100 Subject: feat: launch: design of ne_launch done. Signed-off-by: Amlal El Mahrouss --- dev/boot/src/BootFileReader.cc | 2 +- dev/launch/src/AppMain.cc | 2 +- dev/libMsg/MsgKit/Server.h | 2 +- dev/modules/CoreGfx/CoreGfx.h | 2 +- dev/modules/NVME/NVME.h | 2 +- dev/modules/Power/PowerFactory.h | 6 ++---- dev/modules/SCSI/SCSI.h | 5 +++-- dev/modules/XHCI/XHCI.h | 4 ++-- docs/drawio/LAUNCH_DESIGN.drawio | 13 +++++++++++-- 9 files changed, 23 insertions(+), 15 deletions(-) (limited to 'docs/drawio') diff --git a/dev/boot/src/BootFileReader.cc b/dev/boot/src/BootFileReader.cc index 5aadd608..c95623b6 100644 --- a/dev/boot/src/BootFileReader.cc +++ b/dev/boot/src/BootFileReader.cc @@ -75,7 +75,7 @@ Boot::BootFileReader::BootFileReader(const CharacterTypeUTF16* path, EfiHandlePt mWriter.Write(L"BootZ: Fetch-Protocol: No-Such-Path: ").Write(mPath).Write(L"\r"); this->mErrorCode = kNotSupported; - fb_render_string("BootZ: PLEASE RECOVER YOUR MINKRNL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + fb_render_string("BootZ: PLEASE RECOVER YOUR NEKERNEL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF)); mRootFs->Close(mRootFs); diff --git a/dev/launch/src/AppMain.cc b/dev/launch/src/AppMain.cc index eef95fba..ae9917bc 100644 --- a/dev/launch/src/AppMain.cc +++ b/dev/launch/src/AppMain.cc @@ -10,7 +10,7 @@ /// @note This called by _NeMain from its own runtime. extern "C" SInt32 nelaunch_startup_fn(Void) { - /// @todo Start LaunchServices.fwrk services, make the launcher manageable too (via mgmt.launch) + /// @todo Start LaunchHelpers.fwrk services, make the launcher manageable too (via mgmt.launch) NELAUNCH_INFO("Turning on launcher..."); diff --git a/dev/libMsg/MsgKit/Server.h b/dev/libMsg/MsgKit/Server.h index 5bc9617d..86bf6549 100644 --- a/dev/libMsg/MsgKit/Server.h +++ b/dev/libMsg/MsgKit/Server.h @@ -24,7 +24,7 @@ struct LIBMSG_EXPR final { CF::CFString* l_key{nullptr}; CF::CFString* l_value{nullptr}; #else - // if we use C< we won't know about CF, so let's make those private. + // if we use C, we won't know about CF, so let's make those private. VoidPtr l_private_data[2]{nullptr}; #endif diff --git a/dev/modules/CoreGfx/CoreGfx.h b/dev/modules/CoreGfx/CoreGfx.h index 7d23c17e..d5cfa5a3 100644 --- a/dev/modules/CoreGfx/CoreGfx.h +++ b/dev/modules/CoreGfx/CoreGfx.h @@ -12,7 +12,7 @@ #define fb_color(R, G, B) RGB(R, G, B) -#define fb_get_clear_clr() RGB(0x20, 0x20, 0x20) +#define fb_get_clear_clr() RGB(0, 0, 0x80) #define fb_clear() kCGCursor = 0UL diff --git a/dev/modules/NVME/NVME.h b/dev/modules/NVME/NVME.h index c0894194..21f5323e 100644 --- a/dev/modules/NVME/NVME.h +++ b/dev/modules/NVME/NVME.h @@ -93,7 +93,7 @@ inline Bool nvme_create_io_command(HAL_NVME_QUEUE* entry, UInt64 baseAddress, entry->CommandSpecific[9] = identify; if (namespaceIdentify) { - entry->CommandSpecific[0] = 1; + entry->CommandSpecific[0] = YES; } } diff --git a/dev/modules/Power/PowerFactory.h b/dev/modules/Power/PowerFactory.h index b7c13280..770c7076 100644 --- a/dev/modules/Power/PowerFactory.h +++ b/dev/modules/Power/PowerFactory.h @@ -15,8 +15,6 @@ #define NE_POWER_FACTORY : public PowerFactory namespace Kernel { -class PowerFactory; - class PowerFactory { public: explicit PowerFactory() = default; @@ -26,7 +24,7 @@ class PowerFactory { PowerFactory(const PowerFactory&) = default; public: - Bool Shutdown() { return NO; }; // shutdown - Void Reboot(){}; // soft-reboot + virtual Bool Shutdown() { return NO; } // shutdown + virtual Void Reboot() {} // soft-reboot }; } // namespace Kernel \ No newline at end of file diff --git a/dev/modules/SCSI/SCSI.h b/dev/modules/SCSI/SCSI.h index d9ede8b4..88a47ed8 100644 --- a/dev/modules/SCSI/SCSI.h +++ b/dev/modules/SCSI/SCSI.h @@ -12,9 +12,10 @@ /// @brief Small Computer System Interface device. namespace Kernel { -template +template using scsi_packet_type = Kernel::UInt16[PacketBitLen]; + using scsi_packet_type_12 = scsi_packet_type<12>; -extern const scsi_packet_type<12> kCDRomPacketTemplate; +extern const scsi_packet_type_12 kCDRomPacketTemplate; } // namespace Kernel \ No newline at end of file diff --git a/dev/modules/XHCI/XHCI.h b/dev/modules/XHCI/XHCI.h index 8829d29b..55b1623e 100644 --- a/dev/modules/XHCI/XHCI.h +++ b/dev/modules/XHCI/XHCI.h @@ -16,8 +16,6 @@ #include -using namespace Kernel; - #define kUSBCommand (UInt16) 0x0 #define kUSBStatus (UInt16) 0x2 #define kUSBInterruptEnable (UInt16) 0x4 @@ -27,6 +25,7 @@ using namespace Kernel; #define kUSBPort1StatusCtrl (UInt16) 0x10 #define kUSBPort2StatusCtrl (UInt16) 0x12 +namespace Kernel { typedef struct USBCommandRegister final { UInt8 mReserved[8]; // Reserved UInt8 mMaxPacket; // 0 = Max packet size 32 bits 1 = Max packet size 64 bits @@ -64,3 +63,4 @@ typedef struct USBInterruptEnableRegister final { 32-bit physical adress of Frame List. Remember that first 12 bytes are always 0. The Frame List must contain 1024 entries. */ +} // namespace Kernel \ No newline at end of file diff --git a/docs/drawio/LAUNCH_DESIGN.drawio b/docs/drawio/LAUNCH_DESIGN.drawio index a1cfc8cc..32fe8eda 100644 --- a/docs/drawio/LAUNCH_DESIGN.drawio +++ b/docs/drawio/LAUNCH_DESIGN.drawio @@ -4,8 +4,17 @@ - - + + + + + + + + + + + -- cgit v1.2.3 From 0d931fe17b32cc5082f1180138dbb7bd6416dd14 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 17 Nov 2025 09:19:52 +0100 Subject: tools: feat: new syntax for function. Signed-off-by: Amlal El Mahrouss --- .gitignore | 1 + dev/boot/BootKit/Qr.h | 4 +- dev/boot/src/BootFileReader.cc | 2 +- dev/boot/src/HEL/AMD64/BootEFI.cc | 2 +- dev/kernel/HALKit/AMD64/HalDebugOutput.cc | 8 ++-- dev/kernel/HALKit/AMD64/HalKernelMain.cc | 2 +- dev/kernel/HALKit/ARM64/HalKernelMain.cc | 2 +- dev/kernel/KernelKit/KernelTaskScheduler.h | 2 +- dev/kernel/src/UserProcessScheduler.cc | 6 ++- dev/modules/APM/APM.h | 4 +- dev/modules/CoreGfx/CoreAccess.h | 8 ++-- dev/modules/CoreGfx/CoreGfx.h | 14 +++--- dev/modules/CoreGfx/MathGfx.h | 6 +-- dev/modules/CoreGfx/TextGfx.h | 6 +-- dev/modules/HPET/.gitkeep | 0 docs/drawio/GUI_DESIGN.drawio | 6 +-- tools/chk.hefs.cc | 76 ++++++++++++++++++++++++++++++ tools/chk.hefs.json | 16 +++++++ tools/fsck.hefs.cc | 76 ------------------------------ tools/fsck.hefs.json | 16 ------- tools/libmkfs/mkfs.h | 5 +- tools/mkfs.hefs.cc | 47 +++++++++--------- 22 files changed, 156 insertions(+), 153 deletions(-) delete mode 100644 dev/modules/HPET/.gitkeep create mode 100644 tools/chk.hefs.cc create mode 100644 tools/chk.hefs.json delete mode 100644 tools/fsck.hefs.cc delete mode 100644 tools/fsck.hefs.json (limited to 'docs/drawio') diff --git a/.gitignore b/.gitignore index 329688e2..fcd84d09 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ neoskrnl/neoskrnl.xcodeproj/project.xcworkspace/xcshareddata/ tools/dist/mkfs.* tools/dist/fsck.* +tools/dist/chk.* html/ latex/ diff --git a/dev/boot/BootKit/Qr.h b/dev/boot/BootKit/Qr.h index 2dcfc5fe..f537aa5e 100644 --- a/dev/boot/BootKit/Qr.h +++ b/dev/boot/BootKit/Qr.h @@ -306,7 +306,7 @@ template bool Qr::draw(int whereX, int whereY) noexcept { if (!this->status) return false; // it may be invalid. - fb_init(); + cg_init(); for (int y = 0; y < (this->side_size()); ++y) { for (int x = 0; x < (this->side_size()); ++x) { @@ -315,7 +315,7 @@ bool Qr::draw(int whereX, int whereY) noexcept { } } - fb_clear(); + cg_clear(); return false; } diff --git a/dev/boot/src/BootFileReader.cc b/dev/boot/src/BootFileReader.cc index c95623b6..dca260bc 100644 --- a/dev/boot/src/BootFileReader.cc +++ b/dev/boot/src/BootFileReader.cc @@ -75,7 +75,7 @@ Boot::BootFileReader::BootFileReader(const CharacterTypeUTF16* path, EfiHandlePt mWriter.Write(L"BootZ: Fetch-Protocol: No-Such-Path: ").Write(mPath).Write(L"\r"); this->mErrorCode = kNotSupported; - fb_render_string("BootZ: PLEASE RECOVER YOUR NEKERNEL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + cg_render_string("BootZ: PLEASE RECOVER YOUR NEKERNEL INSTALL.", 40, 10, RGB(0xFF, 0xFF, 0xFF)); mRootFs->Close(mRootFs); diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index 5bcdff5a..1cefa70c 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -111,7 +111,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa kHandoverHeader = handover_hdr; - FB::fb_clear_video(); + FB::cg_clear_video(); UInt32 cnt_enabled = 0; UInt32 cnt_disabled = 0; diff --git a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc index 789c1067..aa3f284f 100644 --- a/dev/kernel/HALKit/AMD64/HalDebugOutput.cc +++ b/dev/kernel/HALKit/AMD64/HalDebugOutput.cc @@ -90,7 +90,7 @@ EXTERN_C void ke_utf_io_write(DeviceInterface* obj, const Utf8C tmp_str[0] = (bytes[index] > 127) ? '?' : bytes[index]; tmp_str[1] = 0; - fb_render_string(tmp_str, kY, kX, RGB(0xff, 0xff, 0xff)); + cg_render_string(tmp_str, kY, kX, RGB(0xff, 0xff, 0xff)); if (bytes[index] == '\r') { kY += kFontSizeY; @@ -106,7 +106,7 @@ EXTERN_C void ke_utf_io_write(DeviceInterface* obj, const Utf8C if (kY > kHandoverHeader->f_GOP.f_Height) { kY = kFontSizeY; - FBDrawInRegion(fb_get_clear_clr(), FB::FBAccessibilty::Height(), FB::FBAccessibilty::Width(), + FBDrawInRegion(cg_get_clear_clr(), FB::CGAccessibilty::Height(), FB::CGAccessibilty::Width(), 0, 0); } @@ -146,7 +146,7 @@ EXTERN_C void ke_io_write(DeviceInterface* obj, const Char* bytes) tmp_str[0] = bytes[index]; tmp_str[1] = 0; - fb_render_string(tmp_str, kY, kX, RGB(0xff, 0xff, 0xff)); + cg_render_string(tmp_str, kY, kX, RGB(0xff, 0xff, 0xff)); if (bytes[index] == '\r') { kY += kFontSizeY; @@ -162,7 +162,7 @@ EXTERN_C void ke_io_write(DeviceInterface* obj, const Char* bytes) if (kY > kHandoverHeader->f_GOP.f_Height) { kY = kFontSizeY; - FBDrawInRegion(fb_get_clear_clr(), FB::FBAccessibilty::Height(), FB::FBAccessibilty::Width(), + FBDrawInRegion(cg_get_clear_clr(), FB::CGAccessibilty::Height(), FB::CGAccessibilty::Width(), 0, 0); } diff --git a/dev/kernel/HALKit/AMD64/HalKernelMain.cc b/dev/kernel/HALKit/AMD64/HalKernelMain.cc index e67501cc..2339f56d 100644 --- a/dev/kernel/HALKit/AMD64/HalKernelMain.cc +++ b/dev/kernel/HALKit/AMD64/HalKernelMain.cc @@ -118,7 +118,7 @@ EXTERN_C Int32 hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { kGDTArray[4].fFlags = 0; kGDTArray[4].fBaseHigh = 0; - FB::fb_clear_video(); + FB::cg_clear_video(); // Load memory descriptors. HAL::Register64 gdt_reg; diff --git a/dev/kernel/HALKit/ARM64/HalKernelMain.cc b/dev/kernel/HALKit/ARM64/HalKernelMain.cc index b711b833..ad516539 100644 --- a/dev/kernel/HALKit/ARM64/HalKernelMain.cc +++ b/dev/kernel/HALKit/ARM64/HalKernelMain.cc @@ -42,7 +42,7 @@ EXTERN_C void hal_init_platform(Kernel::HEL::BootInfoHeader* handover_hdr) { handover_hdr->f_HardwareTables.f_ImageHandle); #endif - FB::fb_clear_video(); + FB::cg_clear_video(); /************************************** */ /* INITIALIZE BIT MAP. */ diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index 2029ae7b..659362fe 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -29,7 +29,7 @@ class KERNEL_TASK final { UInt8* StackReserve{nullptr}; SizeT StackSize{kSchedMaxStackSz}; ProcessImage Image{}; - /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within + /// @brief a KID is a Kernel ID, it is used to find a task running within /// the kernel. KID Kid{0}; }; diff --git a/dev/kernel/src/UserProcessScheduler.cc b/dev/kernel/src/UserProcessScheduler.cc index ac25c3d8..02d5c1d6 100644 --- a/dev/kernel/src/UserProcessScheduler.cc +++ b/dev/kernel/src/UserProcessScheduler.cc @@ -678,11 +678,13 @@ UserProcessScheduler::operator bool() { /// @brief this checks if no process is on the team. //////////////////////////////////////////////////////////// Bool UserProcessScheduler::operator!() { + SInt64 cnt = 0UL; + for (auto process_index = 0UL; process_index < mTeam.AsArray().Count(); ++process_index) { auto& process = mTeam.AsArray()[process_index]; - if (UserProcessHelper::CanBeScheduled(process)) return false; + if (UserProcessHelper::CanBeScheduled(process)) ++cnt; } - return true; + return cnt == 0L; } } // namespace Kernel diff --git a/dev/modules/APM/APM.h b/dev/modules/APM/APM.h index 29de5114..95c749e1 100644 --- a/dev/modules/APM/APM.h +++ b/dev/modules/APM/APM.h @@ -21,9 +21,9 @@ enum { kAPMPowerCommandReboot = 0x08, }; -/// @brief Send a APM command into it's own IO space. +/// @brief Send a APM command into it's controller. (Shutdown, Reboot, Sleep...) /// @param base_dma the IO base port. /// @param cmd the command. -/// @return status code. +/// @return status code of the APM command. EXTERN_C Int32 apm_send_io_command(UInt16 cmd); } // namespace Kernel diff --git a/dev/modules/CoreGfx/CoreAccess.h b/dev/modules/CoreGfx/CoreAccess.h index f092b5a6..246b386a 100644 --- a/dev/modules/CoreGfx/CoreAccess.h +++ b/dev/modules/CoreGfx/CoreAccess.h @@ -17,12 +17,12 @@ namespace FB { using namespace Kernel; /// @brief common User interface class. -class FBAccessibilty final { - explicit FBAccessibilty() = default; - ~FBAccessibilty() = default; +class CGAccessibilty final { + explicit CGAccessibilty() = default; + ~CGAccessibilty() = default; public: - NE_COPY_DELETE(FBAccessibilty) + NE_COPY_DELETE(CGAccessibilty) static UInt64 Width() noexcept { return kHandoverHeader->f_GOP.f_Width; } diff --git a/dev/modules/CoreGfx/CoreGfx.h b/dev/modules/CoreGfx/CoreGfx.h index d5cfa5a3..0ab3bcbc 100644 --- a/dev/modules/CoreGfx/CoreGfx.h +++ b/dev/modules/CoreGfx/CoreGfx.h @@ -8,13 +8,13 @@ #include -#define fb_init() Kernel::UInt32 kCGCursor = 0 +#define cg_init() Kernel::UInt32 kCGCursor = 0 -#define fb_color(R, G, B) RGB(R, G, B) +#define cg_color(R, G, B) RGB(R, G, B) -#define fb_get_clear_clr() RGB(0, 0, 0x80) +#define cg_get_clear_clr() RGB(0, 0, 0x80) -#define fb_clear() kCGCursor = 0UL +#define cg_clear() kCGCursor = 0UL #ifdef __NE_AMD64__ /// @brief Performs Alpha drawing on the framebuffer. @@ -57,7 +57,7 @@ for (Kernel::UInt32 u = base_y; u < (height + base_y); ++u) { \ *(((volatile Kernel::UInt32*) (kHandoverHeader->f_GOP.f_The + \ 4 * kHandoverHeader->f_GOP.f_PixelPerLine * i + 4 * u))) = \ - fb_get_clear_clr(); \ + cg_get_clear_clr(); \ } \ } @@ -111,8 +111,8 @@ #endif // ifndef CORE_GFX_ACCESSIBILITY_H namespace FB { -inline Void fb_clear_video() noexcept { - FBDrawInRegion(fb_get_clear_clr(), FB::FBAccessibilty::Height(), FB::FBAccessibilty::Width(), 0, +inline Void cg_clear_video() noexcept { + FBDrawInRegion(cg_get_clear_clr(), FB::CGAccessibilty::Height(), FB::CGAccessibilty::Width(), 0, 0); } } // namespace FB \ No newline at end of file diff --git a/dev/modules/CoreGfx/MathGfx.h b/dev/modules/CoreGfx/MathGfx.h index 0b483fad..523f4b31 100644 --- a/dev/modules/CoreGfx/MathGfx.h +++ b/dev/modules/CoreGfx/MathGfx.h @@ -11,9 +11,9 @@ namespace UI { #ifdef NE_CORE_GFX_USE_DOUBLE -typedef double fb_real_t; +typedef double cg_real_t; #else -typedef float fb_real_t; +typedef float cg_real_t; #endif /// @brief Linear interpolation equation solver. @@ -21,7 +21,7 @@ typedef float fb_real_t; /// @param to to which value. /// @param stat /// @return Linear interop value. -inline fb_real_t fb_math_lerp(fb_real_t to, fb_real_t from, fb_real_t stat) { +inline cg_real_t cg_math_lerp(cg_real_t to, cg_real_t from, cg_real_t stat) { return (from) + (to - from) * stat; } } // namespace UI \ No newline at end of file diff --git a/dev/modules/CoreGfx/TextGfx.h b/dev/modules/CoreGfx/TextGfx.h index 1bcc1397..359af6a8 100644 --- a/dev/modules/CoreGfx/TextGfx.h +++ b/dev/modules/CoreGfx/TextGfx.h @@ -145,7 +145,7 @@ inline const Kernel::UInt8 kFontBitmap[kFontNOFChars][kFontSizeX] = { }; -inline Kernel::Void fb_render_string_for_bitmap(const Kernel::UInt8* bitmap, +inline Kernel::Void cg_render_string_for_bitmap(const Kernel::UInt8* bitmap, const Kernel::SizeT x_sz, const Kernel::SizeT y_sz, Kernel::Int32& x_dst, Kernel::Int32& y_dst, Kernel::Int32& color) { @@ -167,7 +167,7 @@ inline Kernel::Void fb_render_string_for_bitmap(const Kernel::UInt8* bitmap, } } -inline Kernel::Void fb_render_string(const Kernel::Char* text, Kernel::Int32 x_dst, +inline Kernel::Void cg_render_string(const Kernel::Char* text, Kernel::Int32 x_dst, Kernel::Int32 y_dst, Kernel::Int32 color) { #ifndef __BOOTZ__ auto len = Kernel::rt_string_len(text); @@ -176,7 +176,7 @@ inline Kernel::Void fb_render_string(const Kernel::Char* text, Kernel::Int32 x_d #endif for (Kernel::SizeT i = 0; i < len; ++i) { - fb_render_string_for_bitmap(&kFontBitmap[(Kernel::UInt8) text[i]][0], kFontSizeX, kFontSizeY, + cg_render_string_for_bitmap(&kFontBitmap[(Kernel::UInt8) text[i]][0], kFontSizeX, kFontSizeY, x_dst, y_dst, color); y_dst += kFontSizeY; } diff --git a/dev/modules/HPET/.gitkeep b/dev/modules/HPET/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/drawio/GUI_DESIGN.drawio b/docs/drawio/GUI_DESIGN.drawio index 31fc11cf..bdf977af 100644 --- a/docs/drawio/GUI_DESIGN.drawio +++ b/docs/drawio/GUI_DESIGN.drawio @@ -1,16 +1,16 @@ - + - + - + diff --git a/tools/chk.hefs.cc b/tools/chk.hefs.cc new file mode 100644 index 00000000..121604f1 --- /dev/null +++ b/tools/chk.hefs.cc @@ -0,0 +1,76 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include +#include +#include +#include + +/// @note decimal base. +static uint16_t kNumericalBase = 10; + +int main(int argc, char** argv) { + if (argc < 2) { + mkfs::console_out() << "fsck: hefs: usage: chk.hefs -in= -b=" + << "\n"; + return EXIT_FAILURE; + } + + auto args = mkfs::detail::build_args(argc, argv); + + auto opt_disk = mkfs::get_option(args, "in"); + + auto origin = mkfs::get_option(args, "b"); + + if (opt_disk.empty()) { + mkfs::console_out() << "fsck: hefs: error: OpenHeFS partition is empty! Exiting..." + << "\n"; + return EXIT_FAILURE; + } + + auto out_origin = 0L; + + if (!mkfs::detail::parse_signed(origin, out_origin, kNumericalBase)) { + mkfs::console_out() << "hefs: error: Invalid -org= argument.\n"; + return EXIT_FAILURE; + } + + std::ifstream output_device(opt_disk, std::ios::binary); + + if (!output_device.good()) { + mkfs::console_out() << "hefs: error: Unable to open output device: " << opt_disk << "\n"; + return EXIT_FAILURE; + } + + output_device.seekg(out_origin); + + if (!output_device.good()) { + mkfs::console_out() << "hefs: error: Failed seek to origin.\n"; + return EXIT_FAILURE; + } + + // @note use modern intializer list here to empty out the fields according to the struct layout. + mkfs::hefs::BootNode boot_node{}; + + output_device.read(reinterpret_cast(&boot_node), sizeof(boot_node)); + + if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || + boot_node.sectorSize < kMkFsSectorSz) { + mkfs::console_out() << "hefs: error: Device is not an OpenHeFS disk: " << opt_disk << "\n"; + return EXIT_FAILURE; + } + + if (boot_node.badSectors > kMkFsMaxBadSectors) { + mkfs::console_out() << "hefs: error: OpenHeFS disk has too much bad sectors: " << opt_disk << "\n"; + return EXIT_FAILURE; + } + + mkfs::console_out() << "hefs: OpenHeFS partition is healthy. Exiting...\n"; + + output_device.close(); + + return EXIT_SUCCESS; +} diff --git a/tools/chk.hefs.json b/tools/chk.hefs.json new file mode 100644 index 00000000..58918613 --- /dev/null +++ b/tools/chk.hefs.json @@ -0,0 +1,16 @@ +{ + "compiler_path": "clang++", + "compiler_std": "c++20", + "headers_path": [ + "../" + ], + "sources_path": [ + "chk.hefs.cc" + ], + "output_name": "./dist/chk.hefs", + "cpp_macros": [ + "kFsckHeFSVersion=0x0100", + "kFsckHeFSVersionHighest=0x0100", + "kFsckHeFSVersionLowest=0x0100" + ] +} \ No newline at end of file diff --git a/tools/fsck.hefs.cc b/tools/fsck.hefs.cc deleted file mode 100644 index a2162a4f..00000000 --- a/tools/fsck.hefs.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include -#include -#include - -/// @note decimal base. -static uint16_t kNumericalBase = 10; - -int main(int argc, char** argv) { - if (argc < 2) { - mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -in= -org=" - << "\n"; - return EXIT_FAILURE; - } - - auto args = mkfs::detail::build_args(argc, argv); - - auto opt_disk = mkfs::get_option(args, "-in"); - - auto origin = mkfs::get_option(args, "-org"); - - if (opt_disk.empty()) { - mkfs::console_out() << "fsck: hefs: error: OpenHeFS partition is empty! Exiting..." - << "\n"; - return EXIT_FAILURE; - } - - auto out_origin = 0L; - - if (!mkfs::detail::parse_signed(origin, out_origin, kNumericalBase)) { - mkfs::console_out() << "hefs: error: Invalid -org= argument.\n"; - return EXIT_FAILURE; - } - - std::ifstream output_device(opt_disk, std::ios::binary); - - if (!output_device.good()) { - mkfs::console_out() << "hefs: error: Unable to open output device: " << opt_disk << "\n"; - return EXIT_FAILURE; - } - - output_device.seekg(out_origin); - - if (!output_device.good()) { - mkfs::console_out() << "hefs: error: Failed seek to origin.\n"; - return EXIT_FAILURE; - } - - // @note use modern intializer list here to empty out the fields according to the struct layout. - mkfs::hefs::BootNode boot_node{}; - - output_device.read(reinterpret_cast(&boot_node), sizeof(boot_node)); - - if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || - boot_node.sectorSize < kMkFsSectorSz) { - mkfs::console_out() << "hefs: error: Device is not an OpenHeFS disk: " << opt_disk << "\n"; - return EXIT_FAILURE; - } - - if (boot_node.badSectors > kMkFsMaxBadSectors) { - mkfs::console_out() << "hefs: error: OpenHeFS disk has too much bad sectors: " << opt_disk << "\n"; - return EXIT_FAILURE; - } - - mkfs::console_out() << "hefs: OpenHeFS partition is healthy, exiting...\n"; - - output_device.close(); - - return EXIT_SUCCESS; -} diff --git a/tools/fsck.hefs.json b/tools/fsck.hefs.json deleted file mode 100644 index 970665aa..00000000 --- a/tools/fsck.hefs.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "compiler_path": "clang++", - "compiler_std": "c++20", - "headers_path": [ - "../" - ], - "sources_path": [ - "fsck.hefs.cc" - ], - "output_name": "./dist/fsck.hefs", - "cpp_macros": [ - "kFsckHeFSVersion=0x0100", - "kFsckHeFSVersionHighest=0x0100", - "kFsckHeFSVersionLowest=0x0100" - ] -} \ No newline at end of file diff --git a/tools/libmkfs/mkfs.h b/tools/libmkfs/mkfs.h index 6e242293..18ed571b 100644 --- a/tools/libmkfs/mkfs.h +++ b/tools/libmkfs/mkfs.h @@ -8,7 +8,6 @@ #include #include -#include #include #define kMkFsSectorSz (512U) @@ -63,10 +62,10 @@ namespace detail { template inline std::basic_string get_option(const std::basic_string& args, const std::basic_string& option) { - size_t pos = args.find(option + CharType('=')); + size_t pos = args.find(CharType('-') + option + CharType('=')); if (pos != std::string::npos) { - size_t start = pos + option.length() + 1; + size_t start = pos + option.length() + 2; size_t end = args.find(' ', start); return args.substr(start, end - start); } diff --git a/tools/mkfs.hefs.cc b/tools/mkfs.hefs.cc index d1139e10..77dd1658 100644 --- a/tools/mkfs.hefs.cc +++ b/tools/mkfs.hefs.cc @@ -12,12 +12,13 @@ #include #include -static size_t kDiskSize = mkfs::detail::gib_cast(4UL); static uint16_t kVersion = kHeFSVersion; -static std::u8string kLabel; -static size_t kSectorSize = 512; static uint16_t kNumericalBase = 10; +static size_t kDiskSize = mkfs::detail::gib_cast(4UL); +static std::u8string kDiskLabel; +static size_t kDiskSectorSz = 512; + int main(int argc, char** argv) { if (argc < 2) { mkfs::console_out() @@ -30,13 +31,13 @@ int main(int argc, char** argv) { std::string args = mkfs::detail::build_args(argc, argv); - auto output_path = mkfs::get_option(args, "-o"); + auto output_path = mkfs::get_option(args, "o"); if (output_path.empty()) { mkfs::console_out() << "hefs: error: Missing -o argument.\n"; return EXIT_FAILURE; } - auto opt_s = mkfs::get_option(args, "-s"); + auto opt_s = mkfs::get_option(args, "s"); long parsed_s = 0; if (!mkfs::detail::parse_signed(opt_s, parsed_s, kNumericalBase) || parsed_s == 0) { mkfs::console_out() << "hefs: error: Invalid sector size \"" << opt_s @@ -49,20 +50,20 @@ int main(int argc, char** argv) { << "\" is not a power of two.\n"; return EXIT_FAILURE; } - kSectorSize = static_cast(parsed_s); + kDiskSectorSz = static_cast(parsed_s); - auto opt_L = mkfs::get_option(args, "-L"); + auto opt_L = mkfs::get_option(args, "L"); if (!opt_L.empty()) { - kLabel.clear(); - for (char c : opt_L) kLabel.push_back(static_cast(c)); + kDiskLabel.clear(); + for (char c : opt_L) kDiskLabel.push_back(static_cast(c)); } else { - kLabel.clear(); + kDiskLabel.clear(); for (size_t i = 0; i < kHeFSPartNameLen && kHeFSDefaultVolumeName[i] != u'\0'; ++i) { - kLabel.push_back(static_cast(kHeFSDefaultVolumeName[i])); + kDiskLabel.push_back(static_cast(kHeFSDefaultVolumeName[i])); } } - auto opt_S = mkfs::get_option(args, "-S"); + auto opt_S = mkfs::get_option(args, "S"); unsigned long long gb = 0; if (!mkfs::detail::parse_decimal(opt_S, gb) || gb == 0ULL) { mkfs::console_out() << "hefs: error: Invalid disk size \"" << opt_S @@ -76,12 +77,12 @@ int main(int argc, char** argv) { } kDiskSize = static_cast(gb * 1024ULL * 1024ULL * 1024ULL); - auto opt_b = mkfs::get_option(args, "-b"); - auto opt_e = mkfs::get_option(args, "-e"); - auto opt_bs = mkfs::get_option(args, "-bs"); - auto opt_be = mkfs::get_option(args, "-be"); - auto opt_is = mkfs::get_option(args, "-is"); - auto opt_ie = mkfs::get_option(args, "-ie"); + auto opt_b = mkfs::get_option(args, "b"); + auto opt_e = mkfs::get_option(args, "e"); + auto opt_bs = mkfs::get_option(args, "bs"); + auto opt_be = mkfs::get_option(args, "be"); + auto opt_is = mkfs::get_option(args, "is"); + auto opt_ie = mkfs::get_option(args, "ie"); long start_ind = 0, end_ind = 0; long start_block = 0, end_block = 0; @@ -117,7 +118,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - if (static_cast(end_block) * kSectorSize > kDiskSize || + if (static_cast(end_block) * kDiskSectorSz > kDiskSize || static_cast(end_ind) > kDiskSize || static_cast(end_in) > kDiskSize) { mkfs::console_out() << "hefs: error: One or more ranges exceed disk size.\n"; return EXIT_FAILURE; @@ -137,8 +138,8 @@ int main(int argc, char** argv) { boot_node.diskKind = mkfs::hefs::kHeFSHardDrive; boot_node.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8; boot_node.diskSize = kDiskSize; - boot_node.sectorSize = kSectorSize; - boot_node.sectorCount = kDiskSize / kSectorSize; + boot_node.sectorSize = kDiskSectorSz; + boot_node.sectorCount = kDiskSize / kDiskSectorSz; boot_node.startIND = static_cast(start_ind) + sizeof(mkfs::hefs::BootNode); boot_node.endIND = static_cast(end_ind); boot_node.startIN = static_cast(start_in); @@ -161,10 +162,10 @@ int main(int argc, char** argv) { std::memset(boot_node.volumeName, 0, sizeof(boot_node.volumeName)); - size_t label_units = std::min(kLabel.size(), vol_slots - 1); + size_t label_units = std::min(kDiskLabel.size(), vol_slots - 1); for (size_t i = 0; i < label_units; ++i) { - boot_node.volumeName[i] = static_cast(kLabel[i]); + boot_node.volumeName[i] = static_cast(kDiskLabel[i]); } boot_node.volumeName[label_units] = 0U; -- cgit v1.2.3