• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2020 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef UPDATE_ENGINE_VABC_PARTITION_WRITER_H_
18 #define UPDATE_ENGINE_VABC_PARTITION_WRITER_H_
19 
20 #include <memory>
21 #include <vector>
22 
23 #include <libsnapshot/snapshot_writer.h>
24 
25 #include "update_engine/common/cow_operation_convert.h"
26 #include "update_engine/payload_consumer/install_plan.h"
27 #include "update_engine/payload_consumer/partition_writer.h"
28 
29 namespace chromeos_update_engine {
30 class VABCPartitionWriter final : public PartitionWriter {
31  public:
32   using PartitionWriter::PartitionWriter;
33   [[nodiscard]] bool Init(const InstallPlan* install_plan,
34                           bool source_may_exist,
35                           size_t next_op_index) override;
36   ~VABCPartitionWriter() override;
37 
38   [[nodiscard]] std::unique_ptr<ExtentWriter> CreateBaseExtentWriter() override;
39 
40   // Only ZERO and SOURCE_COPY InstallOperations are treated special by VABC
41   // Partition Writer. These operations correspond to COW_ZERO and COW_COPY. All
42   // other operations just get converted to COW_REPLACE.
43   [[nodiscard]] bool PerformZeroOrDiscardOperation(
44       const InstallOperation& operation) override;
45   [[nodiscard]] bool PerformSourceCopyOperation(
46       const InstallOperation& operation, ErrorCode* error) override;
47 
48   void CheckpointUpdateProgress(size_t next_op_index) override;
49 
50   static bool WriteAllCowOps(size_t block_size,
51                              const std::vector<CowOperation>& converted,
52                              android::snapshot::ICowWriter* cow_writer,
53                              FileDescriptorPtr source_fd);
54 
55   [[nodiscard]] bool FinishedInstallOps() override;
56 
57  private:
58   std::unique_ptr<android::snapshot::ISnapshotWriter> cow_writer_;
59 };
60 
61 }  // namespace chromeos_update_engine
62 
63 #endif
64