pmt: The basis of the system for adding features was created and improvements were made.

- The basic header contents of the system, designed to easily add features, were written.
 - The [CLI11](https://github.com/CLIUtils/CLI11) project was included to provide a better experience for the project.
 - Improved logging system.
 - Unnecessary code cleaned.
This commit is contained in:
2025-07-24 17:38:31 +03:00
parent 18b5700cbd
commit 9cd97a085e
16 changed files with 11763 additions and 46 deletions

View File

@@ -20,7 +20,6 @@ set(LIBPARTITION_MAP_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/PartitionMap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Type.cpp
)
set(LIBPARTITION_MAP_FLAGS -DLOG_FILE="/storage/emulated/0/.last_pmt.log" -DPROGRAM_NAME="libpartition_map")
# Add targets
add_library(partition_map_shared SHARED ${LIBPARTITION_MAP_SOURCES})
@@ -31,10 +30,7 @@ add_executable(libpartition_map_test tests/test.cpp)
set_target_properties(partition_map_shared PROPERTIES OUTPUT_NAME "partition_map")
set_target_properties(partition_map_static PROPERTIES OUTPUT_NAME "partition_map")
# Set compiler flags
target_compile_options(partition_map_shared PRIVATE ${LIBPARTITION_MAP_FLAGS})
target_compile_options(partition_map_static PRIVATE ${LIBPARTITION_MAP_FLAGS})
target_compile_options(libpartition_map_test PRIVATE ${LIBPARTITION_MAP_FLAGS})
# Set linker flags
target_link_options(libpartition_map_test PRIVATE "LINKER:-rpath,/data/data/com.termux/files/usr/lib")
target_link_options(partition_map_shared PRIVATE "LINKER:-rpath,/data/data/com.termux/files/usr/lib")
target_link_libraries(libpartition_map_test PRIVATE partition_map_shared PRIVATE helper_shared)

View File

@@ -325,4 +325,6 @@ using Map = basic_partition_map_builder;
} // namespace PartitionMap
#define MAP "libpartition_map"
#endif // #ifndef LIBPARTITION_MAP_LIB_HPP

View File

@@ -55,12 +55,14 @@ Map_t basic_partition_map_builder::_build_map(std::string_view path, bool logica
return a.path().filename() < b.path().filename();
});
LOGN_IF(MAP, WARNING, entries.empty()) << __func__ << "(): " << path << "is exists but generated vector is empty (std::vector<std::filesystem::directory_entry>)." << std::endl;
for (const auto& entry : entries) {
if (entry.path().filename() != "by-uuid"
&& std::string(entry.path()).find("com.") == std::string::npos)
map.insert(entry.path().filename().string(), _get_size(entry.path()), logical);
}
LOGN(MAP, INFO) << std::boolalpha << __func__ << "(): Map generated successfully. is_logical_map=" << logical << std::endl;
return map;
}
@@ -94,6 +96,8 @@ uint64_t basic_partition_map_builder::_get_size(const std::string path)
basic_partition_map_builder::basic_partition_map_builder()
{
LOGN(MAP, INFO) << __func__ << "(): default constructor called. Starting build." << std::endl;
for (const auto& path : defaultEntryList) {
if (std::filesystem::exists(path)) {
_current_map = _build_map(path);
@@ -110,12 +114,15 @@ basic_partition_map_builder::basic_partition_map_builder()
if (_current_map.empty())
throw Error("Cannot build map by any default search entry.");
LOGN(MAP, INFO) << __func__ << "(): default constructor successfully ended work." << std::endl;
_insert_logicals(_build_map("/dev/block/mapper", true));
_map_builded = true;
}
basic_partition_map_builder::basic_partition_map_builder(const std::string_view path)
{
LOGN(MAP, INFO) << __func__ << "(): argument-based constructor called. Starting build." << std::endl;
if (std::filesystem::exists(path)) {
_is_real_block_dir(path);
_current_map = _build_map(path);
@@ -124,6 +131,7 @@ basic_partition_map_builder::basic_partition_map_builder(const std::string_view
} else
throw Error("Cannot find directory: %s. Cannot build partition map!", path.data());
LOGN(MAP, INFO) << __func__ << "(): argument-based constructor successfully ended work." << std::endl;
_insert_logicals(_build_map("/dev/block/mapper", true));
_map_builded = true;
}
@@ -150,6 +158,7 @@ void basic_partition_map_builder::clear()
bool basic_partition_map_builder::readDirectory(const std::string_view path)
{
_map_builded = false;
LOGN(MAP, INFO) << __func__ << "(): read " << path << " directory request." << std::endl;
if (std::filesystem::exists(path)) {
if (!_is_real_block_dir(path)) return false;
@@ -161,6 +170,7 @@ bool basic_partition_map_builder::readDirectory(const std::string_view path)
} else
throw Error("Cannot find directory: %s. Cannot build partition map!", path.data());
LOGN(MAP, INFO) << __func__ << "(): read " << path << " successfull." << std::endl;
_insert_logicals(_build_map("/dev/block/mapper", true));
_map_builded = true;
return true;

View File

@@ -142,13 +142,16 @@ bool basic_partition_map::insert(const std::string name, uint64_t size, bool log
if (_count == _capacity) _resize_map();
_data[_count++] = {name, {size, logical}};
LOGN(MAP, INFO) << std::boolalpha << __func__ << "(): partition " << name << " inserted (size=" << size << ", is_logical=" << logical << ")." << std::endl;
return true;
}
void basic_partition_map::merge(const basic_partition_map& map)
{
LOGN(MAP, INFO) << __func__ << "(): map merge request." << std::endl;
for (const auto& [name, props] : map)
insert(name, props.size, props.isLogical);
LOGN(MAP, INFO) << __func__ << "(): map merged successfully." << std::endl;
}
uint64_t basic_partition_map::get_size(const std::string_view name) const
@@ -203,6 +206,7 @@ bool basic_partition_map::empty() const
void basic_partition_map::clear()
{
LOGN(MAP, INFO) << __func__ << "(): map clean requested. Map is empty now." << std::endl;
delete[] _data;
_count = 0;
_capacity = 6;