Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d95a49f5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes I3968ff53,I0029838d

* changes:
  inspect_cow: Add -l option to show all ops
  inspect_cow: Add -o to view Sequence Data
parents fe657ea9 b7885099
Loading
Loading
Loading
Loading
+34 −4
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@
#include <stdio.h>
#include <unistd.h>

#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

#include <android-base/logging.h>
#include <android-base/unique_fd.h>
@@ -39,8 +41,10 @@ static void usage(void) {
    LOG(ERROR) << "Usage: inspect_cow [-sd] <COW_FILE>";
    LOG(ERROR) << "\t -s Run Silent";
    LOG(ERROR) << "\t -d Attempt to decompress";
    LOG(ERROR) << "\t -b Show data for failed decompress\n";
    LOG(ERROR) << "\t -m Show ops in reverse merge order\n";
    LOG(ERROR) << "\t -b Show data for failed decompress";
    LOG(ERROR) << "\t -l Show ops";
    LOG(ERROR) << "\t -m Show ops in reverse merge order";
    LOG(ERROR) << "\t -o Shows sequence op block order\n";
}

enum OpIter { Normal, RevMerge };
@@ -48,7 +52,9 @@ enum OpIter { Normal, RevMerge };
struct Options {
    bool silent;
    bool decompress;
    bool show_ops;
    bool show_bad;
    bool show_seq;
    OpIter iter_type;
};

@@ -137,7 +143,7 @@ static bool Inspect(const std::string& path, Options opt) {
    while (!iter->Done()) {
        const CowOperation& op = iter->Get();

        if (!opt.silent) std::cout << op << "\n";
        if (!opt.silent && opt.show_ops) std::cout << op << "\n";

        if (opt.decompress && op.type == kCowReplaceOp && op.compression != kCowCompressNone) {
            if (!reader.ReadData(op, &sink)) {
@@ -148,6 +154,24 @@ static bool Inspect(const std::string& path, Options opt) {
            sink.Reset();
        }

        if (op.type == kCowSequenceOp && opt.show_seq) {
            size_t read;
            std::vector<uint32_t> merge_op_blocks;
            size_t seq_len = op.data_length / sizeof(uint32_t);
            merge_op_blocks.resize(seq_len);
            if (!reader.GetRawBytes(op.source, merge_op_blocks.data(), op.data_length, &read)) {
                PLOG(ERROR) << "Failed to read sequence op!";
                return false;
            }
            if (!opt.silent) {
                std::cout << "Sequence for " << op << " is :\n";
                for (size_t i = 0; i < seq_len; i++) {
                    std::cout << std::setfill('0') << std::setw(6) << merge_op_blocks[i] << ", ";
                    if ((i + 1) % 10 == 0 || i + 1 == seq_len) std::cout << "\n";
                }
            }
        }

        iter->Next();
    }

@@ -164,7 +188,7 @@ int main(int argc, char** argv) {
    opt.decompress = false;
    opt.show_bad = false;
    opt.iter_type = android::snapshot::Normal;
    while ((ch = getopt(argc, argv, "sdbm")) != -1) {
    while ((ch = getopt(argc, argv, "sdbmol")) != -1) {
        switch (ch) {
            case 's':
                opt.silent = true;
@@ -178,6 +202,12 @@ int main(int argc, char** argv) {
            case 'm':
                opt.iter_type = android::snapshot::RevMerge;
                break;
            case 'o':
                opt.show_seq = true;
                break;
            case 'l':
                opt.show_ops = true;
                break;
            default:
                android::snapshot::usage();
        }