summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dev/Kernel/FSKit/NeFS.h2
-rw-r--r--dev/Kernel/HALKit/AMD64/Storage/AHCI.cc12
-rw-r--r--dev/Kernel/src/FS/NeFS.cc1
-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
6 files changed, 84 insertions, 55 deletions
diff --git a/dev/Kernel/FSKit/NeFS.h b/dev/Kernel/FSKit/NeFS.h
index bd11c86d..981cd0d9 100644
--- a/dev/Kernel/FSKit/NeFS.h
+++ b/dev/Kernel/FSKit/NeFS.h
@@ -92,7 +92,7 @@ default.
/// @note Start after the partition map header. (Virtual addressing)
#define kNeFSRootCatalogStartAddress (1024)
-#define kNeFSCatalogStartAddress ((2048) + sizeof(NEFS_ROOT_PARTITION_BLOCK))
+#define kNeFSCatalogStartAddress (kNeFSRootCatalogStartAddress + sizeof(NEFS_ROOT_PARTITION_BLOCK))
#define kResourceTypeDialog (10)
#define kResourceTypeString (11)
diff --git a/dev/Kernel/HALKit/AMD64/Storage/AHCI.cc b/dev/Kernel/HALKit/AMD64/Storage/AHCI.cc
index 22d52486..5726189a 100644
--- a/dev/Kernel/HALKit/AMD64/Storage/AHCI.cc
+++ b/dev/Kernel/HALKit/AMD64/Storage/AHCI.cc
@@ -60,7 +60,7 @@ STATIC Void drv_compute_disk_ahci() noexcept;
STATIC PCI::Device kPCIDevice;
STATIC HbaMem* kSATA[kSATAPortCnt] = {};
STATIC SizeT kSATAIndex = 0UL;
-STATIC Lba kHighestLBA = 0UL;
+STATIC Lba kSATASectorCount = 0UL;
STATIC UInt16 kSATAPortsImplemented = 0U;
@@ -68,7 +68,7 @@ BOOL kAHCICommandIssued = NO;
STATIC Void drv_compute_disk_ahci() noexcept
{
- kHighestLBA = 0UL;
+ kSATASectorCount = 0UL;
const UInt16 kSzIdent = 512U;
@@ -78,10 +78,10 @@ STATIC Void drv_compute_disk_ahci() noexcept
drv_std_input_output<NO, YES, YES>(0, identify_data, 0, kSzIdent);
- kHighestLBA = (identify_data[61] << 16) | identify_data[60];
+ kSATASectorCount = (identify_data[61] << 16) | identify_data[60];
kout << "Disk Size: " << number(drv_get_size()) << kendl;
- kout << "Highest LBA: " << number(kHighestLBA) << kendl;
+ kout << "Highest LBA: " << number(kSATASectorCount) << kendl;
}
STATIC Int32 drv_find_cmd_slot(HbaPort* port) noexcept
@@ -173,8 +173,8 @@ STATIC Void drv_std_input_output(UInt64 lba, UInt8* buffer, SizeT sector_sz, Siz
*/
SizeT drv_get_sector_count_ahci()
{
- MUST_PASS(kHighestLBA > 0);
- return kHighestLBA;
+ MUST_PASS(kSATASectorCount > 0);
+ return kSATASectorCount;
}
/// @brief Get the drive size.
diff --git a/dev/Kernel/src/FS/NeFS.cc b/dev/Kernel/src/FS/NeFS.cc
index f5fdf63f..adee0322 100644
--- a/dev/Kernel/src/FS/NeFS.cc
+++ b/dev/Kernel/src/FS/NeFS.cc
@@ -587,6 +587,7 @@ bool NeFileSystemParser::Format(_Input _Output DriveTrait* drive, _Input const L
part_block->StartCatalog = kNeFSCatalogStartAddress;
part_block->Flags = kNeFSPartitionTypeStandard;
part_block->CatalogCount = sectorCount / sizeof(NEFS_CATALOG_STRUCT);
+ part_block->FreeSectors = sectorCount / sizeof(NEFS_CATALOG_STRUCT);
part_block->SectorCount = sectorCount;
part_block->DiskSize = diskSize;
part_block->FreeCatalog = sectorCount / sizeof(NEFS_CATALOG_STRUCT);
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",