summaryrefslogtreecommitdiffhomepage
path: root/public/tools
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-07 20:11:47 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-07 20:11:47 +0100
commit1634815f39f3c3f8a2b461d1e673aedbb3f18526 (patch)
tree436b35048856e3e185d1952516f3a97b1bac5e82 /public/tools
parentcf02a150f5bc84f722d01193d5aae91e60f69b7f (diff)
NeFS.h: Tailor header to private specifications.
make_fs/CommandLine.cc: Include NEFS_ROOT_PARTITION_BLOCK too.
Diffstat (limited to 'public/tools')
-rw-r--r--public/tools/make_fs/CommandLine.cc75
-rw-r--r--public/tools/make_fs/make_fs.cc47
-rw-r--r--public/tools/make_fs/make_fs.json2
3 files changed, 76 insertions, 48 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
diff --git a/public/tools/make_fs/make_fs.cc b/public/tools/make_fs/make_fs.cc
deleted file mode 100644
index 98c31346..00000000
--- a/public/tools/make_fs/make_fs.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -------------------------------------------
-
- 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;
-
-/// @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));
-
- output_epm.close();
-
- std::cout << "make_fs: EPM image has been written to disk.eimg.\n";
-
- return 0;
-} \ No newline at end of file
diff --git a/public/tools/make_fs/make_fs.json b/public/tools/make_fs/make_fs.json
index 13c66dbb..584cf3c3 100644
--- a/public/tools/make_fs/make_fs.json
+++ b/public/tools/make_fs/make_fs.json
@@ -2,7 +2,7 @@
"compiler_path": "g++",
"compiler_std": "c++20",
"headers_path": ["./", "../../../dev/Kernel", "../../../dev/"],
- "sources_path": ["make_fs.cc"],
+ "sources_path": ["CommandLine.cc"],
"output_name": "./dist/make_fs",
"cpp_macros": [
"kMKFSVersion=0x0100",