diff options
author | David Anderson <dvander@google.com> | 2018-11-13 11:39:19 -0800 |
---|---|---|
committer | David Anderson <dvander@google.com> | 2018-11-13 11:41:57 -0800 |
commit | 8a403a824e30279ca55747f78a7ac338c4ffc10c (patch) | |
tree | 55012d49ba1f8eb2b4481f92f4c60d50fbf903fe /partition_tools | |
parent | 14a93639fd124abc8c100fb6f6c7a017236b05b1 (diff) | |
download | extras-8a403a824e30279ca55747f78a7ac338c4ffc10c.tar.gz |
lpdump: Allow reading local partition images.
PartitionOpener expects a partition name, but for debugging, lpdump
should be able to open a local file too.
Bug: N/A
Test: manual test
Change-Id: I85f6ce7f3508cf4343d89ea368309a6e960af938
Diffstat (limited to 'partition_tools')
-rw-r--r-- | partition_tools/lpdump.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/partition_tools/lpdump.cc b/partition_tools/lpdump.cc index e3689d23..8afb13e1 100644 --- a/partition_tools/lpdump.cc +++ b/partition_tools/lpdump.cc @@ -57,6 +57,18 @@ static bool IsBlockDevice(const char* file) { return !stat(file, &s) && S_ISBLK(s.st_mode); } +class FileOrBlockDeviceOpener final : public PartitionOpener { +public: + android::base::unique_fd Open(const std::string& path, int flags) const override { + // Try a local file first. + android::base::unique_fd fd(open(path.c_str(), flags)); + if (fd >= 0) { + return fd; + } + return PartitionOpener::Open(path, flags); + } +}; + int main(int argc, char* argv[]) { struct option options[] = { { "slot", required_argument, nullptr, 's' }, @@ -84,7 +96,8 @@ int main(int argc, char* argv[]) { } const char* file = argv[optind++]; - auto pt = ReadMetadata(file, slot); + FileOrBlockDeviceOpener opener; + auto pt = ReadMetadata(opener, file, slot); if (!pt && !IsBlockDevice(file)) { pt = ReadFromImageFile(file); } |