diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-07 20:11:47 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-07 20:11:47 +0100 |
| commit | 1634815f39f3c3f8a2b461d1e673aedbb3f18526 (patch) | |
| tree | 436b35048856e3e185d1952516f3a97b1bac5e82 /public/tools/make_fs/CommandLine.cc | |
| parent | cf02a150f5bc84f722d01193d5aae91e60f69b7f (diff) | |
NeFS.h: Tailor header to private specifications.
make_fs/CommandLine.cc: Include NEFS_ROOT_PARTITION_BLOCK too.
Diffstat (limited to 'public/tools/make_fs/CommandLine.cc')
| -rw-r--r-- | public/tools/make_fs/CommandLine.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/public/tools/make_fs/CommandLine.cc b/public/tools/make_fs/CommandLine.cc new file mode 100644 index 00000000..da6e7a5b --- /dev/null +++ b/public/tools/make_fs/CommandLine.cc @@ -0,0 +1,75 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal EL Mahrouss, all rights reserved. + + FILE: NeFS.h + PURPOSE: NeFS (New extended File System) support. + + ------------------------------------------- */ + +#include <iostream> +#include <fstream> +#include <FirmwareKit/EPM.h> +#include <FSKit/NeFS.h> +#include <uuid/uuid.h> + +static const char* kDiskName = "Disk"; +static const int kDiskSectorSz = 512; +static const int kDiskBlockCnt = 1; +static const size_t kDiskSz = gib_cast(4); + +/// @brief Filesystem tool entrypoint. +int main(int argc, char** argv) +{ + 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, strlen(kDiskName)); + ::memcpy(block.Magic, kEPMMagic86, strlen(kEPMMagic86)); + + ::uuid_generate_random((NeOS::UInt8*)&block.Guid); + + std::ofstream output_epm("disk.eimg"); + output_epm.write((NeOS::Char*)&block, sizeof(struct ::EPM_PART_BLOCK)); + + struct ::NEFS_ROOT_PARTITION_BLOCK rpb{}; + + ::memcpy(rpb.PartitionName, kDiskName, strlen(kDiskName)); + ::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 disk.eimg.\n"; + + return 0; +}
\ No newline at end of file |
