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_BLOCK_WRITER_H 17 #define UPDATER_BLOCK_WRITER_H 18 #include <cstdio> 19 #include <string> 20 #include <unistd.h> 21 #include "applypatch/block_set.h" 22 #include "applypatch/data_writer.h" 23 24 namespace updater { 25 class BlockWriter : public DataWriter { 26 public: 27 virtual bool Write(const uint8_t *addr, size_t len, WriteMode mode, const std::string &partitionName); ~BlockWriter()28 virtual ~BlockWriter() {} BlockWriter(int fd,BlockSet & bs)29 BlockWriter(int fd, BlockSet& bs) : fd_(fd), bs_(bs), totalWritten_(0), blockIndex_(0), 30 currentBlockLeft_(0) {} 31 size_t GetTotalWritten() const; 32 size_t GetBlocksSize() const; 33 bool IsWriteDone() const; 34 private: 35 BlockWriter(const BlockWriter&) = delete; 36 const BlockWriter& operator=(const BlockWriter&) = delete; 37 int fd_; 38 BlockSet bs_; 39 size_t totalWritten_; 40 // index of BlockPair in BlockSet 41 size_t blockIndex_; 42 size_t currentBlockLeft_; 43 }; 44 } // namespace updater 45 #endif // UPDATER_BLOCK_WRITER_H 46