diff options
author | Alex Deymo <deymo@google.com> | 2016-11-04 15:49:53 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-08-31 14:19:54 -0700 |
commit | 21ec92f9356a7f486ba7ce017b9aa557323e7050 (patch) | |
tree | 9f1163923dac3114158e769a925d22ac950db2d4 /payload_consumer/file_descriptor_utils.h | |
parent | 69583ba50b96d51c7206e834ff165a871c7f2ffd (diff) |
Move extent copy and hash logic to a new file.
The SOURCE_COPY operation used to copy the source blocks one by one to
the target partition. This process is sub-optimal if there are several
consecutive blocks. This patch moves this copy and hash logic to a new
file and adds several unittests for it. The new logic copies in chunks
of up to 1MiB when the source and target data is contiguous.
BUG=b:34284069
TEST=Added unittests.
Change-Id: I9ed52b429a54a2b4d6edaba051284b7dcd8a9525
(cherry picked from commit a48f630400429ca010c5462967607985f2ffa7e4)
Reviewed-on: https://chromium-review.googlesource.com/641958
Commit-Ready: Amin Hassani <ahassani@chromium.org>
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Sen Jiang <senj@chromium.org>
Diffstat (limited to 'payload_consumer/file_descriptor_utils.h')
-rw-r--r-- | payload_consumer/file_descriptor_utils.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/payload_consumer/file_descriptor_utils.h b/payload_consumer/file_descriptor_utils.h new file mode 100644 index 00000000..b73defbd --- /dev/null +++ b/payload_consumer/file_descriptor_utils.h @@ -0,0 +1,50 @@ +// +// Copyright (C) 2017 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef UPDATE_ENGINE_PAYLOAD_CONSUMER_FILE_DESCRIPTOR_UTILS_H_ +#define UPDATE_ENGINE_PAYLOAD_CONSUMER_FILE_DESCRIPTOR_UTILS_H_ + +#include <vector> + +#include <brillo/secure_blob.h> + +#include "update_engine/payload_consumer/file_descriptor.h" +#include "update_engine/update_metadata.pb.h" + +namespace chromeos_update_engine { +namespace fd_utils { + +// Copy a blocks from the |source| file to the |target| file and hash the +// contents. The blocks to copy from the |source| to the |target| files are +// specified by the |src_extents| and |tgt_extents| list of Extents, which +// must have the same length in number of blocks. Stores the hash of the +// copied blocks in Blob pointed by |hash_out| if not null. The block size +// is passed as |block_size|. In case of error reading or writing, returns +// false and the value pointed by |hash_out| is undefined. +// The |source| and |target| files must be different, or otherwise |src_extents| +// and |tgt_extents| must not overlap. +bool CopyAndHashExtents( + FileDescriptorPtr source, + const google::protobuf::RepeatedPtrField<Extent>& src_extents, + FileDescriptorPtr target, + const google::protobuf::RepeatedPtrField<Extent>& tgt_extents, + uint32_t block_size, + brillo::Blob* hash_out); + +} // namespace fd_utils +} // namespace chromeos_update_engine + +#endif // UPDATE_ENGINE_PAYLOAD_CONSUMER_FILE_DESCRIPTOR_UTILS_H_ |