diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-07-24 10:31:18 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-07-24 10:31:18 +0100 |
| commit | 989092c04649ff07bbb552b2ccc7c9f44569b75c (patch) | |
| tree | 62fe8e3f331179c4a0cf2ae692cabe53c2d36920 /tooling/fsck.hefs.cc | |
| parent | 5dcf3ce391288e9d4f5f25120cf722f962e30881 (diff) | |
fix: tooling: fix 'fsck.hefs', 'mkfs.hefs', and 'mk_img.py' tools.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'tooling/fsck.hefs.cc')
| -rw-r--r-- | tooling/fsck.hefs.cc | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc index e59cacc0..9d0b3e03 100644 --- a/tooling/fsck.hefs.cc +++ b/tooling/fsck.hefs.cc @@ -9,6 +9,8 @@ #include <cstdlib> #include <fstream> +static uint16_t kNumericalBase = 10; + int main(int argc, char** argv) { if (argc < 2) { mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=<input_device>" @@ -20,12 +22,21 @@ int main(int argc, char** argv) { auto opt_disk = mkfs::get_option<char>(args, "-i"); + auto origin = mkfs::get_option<char>(args, "-o"); + if (opt_disk.empty()) { mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." << "\n"; return EXIT_FAILURE; } + auto out_origin = 0L; + + if (!mkfs::detail::parse_signed(origin, out_origin, kNumericalBase)) { + mkfs::console_out() << "hefs: error: Invalid -o <dec> argument.\n"; + return EXIT_FAILURE; + } + std::ifstream output_device(opt_disk, std::ios::binary); if (!output_device.good()) { @@ -33,9 +44,18 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } + output_device.seekg(out_origin); + + if (!output_device.good()) { + mkfs::console_out() << "hefs: error: Failed seek to origin.\n"; + return EXIT_FAILURE; + } + mkfs::hefs::BootNode boot_node; - + std::memset(&boot_node, 0, sizeof(boot_node)); + + output_device.read(reinterpret_cast<char*>(&boot_node), sizeof(boot_node)); if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || boot_node.sectorSize < kMkFsSectorSz) { @@ -48,6 +68,9 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - mkfs::console_out() << "hefs: HeFS partition is is healthy, exiting...\r"; + mkfs::console_out() << "hefs: HeFS partition is is healthy, exiting...\n"; + + output_device.close(); + return EXIT_SUCCESS; }
\ No newline at end of file |
