summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2020-12-30 00:54:40 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-12-30 00:54:40 +0000
commitcf0b935a076ac0064affe9800045f11fc1b2beec (patch)
treef3be1ac1e4df7b697fc02d1838a8fe0c3ca6a45e
parent588f732b917c3ae6c97effe3e12468f399d286e3 (diff)
parentff5f4cc7348e4e2e42b66e891fa4e24cbc1a8eca (diff)
Merge "libsnapshot: Add decompression check to Inspect_Cow" am: ff5f4cc734
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1533827 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I2b971727bf8b5cca77b42f1c8e646f62a88006ba
-rw-r--r--fs_mgr/libsnapshot/inspect_cow.cpp44
1 files changed, 39 insertions, 5 deletions
diff --git a/fs_mgr/libsnapshot/inspect_cow.cpp b/fs_mgr/libsnapshot/inspect_cow.cpp
index 5ad61f37d..453b5c61e 100644
--- a/fs_mgr/libsnapshot/inspect_cow.cpp
+++ b/fs_mgr/libsnapshot/inspect_cow.cpp
@@ -36,10 +36,30 @@ void MyLogger(android::base::LogId, android::base::LogSeverity severity, const c
}
static void usage(void) {
- LOG(ERROR) << "Usage: inspect_cow [-s] <COW_FILE>";
+ LOG(ERROR) << "Usage: inspect_cow [-sd] <COW_FILE>";
+ LOG(ERROR) << "\t -s Run Silent";
+ LOG(ERROR) << "\t -d Attempt to decompress\n";
}
-static bool Inspect(const std::string& path, bool silent) {
+// Sink that always appends to the end of a string.
+class StringSink : public IByteSink {
+ public:
+ void* GetBuffer(size_t requested, size_t* actual) override {
+ size_t old_size = stream_.size();
+ stream_.resize(old_size + requested, '\0');
+ *actual = requested;
+ return stream_.data() + old_size;
+ }
+ bool ReturnData(void*, size_t) override { return true; }
+ void Reset() { stream_.clear(); }
+
+ std::string& stream() { return stream_; }
+
+ private:
+ std::string stream_;
+};
+
+static bool Inspect(const std::string& path, bool silent, bool decompress) {
android::base::unique_fd fd(open(path.c_str(), O_RDONLY));
if (fd < 0) {
PLOG(ERROR) << "open failed: " << path;
@@ -76,15 +96,25 @@ static bool Inspect(const std::string& path, bool silent) {
}
auto iter = reader.GetOpIter();
+ StringSink sink;
+ bool success = true;
while (!iter->Done()) {
const CowOperation& op = iter->Get();
if (!silent) std::cout << op << "\n";
+ if (decompress && op.type == kCowReplaceOp && op.compression != kCowCompressNone) {
+ if (!reader.ReadData(op, &sink)) {
+ std::cerr << "Failed to decompress for :" << op << "\n";
+ success = false;
+ }
+ sink.Reset();
+ }
+
iter->Next();
}
- return true;
+ return success;
}
} // namespace snapshot
@@ -93,11 +123,15 @@ static bool Inspect(const std::string& path, bool silent) {
int main(int argc, char** argv) {
int ch;
bool silent = false;
- while ((ch = getopt(argc, argv, "s")) != -1) {
+ bool decompress = false;
+ while ((ch = getopt(argc, argv, "sd")) != -1) {
switch (ch) {
case 's':
silent = true;
break;
+ case 'd':
+ decompress = true;
+ break;
default:
android::snapshot::usage();
}
@@ -109,7 +143,7 @@ int main(int argc, char** argv) {
return 1;
}
- if (!android::snapshot::Inspect(argv[optind], silent)) {
+ if (!android::snapshot::Inspect(argv[optind], silent, decompress)) {
return 1;
}
return 0;