summaryrefslogtreecommitdiffhomepage
path: root/public/frameworks
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-22 09:04:10 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-22 09:04:10 +0100
commit89e8d71556a88fa36f8b18a553f589ab66748895 (patch)
tree3847437128001ae06f072252ea10d4f0644178ac /public/frameworks
parent6ae47a1fe04296eba06fcde0af4e89e100c6eb76 (diff)
fwrk(DiskImage): Add JSON build config, rename API, and unify disk formatting logic
Changes: - Added DiskImage.json build description for use with Redub (custom build system) - Replaced hardcoded strings with constants (kDIDefaultDiskName, etc.) - Renamed: - DIFormatDisk → DIFormatPartitionEPM - DIFormatNeFS → DIFormatFilesystemNeFS - Unified internal formatting logic by removing local aliases - Restored #include for EPM.h and NeFS.h - Removed unused uuid_generate_random call - Minor cleanup of types (Char, SizeT, SInt32), ensuring consistency across DI_DISK_IMAGE Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'public/frameworks')
-rw-r--r--public/frameworks/DiskImage.fwrk/DiskImage.json22
-rw-r--r--public/frameworks/DiskImage.fwrk/headers/DiskImage.h23
-rw-r--r--public/frameworks/DiskImage.fwrk/src/DiskImage.cc51
3 files changed, 52 insertions, 44 deletions
diff --git a/public/frameworks/DiskImage.fwrk/DiskImage.json b/public/frameworks/DiskImage.fwrk/DiskImage.json
new file mode 100644
index 00000000..184d877e
--- /dev/null
+++ b/public/frameworks/DiskImage.fwrk/DiskImage.json
@@ -0,0 +1,22 @@
+{
+ "compiler_path": "x86_64-w64-mingw32-g++",
+ "compiler_std": "c++20",
+ "headers_path": ["../", "./", "../../../dev", "../../../dev/Kernel"],
+ "sources_path": ["src/*.cc"],
+ "output_name": "libDiskImage.dylib",
+ "compiler_flags": [
+ "-fPIC",
+ "-ffreestanding",
+ "-shared",
+ "-fno-rtti",
+ "-fno-exceptions",
+ "-Wl,--subsystem=17"
+ ],
+ "cpp_macros": [
+ "kDIVersion=0x0100",
+ "kDIVersionHighest=0x0100",
+ "kDIVersionLowest=0x0100",
+ "__NE_AMD64__"
+ ]
+ }
+ \ No newline at end of file
diff --git a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h
index 7254009e..704776a4 100644
--- a/public/frameworks/DiskImage.fwrk/headers/DiskImage.h
+++ b/public/frameworks/DiskImage.fwrk/headers/DiskImage.h
@@ -9,15 +9,12 @@
#pragma once
-#include <FirmwareKit/EPM.h>
-#include <FSKit/NeFS.h>
-#include <uuid/uuid.h>
#include <LibSCI/SCI.h>
#define kDISectorSz (512)
-#define kDIMinDiskSz gib_cast(1)
+#define kDIMinDiskSz (1024 * 1024 * 1024)
#define kDIDefaultOutputName "disk.eimg"
-
+#define kDIDefaultDiskName "Disk"
#define kDISuccessStatus (0)
#define kDIFailureStatus (1)
@@ -25,19 +22,19 @@ struct DI_DISK_IMAGE;
struct DI_DISK_IMAGE
{
- char disk_name[512] = "Disk Image";
- int sector_sz = kDISectorSz;
- const int block_cnt = 0;
- size_t disk_sz = kDIMinDiskSz;
- char out_name[256] = kDIDefaultOutputName;
+ Char disk_name[512] = kDIDefaultDiskName;
+ SInt32 sector_sz = kDISectorSz;
+ SInt32 block_cnt = 0;
+ SizeT disk_sz = kDIMinDiskSz;
+ Char out_name[256] = kDIDefaultOutputName;
};
-/// @brief EPM format disk
+/// @brief Format with an EPM partition.
/// @param img disk image structure.
/// @return Status code upon completion.
-SInt32 DIFormatDisk(struct DI_DISK_IMAGE& img) noexcept;
+SInt32 DIFormatPartitionEPM(struct DI_DISK_IMAGE& img) noexcept;
/// @brief NeFS format over EPM.
/// @param img disk image structure.
/// @return Status code upon completion.
-SInt32 DIFormatNeFS(struct DI_DISK_IMAGE& img) noexcept;
+SInt32 DIFormatFilesystemNeFS(struct DI_DISK_IMAGE& img) noexcept;
diff --git a/public/frameworks/DiskImage.fwrk/src/DiskImage.cc b/public/frameworks/DiskImage.fwrk/src/DiskImage.cc
index d009a19c..451a234f 100644
--- a/public/frameworks/DiskImage.fwrk/src/DiskImage.cc
+++ b/public/frameworks/DiskImage.fwrk/src/DiskImage.cc
@@ -9,46 +9,41 @@
#include <DiskImage.fwrk/headers/DiskImage.h>
+#include <FirmwareKit/EPM.h>
+#include <FSKit/NeFS.h>
+
/// @brief EPM format disk
/// @param img disk image structure.
/// @return Status code upon completion.
-SInt32 DIFormatDisk(struct DI_DISK_IMAGE& img) noexcept
+SInt32 DIFormatPartitionEPM(struct DI_DISK_IMAGE& img) noexcept
{
- const char* disk_name = img.disk_name;
- int sector_sz = img.sector_sz;
- const int block_cnt = img.block_cnt;
- size_t disk_sz = img.disk_sz;
- const char* out = img.out_name;
-
if (!img.sector_sz || (img.sector_sz % 512 != 0))
return kDIFailureStatus;
- if (*out == 0 ||
- *disk_name == 0)
+ if (*img.out_name == 0 ||
+ *img.disk_name == 0)
return kDIFailureStatus;
struct ::EPM_PART_BLOCK block
{
};
- block.NumBlocks = block_cnt;
- block.SectorSz = sector_sz;
+ block.NumBlocks = img.block_cnt;
+ block.SectorSz = img.sector_sz;
block.Version = kEPMRevisionBcd;
block.LbaStart = sizeof(struct ::EPM_PART_BLOCK);
- block.LbaEnd = disk_sz - block.LbaStart;
+ block.LbaEnd = img.disk_sz - block.LbaStart;
block.FsVersion = kNeFSVersionInteger;
- ::MmCopyMemory(block.Name, (VoidPtr)disk_name, ::MmStrLen(disk_name));
+ ::MmCopyMemory(block.Name, (VoidPtr)img.disk_name, ::MmStrLen(img.disk_name));
::MmCopyMemory(block.Magic, (VoidPtr)kEPMMagic86, ::MmStrLen(kEPMMagic86));
- ::uuid_generate_random((NeOS::UInt8*)&block.Guid);
-
- IOObject handle = IoOpenFile(out, nullptr);
+ IOObject handle = IoOpenFile(img.out_name, nullptr);
if (!handle)
return kDIFailureStatus;
- ::IoWriteFile(handle, (NeOS::Char*)&block, sizeof(struct ::EPM_PART_BLOCK));
+ ::IoWriteFile(handle, (Char*)&block, sizeof(struct ::EPM_PART_BLOCK));
::IoCloseFile(handle);
@@ -60,26 +55,20 @@ SInt32 DIFormatDisk(struct DI_DISK_IMAGE& img) noexcept
/// @brief NeFS format over EPM.
/// @param img disk image structure.
/// @return Status code upon completion.
-SInt32 DIFormatNeFS(struct DI_DISK_IMAGE& img) noexcept
+SInt32 DIFormatFilesystemNeFS(struct DI_DISK_IMAGE& img) noexcept
{
- const char* disk_name = img.disk_name;
- int sector_sz = img.sector_sz;
- const int block_cnt = img.block_cnt;
- size_t disk_sz = img.disk_sz;
- const char* out = img.out_name;
-
if (!img.sector_sz || (img.sector_sz % 512 != 0))
return kDIFailureStatus;
- if (*out == 0 ||
- *disk_name == 0)
+ if (*img.out_name == 0 ||
+ *img.disk_name == 0)
return kDIFailureStatus;
struct ::NEFS_ROOT_PARTITION_BLOCK rpb
{
};
- ::MmCopyMemory(rpb.PartitionName, (VoidPtr)disk_name, ::MmStrLen(disk_name));
+ ::MmCopyMemory(rpb.PartitionName, (VoidPtr)img.disk_name, ::MmStrLen(img.disk_name));
::MmCopyMemory(rpb.Ident, (VoidPtr)kNeFSIdent, ::MmStrLen(kNeFSIdent));
rpb.Version = kNeFSVersionInteger;
@@ -88,22 +77,22 @@ SInt32 DIFormatNeFS(struct DI_DISK_IMAGE& img) noexcept
rpb.StartCatalog = kNeFSCatalogStartAddress;
rpb.CatalogCount = 0;
- rpb.DiskSize = disk_sz;
+ rpb.DiskSize = img.disk_sz;
- rpb.SectorSize = sector_sz;
+ rpb.SectorSize = img.sector_sz;
rpb.SectorCount = rpb.DiskSize / rpb.SectorSize;
rpb.FreeSectors = rpb.SectorCount;
rpb.FreeCatalog = rpb.DiskSize / sizeof(NEFS_CATALOG_STRUCT);
- IOObject handle = IoOpenFile(out, nullptr);
+ IOObject handle = IoOpenFile(img.out_name, nullptr);
if (!handle)
return kDIFailureStatus;
UInt64 p_prev = ::IoTellFile(handle);
- ::IoWriteFile(handle, (NeOS::Char*)&rpb, sizeof(struct ::NEFS_ROOT_PARTITION_BLOCK));
+ ::IoWriteFile(handle, (Char*)&rpb, sizeof(struct ::NEFS_ROOT_PARTITION_BLOCK));
::IoSeekFile(handle, p_prev);