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_DATA_WRITER_H 17 #define UPDATER_DATA_WRITER_H 18 19 #include <cstdio> 20 #include <memory> 21 #include <string> 22 #include <unistd.h> 23 #include "updater_env.h" 24 25 namespace updater { 26 enum WriteMode : int { 27 WRITE_SPARSE = 1, 28 WRITE_RAW = 2, 29 WRITE_DECRYPT = 3, 30 WRITE_BLOCK = 4, 31 }; 32 33 class DataWriter { 34 public: 35 using DataWriterPtr = DataWriter *; 36 virtual bool Write(const uint8_t *addr, size_t len, WriteMode mode, const std::string &partitionName) = 0; 37 virtual int OpenPartition(const std::string &partitionName); ~DataWriter()38 virtual ~DataWriter() {} 39 static std::unique_ptr<DataWriter> CreateDataWriter(WriteMode mode, const std::string &partitionName, 40 UpdaterEnv *env); 41 static std::unique_ptr<DataWriter> CreateDataWriter(WriteMode mode, const std::string &partitionName); 42 static UpdaterEnv *GetUpdaterEnv(); 43 static void ReleaseDataWriter(std::unique_ptr<DataWriter> &writer); 44 private: 45 static UpdaterEnv *env_; 46 }; 47 48 // Maybe we should read sector size from flash. 49 #define DEFAULT_SECTOR_SIZE (512) 50 } // updater 51 #endif // UPDATER_DATA_WRITER_H 52