summaryrefslogtreecommitdiffhomepage
path: root/public/tools/make_fs/CommandLine.cc
diff options
context:
space:
mode:
Diffstat (limited to 'public/tools/make_fs/CommandLine.cc')
-rw-r--r--public/tools/make_fs/CommandLine.cc75
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