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

Commit c9c120e0 authored by Daniel Zheng's avatar Daniel Zheng Committed by Gerrit Code Review
Browse files

Merge "libsnapshot: Add Parser v3 + stub" into main

parents cb618c18 875df343
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -198,6 +198,7 @@ cc_library_static {
        "libsnapshot_cow/cow_format.cpp",
        "libsnapshot_cow/cow_reader.cpp",
        "libsnapshot_cow/parser_v2.cpp",
        "libsnapshot_cow/parser_v3.cpp",
        "libsnapshot_cow/snapshot_reader.cpp",
        "libsnapshot_cow/writer_base.cpp",
        "libsnapshot_cow/writer_v2.cpp",
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@

#include <android-base/unique_fd.h>
#include <libsnapshot/cow_format.h>
#include "parser_base.h"
#include <libsnapshot_cow/parser_base.h>

namespace android {
namespace snapshot {
+45 −0
Original line number Diff line number Diff line
// Copyright (C) 2023 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "parser_v3.h"

#include <android-base/file.h>
#include <android-base/logging.h>

#include <libsnapshot/cow_format.h>

namespace android {
namespace snapshot {

using android::base::borrowed_fd;

bool CowParserV3::Parse(borrowed_fd fd, const CowHeaderV3& header, std::optional<uint64_t> label) {
    LOG(ERROR) << "this function should never be called";
    if (fd.get() || sizeof(header) > 0 || label) return false;
    return false;
}

bool CowParserV3::ParseOps(android::base::borrowed_fd fd, std::optional<uint64_t> label) {
    LOG(ERROR) << "this function should never be called";
    if (fd.get() || label) return false;
    return false;
}

bool CowParserV3::Translate(TranslatedCowOps* out) {
    out->ops = ops_;
    out->header = header_;
    return true;
}

}  // namespace snapshot
}  // namespace android
+60 −0
Original line number Diff line number Diff line
// Copyright (C) 2023 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright (C) 2023 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once

#include <stdint.h>

#include <memory>
#include <optional>
#include <unordered_map>
#include <vector>

#include <android-base/unique_fd.h>
#include <libsnapshot/cow_format.h>
#include <libsnapshot_cow/parser_base.h>

namespace android {
namespace snapshot {

class CowParserV3 final : public CowParserBase {
  public:
    bool Parse(android::base::borrowed_fd fd, const CowHeaderV3& header,
               std::optional<uint64_t> label = {}) override;
    bool Translate(TranslatedCowOps* out) override;
    std::shared_ptr<std::unordered_map<uint64_t, uint64_t>> data_loc() const override {
        return nullptr;
    };

  private:
    bool ParseOps(android::base::borrowed_fd fd, std::optional<uint64_t> label);

    CowHeaderV3 header_ = {};
    std::shared_ptr<std::vector<CowOperationV3>> ops_;
};

}  // namespace snapshot
}  // namespace android