/* ======================================== Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. ======================================== */ #pragma once #include #include #include #define kMkFsSectorSz (512U) #define kMkFsMaxBadSectors (128U) /// @internal namespace mkfs { namespace detail { /// @internal /// @brief GB‐to‐byte conversion (use multiplication, not XOR). inline constexpr size_t gib_cast(uint32_t gb) { return static_cast(gb) * 1024ULL * 1024ULL * 1024ULL; } inline bool parse_decimal(const std::string& opt, unsigned long long& out) { if (opt.empty()) return false; char* endptr = nullptr; unsigned long long val = std::strtoull(opt.c_str(), &endptr, 10); if (endptr == opt.c_str() || *endptr != '\0') return false; out = val; return true; } 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; if (err == ERANGE || err == EINVAL) return false; if (endptr == opt.c_str() || *endptr != '\0') return false; out = val; return true; } inline std::string build_args(int argc, char** argv) { std::string combined; for (int i = 1; i < argc; ++i) { combined += argv[i]; combined += ' '; } return combined; } } // namespace detail /// @brief Helper function to get the option value from command line arguments. template inline std::basic_string get_option(const std::basic_string& args, const std::basic_string& option) { 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); return args.substr(start, end - start); } return std::basic_string{}; } inline auto console_out() -> std::ostream& { std::ostream& conout = std::cout; conout << rang::fg::red << "mkfs: " << rang::style::reset; return conout; } } // namespace mkfs