1 // Copyright (C) 2023 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // Copyright (C) 2023 The Android Open Source Project 15 // 16 // Licensed under the Apache License, Version 2.0 (the "License"); 17 // you may not use this file except in compliance with the License. 18 // You may obtain a copy of the License at 19 // 20 // http://www.apache.org/licenses/LICENSE-2.0 21 // 22 // Unless required by applicable law or agreed to in writing, software 23 // distributed under the License is distributed on an "AS IS" BASIS, 24 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 // See the License for the specific language governing permissions and 26 // limitations under the License. 27 #pragma once 28 29 #include <stdint.h> 30 31 #include <memory> 32 #include <optional> 33 #include <unordered_map> 34 #include <vector> 35 36 #include <android-base/unique_fd.h> 37 #include <libsnapshot/cow_format.h> 38 #include <libsnapshot_cow/parser_base.h> 39 40 namespace android { 41 namespace snapshot { 42 43 class CowParserV3 final : public CowParserBase { 44 public: 45 bool Parse(android::base::borrowed_fd fd, const CowHeaderV3& header, 46 std::optional<uint64_t> label = {}) override; 47 bool Translate(TranslatedCowOps* out) override; resume_points()48 std::shared_ptr<std::vector<ResumePoint>> resume_points() const { return resume_points_; } 49 50 private: 51 bool ParseOps(android::base::borrowed_fd fd, const uint32_t op_index); 52 std::optional<uint32_t> FindResumeOp(const uint64_t label); 53 CowHeaderV3 header_ = {}; 54 std::shared_ptr<std::vector<CowOperationV3>> ops_; 55 bool ReadResumeBuffer(android::base::borrowed_fd fd); 56 std::shared_ptr<std::vector<ResumePoint>> resume_points_; 57 }; 58 59 } // namespace snapshot 60 } // namespace android 61