• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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  */
15 
16 #ifndef UPDATER_UPDATE_IMAGE_BLOCK_H
17 #define UPDATER_UPDATE_IMAGE_BLOCK_H
18 #include "pkg_manager.h"
19 #include "script_instruction.h"
20 #include "script_manager.h"
21 
22 namespace Updater {
23 struct UpdateBlockInfo {
24     std::string partitionName;
25     std::string transferName;
26     std::string newDataName;
27     std::string patchDataName;
28     std::string devPath;
29 };
30 
31 class UScriptInstructionBlockUpdate : public Uscript::UScriptInstruction {
32 public:
UScriptInstructionBlockUpdate()33     UScriptInstructionBlockUpdate() {}
~UScriptInstructionBlockUpdate()34     virtual ~UScriptInstructionBlockUpdate() {}
35     int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override;
36 };
37 
38 class UScriptInstructionBlockCheck : public Uscript::UScriptInstruction {
39 public:
UScriptInstructionBlockCheck()40     UScriptInstructionBlockCheck() {}
~UScriptInstructionBlockCheck()41     virtual ~UScriptInstructionBlockCheck() {}
42     int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override;
43 private:
44     bool ExecReadBlockInfo(const std::string &devPath, Uscript::UScriptContext &context,
45         time_t &mountTime, uint16_t &mountCount);
46 };
47 
48 class UScriptInstructionShaCheck : public Uscript::UScriptInstruction {
49 public:
50     struct ShaInfo {
51         std::string blockPairs {};
52         std::string contrastSha {};
53         std::string targetPairs {};
54         std::string targetSha {};
55     };
UScriptInstructionShaCheck()56     UScriptInstructionShaCheck() {}
~UScriptInstructionShaCheck()57     virtual ~UScriptInstructionShaCheck() {}
58     int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override;
59 private:
60     int ExecReadShaInfo(Uscript::UScriptEnv &env, const std::string &devPath, const ShaInfo &shaInfo,
61         const std::string &partitionName);
62     int32_t DoBlocksVerify(Uscript::UScriptEnv &env, const std::string &partitionName, const std::string &devPath);
63     void PrintAbnormalBlockHash(const std::string &devPath, const std::string &blockPairs);
64     std::string CalculateBlockSha(const std::string &devPath, const std::string &blockPairs);
65     int32_t SetShaInfo(Uscript::UScriptContext &context, ShaInfo &shaInfo);
66     bool IsTargetShaDiff(const std::string &devPath, const ShaInfo &shaInfo);
67 };
68 
69 #ifdef __cplusplus
70 #if __cplusplus
71 extern "C" {
72 #endif
73 #endif /* __cplusplus */
74 void GetWriteDevPath(const std::string &path, [[maybe_unused]]const std::string &partitionName,
75                      std::string &devPath);
76 void SyncWriteDevPath(int fd, [[maybe_unused]] const std::string &partitionName);
77 #ifdef __cplusplus
78 #if __cplusplus
79 }
80 #endif
81 #endif /* __cplusplus */
82 }
83 
84 #endif // UPDATER_UPDATE_IMAGE_BLOCK_H
85