pmt: Improve pmt & libpartition_map
- Change some operator returnn types. - Use std::map instead of std::unordered on magic number maps. - Some improvements.
This commit is contained in:
@@ -25,10 +25,10 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define BFUN "backupFunction"
|
#define BFUN "backupFunction"
|
||||||
|
#define FUNCTION_CLASS backupFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
RUN_ASYNC(backupFunction)(const std::string &partitionName,
|
RUN_ASYNC(const std::string &partitionName, const std::string &outputName,
|
||||||
const std::string &outputName,
|
|
||||||
const uint64_t bufferSize) {
|
const uint64_t bufferSize) {
|
||||||
if (!Variables->PartMap->hasPartition(partitionName))
|
if (!Variables->PartMap->hasPartition(partitionName))
|
||||||
return {format("Couldn't find partition: %s", partitionName.data()), false};
|
return {format("Couldn't find partition: %s", partitionName.data()), false};
|
||||||
@@ -105,7 +105,7 @@ RUN_ASYNC(backupFunction)(const std::string &partitionName,
|
|||||||
true};
|
true};
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT(backupFunction) {
|
INIT {
|
||||||
LOGN(BFUN, INFO) << "Initializing variables of backup function." << std::endl;
|
LOGN(BFUN, INFO) << "Initializing variables of backup function." << std::endl;
|
||||||
cmd = _app.add_subcommand("backup", "Backup partition(s) to file(s)");
|
cmd = _app.add_subcommand("backup", "Backup partition(s) to file(s)");
|
||||||
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
|
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
|
||||||
@@ -123,7 +123,7 @@ INIT(backupFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(backupFunction) {
|
RUN {
|
||||||
processCommandLine(partitions, outputNames, rawPartitions, rawOutputNames,
|
processCommandLine(partitions, outputNames, rawPartitions, rawOutputNames,
|
||||||
',', true);
|
',', true);
|
||||||
if (!outputNames.empty() && partitions.size() != outputNames.size())
|
if (!outputNames.empty() && partitions.size() != outputNames.size())
|
||||||
@@ -161,7 +161,7 @@ RUN(backupFunction) {
|
|||||||
return endResult;
|
return endResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(backupFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(backupFunction) { return BFUN; }
|
NAME { return BFUN; }
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ Copyright 2025 Yağız Zengin
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define EFUN "eraseFunction"
|
#define EFUN "eraseFunction"
|
||||||
|
#define FUNCTION_CLASS eraseFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
RUN_ASYNC(eraseFunction)(const std::string &partitionName,
|
RUN_ASYNC(const std::string &partitionName, const uint64_t bufferSize) {
|
||||||
const uint64_t bufferSize) {
|
|
||||||
if (!Variables->PartMap->hasPartition(partitionName))
|
if (!Variables->PartMap->hasPartition(partitionName))
|
||||||
return {format("Couldn't find partition: %s", partitionName.data()), false};
|
return {format("Couldn't find partition: %s", partitionName.data()), false};
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ RUN_ASYNC(eraseFunction)(const std::string &partitionName,
|
|||||||
true};
|
true};
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT(eraseFunction) {
|
INIT {
|
||||||
LOGN(EFUN, INFO) << "Initializing variables of erase function." << std::endl;
|
LOGN(EFUN, INFO) << "Initializing variables of erase function." << std::endl;
|
||||||
cmd = _app.add_subcommand("erase", "Writes zero bytes to partition(s)");
|
cmd = _app.add_subcommand("erase", "Writes zero bytes to partition(s)");
|
||||||
cmd->add_option("partition(s)", partitions, "Partition name(s)")
|
cmd->add_option("partition(s)", partitions, "Partition name(s)")
|
||||||
@@ -100,7 +100,7 @@ INIT(eraseFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(eraseFunction) {
|
RUN {
|
||||||
std::vector<std::future<pair>> futures;
|
std::vector<std::future<pair>> futures;
|
||||||
for (const auto &partitionName : partitions) {
|
for (const auto &partitionName : partitions) {
|
||||||
uint64_t buf = bufferSize;
|
uint64_t buf = bufferSize;
|
||||||
@@ -127,7 +127,7 @@ RUN(eraseFunction) {
|
|||||||
return endResult;
|
return endResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(eraseFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(eraseFunction) { return EFUN; }
|
NAME { return EFUN; }
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ Copyright 2025 Yağız Zengin
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define FFUN "flashFunction"
|
#define FFUN "flashFunction"
|
||||||
|
#define FUNCTION_CLASS flashFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
RUN_ASYNC(flashFunction)(const std::string &partitionName,
|
RUN_ASYNC(const std::string &partitionName, const std::string &imageName,
|
||||||
const std::string &imageName,
|
|
||||||
const uint64_t bufferSize) {
|
const uint64_t bufferSize) {
|
||||||
if (!Helper::fileIsExists(imageName))
|
if (!Helper::fileIsExists(imageName))
|
||||||
return {format("Couldn't find image file: %s", imageName.data()), false};
|
return {format("Couldn't find image file: %s", imageName.data()), false};
|
||||||
@@ -92,7 +92,7 @@ RUN_ASYNC(flashFunction)(const std::string &partitionName,
|
|||||||
true};
|
true};
|
||||||
}
|
}
|
||||||
|
|
||||||
INIT(flashFunction) {
|
INIT {
|
||||||
LOGN(FFUN, INFO) << "Initializing variables of flash function." << std::endl;
|
LOGN(FFUN, INFO) << "Initializing variables of flash function." << std::endl;
|
||||||
cmd = _app.add_subcommand("flash", "Flash image(s) to partition(s)");
|
cmd = _app.add_subcommand("flash", "Flash image(s) to partition(s)");
|
||||||
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
|
cmd->add_option("partition(s)", rawPartitions, "Partition name(s)")
|
||||||
@@ -110,7 +110,7 @@ INIT(flashFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(flashFunction) {
|
RUN {
|
||||||
processCommandLine(partitions, imageNames, rawPartitions, rawImageNames, ',',
|
processCommandLine(partitions, imageNames, rawPartitions, rawImageNames, ',',
|
||||||
true);
|
true);
|
||||||
if (partitions.size() != imageNames.size())
|
if (partitions.size() != imageNames.size())
|
||||||
@@ -148,7 +148,7 @@ RUN(flashFunction) {
|
|||||||
return endResult;
|
return endResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(flashFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(flashFunction) { return FFUN; }
|
NAME { return FFUN; }
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -22,10 +22,11 @@ Copyright 2025 Yağız Zengin
|
|||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#define IFUN "infoFunction"
|
#define IFUN "infoFunction"
|
||||||
|
#define FUNCTION_CLASS infoFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
|
|
||||||
INIT(infoFunction) {
|
INIT {
|
||||||
LOGN(IFUN, INFO) << "Initializing variables of info printer function."
|
LOGN(IFUN, INFO) << "Initializing variables of info printer function."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cmd = _app.add_subcommand("info", "Tell info(s) of input partition list")
|
cmd = _app.add_subcommand("info", "Tell info(s) of input partition list")
|
||||||
@@ -56,7 +57,7 @@ INIT(infoFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(infoFunction) {
|
RUN {
|
||||||
std::vector<PartitionMap::Partition_t> jParts;
|
std::vector<PartitionMap::Partition_t> jParts;
|
||||||
auto func = [this, &jParts] COMMON_LAMBDA_PARAMS -> bool {
|
auto func = [this, &jParts] COMMON_LAMBDA_PARAMS -> bool {
|
||||||
if (Variables->onLogical && !props.isLogical) {
|
if (Variables->onLogical && !props.isLogical) {
|
||||||
@@ -106,7 +107,7 @@ RUN(infoFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(infoFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(infoFunction) { return IFUN; };
|
NAME { return IFUN; };
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ Copyright 2025 Yağız Zengin
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#define MTFUN "memoryTestFunction"
|
#define MTFUN "memoryTestFunction"
|
||||||
|
#define FUNCTION_CLASS memoryTestFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
|
|
||||||
INIT(memoryTestFunction) {
|
INIT {
|
||||||
LOGN(MTFUN, INFO) << "Initializing variables of memory test function."
|
LOGN(MTFUN, INFO) << "Initializing variables of memory test function."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cmd = _app.add_subcommand("memtest", "Test your write/read speed of device.");
|
cmd = _app.add_subcommand("memtest", "Test your write/read speed of device.");
|
||||||
@@ -56,7 +57,7 @@ INIT(memoryTestFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(memoryTestFunction) {
|
RUN {
|
||||||
LOGN(MTFUN, INFO) << "Starting memory test on " << testPath << std::endl;
|
LOGN(MTFUN, INFO) << "Starting memory test on " << testPath << std::endl;
|
||||||
Helper::garbageCollector collector;
|
Helper::garbageCollector collector;
|
||||||
const std::string test = Helper::pathJoin(testPath, "test.bin");
|
const std::string test = Helper::pathJoin(testPath, "test.bin");
|
||||||
@@ -121,7 +122,7 @@ RUN(memoryTestFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(memoryTestFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(memoryTestFunction) { return MTFUN; }
|
NAME { return MTFUN; }
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ Copyright 2025 Yağız Zengin
|
|||||||
#include <PartitionManager/PartitionManager.hpp>
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define SFUN "partitionSizeFunction"
|
#define SFUN "partitionSizeFunction"
|
||||||
|
#define FUNCTION_CLASS partitionSizeFunction
|
||||||
|
|
||||||
static std::string convertTo(const uint64_t size, const std::string &multiple) {
|
static std::string convertTo(const uint64_t size, const std::string &multiple) {
|
||||||
if (multiple == "KB") return std::to_string(TO_KB(size));
|
if (multiple == "KB") return std::to_string(TO_KB(size));
|
||||||
@@ -27,7 +28,7 @@ static std::string convertTo(const uint64_t size, const std::string &multiple) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
INIT(partitionSizeFunction) {
|
INIT {
|
||||||
LOGN(SFUN, INFO)
|
LOGN(SFUN, INFO)
|
||||||
<< "Initializing variables of partition size getter function."
|
<< "Initializing variables of partition size getter function."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@@ -59,7 +60,7 @@ INIT(partitionSizeFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(partitionSizeFunction) {
|
RUN {
|
||||||
auto func = [this] COMMON_LAMBDA_PARAMS -> bool {
|
auto func = [this] COMMON_LAMBDA_PARAMS -> bool {
|
||||||
if (Variables->onLogical && !props.isLogical) {
|
if (Variables->onLogical && !props.isLogical) {
|
||||||
if (Variables->forceProcess)
|
if (Variables->forceProcess)
|
||||||
@@ -97,7 +98,7 @@ RUN(partitionSizeFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(partitionSizeFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(partitionSizeFunction) { return SFUN; }
|
NAME { return SFUN; }
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -18,9 +18,10 @@
|
|||||||
#include <PartitionManager/PartitionManager.hpp>
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define RPFUN "realPathFunction"
|
#define RPFUN "realPathFunction"
|
||||||
|
#define FUNCTION_CLASS realPathFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
INIT(realPathFunction) {
|
INIT {
|
||||||
LOGN(RPFUN, INFO) << "Initializing variables of real path function."
|
LOGN(RPFUN, INFO) << "Initializing variables of real path function."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
cmd = _app.add_subcommand("real-path", "Tell real paths of partition(s)");
|
cmd = _app.add_subcommand("real-path", "Tell real paths of partition(s)");
|
||||||
@@ -32,7 +33,7 @@ INIT(realPathFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(realPathFunction) {
|
RUN {
|
||||||
for (const auto &partition : partitions) {
|
for (const auto &partition : partitions) {
|
||||||
if (!Variables->PartMap->hasPartition(partition))
|
if (!Variables->PartMap->hasPartition(partition))
|
||||||
throw Error("Couldn't find partition: %s", partition.data());
|
throw Error("Couldn't find partition: %s", partition.data());
|
||||||
@@ -56,7 +57,7 @@ RUN(realPathFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(realPathFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(realPathFunction) { return RPFUN; }
|
NAME { return RPFUN; }
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ Copyright 2025 Yağız Zengin
|
|||||||
#include <PartitionManager/PartitionManager.hpp>
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
|
||||||
#define RFUN "rebootFunction"
|
#define RFUN "rebootFunction"
|
||||||
|
#define FUNCTION_CLASS rebootFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
INIT(rebootFunction) {
|
INIT {
|
||||||
LOGN(RFUN, INFO) << "Initializing variables of reboot function." << std::endl;
|
LOGN(RFUN, INFO) << "Initializing variables of reboot function." << std::endl;
|
||||||
cmd = _app.add_subcommand("reboot", "Reboots device");
|
cmd = _app.add_subcommand("reboot", "Reboots device");
|
||||||
cmd->add_option("rebootTarget", rebootTarget,
|
cmd->add_option("rebootTarget", rebootTarget,
|
||||||
@@ -28,7 +29,7 @@ INIT(rebootFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(rebootFunction) {
|
RUN {
|
||||||
LOGN(RFUN, INFO) << "Rebooting device!!! (custom reboot target: "
|
LOGN(RFUN, INFO) << "Rebooting device!!! (custom reboot target: "
|
||||||
<< (rebootTarget.empty() ? "none" : rebootTarget)
|
<< (rebootTarget.empty() ? "none" : rebootTarget)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@@ -39,7 +40,7 @@ RUN(rebootFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(rebootFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(rebootFunction) { return RFUN; }
|
NAME { return RFUN; }
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -16,11 +16,13 @@
|
|||||||
|
|
||||||
#include "functions.hpp"
|
#include "functions.hpp"
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#define TFUN "typeFunction"
|
#define TFUN "typeFunction"
|
||||||
|
#define FUNCTION_CLASS typeFunction
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
INIT(typeFunction) {
|
INIT {
|
||||||
LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl;
|
LOGN(TFUN, INFO) << "Initializing variables of type function." << std::endl;
|
||||||
cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)");
|
cmd = _app.add_subcommand("type", "Get type of the partition(s) or image(s)");
|
||||||
cmd->add_option("content(s)", contents, "Content(s)")
|
cmd->add_option("content(s)", contents, "Content(s)")
|
||||||
@@ -39,8 +41,8 @@ INIT(typeFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUN(typeFunction) {
|
RUN {
|
||||||
std::unordered_map<uint64_t, std::string> magics;
|
std::map<uint64_t, std::string> magics;
|
||||||
if (onlyCheckAndroidMagics)
|
if (onlyCheckAndroidMagics)
|
||||||
magics.merge(PartitionMap::Extras::AndroidMagicMap);
|
magics.merge(PartitionMap::Extras::AndroidMagicMap);
|
||||||
else if (onlyCheckFileSystemMagics)
|
else if (onlyCheckFileSystemMagics)
|
||||||
@@ -74,8 +76,8 @@ RUN(typeFunction) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IS_USED_COMMON_BODY(typeFunction)
|
IS_USED_COMMON_BODY
|
||||||
|
|
||||||
NAME(typeFunction) { return TFUN; }
|
NAME { return TFUN; }
|
||||||
|
|
||||||
} // namespace PartitionManager
|
} // namespace PartitionManager
|
||||||
|
|||||||
@@ -21,16 +21,18 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define INIT(cls) bool cls::init(CLI::App &_app)
|
#define INIT bool FUNCTION_CLASS::init(CLI::App &_app)
|
||||||
#define RUN(cls) bool cls::run()
|
#define RUN bool FUNCTION_CLASS::run()
|
||||||
#define RUN_ASYNC(cls) pair cls::runAsync
|
#define RUN_ASYNC pair FUNCTION_CLASS::runAsync
|
||||||
#define IS_USED(cls) bool cls::isUsed() const
|
#define IS_USED bool FUNCTION_CLASS::isUsed() const
|
||||||
#define IS_USED_COMMON_BODY(cls) \
|
#define IS_USED_COMMON_BODY \
|
||||||
bool cls::isUsed() const { return cmd->parsed(); }
|
bool FUNCTION_CLASS::isUsed() const { return cmd->parsed(); }
|
||||||
#define NAME(cls) const char *cls::name() const
|
#define NAME const char *FUNCTION_CLASS::name() const
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Please define FUNCTION_CLASS before using these macros!!! (INIT etc.)
|
||||||
|
*/
|
||||||
|
|
||||||
#define COMMON_LAMBDA_PARAMS \
|
|
||||||
(std::string partition, const PartitionMap::Map_t::BasicInf props)
|
|
||||||
#define COMMON_FUNCTION_BODY() \
|
#define COMMON_FUNCTION_BODY() \
|
||||||
CLI::App *cmd = nullptr; \
|
CLI::App *cmd = nullptr; \
|
||||||
bool init(CLI::App &_app) override; \
|
bool init(CLI::App &_app) override; \
|
||||||
|
|||||||
@@ -22,12 +22,11 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <tuple>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility> // for std::pair
|
#include <utility> // for std::pair
|
||||||
|
|
||||||
namespace PartitionMap {
|
namespace PartitionMap {
|
||||||
@@ -40,6 +39,14 @@ struct _entry {
|
|||||||
} props;
|
} props;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _returnable_entry {
|
||||||
|
uint64_t size;
|
||||||
|
bool isLogical;
|
||||||
|
};
|
||||||
|
|
||||||
|
using BasicInf = _returnable_entry;
|
||||||
|
using Info = _entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main type of the library. The Builder class is designed
|
* The main type of the library. The Builder class is designed
|
||||||
* to be easily manipulated and modified only on this class.
|
* to be easily manipulated and modified only on this class.
|
||||||
@@ -54,13 +61,6 @@ public:
|
|||||||
_entry *_data;
|
_entry *_data;
|
||||||
size_t _count{}, _capacity{};
|
size_t _count{}, _capacity{};
|
||||||
|
|
||||||
struct _returnable_entry {
|
|
||||||
uint64_t size;
|
|
||||||
bool isLogical;
|
|
||||||
};
|
|
||||||
|
|
||||||
using BasicInf = _returnable_entry;
|
|
||||||
|
|
||||||
basic_partition_map(const std::string &name, uint64_t size, bool logical);
|
basic_partition_map(const std::string &name, uint64_t size, bool logical);
|
||||||
basic_partition_map(const basic_partition_map &other);
|
basic_partition_map(const basic_partition_map &other);
|
||||||
basic_partition_map(basic_partition_map &&other) noexcept;
|
basic_partition_map(basic_partition_map &&other) noexcept;
|
||||||
@@ -84,7 +84,7 @@ public:
|
|||||||
bool operator==(const basic_partition_map &other) const;
|
bool operator==(const basic_partition_map &other) const;
|
||||||
bool operator!=(const basic_partition_map &other) const;
|
bool operator!=(const basic_partition_map &other) const;
|
||||||
|
|
||||||
operator std::vector<std::tuple<std::string, uint64_t, bool>>() const;
|
operator std::vector<Info>() const;
|
||||||
operator int() const;
|
operator int() const;
|
||||||
|
|
||||||
class iterator {
|
class iterator {
|
||||||
@@ -256,26 +256,26 @@ public:
|
|||||||
* Do input function (lambda) for all partitions.
|
* Do input function (lambda) for all partitions.
|
||||||
*/
|
*/
|
||||||
void doForAllPartitions(
|
void doForAllPartitions(
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const;
|
const std::function<bool(std::string, BasicInf)> &func) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do input function (lambda) for physical partitions.
|
* Do input function (lambda) for physical partitions.
|
||||||
*/
|
*/
|
||||||
void doForPhysicalPartitions(
|
void doForPhysicalPartitions(
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const;
|
const std::function<bool(std::string, BasicInf)> &func) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do input function (lambda) for logical partitions.
|
* Do input function (lambda) for logical partitions.
|
||||||
*/
|
*/
|
||||||
void doForLogicalPartitions(
|
void doForLogicalPartitions(
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const;
|
const std::function<bool(std::string, BasicInf)> &func) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do input function (lambda) for input partition list.
|
* Do input function (lambda) for input partition list.
|
||||||
*/
|
*/
|
||||||
void doForPartitionList(
|
void doForPartitionList(
|
||||||
const std::vector<std::string> &partitions,
|
const std::vector<std::string> &partitions,
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const;
|
const std::function<bool(std::string, BasicInf)> &func) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entered path is defined as the new search
|
* The entered path is defined as the new search
|
||||||
@@ -346,10 +346,9 @@ public:
|
|||||||
const Map_t &operator*() const;
|
const Map_t &operator*() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get map contents as vector (std::tuple type).
|
* Get map contents as vector (PartitionManager::Info type).
|
||||||
*/
|
*/
|
||||||
[[nodiscard]]
|
[[nodiscard]] operator std::vector<Info>() const;
|
||||||
operator std::vector<std::tuple<std::string, uint64_t, bool>>() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get total partition count in map (int type).
|
* Get total partition count in map (int type).
|
||||||
@@ -399,9 +398,9 @@ constexpr uint64_t ELF =
|
|||||||
constexpr uint64_t RAW = 0x00000000;
|
constexpr uint64_t RAW = 0x00000000;
|
||||||
} // namespace AndroidMagic
|
} // namespace AndroidMagic
|
||||||
|
|
||||||
extern std::unordered_map<uint64_t, std::string> FileSystemMagicMap;
|
extern std::map<uint64_t, std::string> FileSystemMagicMap;
|
||||||
extern std::unordered_map<uint64_t, std::string> AndroidMagicMap;
|
extern std::map<uint64_t, std::string> AndroidMagicMap;
|
||||||
extern std::unordered_map<uint64_t, std::string> MagicMap;
|
extern std::map<uint64_t, std::string> MagicMap;
|
||||||
|
|
||||||
size_t getMagicLength(uint64_t magic);
|
size_t getMagicLength(uint64_t magic);
|
||||||
bool hasMagic(uint64_t magic, ssize_t buf, const std::string &path);
|
bool hasMagic(uint64_t magic, ssize_t buf, const std::string &path);
|
||||||
@@ -411,9 +410,7 @@ std::string formatMagic(uint64_t magic);
|
|||||||
|
|
||||||
#define MAP "libpartition_map"
|
#define MAP "libpartition_map"
|
||||||
|
|
||||||
#define T_NAME 0
|
#define COMMON_LAMBDA_PARAMS \
|
||||||
#define T_TYPE 1
|
(const std::string &partition, const PartitionMap::BasicInf props)
|
||||||
#define T_SIZE 2
|
|
||||||
#define T_VEC_DECL_TYPE std::vector<std::tuple<std::string, uint64_t, bool>>
|
|
||||||
|
|
||||||
#endif // #ifndef LIBPARTITION_MAP_LIB_HPP
|
#endif // #ifndef LIBPARTITION_MAP_LIB_HPP
|
||||||
|
|||||||
@@ -17,15 +17,15 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "PartitionManager/PartitionManager.hpp"
|
#include "PartitionManager/PartitionManager.hpp"
|
||||||
|
|
||||||
namespace PartitionMap::Extras {
|
namespace PartitionMap::Extras {
|
||||||
std::unordered_map<uint64_t, std::string> FileSystemMagicMap = {
|
std::map<uint64_t, std::string> FileSystemMagicMap = {
|
||||||
{FileSystemMagic::EXTFS_FS, "EXT2/3/4"},
|
{FileSystemMagic::EXTFS_FS, "EXT2/3/4"},
|
||||||
{FileSystemMagic::F2FS_FS, "F2FS"},
|
{FileSystemMagic::F2FS_FS, "F2FS"},
|
||||||
{FileSystemMagic::EROFS_FS, "EROFS"},
|
{FileSystemMagic::EROFS_FS, "EROFS"},
|
||||||
@@ -36,7 +36,7 @@ std::unordered_map<uint64_t, std::string> FileSystemMagicMap = {
|
|||||||
{FileSystemMagic::NTFS_FS, "NTFS"},
|
{FileSystemMagic::NTFS_FS, "NTFS"},
|
||||||
{FileSystemMagic::MSDOS_FS, "MSDOS"}};
|
{FileSystemMagic::MSDOS_FS, "MSDOS"}};
|
||||||
|
|
||||||
std::unordered_map<uint64_t, std::string> AndroidMagicMap = {
|
std::map<uint64_t, std::string> AndroidMagicMap = {
|
||||||
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
||||||
{AndroidMagic::VBOOT_IMAGE, "Android Vendor Boot Image"},
|
{AndroidMagic::VBOOT_IMAGE, "Android Vendor Boot Image"},
|
||||||
{AndroidMagic::LK_IMAGE, "Android LK (Bootloader)"},
|
{AndroidMagic::LK_IMAGE, "Android LK (Bootloader)"},
|
||||||
@@ -47,7 +47,7 @@ std::unordered_map<uint64_t, std::string> AndroidMagicMap = {
|
|||||||
{AndroidMagic::ELF, "ELF"},
|
{AndroidMagic::ELF, "ELF"},
|
||||||
{AndroidMagic::RAW, "Raw Data"}};
|
{AndroidMagic::RAW, "Raw Data"}};
|
||||||
|
|
||||||
std::unordered_map<uint64_t, std::string> MagicMap = {
|
std::map<uint64_t, std::string> MagicMap = {
|
||||||
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
{AndroidMagic::BOOT_IMAGE, "Android Boot Image"},
|
||||||
{AndroidMagic::VBOOT_IMAGE, "Android Vendor Boot Image"},
|
{AndroidMagic::VBOOT_IMAGE, "Android Vendor Boot Image"},
|
||||||
{AndroidMagic::LK_IMAGE, "Android LK (Bootloader)"},
|
{AndroidMagic::LK_IMAGE, "Android LK (Bootloader)"},
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ bool basic_partition_map_builder::empty() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void basic_partition_map_builder::doForAllPartitions(
|
void basic_partition_map_builder::doForAllPartitions(
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const {
|
const std::function<bool(std::string, BasicInf)> &func) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "Doing input function for all partitions." << std::endl;
|
LOGN(MAP, INFO) << "Doing input function for all partitions." << std::endl;
|
||||||
@@ -303,7 +303,7 @@ void basic_partition_map_builder::doForAllPartitions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void basic_partition_map_builder::doForPhysicalPartitions(
|
void basic_partition_map_builder::doForPhysicalPartitions(
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const {
|
const std::function<bool(std::string, BasicInf)> &func) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "Doing input function for physical partitions."
|
LOGN(MAP, INFO) << "Doing input function for physical partitions."
|
||||||
@@ -320,7 +320,7 @@ void basic_partition_map_builder::doForPhysicalPartitions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void basic_partition_map_builder::doForLogicalPartitions(
|
void basic_partition_map_builder::doForLogicalPartitions(
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const {
|
const std::function<bool(std::string, BasicInf)> &func) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "Doing input function for logical partitions."
|
LOGN(MAP, INFO) << "Doing input function for logical partitions."
|
||||||
@@ -338,7 +338,7 @@ void basic_partition_map_builder::doForLogicalPartitions(
|
|||||||
|
|
||||||
void basic_partition_map_builder::doForPartitionList(
|
void basic_partition_map_builder::doForPartitionList(
|
||||||
const std::vector<std::string> &partitions,
|
const std::vector<std::string> &partitions,
|
||||||
const std::function<bool(std::string, Map_t::BasicInf)> &func) const {
|
const std::function<bool(std::string, BasicInf)> &func) const {
|
||||||
_map_build_check();
|
_map_build_check();
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "Doing input function for input partition list."
|
LOGN(MAP, INFO) << "Doing input function for input partition list."
|
||||||
@@ -388,8 +388,7 @@ const Map_t &basic_partition_map_builder::operator*() const {
|
|||||||
return _current_map;
|
return _current_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map_builder::operator std::vector<
|
basic_partition_map_builder::operator std::vector<Info>() const {
|
||||||
std::tuple<std::string, uint64_t, bool>>() const {
|
|
||||||
return _current_map;
|
return _current_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ bool basic_partition_map::is_logical(const std::string_view name) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::_returnable_entry
|
_returnable_entry
|
||||||
basic_partition_map::get_all(const std::string_view name) const {
|
basic_partition_map::get_all(const std::string_view name) const {
|
||||||
if (const int pos = _index_of(name); name == _data[pos].name)
|
if (const int pos = _index_of(name); name == _data[pos].name)
|
||||||
return _returnable_entry{_data[pos].props.size, _data[pos].props.isLogical};
|
return _returnable_entry{_data[pos].props.size, _data[pos].props.isLogical};
|
||||||
@@ -229,13 +229,12 @@ bool basic_partition_map::operator!=(const basic_partition_map &other) const {
|
|||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::operator std::vector<
|
basic_partition_map::operator std::vector<Info>() const {
|
||||||
std::tuple<std::string, uint64_t, bool>>() const {
|
std::vector<Info> v;
|
||||||
std::vector<std::tuple<std::string, uint64_t, bool>> v;
|
|
||||||
if (_count == 0) return {};
|
if (_count == 0) return {};
|
||||||
for (size_t i = 0; i < _count; i++)
|
for (size_t i = 0; i < _count; i++)
|
||||||
v.emplace_back(_data[i].name, _data[i].props.size,
|
v.push_back(
|
||||||
_data[i].props.isLogical);
|
{_data[i].name, {_data[i].props.size, _data[i].props.isLogical}});
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <libpartition_map/lib.hpp>
|
#include <libpartition_map/lib.hpp>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -54,10 +55,26 @@ int main() {
|
|||||||
for (const auto &name : *physicals)
|
for (const auto &name : *physicals)
|
||||||
std::cout << " - " << name << std::endl;
|
std::cout << " - " << name << std::endl;
|
||||||
|
|
||||||
|
if (const std::vector<PartitionMap::Info> parts = MyMap; parts.empty())
|
||||||
|
throw PartitionMap::Error(
|
||||||
|
"operator std::vector>PartitionMap::Info>() returned empty vector");
|
||||||
|
|
||||||
|
auto func = [](const std::string &partition,
|
||||||
|
const PartitionMap::BasicInf props) -> bool {
|
||||||
|
std::ofstream f("parts.txt");
|
||||||
|
f << "Partition: " << partition << ", size: " << props.size
|
||||||
|
<< ", logical: " << props.isLogical;
|
||||||
|
return !f.fail();
|
||||||
|
};
|
||||||
|
MyMap.doForAllPartitions(func);
|
||||||
|
|
||||||
|
std::cout << "Total partitions count: " << (int)MyMap << std::endl;
|
||||||
std::cout << "Boot: " << MyMap.getRealLinkPathOf("boot") << std::endl;
|
std::cout << "Boot: " << MyMap.getRealLinkPathOf("boot") << std::endl;
|
||||||
std::cout << "Boot (realpath): " << MyMap.getRealPathOf("boot")
|
std::cout << "Boot (realpath): " << MyMap.getRealPathOf("boot")
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << "Search dir: " << MyMap.getCurrentWorkDir() << std::endl;
|
std::cout << "Search dir: " << MyMap.getCurrentWorkDir() << std::endl;
|
||||||
|
std::cout << "Search dir test 2: " << static_cast<std::string>(MyMap)
|
||||||
|
<< std::endl;
|
||||||
std::cout << "Has partition cache? = " << MyMap.hasPartition("cache")
|
std::cout << "Has partition cache? = " << MyMap.hasPartition("cache")
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << "system partition is logical? = " << MyMap.isLogical("system")
|
std::cout << "system partition is logical? = " << MyMap.isLogical("system")
|
||||||
|
|||||||
Reference in New Issue
Block a user