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 #pragma once
15 
16 #include <stdint.h>
17 
18 #include <memory>
19 #include <optional>
20 #include <vector>
21 
22 #include <android-base/unique_fd.h>
23 #include <libsnapshot/cow_format.h>
24 #include <libsnapshot_cow/parser_base.h>
25 
26 namespace android {
27 namespace snapshot {
28 
29 class CowParserV2 final : public CowParserBase {
30   public:
31     bool Parse(android::base::borrowed_fd fd, const CowHeaderV3& header,
32                std::optional<uint64_t> label = {}) override;
33     bool Translate(TranslatedCowOps* out) override;
footer()34     std::optional<CowFooter> footer() const override { return footer_; }
35 
header()36     const CowHeader& header() const { return header_; }
get_v2ops()37     std::shared_ptr<std::vector<CowOperationV2>> get_v2ops() { return v2_ops_; }
38 
39   private:
40     bool ParseOps(android::base::borrowed_fd fd, std::optional<uint64_t> label);
41     std::shared_ptr<std::vector<CowOperationV2>> v2_ops_;
42     std::optional<CowFooter> footer_;
43 };
44 
45 }  // namespace snapshot
46 }  // namespace android
47