From 5bf5213bc1f2adf5e3a9e707fb4026ded95fcc14 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 9 Mar 2025 05:09:31 +0100 Subject: ADD: Replace make_fs with diutil. --- .gitignore | 2 +- dev/Kernel/FirmwareKit/EPM.h | 2 +- public/tools/diutil/.keep | 0 public/tools/diutil/CommandLine.cc | 123 ++++++++++++++++++++++++++++++++++++ public/tools/diutil/dist/.keep | 0 public/tools/diutil/diutil.json | 13 ++++ public/tools/make_fs/.keep | 0 public/tools/make_fs/CommandLine.cc | 117 ---------------------------------- public/tools/make_fs/dist/.keep | 0 public/tools/make_fs/make_fs.json | 13 ---- 10 files changed, 138 insertions(+), 132 deletions(-) create mode 100644 public/tools/diutil/.keep create mode 100644 public/tools/diutil/CommandLine.cc create mode 100644 public/tools/diutil/dist/.keep create mode 100644 public/tools/diutil/diutil.json delete mode 100644 public/tools/make_fs/.keep delete mode 100644 public/tools/make_fs/CommandLine.cc delete mode 100644 public/tools/make_fs/dist/.keep delete mode 100644 public/tools/make_fs/make_fs.json diff --git a/.gitignore b/.gitignore index 08cbd118..300deae4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ syntax: glob xcuserdata/ -public/tools/make_fs/dist/make_fs +public/tools/diutil/dist/diutil *.hmap *.ipa diff --git a/dev/Kernel/FirmwareKit/EPM.h b/dev/Kernel/FirmwareKit/EPM.h index a6b8c5b6..b5e49d02 100644 --- a/dev/Kernel/FirmwareKit/EPM.h +++ b/dev/Kernel/FirmwareKit/EPM.h @@ -72,7 +72,7 @@ typedef struct EPM_GUID NeOS::UInt16 Data2; NeOS::UInt16 Data3; NeOS::UInt8 Data4[8]; -} EPM_GUID; +} PACKED EPM_GUID; /** * @brief The EPM boot block. diff --git a/public/tools/diutil/.keep b/public/tools/diutil/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/diutil/CommandLine.cc b/public/tools/diutil/CommandLine.cc new file mode 100644 index 00000000..973a1fc5 --- /dev/null +++ b/public/tools/diutil/CommandLine.cc @@ -0,0 +1,123 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal EL Mahrouss, all rights reserved. + + FILE: NeFS.h + PURPOSE: NeFS (New extended File System) support. + + ------------------------------------------- */ + +#include "NewKit/Defines.h" +#include +#include +#include + +#include +#include +#include + +static std::string kDiskName = "Disk"; +static int kDiskSectorSz = 512; +static const int kDiskBlockCnt = 1; +static size_t kDiskSz = gib_cast(4); +static std::string kOutDisk = "disk.eimg"; + +/// @brief Filesystem tool entrypoint. +int main(int argc, char** argv) +{ + for (size_t arg = 0; arg < argc; ++arg) + { + std::string arg_s = argv[arg]; + + if (arg_s == "--disk-output-name") + { + if ((arg + 1) < argc) + { + kOutDisk = argv[arg + 1]; + } + } + else if (arg_s == "--disk-output-size") + { + if ((arg + 1) < argc) + { + kDiskSz = strtol(argv[arg + 1], nullptr, 10); + } + } + else if (arg_s == "--disk-sector-size") + { + if ((arg + 1) < argc) + { + kDiskSectorSz = strtol(argv[arg + 1], nullptr, 10); + } + } + else if (arg_s == "--disk-part-name") + { + if ((arg + 1) < argc) + { + kDiskName = argv[arg + 1]; + } + } + } + + std::cout << "diutil: EPM Disk Tool.\n"; + + struct ::EPM_PART_BLOCK block + { + 0 + }; + + block.NumBlocks = kDiskBlockCnt; + block.SectorSz = kDiskSectorSz; + block.Version = kEPMRevisionBcd; + block.LbaStart = sizeof(struct ::EPM_PART_BLOCK); + block.LbaEnd = kDiskSz - sizeof(struct ::EPM_PART_BLOCK); + block.FsVersion = kNeFSVersionInteger; + + ::memcpy(block.Name, kDiskName.c_str(), strlen(kDiskName.c_str())); + ::memcpy(block.Magic, kEPMMagic86, strlen(kEPMMagic86)); + + ::uuid_generate_random((NeOS::UInt8*)&block.Guid); + + uuid_string_t str; + + ::uuid_unparse((NeOS::UInt8*)&block.Guid, str); + + std::cout << "diutil: Partition UUID: " << str << std::endl; + + std::ofstream output_epm(kOutDisk); + output_epm.write((NeOS::Char*)&block, sizeof(struct ::EPM_PART_BLOCK)); + + struct ::NEFS_ROOT_PARTITION_BLOCK rpb + { + 0 + }; + + ::memcpy(rpb.PartitionName, kDiskName.c_str(), strlen(kDiskName.c_str())); + ::memcpy(rpb.Ident, kNeFSIdent, strlen(kNeFSIdent)); + + rpb.Version = kNeFSVersionInteger; + rpb.EpmBlock = kEPMBootBlockLba; + + rpb.StartCatalog = kNeFSCatalogStartAddress; + rpb.CatalogCount = 0; + + rpb.DiskSize = kDiskSz; + + rpb.SectorSize = kDiskSectorSz; + rpb.SectorCount = rpb.DiskSize / rpb.SectorSize; + + rpb.FreeSectors = rpb.SectorCount; + rpb.FreeCatalog = rpb.DiskSize / sizeof(NEFS_CATALOG_STRUCT); + + auto p_prev = output_epm.tellp(); + + output_epm.seekp(kNeFSRootCatalogStartAddress); + output_epm.write((NeOS::Char*)&rpb, sizeof(struct ::NEFS_ROOT_PARTITION_BLOCK)); + + output_epm.seekp(p_prev); + output_epm.close(); + + std::cout << "diutil: EPM Disk has been written to: " << kOutDisk << "\n"; + + return 0; +} \ No newline at end of file diff --git a/public/tools/diutil/dist/.keep b/public/tools/diutil/dist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/public/tools/diutil/diutil.json b/public/tools/diutil/diutil.json new file mode 100644 index 00000000..6c917bd2 --- /dev/null +++ b/public/tools/diutil/diutil.json @@ -0,0 +1,13 @@ +{ + "compiler_path": "g++", + "compiler_std": "c++20", + "headers_path": ["./", "../../../dev/Kernel", "../../../dev/"], + "sources_path": ["CommandLine.cc"], + "output_name": "./dist/diutil", + "cpp_macros": [ + "kMKFSVersion=0x0100", + "kMKFSVersionHighest=0x0100", + "kMKFSVersionLowest=0x0100", + "__NE_SDK__" + ] +} diff --git a/public/tools/make_fs/.keep b/public/tools/make_fs/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/public/tools/make_fs/CommandLine.cc b/public/tools/make_fs/CommandLine.cc deleted file mode 100644 index f3ea3f18..00000000 --- a/public/tools/make_fs/CommandLine.cc +++ /dev/null @@ -1,117 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2025, Amlal EL Mahrouss, all rights reserved. - - FILE: NeFS.h - PURPOSE: NeFS (New extended File System) support. - - ------------------------------------------- */ - -#include -#include -#include - -#include -#include -#include - -static std::string kDiskName = "Disk"; -static int kDiskSectorSz = 512; -static const int kDiskBlockCnt = 1; -static size_t kDiskSz = gib_cast(4); -static std::string kOutDisk = "disk.eimg"; - -/// @brief Filesystem tool entrypoint. -int main(int argc, char** argv) -{ - for (size_t arg = 0; arg < argc; ++arg) - { - std::string arg_s = argv[arg]; - - if (arg_s == "--disk-output-name") - { - if ((arg + 1) < argc) - { - kOutDisk = argv[arg + 1]; - } - } - else if (arg_s == "--disk-size") - { - if ((arg + 1) < argc) - { - kDiskSz = strtol(argv[arg + 1], nullptr, 10); - } - } - else if (arg_s == "--disk-sector-size") - { - if ((arg + 1) < argc) - { - kDiskSectorSz = strtol(argv[arg + 1], nullptr, 10); - } - } - else if (arg_s == "--disk-name") - { - if ((arg + 1) < argc) - { - kDiskName = argv[arg + 1]; - } - } - } - - std::cout << "make_fs: EPM Image Creator.\n"; - - struct ::EPM_PART_BLOCK block - { - 0 - }; - - block.NumBlocks = kDiskBlockCnt; - block.SectorSz = kDiskSectorSz; - block.Version = kEPMRevisionBcd; - block.LbaStart = sizeof(struct ::EPM_PART_BLOCK); - block.LbaEnd = 0; - block.FsVersion = kNeFSVersionInteger; - - ::memcpy(block.Name, kDiskName.c_str(), strlen(kDiskName.c_str())); - ::memcpy(block.Magic, kEPMMagic86, strlen(kEPMMagic86)); - - ::uuid_generate_random((NeOS::UInt8*)&block.Guid); - - std::ofstream output_epm(kOutDisk); - output_epm.write((NeOS::Char*)&block, sizeof(struct ::EPM_PART_BLOCK)); - - struct ::NEFS_ROOT_PARTITION_BLOCK rpb - { - }; - - ::memcpy(rpb.PartitionName, kDiskName.c_str(), strlen(kDiskName.c_str())); - ::memcpy(rpb.Ident, kNeFSIdent, strlen(kNeFSIdent)); - - rpb.Version = kNeFSVersionInteger; - rpb.EpmBlock = kEPMBootBlockLba; - - rpb.StartCatalog = kNeFSCatalogStartAddress; - rpb.CatalogCount = 0; - - rpb.DiskSize = kDiskSz; - - rpb.SectorSize = kDiskSectorSz; - rpb.SectorCount = rpb.DiskSize / rpb.SectorSize; - - rpb.FreeSectors = rpb.SectorCount; - rpb.FreeCatalog = rpb.DiskSize / sizeof(NEFS_CATALOG_STRUCT); - - auto p_prev = output_epm.tellp(); - - output_epm.seekp(kNeFSRootCatalogStartAddress); - - output_epm.write((NeOS::Char*)&rpb, sizeof(struct ::NEFS_ROOT_PARTITION_BLOCK)); - - output_epm.seekp(p_prev); - - output_epm.close(); - - std::cout << "make_fs: EPM Image has been written to: " << kOutDisk << "\n"; - - return 0; -} \ No newline at end of file diff --git a/public/tools/make_fs/dist/.keep b/public/tools/make_fs/dist/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/public/tools/make_fs/make_fs.json b/public/tools/make_fs/make_fs.json deleted file mode 100644 index 584cf3c3..00000000 --- a/public/tools/make_fs/make_fs.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compiler_path": "g++", - "compiler_std": "c++20", - "headers_path": ["./", "../../../dev/Kernel", "../../../dev/"], - "sources_path": ["CommandLine.cc"], - "output_name": "./dist/make_fs", - "cpp_macros": [ - "kMKFSVersion=0x0100", - "kMKFSVersionHighest=0x0100", - "kMKFSVersionLowest=0x0100", - "__NE_SDK__" - ] -} -- cgit v1.2.3