pmt: Introduce, fixup
- Fix pstderr file pointer. - Improve and add more functions on libpartition_map. - Improve functions.
This commit is contained in:
@@ -30,8 +30,10 @@ INIT(infoFunction) {
|
||||
<< std::endl;
|
||||
cmd = _app.add_subcommand("info", "Tell info(s) of input partition list")
|
||||
->footer("Use get-all or getvar-all as partition name for getting "
|
||||
"info's of all "
|
||||
"partitions.");
|
||||
"info's of all partitions.\nUse get-logicals as partition "
|
||||
"name for getting info's of logical partitions.\n"
|
||||
"Use get-physical as partition name for getting info's of "
|
||||
"physical partitions.");
|
||||
cmd->add_option("partition(s)", partitions, "Partition name(s).")
|
||||
->required()
|
||||
->delimiter(',');
|
||||
@@ -55,19 +57,11 @@ INIT(infoFunction) {
|
||||
}
|
||||
|
||||
RUN(infoFunction) {
|
||||
if (partitions.back() == "get-all" || partitions.back() == "getvar-all") {
|
||||
if (!Variables->PartMap->copyPartitionsToVector(partitions))
|
||||
throw Error("Cannot get list of all partitions! See logs for more "
|
||||
"information (%s)",
|
||||
Helper::LoggingProperties::FILE.data());
|
||||
}
|
||||
|
||||
std::vector<PartitionMap::Partition_t> jParts;
|
||||
for (const auto &partition : partitions) {
|
||||
if (!Variables->PartMap->hasPartition(partition))
|
||||
throw Error("Couldn't find partition: %s", partition.data());
|
||||
|
||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
||||
auto func = [this,
|
||||
&jParts](std::string partition,
|
||||
const PartitionMap::Map_t::BasicInf props) -> bool {
|
||||
if (Variables->onLogical && !props.isLogical) {
|
||||
if (Variables->forceProcess)
|
||||
LOGN(IFUN, WARNING)
|
||||
<< "Partition " << partition
|
||||
@@ -79,18 +73,25 @@ RUN(infoFunction) {
|
||||
}
|
||||
|
||||
if (jsonFormat)
|
||||
jParts.push_back({partition,
|
||||
{Variables->PartMap->sizeOf(partition),
|
||||
Variables->PartMap->isLogical(partition)}});
|
||||
jParts.push_back({partition, {props.size, props.isLogical}});
|
||||
else
|
||||
#ifdef __LP64__
|
||||
println("partition=%s size=%lu isLogical=%s",
|
||||
#else
|
||||
println("partition=%s size=%llu isLogical=%s",
|
||||
#endif
|
||||
partition.data(), Variables->PartMap->sizeOf(partition),
|
||||
Variables->PartMap->isLogical(partition) ? "true" : "false");
|
||||
}
|
||||
partition.data(), props.size, props.isLogical ? "true" : "false");
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
if (partitions.back() == "get-all" || partitions.back() == "getvar-all")
|
||||
Variables->PartMap->doForAllPartitions(func);
|
||||
else if (partitions.back() == "get-logicals")
|
||||
Variables->PartMap->doForLogicalPartitions(func);
|
||||
else if (partitions.back() == "get-physicals")
|
||||
Variables->PartMap->doForPhysicalPartitions(func);
|
||||
else Variables->PartMap->doForPartitionList(partitions, func);
|
||||
|
||||
if (jsonFormat) {
|
||||
nlohmann::json j;
|
||||
|
||||
@@ -74,15 +74,14 @@ RUN(memoryTestFunction) {
|
||||
|
||||
const int wfd = Helper::openAndAddToCloseList(
|
||||
test, collector, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, 0644);
|
||||
if (wfd < 0)
|
||||
throw Error("Can't open/create test file: %s\n", strerror(errno));
|
||||
if (wfd < 0) throw Error("Can't open/create test file: %s", strerror(errno));
|
||||
|
||||
LOGN(MTFUN, INFO) << "Sequential write test started!" << std::endl;
|
||||
const auto startWrite = std::chrono::high_resolution_clock::now();
|
||||
ssize_t bytesWritten = 0;
|
||||
while (bytesWritten < testFileSize) {
|
||||
const ssize_t ret = write(wfd, buffer, bufferSize);
|
||||
if (ret < 0) throw Error("Can't write to test file: %s\n", strerror(errno));
|
||||
if (ret < 0) throw Error("Can't write to test file: %s", strerror(errno));
|
||||
bytesWritten += ret;
|
||||
}
|
||||
|
||||
@@ -101,7 +100,7 @@ RUN(memoryTestFunction) {
|
||||
(reinterpret_cast<uintptr_t>(rawBuffer) + 4096 - 1) & ~(4096 - 1));
|
||||
const int rfd =
|
||||
Helper::openAndAddToCloseList(test, collector, O_RDONLY | O_DIRECT);
|
||||
if (rfd < 0) throw Error("Can't open test file: %s\n", strerror(errno));
|
||||
if (rfd < 0) throw Error("Can't open test file: %s", strerror(errno));
|
||||
|
||||
LOGN(MTFUN, INFO) << "Sequential read test started!" << std::endl;
|
||||
const auto startRead = std::chrono::high_resolution_clock::now();
|
||||
|
||||
@@ -33,8 +33,10 @@ INIT(partitionSizeFunction) {
|
||||
<< std::endl;
|
||||
cmd = _app.add_subcommand("sizeof", "Tell size(s) of input partition list")
|
||||
->footer("Use get-all or getvar-all as partition name for getting "
|
||||
"sizes of all "
|
||||
"partitions.");
|
||||
"sizes of all partitions.\nUse get-logicals as partition "
|
||||
"name for getting sizes of logical partitions.\n"
|
||||
"Use get-physical as partition name for getting sizes of "
|
||||
"physical partitions.");
|
||||
cmd->add_option("partition(s)", partitions, "Partition name(s).")
|
||||
->required()
|
||||
->delimiter(',');
|
||||
@@ -58,18 +60,9 @@ INIT(partitionSizeFunction) {
|
||||
}
|
||||
|
||||
RUN(partitionSizeFunction) {
|
||||
if (partitions.back() == "get-all" || partitions.back() == "getvar-all") {
|
||||
if (!Variables->PartMap->copyPartitionsToVector(partitions))
|
||||
throw Error("Cannot get list of all partitions! See logs for more "
|
||||
"information (%s)",
|
||||
Helper::LoggingProperties::FILE.data());
|
||||
}
|
||||
|
||||
for (const auto &partition : partitions) {
|
||||
if (!Variables->PartMap->hasPartition(partition))
|
||||
throw Error("Couldn't find partition: %s", partition.data());
|
||||
|
||||
if (Variables->onLogical && !Variables->PartMap->isLogical(partition)) {
|
||||
auto func = [this](std::string partition,
|
||||
PartitionMap::Map_t::BasicInf props) -> bool {
|
||||
if (Variables->onLogical && !props.isLogical) {
|
||||
if (Variables->forceProcess)
|
||||
LOGN(SFUN, WARNING)
|
||||
<< "Partition " << partition
|
||||
@@ -86,15 +79,21 @@ RUN(partitionSizeFunction) {
|
||||
if (asMega) multiple = "MB";
|
||||
if (asGiga) multiple = "GB";
|
||||
|
||||
if (onlySize)
|
||||
println(
|
||||
"%s",
|
||||
convertTo(Variables->PartMap->sizeOf(partition), multiple).data());
|
||||
if (onlySize) println("%s", convertTo(props.size, multiple).data());
|
||||
else
|
||||
println("%s: %s%s", partition.data(),
|
||||
convertTo(Variables->PartMap->sizeOf(partition), multiple).data(),
|
||||
multiple.data());
|
||||
}
|
||||
convertTo(props.size, multiple).data(), multiple.data());
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
if (partitions.back() == "get-all" || partitions.back() == "getvar-all")
|
||||
Variables->PartMap->doForAllPartitions(func);
|
||||
else if (partitions.back() == "get-logicals")
|
||||
Variables->PartMap->doForLogicalPartitions(func);
|
||||
else if (partitions.back() == "get-physicals")
|
||||
Variables->PartMap->doForPhysicalPartitions(func);
|
||||
else Variables->PartMap->doForPartitionList(partitions, func);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ RUN(typeFunction) {
|
||||
for (const auto &content : contents) {
|
||||
if (!Variables->PartMap->hasPartition(content) &&
|
||||
!Helper::fileIsExists(content))
|
||||
throw Error("Couldn't find partition or image file: %s\n",
|
||||
content.data());
|
||||
throw Error("Couldn't find partition or image file: %s", content.data());
|
||||
|
||||
bool found = false;
|
||||
for (const auto &[magic, name] : magics) {
|
||||
@@ -68,7 +67,7 @@ RUN(typeFunction) {
|
||||
}
|
||||
|
||||
if (!found)
|
||||
throw Error("Couldn't determine type of %s%s\n", content.data(),
|
||||
throw Error("Couldn't determine type of %s%s", content.data(),
|
||||
content == "userdata" ? " (encrypted file system?)" : "");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user