pmt: Improve libpartition_map types and some functions.
- Add new operators to Map_t. - Add new flags to info function. - Move some local pmt function(s) to libhelper. - Etc...
This commit is contained in:
@@ -42,6 +42,18 @@ INIT {
|
||||
"Print info(s) as JSON body. The body of each partition will "
|
||||
"be written separately")
|
||||
->default_val(false);
|
||||
cmd->add_flag("--as-byte", asByte,
|
||||
"View sizes as byte.")
|
||||
->default_val(true);
|
||||
cmd->add_flag("--as-kilobyte", asKiloBytes,
|
||||
"View sizes as kilobyte.")
|
||||
->default_val(false);
|
||||
cmd->add_flag("--as-megabyte", asMega,
|
||||
"View sizes as megabyte.")
|
||||
->default_val(false);
|
||||
cmd->add_flag("--as-gigabyte", asGiga,
|
||||
"View sizes as gigabyte.")
|
||||
->default_val(false);
|
||||
cmd->add_option("--json-partition-name", jNamePartition,
|
||||
"Specify partition name element for JSON body")
|
||||
->default_val("name");
|
||||
@@ -59,7 +71,13 @@ INIT {
|
||||
|
||||
RUN {
|
||||
std::vector<PartitionMap::Partition_t> jParts;
|
||||
auto func = [this, &jParts] COMMON_LAMBDA_PARAMS -> bool {
|
||||
std::string multiple;
|
||||
if (asByte) multiple = "B";
|
||||
if (asKiloBytes) multiple = "KB";
|
||||
if (asMega) multiple = "MB";
|
||||
if (asGiga) multiple = "GB";
|
||||
|
||||
auto func = [this, &jParts, &multiple] COMMON_LAMBDA_PARAMS -> bool {
|
||||
if (VARS.onLogical && !props.isLogical) {
|
||||
if (VARS.forceProcess)
|
||||
LOGN(IFUN, WARNING)
|
||||
@@ -72,14 +90,10 @@ RUN {
|
||||
}
|
||||
|
||||
if (jsonFormat)
|
||||
jParts.push_back({partition, {props.size, props.isLogical}});
|
||||
jParts.push_back({partition, {std::stoull(Helper::convertTo(props.size, multiple)), props.isLogical}});
|
||||
else
|
||||
#ifdef __LP64__
|
||||
println("partition=%s size=%lu isLogical=%s",
|
||||
#else
|
||||
println("partition=%s size=%llu isLogical=%s",
|
||||
#endif
|
||||
partition.data(), props.size, props.isLogical ? "true" : "false");
|
||||
println("partition=%s size=%s isLogical=%s",
|
||||
partition.data(), Helper::convertTo(props.size, multiple).data(), props.isLogical ? "true" : "false");
|
||||
|
||||
return true;
|
||||
};
|
||||
@@ -94,6 +108,7 @@ RUN {
|
||||
|
||||
if (jsonFormat) {
|
||||
nlohmann::json j;
|
||||
j["multipleType"] = multiple;
|
||||
j["partitions"] = nlohmann::json::array();
|
||||
for (const auto &[name, props] : jParts) {
|
||||
j["partitions"].push_back({{jNamePartition, name},
|
||||
|
||||
@@ -20,13 +20,6 @@ Copyright 2025 Yağız Zengin
|
||||
#define SFUN "partitionSizeFunction"
|
||||
#define FUNCTION_CLASS partitionSizeFunction
|
||||
|
||||
static std::string convertTo(const uint64_t size, const std::string &multiple) {
|
||||
if (multiple == "KB") return std::to_string(TO_KB(size));
|
||||
if (multiple == "MB") return std::to_string(TO_MB(size));
|
||||
if (multiple == "GB") return std::to_string(TO_GB(size));
|
||||
return std::to_string(size);
|
||||
}
|
||||
|
||||
namespace PartitionManager {
|
||||
INIT {
|
||||
LOGN(SFUN, INFO)
|
||||
@@ -79,10 +72,10 @@ RUN {
|
||||
if (asMega) multiple = "MB";
|
||||
if (asGiga) multiple = "GB";
|
||||
|
||||
if (onlySize) println("%s", convertTo(props.size, multiple).data());
|
||||
if (onlySize) println("%s", Helper::convertTo(props.size, multiple).data());
|
||||
else
|
||||
println("%s: %s%s", partition.data(),
|
||||
convertTo(props.size, multiple).data(), multiple.data());
|
||||
Helper::convertTo(props.size, multiple).data(), multiple.data());
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -99,7 +99,8 @@ private:
|
||||
std::vector<std::string> partitions;
|
||||
std::string jNamePartition, jNameSize, jNameLogical;
|
||||
int jIndentSize = 2;
|
||||
bool jsonFormat = false;
|
||||
bool jsonFormat = false, asByte = true, asKiloBytes = false, asMega = false,
|
||||
asGiga = false;
|
||||
|
||||
public:
|
||||
COMMON_FUNCTION_BODY();
|
||||
|
||||
@@ -324,6 +324,11 @@ std::string pathDirname(std::string_view entry);
|
||||
*/
|
||||
uint64_t getRandomOffset(uint64_t size, uint64_t bufferSize);
|
||||
|
||||
/**
|
||||
* Convert input size to input multiple
|
||||
*/
|
||||
std::string convertTo(uint64_t size, const std::string &multiple);
|
||||
|
||||
// -------------------------------
|
||||
// Android - not throws Helper::Error
|
||||
// -------------------------------
|
||||
|
||||
@@ -241,5 +241,12 @@ uint64_t getRandomOffset(const uint64_t size, const uint64_t bufferSize) {
|
||||
return rand() % maxOffset;
|
||||
}
|
||||
|
||||
std::string convertTo(const uint64_t size, const std::string &multiple) {
|
||||
if (multiple == "KB") return std::to_string(TO_KB(size));
|
||||
if (multiple == "MB") return std::to_string(TO_MB(size));
|
||||
if (multiple == "GB") return std::to_string(TO_GB(size));
|
||||
return std::to_string(size);
|
||||
}
|
||||
|
||||
std::string getLibVersion() { MKVERSION("libhelper"); }
|
||||
} // namespace Helper
|
||||
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
|
||||
bool operator==(const basic_partition_map &other) const;
|
||||
bool operator!=(const basic_partition_map &other) const;
|
||||
bool operator!() const;
|
||||
explicit operator bool() const;
|
||||
|
||||
Info operator[](int index) const;
|
||||
BasicInf operator[](const std::string_view& name) const;
|
||||
|
||||
@@ -370,7 +370,7 @@ bool basic_partition_map_builder::doForPartitionList(
|
||||
for (const auto &partition : partitions) {
|
||||
if (!hasPartition(partition))
|
||||
throw Error("Couldn't find partition: %s", partition.data());
|
||||
if (!func(partition, {sizeOf(partition), isLogical(partition)})) {
|
||||
if (!func(partition, _current_map[partition])) {
|
||||
err = true;
|
||||
LOGN(MAP, ERROR) << "Failed progress for " << partition << " partition."
|
||||
<< std::endl;
|
||||
|
||||
@@ -185,8 +185,7 @@ std::string basic_partition_map::find_(const std::string &name) const {
|
||||
size_t basic_partition_map::size() const { return _count; }
|
||||
|
||||
bool basic_partition_map::empty() const {
|
||||
if (_count > 0) return false;
|
||||
return true;
|
||||
return _count > 0;
|
||||
}
|
||||
|
||||
void basic_partition_map::clear() {
|
||||
@@ -229,6 +228,14 @@ bool basic_partition_map::operator!=(const basic_partition_map &other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
basic_partition_map::operator bool() const{
|
||||
return _count > 0;
|
||||
}
|
||||
|
||||
bool basic_partition_map::operator!() const{
|
||||
return _count == 0;
|
||||
}
|
||||
|
||||
Info basic_partition_map::operator[](const int index) const {
|
||||
if (_count == 0 || index >= _count) return {};
|
||||
return _data[index];
|
||||
|
||||
Reference in New Issue
Block a user