1 //
2 // Copyright (C) 2021 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_PARTITION_WRITER_INTERFACE_H_
18 #define UPDATE_ENGINE_PARTITION_WRITER_INTERFACE_H_
19 
20 #include <cstdint>
21 #include <string>
22 
23 #include <brillo/secure_blob.h>
24 #include <gtest/gtest_prod.h>
25 
26 #include "update_engine/payload_consumer/install_plan.h"
27 #include "update_engine/update_metadata.pb.h"
28 
29 namespace chromeos_update_engine {
30 class PartitionWriterInterface {
31  public:
32   virtual ~PartitionWriterInterface() = default;
33 
34   // Perform necessary initialization work before InstallOperation can be
35   // applied to this partition
36   [[nodiscard]] virtual bool Init(const InstallPlan* install_plan,
37                                   bool source_may_exist,
38                                   size_t next_op_index) = 0;
39 
40   // |CheckpointUpdateProgress| will be called after SetNextOpIndex(), but it's
41   // optional. DeltaPerformer may or may not call this everytime an operation is
42   // applied.
43   //   |next_op_index| is index of next operation that should be applied.
44   // |next_op_index-1| is the last operation that is already applied.
45   virtual void CheckpointUpdateProgress(size_t next_op_index) = 0;
46 
47   // Close partition writer, when calling this function there's no guarantee
48   // that all |InstallOperations| are sent to |PartitionWriter|. This function
49   // will be called even if we are pausing/aborting the update.
50   virtual int Close() = 0;
51 
52   // These perform a specific type of operation and return true on success.
53   // |error| will be set if source hash mismatch, otherwise |error| might not be
54   // set even if it fails.
55   [[nodiscard]] virtual bool PerformReplaceOperation(
56       const InstallOperation& operation, const void* data, size_t count) = 0;
57   [[nodiscard]] virtual bool PerformZeroOrDiscardOperation(
58       const InstallOperation& operation) = 0;
59 
60   [[nodiscard]] virtual bool PerformSourceCopyOperation(
61       const InstallOperation& operation, ErrorCode* error) = 0;
62   [[nodiscard]] virtual bool PerformDiffOperation(
63       const InstallOperation& operation,
64       ErrorCode* error,
65       const void* data,
66       size_t count) = 0;
67 
68   // |DeltaPerformer| calls this when all Install Ops are sent to partition
69   // writer. No |Perform*Operation| methods will be called in the future, and
70   // the partition writer is expected to be closed soon.
71   [[nodiscard]] virtual bool FinishedInstallOps() = 0;
72 };
73 }  // namespace chromeos_update_engine
74 
75 #endif
76