summaryrefslogtreecommitdiffhomepage
path: root/tooling
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-07-05 10:32:16 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-07-05 10:32:16 +0200
commitf4370b44bacfa3035496aa6f5aca24469326ebff (patch)
treedae3af2a258d2561f70c6050fed8bbbbb390b3b9 /tooling
parent65350ab87ab7d577cd6d85bc6e9727beef5ee737 (diff)
feat: add magic check in `fsck.hefs`
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'tooling')
-rw-r--r--tooling/fsck.hefs.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/tooling/fsck.hefs.cc b/tooling/fsck.hefs.cc
index ce386152..0fa697be 100644
--- a/tooling/fsck.hefs.cc
+++ b/tooling/fsck.hefs.cc
@@ -18,7 +18,7 @@ int main(int argc, char** argv) {
auto args = mkfs::detail::build_args(argc, argv);
- auto opt_disk = mkfs::get_option<char>(args, "-i");
+ auto opt_disk = mkfs::get_option<char>(args, "-i");
if (opt_disk.empty()) {
mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..."
@@ -26,7 +26,6 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
-
std::ifstream output_device(opt_disk, std::ios::binary);
if (!output_device.good()) {
@@ -37,6 +36,11 @@ int main(int argc, char** argv) {
mkfs::hefs::BootNode boot_node;
std::memset(&boot_node, 0, sizeof(boot_node));
+ if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0) {
+ mkfs::console_out() << "hefs: error: Device is not an HeFS disk: " << opt_disk << "\n";
+ return EXIT_FAILURE;
+ }
+
mkfs::console_out() << "hefs: HeFS partition is is healthy, exiting...\r";
return EXIT_SUCCESS;