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 23 namespace Flashd { 24 class Partition { 25 public: Partition(const std::string & devName)26 explicit Partition(const std::string &devName) : devName_(devName) {} Partition(const std::string & devName,std::unique_ptr<FlashdWriter> writer)27 Partition(const std::string &devName, std::unique_ptr<FlashdWriter> writer) : devName_(devName), 28 writer_(std::move(writer)) {} ~Partition()29 ~Partition() {}; 30 int DoFlash(const uint8_t *buffer, int bufferSize) const; 31 int DoFormat() const; 32 int DoErase() const; 33 34 private: 35 uint64_t GetBlockDeviceSize(int fd) const; 36 37 std::string devName_ = ""; 38 std::unique_ptr<FlashdWriter> writer_ = nullptr; 39 }; 40 } 41 #endif