1 // 2 // Copyright (C) 2017 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_FILE_DESCRIPTOR_UTILS_H_ 18 #define UPDATE_ENGINE_PAYLOAD_CONSUMER_FILE_DESCRIPTOR_UTILS_H_ 19 20 #include <brillo/secure_blob.h> 21 22 #include "update_engine/payload_consumer/file_descriptor.h" 23 #include "update_engine/update_metadata.pb.h" 24 25 namespace chromeos_update_engine { 26 namespace fd_utils { 27 28 // Copy blocks from the |source| file to the |target| file and hashes the 29 // contents. The blocks to copy from the |source| to the |target| files are 30 // specified by the |src_extents| and |tgt_extents| list of Extents, which 31 // must have the same length in number of blocks. Stores the hash of the 32 // copied blocks in Blob pointed by |hash_out| if not null. The block size 33 // is passed as |block_size|. In case of error reading or writing, returns 34 // false and the value pointed by |hash_out| is undefined. 35 // The |source| and |target| files must be different, or otherwise |src_extents| 36 // and |tgt_extents| must not overlap. 37 bool CopyAndHashExtents( 38 FileDescriptorPtr source, 39 const google::protobuf::RepeatedPtrField<Extent>& src_extents, 40 FileDescriptorPtr target, 41 const google::protobuf::RepeatedPtrField<Extent>& tgt_extents, 42 uint64_t block_size, 43 brillo::Blob* hash_out); 44 45 // Reads blocks from |source| and calculates the hash. The blocks to read are 46 // specified by |extents|. Stores the hash in |hash_out| if it is not null. The 47 // block sizes are passed as |block_size|. In case of error reading, it returns 48 // false and the value pointed by |hash_out| is undefined. 49 bool ReadAndHashExtents( 50 FileDescriptorPtr source, 51 const google::protobuf::RepeatedPtrField<Extent>& extents, 52 uint64_t block_size, 53 brillo::Blob* hash_out); 54 55 } // namespace fd_utils 56 } // namespace chromeos_update_engine 57 58 #endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_FILE_DESCRIPTOR_UTILS_H_ 59