From 6ba2d0c55411baf9d88e35221489f62d6d7cee42 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Mon, 23 Sep 2019 18:01:20 -0700 Subject: lpdump: print partitions in super in order Easier to understand where are all the extents. Test: run it Change-Id: I88511fe4ed0d23882872c7434422f0a42cd3ee1f --- partition_tools/lpdump.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'partition_tools') 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 #include +#include #include #include #include @@ -274,6 +275,16 @@ public: } }; +std::optional> +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> 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) { -- cgit v1.2.3