diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-08 18:08:34 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-08 18:08:34 +0100 |
| commit | 56006ba750d4c7f6d57e9733171e3863652238e4 (patch) | |
| tree | 74cafbbf0225f25d214ad6debef02da5c3ca8967 /public/tools/make_fs/CommandLine.cc | |
| parent | 990e50df4d26b54e35f56a54e06837fdf13f5019 (diff) | |
TQ-22: Ticket done.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'public/tools/make_fs/CommandLine.cc')
| -rw-r--r-- | public/tools/make_fs/CommandLine.cc | 188 |
1 files changed, 97 insertions, 91 deletions
diff --git a/public/tools/make_fs/CommandLine.cc b/public/tools/make_fs/CommandLine.cc index 5cdcba52..f3ea3f18 100644 --- a/public/tools/make_fs/CommandLine.cc +++ b/public/tools/make_fs/CommandLine.cc @@ -7,105 +7,111 @@ ------------------------------------------- */ +#include <string> #include <iostream> #include <fstream> + #include <FirmwareKit/EPM.h> #include <FSKit/NeFS.h> -#include <string> #include <uuid/uuid.h> -static std::string kDiskName = "Disk"; -static int kDiskSectorSz = 512; -static const int kDiskBlockCnt = 1; -static size_t kDiskSz = gib_cast(4); -std::string kOutDisk = "disk.eimg"; +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; + 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 |
