diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-19 07:11:12 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-19 07:11:12 +0100 |
| commit | ad0d5c7e5508286e8bb60f34a821c834ae8ee1b6 (patch) | |
| tree | a4f0cee3880460181773c12c177454dcf05f5d92 | |
| parent | f651858b579138d5df0f89363879825513ece227 (diff) | |
chore: filesystem tooling improvements.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | tools/chk.hefs.cc | 2 | ||||
| -rw-r--r-- | tools/libmkfs/mkfs.h | 20 | ||||
| -rw-r--r-- | tools/mkfs.hefs.cc | 17 |
3 files changed, 20 insertions, 19 deletions
diff --git a/tools/chk.hefs.cc b/tools/chk.hefs.cc index a47e4fc6..d880dbd8 100644 --- a/tools/chk.hefs.cc +++ b/tools/chk.hefs.cc @@ -31,7 +31,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - auto out_origin = 0L; + auto out_origin = 0UL; if (!mkfs::detail::parse_signed(origin, out_origin, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -org=<dec> argument.\n"; diff --git a/tools/libmkfs/mkfs.h b/tools/libmkfs/mkfs.h index 787f93a1..d5efae14 100644 --- a/tools/libmkfs/mkfs.h +++ b/tools/libmkfs/mkfs.h @@ -19,22 +19,22 @@ namespace mkfs { namespace detail { /// @internal /// @brief GB‐to‐byte conversion (use multiplication, not XOR). - inline constexpr size_t gib_cast(uint32_t gb) { + inline constexpr size_t gib_cast(const std::uint32_t& gb) { return static_cast<size_t>(gb) * 1024ULL * 1024ULL * 1024ULL; } /// \brief Parse decimal parameter. - inline bool parse_decimal(const std::string& opt, long& out) { + inline bool parse_decimal(const std::string& opt, std::size_t& out) { if (opt.empty()) return false; - char* endptr = nullptr; - unsigned long long val = std::strtoull(opt.c_str(), &endptr, 10); + char* endptr = nullptr; + std::size_t val = std::strtoull(opt.c_str(), &endptr, 10); if (endptr == opt.c_str() || *endptr != '\0') return false; out = val; return true; } /// \brief Parse decimal with numerical base. - inline bool parse_signed(const std::string& opt, long& out, const int& base = 10) { + inline bool parse_signed(const std::string& opt, std::size_t& out, const int& base = 10) { out = 0L; if (opt.empty()) return true; @@ -65,13 +65,13 @@ namespace detail { template <typename CharType = char> inline std::basic_string<CharType> get_option(const std::basic_string<CharType>& args, const std::basic_string<CharType>& option) { - size_t pos = args.find(CharType('-') + option + CharType('=')); + std::size_t pos = args.find(CharType('-') + option + CharType('=')); - if (pos != std::string::npos) { - size_t start = pos + option.length() + 2; - size_t end = args.find(' ', start); + if (pos != std::basic_string<CharType>::npos) { + std::size_t start = pos + option.length() + 2; + std::size_t end = args.find(' ', start); - if (end == std::string::npos) { + if (end == std::basic_string<CharType>::npos || start > args.size()) { return {}; } diff --git a/tools/mkfs.hefs.cc b/tools/mkfs.hefs.cc index f4cf77ea..f28620c5 100644 --- a/tools/mkfs.hefs.cc +++ b/tools/mkfs.hefs.cc @@ -38,8 +38,8 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - auto opt_s = mkfs::get_option<char>(args, "s"); - long parsed_s = 0; + auto opt_s = mkfs::get_option<char>(args, "s"); + std::size_t parsed_s = 0; if (!mkfs::detail::parse_signed(opt_s, parsed_s, kNumericalBase) || parsed_s == 0) { mkfs::console_out() << "hefs: error: Invalid sector size \"" << opt_s @@ -67,15 +67,16 @@ int main(int argc, char** argv) { } } - auto opt_S = mkfs::get_option<char>(args, "S"); - unsigned long long gb = 0; + auto opt_S = mkfs::get_option<char>(args, "S"); + std::size_t gb = 0; if (!mkfs::detail::parse_decimal(opt_S, gb) || gb == 0ULL) { mkfs::console_out() << "hefs: error: Invalid disk size \"" << opt_S << "\". Must be a positive integer.\n"; return EXIT_FAILURE; } - unsigned long long max_gb = std::numeric_limits<uint64_t>::max() / (1024ULL * 1024ULL * 1024ULL); + + std::size_t max_gb = std::numeric_limits<uint64_t>::max() / (1024ULL * 1024ULL * 1024ULL); if (gb > max_gb) { mkfs::console_out() << "hefs: error: Disk size \"" << gb << "GB\" is too large.\n"; @@ -91,9 +92,9 @@ int main(int argc, char** argv) { auto opt_is = mkfs::get_option<char>(args, "is"); auto opt_ie = mkfs::get_option<char>(args, "ie"); - long start_ind = 0, end_ind = 0; - long start_block = 0, end_block = 0; - long start_in = 0, end_in = 0; + std::size_t start_ind = 0, end_ind = 0; + std::size_t start_block = 0, end_block = 0; + std::size_t start_in = 0, end_in = 0; if (!mkfs::detail::parse_signed(opt_b, start_ind, kNumericalBase)) { mkfs::console_out() << "hefs: error: Invalid -b <dec> argument.\n"; |
