summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-05-08 08:48:57 +0200
committerAmlal <amlal@nekernel.org>2025-05-08 08:48:57 +0200
commita8782019a20f5487494e436f79b876b57f7229e1 (patch)
tree311857e38359e2869286149ae0cc3f0c27efb4d7
parent1afe090bd504c4ec74b8c14c5aa6a520114b88ab (diff)
feat(tooling): update HeFS headers, and better HeFS tooling.
Signed-off-by: Amlal <amlal@nekernel.org>
-rw-r--r--dev/kernel/FSKit/HeFS.h8
-rw-r--r--dev/kernel/src/FS/HeFS+FileSystemParser.cc20
-rw-r--r--dev/modules/MBCI/MBCI.h5
-rw-r--r--tooling/hefs.h4
-rw-r--r--tooling/mkfs.hefs.cc92
5 files changed, 68 insertions, 61 deletions
diff --git a/dev/kernel/FSKit/HeFS.h b/dev/kernel/FSKit/HeFS.h
index f7e1d648..f5f42b47 100644
--- a/dev/kernel/FSKit/HeFS.h
+++ b/dev/kernel/FSKit/HeFS.h
@@ -125,10 +125,10 @@ struct PACKED HEFS_BOOT_NODE final {
Kernel::UInt16 fDiskFlags; /// @brief Flags of the disk. (read-only, read-write, etc).
Kernel::UInt16
fVID; /// @brief Virtual Identification Number within an EPM disk. (0xFFFF if not used).
- Kernel::UInt64 fStartIN; /// @brief Reserved for future use.
- Kernel::UInt64 fEndIN; /// @brief Reserved for future use.
- Kernel::UInt64 fStartBlock; /// @brief Reserved for future use.
- Kernel::UInt64 fEndBlock; /// @brief Reserved for future use.
+ Kernel::UInt64 fStartIN; /// @brief Start INodes range
+ Kernel::UInt64 fEndIN; /// @brief End INodes range
+ Kernel::UInt64 fStartBlock; /// @brief Start Blocks range
+ Kernel::UInt64 fEndBlock; /// @brief End Blocks range
Kernel::Char fPad[272];
};
diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc
index 1cd7e61a..a324da2a 100644
--- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc
+++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc
@@ -459,7 +459,7 @@ namespace Detail {
const Utf8Char* dir_name,
const Utf8Char* file_name,
UInt8 kind, SizeT* cnt) {
- if (mnt) {
+ if (mnt && cnt) {
auto start = root->fStartIND;
if (start > root->fEndIND) return nullptr;
@@ -514,7 +514,7 @@ namespace Detail {
if (start > root->fEndIND) break;
}
- err_global_get() = kErrorSuccess;
+ err_global_get() = kErrorSuccess;
delete dir;
if (start_cnt == 0) {
@@ -535,7 +535,7 @@ namespace Detail {
STATIC ATTRIBUTE(unused) _Output BOOL
hefsi_update_in_status(HEFS_BOOT_NODE* root, DriveTrait* mnt, const Utf8Char* dir_name,
HEFS_INDEX_NODE* node, BOOL delete_or_create) {
- if (!root) return NO;
+ if (!root || !mnt) return NO;
auto start = root->fStartIND;
@@ -555,8 +555,6 @@ namespace Detail {
mnt->fInput(mnt->fPacket);
- kout8 << dir_name << u8"\r";
-
(Void)(kout << hex_number(hefsi_hash_64(dir_name)) << kendl);
(Void)(kout << hex_number(dir->fHashPath) << kendl);
@@ -621,12 +619,6 @@ namespace Detail {
mnt->fInput(mnt->fPacket);
- kout8 << u8"HashPath: ";
- (Void)(kout << hex_number(tmp_node.fHashPath) << kendl);
-
- kout8 << u8"HashPath: ";
- (Void)(kout << hex_number(hash_file) << kendl);
-
if (tmp_node.fHashPath != hash_file) {
continue;
}
@@ -690,7 +682,7 @@ namespace Detail {
auto start = root->fStartIND;
while (YES) {
- if (start == 0 || start > root->fEndIND) break;
+ if (start == 0UL || start > root->fEndIND) break;
mnt->fPacket.fPacketLba = start;
mnt->fPacket.fPacketSize = sizeof(HEFS_INDEX_NODE_DIRECTORY);
@@ -714,10 +706,10 @@ namespace Detail {
mnt->fOutput(mnt->fPacket);
}
- if (dir->fColor == kHeFSBlack && dir->fChild != 0) {
+ if (dir->fColor == kHeFSBlack && dir->fChild != 0UL) {
dir->fColor = kHeFSRed;
hefsi_rotate_tree(start, mnt);
- } else if (dir->fColor == kHeFSBlack && dir->fChild == 0) {
+ } else if (dir->fColor == kHeFSBlack && dir->fChild == 0UL) {
dir->fColor = kHeFSBlack;
mnt->fPacket.fPacketLba = start;
diff --git a/dev/modules/MBCI/MBCI.h b/dev/modules/MBCI/MBCI.h
index 37f802ec..99ecf802 100644
--- a/dev/modules/MBCI/MBCI.h
+++ b/dev/modules/MBCI/MBCI.h
@@ -100,12 +100,11 @@ typedef UInt32 MBCIAuthKeyType;
inline BOOL busi_test_mmio(_Input struct IMBCIHost* host, _Input const UInt32 test) {
host->MMIOTest = test;
UInt16 timeout = 0UL;
-
+
while (host->MMIOTest == test) {
++timeout;
- if (timeout > 0x1000)
- return NO;
+ if (timeout > 0x1000) return NO;
}
return host->MMIOTest == 0;
diff --git a/tooling/hefs.h b/tooling/hefs.h
index f281e7a3..68e0f906 100644
--- a/tooling/hefs.h
+++ b/tooling/hefs.h
@@ -102,8 +102,8 @@ struct __attribute__((packed)) BootNode {
std::uint16_t vid{};
std::uint64_t startIN{};
std::uint64_t endIN{};
- std::uint64_t reserved3{};
- std::uint64_t reserved4{};
+ std::uint64_t startBlock{};
+ std::uint64_t endBlock{};
char pad[272]{};
};
} // namespace mkfs::hefs
diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc
index 5a706646..2ddc7484 100644
--- a/tooling/mkfs.hefs.cc
+++ b/tooling/mkfs.hefs.cc
@@ -16,9 +16,10 @@ static size_t kSectorSize = 512;
int main(int argc, char** argv) {
if (argc < 2) {
- mkfs::console_out() << "hefs: Usage: mkfs.hefs -L <label> -s <sector_size> -p <part_start> -e "
- << "<part_end> -S <disk_size> -o <output_device>" << std::endl;
-
+ mkfs::console_out() << "hefs: usage: mkfs.hefs -L <label> -s <sector_size> -b <ind_start> -e "
+ << "<ind_end> -bs <block_start> -be <block_end> -is <in_start> -ie <in_end> "
+ "-S <disk_size> -o <output_device>"
+ << "\n";
return EXIT_FAILURE;
}
@@ -38,68 +39,83 @@ int main(int argc, char** argv) {
args_wide += u8" ";
}
- auto output_device = mkfs::get_option<char>(args, "-o");
+ auto output_path = mkfs::get_option<char>(args, "-o");
kSectorSize = std::strtol(mkfs::get_option<char>(args, "-s").data(), nullptr, 10);
kLabel = mkfs::get_option<char8_t>(args_wide, u8"-L");
+ if (!kSectorSize) {
+ mkfs::console_out() << "hefs: error: Sector size size is zero.\n";
+ return EXIT_FAILURE;
+ }
+
if (kLabel.empty()) kLabel = kHeFSDefaultVolumeName;
kDiskSize =
std::strtol(mkfs::get_option<char>(args, "-S").data(), nullptr, 10) * 1024 * 1024 * 1024;
- if (kDiskSize == 0) {
- mkfs::console_out() << "hefs: Error: Unable to deduce future disk size for output_device: "
- << output_device << std::endl;
+ if (!kDiskSize) {
+ mkfs::console_out() << "hefs: error: Disk size is zero.\n";
return EXIT_FAILURE;
}
// Open the output_device
- std::ofstream filesystem(output_device, std::ios::binary);
+ std::ofstream output_device(output_path, std::ios::binary);
- if (!filesystem.good()) {
- mkfs::console_out() << "hefs: Info: Unable to open output_device: " << output_device
- << std::endl;
+ if (!output_device.good()) {
+ mkfs::console_out() << "hefs: error: Unable to open output_device: " << output_path
+ << "\n";
return EXIT_FAILURE;
}
// create a boot node, and then allocate a index node directory tree.
- mkfs::hefs::BootNode bootNode{{}, {}, 0, 0, 0, 0, 0, 0, 0, 0};
+ mkfs::hefs::BootNode boot_node{{}, {}, 0, 0, 0, 0, 0, 0, 0, 0};
- auto start_ind = std::strtol(mkfs::get_option<char>(args, "-p").data(), nullptr, 10);
+ auto start_ind = std::strtol(mkfs::get_option<char>(args, "-b").data(), nullptr, 16);
start_ind += sizeof(mkfs::hefs::BootNode);
- auto end_ind = std::strtol(mkfs::get_option<char>(args, "-e").data(), nullptr, 10);
-
- bootNode.version = kVersion;
- bootNode.diskKind = mkfs::hefs::kHeFSHardDrive;
- bootNode.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8;
- bootNode.diskSize = kDiskSize;
- bootNode.sectorSize = kSectorSize;
- bootNode.startIND = start_ind;
- bootNode.endIND = end_ind;
- bootNode.indCount = 0UL;
- bootNode.diskStatus = mkfs::hefs::kHeFSStatusUnlocked;
-
- std::memcpy(bootNode.magic, kHeFSMagic, kHeFSMagicLen - 1);
- std::memcpy(bootNode.volumeName, kLabel.data(), kLabel.size() * sizeof(char16_t));
-
- filesystem.seekp(std::strtol(mkfs::get_option<char>(args, "-p").data(), nullptr, 10));
- filesystem.write(reinterpret_cast<const char*>(&bootNode), sizeof(mkfs::hefs::BootNode));
-
- if (!filesystem.good()) {
- mkfs::console_out() << "hefs: Error: Unable to write FS to output_device: " << output_device
- << std::endl;
+ auto end_ind = std::strtol(mkfs::get_option<char>(args, "-e").data(), nullptr, 16);
+
+ auto start_block = std::strtol(mkfs::get_option<char>(args, "-bs").data(), nullptr, 16);
+ auto end_block = std::strtol(mkfs::get_option<char>(args, "-be").data(), nullptr, 16);
+
+ auto start_in = std::strtol(mkfs::get_option<char>(args, "-is").data(), nullptr, 16);
+ auto end_in = std::strtol(mkfs::get_option<char>(args, "-ie").data(), nullptr, 16);
+
+ boot_node.version = kVersion;
+ boot_node.diskKind = mkfs::hefs::kHeFSHardDrive;
+ boot_node.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8;
+ boot_node.diskSize = kDiskSize;
+ boot_node.sectorSize = kSectorSize;
+ boot_node.startIND = start_ind;
+ boot_node.endIND = end_ind;
+ boot_node.startIN = start_in;
+ boot_node.endIN = end_in;
+ boot_node.startBlock = start_block;
+ boot_node.endBlock = end_block;
+ boot_node.indCount = 0UL;
+ boot_node.diskStatus = mkfs::hefs::kHeFSStatusUnlocked;
+
+ std::memcpy(boot_node.magic, kHeFSMagic, kHeFSMagicLen - 1);
+ std::memcpy(boot_node.volumeName, kLabel.data(), kLabel.size() * sizeof(char16_t));
+
+ output_device.seekp(std::strtol(mkfs::get_option<char>(args, "-b").data(), nullptr, 16));
+ output_device.write(reinterpret_cast<const char*>(&boot_node), sizeof(mkfs::hefs::BootNode));
+
+ if (!output_device.good()) {
+ mkfs::console_out() << "hefs: error: Unable to write filesystem to output_device: "
+ << output_path << "\n";
return EXIT_FAILURE;
}
- filesystem.seekp(bootNode.startIND);
+ output_device.seekp(boot_node.startIND);
- filesystem.flush();
- filesystem.close();
+ output_device.flush();
+ output_device.close();
- mkfs::console_out() << "hefs: Info: Wrote FS to output_device: " << output_device << std::endl;
+ mkfs::console_out() << "hefs: info: Wrote filesystem to output_device: " << output_path
+ << "\n";
return EXIT_SUCCESS;
} \ No newline at end of file