1 /*
2  * Copyright (c) 2024 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_COMPOSITE_PTABLE_H
17 #define UPDATER_COMPOSITE_PTABLE_H
18 
19 #include "ptable.h"
20 
21 namespace Updater {
22 class CompositePtable : public Ptable {
23     DISALLOW_COPY_MOVE(CompositePtable);
24 public:
25     CompositePtable() = default;
~CompositePtable()26     ~CompositePtable() override {}
27 
28     bool ParsePartitionFromBuffer(uint8_t *ptbImgBuffer, const uint32_t imgBufSize) override;
29     bool LoadPtableFromDevice() override;
30     bool WritePartitionTable() override;
31     bool EditPartitionBuf(uint8_t *imageBuf, uint64_t imgBufSize, std::vector<PtnInfo> &modifyList) override;
32     bool GetPtableImageBuffer(uint8_t *imageBuf, const uint32_t imgBufSize) override;
33     void AddChildPtable(std::unique_ptr<Ptable> child) override;
34 
35 private:
CheckBuff(const uint8_t * buf,const uint64_t size)36     bool CheckBuff(const uint8_t *buf, const uint64_t size)
37     {
38         return (buf != nullptr) && (size > 0);
39     }
40 
41     void AppendChildPtnInfo(const std::vector<PtnInfo> &ptnInfo);
42     std::vector<std::unique_ptr<Ptable>> childs_ {};
43 };
44 } // namespace Updater
45 #endif // UPDATER_COMPOSITE_PTABLE_H
46