summaryrefslogtreecommitdiff
path: root/partition_tools
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2019-09-23 18:01:20 -0700
committerYifan Hong <elsk@google.com>2019-09-23 19:54:21 -0700
commit6ba2d0c55411baf9d88e35221489f62d6d7cee42 (patch)
tree621a408a41054387b961b07d9d9a9465c50beeef /partition_tools
parent1720053bc5f952270e274e394423a720d4ef0727 (diff)
downloadextras-6ba2d0c55411baf9d88e35221489f62d6d7cee42.tar.gz
lpdump: print partitions in super in order
Easier to understand where are all the extents. Test: run it Change-Id: I88511fe4ed0d23882872c7434422f0a42cd3ee1f
Diffstat (limited to 'partition_tools')
-rw-r--r--partition_tools/lpdump.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/partition_tools/lpdump.cc b/partition_tools/lpdump.cc
index 1b8f65e7..2eb9f1fe 100644
--- a/partition_tools/lpdump.cc
+++ b/partition_tools/lpdump.cc
@@ -23,6 +23,7 @@
#include <sysexits.h>
#include <unistd.h>
+#include <algorithm>
#include <iostream>
#include <optional>
#include <regex>
@@ -274,6 +275,16 @@ public:
}
};
+std::optional<std::tuple<std::string, uint64_t>>
+ParseLinearExtentData(const LpMetadata& pt, const LpMetadataExtent& extent) {
+ if (extent.target_type != LP_TARGET_TYPE_LINEAR) {
+ return std::nullopt;
+ }
+ const auto& block_device = pt.block_devices[extent.target_source];
+ std::string device_name = GetBlockDevicePartitionName(block_device);
+ return std::make_tuple(std::move(device_name), extent.target_data);
+}
+
static void PrintMetadata(const LpMetadata& pt, std::ostream& cout) {
cout << "Metadata version: " << pt.header.major_version << "." << pt.header.minor_version
<< "\n";
@@ -283,6 +294,8 @@ static void PrintMetadata(const LpMetadata& pt, std::ostream& cout) {
cout << "Partition table:\n";
cout << "------------------------\n";
+ std::vector<std::tuple<std::string, const LpMetadataExtent*>> extents;
+
for (const auto& partition : pt.partitions) {
std::string name = GetPartitionName(partition);
std::string group_name = GetPartitionGroupName(pt.groups[partition.group_index]);
@@ -303,11 +316,29 @@ static void PrintMetadata(const LpMetadata& pt, std::ostream& cout) {
} else if (extent.target_type == LP_TARGET_TYPE_ZERO) {
cout << "zero";
}
+ extents.push_back(std::make_tuple(name, &extent));
cout << "\n";
}
cout << "------------------------\n";
}
+ std::sort(extents.begin(), extents.end(), [&](const auto& x, const auto& y) {
+ auto x_data = ParseLinearExtentData(pt, *std::get<1>(x));
+ auto y_data = ParseLinearExtentData(pt, *std::get<1>(y));
+ return x_data < y_data;
+ });
+
+ cout << "Super partition layout:\n";
+ cout << "------------------------\n";
+ for (auto&& [name, extent] : extents) {
+ auto data = ParseLinearExtentData(pt, *extent);
+ if (!data) continue;
+ auto&& [block_device, offset] = *data;
+ cout << block_device << ": " << offset << " .. " << (offset + extent->num_sectors)
+ << ": " << name << " (" << extent->num_sectors << " sectors)\n";
+ }
+ cout << "------------------------\n";
+
cout << "Block device table:\n";
cout << "------------------------\n";
for (const auto& block_device : pt.block_devices) {