From 7ada9006860084ba5d72b517649d1b2d51e4484a Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 9 Aug 2025 20:01:15 +0200 Subject: feat: warning fixes and Semaphore API patches. what: - The Semaphore API is being preppared for v0.0.4 Signed-off-by: Amlal --- tools/fsck.hefs.cc | 10 ++++------ tools/libmkfs/mkfs.h | 8 ++++---- tools/mkfs.hefs.cc | 44 ++++++++++++++++++++++---------------------- 3 files changed, 30 insertions(+), 32 deletions(-) (limited to 'tools') diff --git a/tools/fsck.hefs.cc b/tools/fsck.hefs.cc index e3837b8a..5a41cec2 100644 --- a/tools/fsck.hefs.cc +++ b/tools/fsck.hefs.cc @@ -9,12 +9,11 @@ #include #include -static uint16_t kNumericalBase = 10; +static uint16_t kNumericalBase = 10; int main(int argc, char** argv) { if (argc < 2) { - mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=" - << "\n"; + mkfs::console_out() << "fsck: hefs: usage: fsck.hefs -i=" << "\n"; return EXIT_FAILURE; } @@ -25,8 +24,7 @@ int main(int argc, char** argv) { auto origin = mkfs::get_option(args, "-o"); if (opt_disk.empty()) { - mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." - << "\n"; + mkfs::console_out() << "fsck: hefs: error: HeFS is empty! Exiting..." << "\n"; return EXIT_FAILURE; } @@ -54,7 +52,7 @@ int main(int argc, char** argv) { mkfs::hefs::BootNode boot_node; std::memset(&boot_node, 0, sizeof(boot_node)); - + output_device.read(reinterpret_cast(&boot_node), sizeof(boot_node)); if (strncmp(boot_node.magic, kHeFSMagic, kHeFSMagicLen) != 0 || boot_node.sectorCount < 1 || diff --git a/tools/libmkfs/mkfs.h b/tools/libmkfs/mkfs.h index e729c29b..6e242293 100644 --- a/tools/libmkfs/mkfs.h +++ b/tools/libmkfs/mkfs.h @@ -7,8 +7,8 @@ #pragma once #include -#include #include +#include #include #define kMkFsSectorSz (512U) @@ -35,13 +35,13 @@ namespace detail { inline bool parse_signed(const std::string& opt, long& out, int base = 10) { out = 0L; - + if (opt.empty()) return true; char* endptr = nullptr; long val = std::strtol(opt.c_str(), &endptr, base); - auto err = errno; - + auto err = errno; + if (err == ERANGE || err == EINVAL) return false; if (endptr == opt.c_str() || *endptr != '\0') return false; diff --git a/tools/mkfs.hefs.cc b/tools/mkfs.hefs.cc index bf790598..9f70b78f 100644 --- a/tools/mkfs.hefs.cc +++ b/tools/mkfs.hefs.cc @@ -15,7 +15,7 @@ static size_t kDiskSize = mkfs::detail::gib_cast(4UL); static uint16_t kVersion = kHeFSVersion; static std::u8string kLabel; -static size_t kSectorSize = 512; +static size_t kSectorSize = 512; static uint16_t kNumericalBase = 10; int main(int argc, char** argv) { @@ -91,22 +91,22 @@ int main(int argc, char** argv) { mkfs::console_out() << "hefs: error: Invalid -b argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_e, end_ind, kNumericalBase) || end_ind <= start_ind) { mkfs::console_out() << "hefs: error: Invalid or out-of-range -e argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_bs, start_block, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -bs argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_be, end_block, kNumericalBase) || end_block <= start_block) { mkfs::console_out() << "hefs: error: Invalid or out-of-range -be argument.\n"; return EXIT_FAILURE; } - + if (!mkfs::detail::parse_signed(opt_is, start_in, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -is argument.\n"; return EXIT_FAILURE; @@ -133,24 +133,24 @@ int main(int argc, char** argv) { mkfs::hefs::BootNode boot_node; std::memset(&boot_node, 0, sizeof(boot_node)); - 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.version = kVersion; + boot_node.diskKind = mkfs::hefs::kHeFSHardDrive; + boot_node.encoding = mkfs::hefs::kHeFSEncodingFlagsUTF8; + boot_node.diskSize = kDiskSize; + boot_node.sectorSize = kSectorSize; boot_node.sectorCount = kDiskSize / kSectorSize; - boot_node.startIND = static_cast(start_ind) + sizeof(mkfs::hefs::BootNode); - boot_node.endIND = static_cast(end_ind); - boot_node.startIN = static_cast(start_in); - boot_node.endIN = static_cast(end_in); - boot_node.startBlock = static_cast(start_block); - boot_node.endBlock = static_cast(end_block); - boot_node.indCount = 0UL; - boot_node.diskStatus = mkfs::hefs::kHeFSStatusUnlocked; + boot_node.startIND = static_cast(start_ind) + sizeof(mkfs::hefs::BootNode); + boot_node.endIND = static_cast(end_ind); + boot_node.startIN = static_cast(start_in); + boot_node.endIN = static_cast(end_in); + boot_node.startBlock = static_cast(start_block); + boot_node.endBlock = static_cast(end_block); + boot_node.indCount = 0UL; + boot_node.diskStatus = mkfs::hefs::kHeFSStatusUnlocked; static_assert(sizeof(boot_node.magic) >= kHeFSMagicLen, "BootNode::magic too small to hold kHeFSMagicLen"); - + std::memset(boot_node.magic, 0, sizeof(boot_node.magic)); size_t magic_copy = (sizeof(boot_node.magic) < kHeFSMagicLen - 1) ? sizeof(boot_node.magic) : (kHeFSMagicLen - 1); @@ -158,15 +158,15 @@ int main(int argc, char** argv) { boot_node.magic[magic_copy] = 0; constexpr size_t vol_slots = kHeFSPartNameLen; - + std::memset(boot_node.volumeName, 0, sizeof(boot_node.volumeName)); - + size_t label_units = std::min(kLabel.size(), vol_slots - 1); for (size_t i = 0; i < label_units; ++i) { boot_node.volumeName[i] = static_cast(kLabel[i]); } - + boot_node.volumeName[label_units] = 0U; output_device.seekp(static_cast(start_ind)); -- cgit v1.2.3