diff options
author | David Anderson <dvander@google.com> | 2018-12-12 13:36:43 -0800 |
---|---|---|
committer | David Anderson <dvander@google.com> | 2018-12-12 13:58:04 -0800 |
commit | 299abc7e219a0acef3fa5da413482304aceba8c9 (patch) | |
tree | c23617c033d0930540cdda98abafce7a32727486 /partition_tools | |
parent | 1309cb5e4d53307af7ba5ead3a28377a66e6a877 (diff) | |
download | extras-299abc7e219a0acef3fa5da413482304aceba8c9.tar.gz |
lpdump: Automatically read from super when used directly on devices.
It's confusing to figure out how to invoke lpdump, especially on
retrofit devices. It should just do the correct thing automatically
when no arguments are passed.
Bug: N/A
Test: lpdump on retrofit device
Change-Id: I0563c10ff276763710fa0a4fb9918a2515f9d054
Diffstat (limited to 'partition_tools')
-rw-r--r-- | partition_tools/Android.bp | 7 | ||||
-rw-r--r-- | partition_tools/lpdump.cc | 28 |
2 files changed, 26 insertions, 9 deletions
diff --git a/partition_tools/Android.bp b/partition_tools/Android.bp index b076178a..4a1bb272 100644 --- a/partition_tools/Android.bp +++ b/partition_tools/Android.bp @@ -39,6 +39,13 @@ cc_binary { srcs: [ "lpdump.cc", ], + target: { + android: { + shared_libs: [ + "libfs_mgr", + ], + }, + }, } cc_binary { diff --git a/partition_tools/lpdump.cc b/partition_tools/lpdump.cc index 524479b6..bde86fc9 100644 --- a/partition_tools/lpdump.cc +++ b/partition_tools/lpdump.cc @@ -27,6 +27,9 @@ #include <android-base/strings.h> #include <android-base/parseint.h> +#ifdef __ANDROID__ +#include <fs_mgr.h> +#endif #include <liblp/liblp.h> using namespace android; @@ -37,7 +40,7 @@ static int usage(int /* argc */, char* argv[]) { "%s - command-line tool for dumping Android Logical Partition images.\n" "\n" "Usage:\n" - " %s [-s,--slot] file-or-device\n" + " %s [-s <SLOT#>|--slot=<SLOT#>] [FILE|DEVICE]\n" "\n" "Options:\n" " -s, --slot=N Slot number or suffix.\n", @@ -107,15 +110,22 @@ int main(int argc, char* argv[]) { } } - if (optind >= argc) { - return usage(argc, argv); - } - const char* file = argv[optind++]; + std::unique_ptr<LpMetadata> pt; + if (optind < argc) { + const char* file = argv[optind++]; - FileOrBlockDeviceOpener opener; - auto pt = ReadMetadata(opener, file, slot); - if (!pt && !IsBlockDevice(file)) { - pt = ReadFromImageFile(file); + FileOrBlockDeviceOpener opener; + pt = ReadMetadata(opener, file, slot); + if (!pt && !IsBlockDevice(file)) { + pt = ReadFromImageFile(file); + } + } else { +#ifdef __ANDROID__ + auto slot_number = SlotNumberForSlotSuffix(fs_mgr_get_slot_suffix()); + pt = ReadMetadata(fs_mgr_get_super_partition_name(), slot_number); +#else + return usage(argc, argv); +#endif } if (!pt) { fprintf(stderr, "Failed to read metadata.\n"); |