• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 FLASHD_PARTITION_H
17 #define FLASHD_PARTITION_H
18 
19 #include <string>
20 
21 #include "image_writer/image_writer.h"
22 #ifdef UPDATER_USE_PTABLE
23 #include "ptable.h"
24 #endif
25 
26 namespace Flashd {
27 class Partition {
28 public:
Partition(const std::string & devName)29     explicit Partition(const std::string &devName) : devName_(devName) {}
Partition(const std::string & devName,std::unique_ptr<FlashdWriter> writer)30     Partition(const std::string &devName, std::unique_ptr<FlashdWriter> writer) : devName_(devName),
31         writer_(std::move(writer)) {}
~Partition()32     ~Partition() {};
33     int DoFlash(const uint8_t *buffer, int bufferSize) const;
34     int DoFormat() const;
35     int DoErase() const;
36     int DoErasePartition() const;
37 #ifdef UPDATER_USE_PTABLE
38     int DoEraseExt(const Ptable::PtnInfo &ptnInfo) const;
39 #endif
40 
41 #ifdef UPDATER_UT
42     uint64_t GetBlockDeviceSize(int fd) const;
43 #else
44 private:
45     uint64_t GetBlockDeviceSize(int fd) const;
46 #endif
47 private:
48     std::string devName_ = "";
49     std::unique_ptr<FlashdWriter> writer_ = nullptr;
50 };
51 }
52 #endif