diff --git a/Library-Documentation.md b/Library-Documentation.md index 5614987..326c316 100644 --- a/Library-Documentation.md +++ b/Library-Documentation.md @@ -614,4 +614,184 @@ If you're going to use it prebuilt, you can find it in the PMT releases. Or you --- ## libpartition_map library -soon! \ No newline at end of file +`libpartition_map` provides a C++ interface to manage, query, and manipulate disk partitions programmatically. It is built on top of `libhelper`. + +--- + +### Namespaces + +#### PartitionMap + +Main namespace of the library. Contains all core types, builder classes, and utilities. + +```c++ +#include +``` + +--- + +### Types + +#### `PartitionMap::Info` + +Represents a single partition entry. + +| Member | Type | Description | +| ------- | ------------- | -------------------- | +| `name` | `std::string` | Partition name | +| `props` | struct | Partition properties | + +```c++ +struct _entry { + std::string name; + struct { + uint64_t size; + bool isLogical; + } props; +}; +``` + +--- + +#### `PartitionMap::BasicInfo` + +Minimal information about a partition. + +| Member | Type | Description | +| ----------- | ---------- | ---------------------- | +| `size` | `uint64_t` | Partition size | +| `isLogical` | `bool` | Logical partition flag | + +--- + +#### Aliases + +| Alias | Type | +| ------------------ | ----------------------------- | +| `Partition_t` | `_entry` | +| `Map_t` | `basic_partition_map` | +| `BuildMap` / `Map` | `basic_partition_map_builder` | +| `BasicInf` | `_returnable_entry` | +| `Info` | `_entry` | +| `Error` | `Helper::Error` | + +--- + +### Classes + +#### Map_t (basic_partition_map) +Core partition map type. + +##### Overview + +```c++ +PartitionMap::Map_t myMap; +``` + +* Supports insertion, merging, clearing, and queries etc... +* Provides **for-each support** via `iterator` and `constant_iterator`: + +```c++ +for (const auto &entry : myMap) { + std::cout << entry.first << " size: " << entry.second.size << " logical: " << entry.second.isLogical << std::endl; +} +``` + +> Note: Direct use of `iterator` and `constant_iterator` is typically unnecessary; use range-based for loops. + +--- + +#### BuildMap (basic_partition_map_builder) + +High-level interface to build and query partition maps. + +##### Example Usage + +```c++ +#include +#include +#include +#include + +int main() { + try { + PartitionMap::Map builder; + + // Read default directories + if (!builder.readDefaultDirectories()) { + std::cerr << "Failed to read default directories" << std::endl; + return 1; + } + + // Query partitions + auto allPartitions = builder.getPartitionList(); + if (allPartitions) { + for (const auto &p : *allPartitions) { + std::cout << p << std::endl; + } + } + + // Use doForAllPartitions lambda + builder.doForAllPartitions([](const std::string &name, PartitionMap::BasicInf props) { + std::cout << name << " -> size: " << props.size << ", logical: " << props.isLogical << std::endl; + return true; // Continue iteration + }); + + // Check specific partition + if (builder.hasPartition("boot")) { + std::cout << "sda1 size: " << builder.sizeOf("boot") << std::endl; + } + + // Other library functions... + + } catch (PartitionMap::Error &e) { + std::cerr << "PartitionMap Error: " << e.what() << std::endl; + } + + return 0; +} +``` + +> Note: `PartitionMap::Error` can be thrown, so always wrap operations in try-catch blocks. + +--- + +### Constants + +#### PartitionMap::Extras::FileSystemMagic + +```c++ +constexpr uint64_t EXTFS_FS = 0xEF53; +constexpr uint64_t F2FS_FS = 0xF2F52010; +constexpr uint64_t EROFS_FS = 0xE0F5E1E2; +constexpr uint64_t EXFAT_FS = 0x5441465845; +// ... and more +``` + +#### PartitionMap::Extras::AndroidMagic + +```c++ +constexpr uint64_t BOOT_IMAGE = 0x2144494F52444E41; +constexpr uint64_t VBOOT_IMAGE = 0x544F4F4252444E56; +constexpr uint64_t LK_IMAGE = 0x00006B6C; +// ... and more +``` + +--- + +### Compling and linking +If you're using CMake in your project, you can include it directly with `add_subdirectory`. Both the static and shared libraries will be compiled. + +```cmake +# Include required libhelper library +add_subdirectory(srclib/libhelper) +add_subdirectory(srclib/libpartition_map) + +# Usage example +add_executable(main main.cpp) +target_link_libraries(main PRIVATE partition_map_shared) # use helper_static if you want link static library +``` + +If you're going to use it prebuilt, you can find it in the PMT releases. Or you can compile it separately... WARNING: PMT releases only include builds for ARM. + +--- \ No newline at end of file