blob: 8f5b826bc495aa5265157bf7ea9937ed5182c05c [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2015 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//
Alex Deymo14158572015-06-13 03:37:08 -070016
17#include "update_engine/payload_generator/payload_file.h"
18
Alex Deymo6f20dd42015-08-18 16:42:46 -070019#include <endian.h>
20
Alex Deymo14158572015-06-13 03:37:08 -070021#include <algorithm>
Simon Glass3d32f852017-06-28 16:38:11 -060022#include <map>
Sen Jiang3a4dfac2018-08-30 16:57:38 -070023#include <utility>
Simon Glass3d32f852017-06-28 16:38:11 -060024
25#include <base/strings/stringprintf.h>
Alex Deymo14158572015-06-13 03:37:08 -070026
Alex Deymo39910dc2015-11-09 17:04:30 -080027#include "update_engine/common/hash_calculator.h"
Kelvin Zhangdeb34452021-01-21 11:54:36 -050028#include "update_engine/common/utils.h"
Alex Deymo39910dc2015-11-09 17:04:30 -080029#include "update_engine/payload_consumer/file_writer.h"
30#include "update_engine/payload_consumer/payload_constants.h"
Alex Deymo14158572015-06-13 03:37:08 -070031#include "update_engine/payload_generator/annotated_operation.h"
Alex Deymo14158572015-06-13 03:37:08 -070032#include "update_engine/payload_generator/delta_diff_utils.h"
33#include "update_engine/payload_generator/payload_signer.h"
34
35using std::string;
36using std::vector;
37
38namespace chromeos_update_engine {
39
40namespace {
41
Alex Deymo14158572015-06-13 03:37:08 -070042struct DeltaObject {
43 DeltaObject(const string& in_name, const int in_type, const off_t in_size)
Amin Hassani232f8f92019-01-14 16:15:31 -080044 : name(in_name), type(in_type), size(in_size) {}
45 bool operator<(const DeltaObject& object) const {
Alex Deymo14158572015-06-13 03:37:08 -070046 return (size != object.size) ? (size < object.size) : (name < object.name);
47 }
48 string name;
49 int type;
50 off_t size;
51};
52
53// Writes the uint64_t passed in in host-endian to the file as big-endian.
54// Returns true on success.
55bool WriteUint64AsBigEndian(FileWriter* writer, const uint64_t value) {
56 uint64_t value_be = htobe64(value);
57 TEST_AND_RETURN_FALSE(writer->Write(&value_be, sizeof(value_be)));
58 return true;
59}
60
61} // namespace
62
Alex Deymo14158572015-06-13 03:37:08 -070063bool PayloadFile::Init(const PayloadGenerationConfig& config) {
Alex Deymoa4073ef2016-03-22 23:40:53 -070064 TEST_AND_RETURN_FALSE(config.version.Validate());
65 major_version_ = config.version.major;
66 manifest_.set_minor_version(config.version.minor);
Alex Deymo14158572015-06-13 03:37:08 -070067 manifest_.set_block_size(config.block_size);
Sen Jiang5011df62017-06-28 17:13:19 -070068 manifest_.set_max_timestamp(config.max_timestamp);
Kelvin Zhangda070182022-09-02 17:34:37 +000069 if (!config.security_patch_level.empty()) {
70 manifest_.set_security_patch_level(config.security_patch_level);
71 }
Yifan Hong398cb542018-10-18 11:29:40 -070072
Amin Hassani55c75412019-10-07 11:20:39 -070073 if (config.target.dynamic_partition_metadata != nullptr)
74 *(manifest_.mutable_dynamic_partition_metadata()) =
75 *(config.target.dynamic_partition_metadata);
Yifan Hong398cb542018-10-18 11:29:40 -070076
Tianjief5baff42020-07-17 21:43:22 -070077 if (config.is_partial_update) {
78 manifest_.set_partial_update(true);
79 }
Kelvin Zhangdeb34452021-01-21 11:54:36 -050080
81 if (!config.apex_info_file.empty()) {
82 ApexMetadata apex_metadata;
83 int fd = open(config.apex_info_file.c_str(), O_RDONLY);
84 if (fd < 0) {
85 PLOG(FATAL) << "Failed to open " << config.apex_info_file << " for read.";
86 }
87 ScopedFdCloser closer{&fd};
88 CHECK(apex_metadata.ParseFromFileDescriptor(fd));
89 if (apex_metadata.apex_info_size() > 0) {
90 *manifest_.mutable_apex_info() =
91 std::move(*apex_metadata.mutable_apex_info());
92 }
93 }
Alex Deymo14158572015-06-13 03:37:08 -070094 return true;
95}
96
Sen Jiangb9ef4912015-09-21 15:06:13 -070097bool PayloadFile::AddPartition(const PartitionConfig& old_conf,
98 const PartitionConfig& new_conf,
Tianjiee9156ec2020-08-11 11:13:54 -070099 vector<AnnotatedOperation> aops,
Kelvin Zhang7a265752020-10-29 15:51:35 -0400100 vector<CowMergeOperation> merge_sequence,
Daniel Zheng09d022d2023-11-13 15:30:03 -0800101 const android::snapshot::CowSizeInfo& cow_info) {
Sen Jiangb9ef4912015-09-21 15:06:13 -0700102 Partition part;
103 part.name = new_conf.name;
Kelvin Zhangb0b9c202020-07-24 16:02:09 -0400104 part.aops = std::move(aops);
Tianjiee9156ec2020-08-11 11:13:54 -0700105 part.cow_merge_sequence = std::move(merge_sequence);
Sen Jiang05feee02015-11-11 15:59:49 -0800106 part.postinstall = new_conf.postinstall;
Sen Jiang3a4dfac2018-08-30 16:57:38 -0700107 part.verity = new_conf.verity;
Kelvin Zhang1f496422020-08-11 17:18:23 -0400108 part.version = new_conf.version;
Daniel Zheng09d022d2023-11-13 15:30:03 -0800109 part.cow_info = cow_info;
Sen Jiangb9ef4912015-09-21 15:06:13 -0700110 // Initialize the PartitionInfo objects if present.
111 if (!old_conf.path.empty())
Amin Hassani232f8f92019-01-14 16:15:31 -0800112 TEST_AND_RETURN_FALSE(
113 diff_utils::InitializePartitionInfo(old_conf, &part.old_info));
114 TEST_AND_RETURN_FALSE(
115 diff_utils::InitializePartitionInfo(new_conf, &part.new_info));
Sen Jiangb9ef4912015-09-21 15:06:13 -0700116 part_vec_.push_back(std::move(part));
Sen Jiang70a6ab02015-08-28 13:23:27 -0700117 return true;
Alex Deymo14158572015-06-13 03:37:08 -0700118}
119
120bool PayloadFile::WritePayload(const string& payload_file,
121 const string& data_blobs_path,
122 const string& private_key_path,
Sen Jiangaef1c6f2015-10-07 10:05:32 -0700123 uint64_t* metadata_size_out) {
Alex Deymo14158572015-06-13 03:37:08 -0700124 // Reorder the data blobs with the manifest_.
Amin Hassanied03b442020-10-26 17:21:29 -0700125 ScopedTempFile ordered_blobs_file("CrAU_temp_data.ordered.XXXXXX");
126 TEST_AND_RETURN_FALSE(
127 ReorderDataBlobs(data_blobs_path, ordered_blobs_file.path()));
Alex Deymo14158572015-06-13 03:37:08 -0700128
Sen Jiang70a6ab02015-08-28 13:23:27 -0700129 // Check that install op blobs are in order.
130 uint64_t next_blob_offset = 0;
Sen Jiangb9ef4912015-09-21 15:06:13 -0700131 for (const auto& part : part_vec_) {
132 for (const auto& aop : part.aops) {
Sen Jiang70a6ab02015-08-28 13:23:27 -0700133 if (!aop.op.has_data_offset())
134 continue;
135 if (aop.op.data_offset() != next_blob_offset) {
Amin Hassani232f8f92019-01-14 16:15:31 -0800136 LOG(FATAL) << "bad blob offset! " << aop.op.data_offset()
137 << " != " << next_blob_offset;
Alex Deymo14158572015-06-13 03:37:08 -0700138 }
Sen Jiang70a6ab02015-08-28 13:23:27 -0700139 next_blob_offset += aop.op.data_length();
Alex Deymo14158572015-06-13 03:37:08 -0700140 }
141 }
142
Sen Jiangb9ef4912015-09-21 15:06:13 -0700143 // Copy the operations and partition info from the part_vec_ to the manifest.
Sen Jiang70a6ab02015-08-28 13:23:27 -0700144 manifest_.clear_partitions();
Sen Jiangb9ef4912015-09-21 15:06:13 -0700145 for (const auto& part : part_vec_) {
Amin Hassani55c75412019-10-07 11:20:39 -0700146 PartitionUpdate* partition = manifest_.add_partitions();
147 partition->set_partition_name(part.name);
Kelvin Zhang1f496422020-08-11 17:18:23 -0400148 if (!part.version.empty()) {
149 partition->set_version(part.version);
150 }
Daniel Zheng09d022d2023-11-13 15:30:03 -0800151 if (part.cow_info.cow_size > 0) {
152 partition->set_estimate_cow_size(part.cow_info.cow_size);
153 }
154 if (part.cow_info.op_count_max > 0) {
155 partition->set_estimate_op_count_max(part.cow_info.op_count_max);
Kelvin Zhang7a265752020-10-29 15:51:35 -0400156 }
Amin Hassani55c75412019-10-07 11:20:39 -0700157 if (part.postinstall.run) {
158 partition->set_run_postinstall(true);
159 if (!part.postinstall.path.empty())
160 partition->set_postinstall_path(part.postinstall.path);
161 if (!part.postinstall.filesystem_type.empty())
162 partition->set_filesystem_type(part.postinstall.filesystem_type);
163 partition->set_postinstall_optional(part.postinstall.optional);
164 }
165 if (!part.verity.IsEmpty()) {
166 if (part.verity.hash_tree_extent.num_blocks() != 0) {
167 *partition->mutable_hash_tree_data_extent() =
168 part.verity.hash_tree_data_extent;
169 *partition->mutable_hash_tree_extent() = part.verity.hash_tree_extent;
170 partition->set_hash_tree_algorithm(part.verity.hash_tree_algorithm);
171 if (!part.verity.hash_tree_salt.empty())
172 partition->set_hash_tree_salt(part.verity.hash_tree_salt.data(),
173 part.verity.hash_tree_salt.size());
Sen Jiang05feee02015-11-11 15:59:49 -0800174 }
Amin Hassani55c75412019-10-07 11:20:39 -0700175 if (part.verity.fec_extent.num_blocks() != 0) {
176 *partition->mutable_fec_data_extent() = part.verity.fec_data_extent;
177 *partition->mutable_fec_extent() = part.verity.fec_extent;
178 partition->set_fec_roots(part.verity.fec_roots);
Alex Deymo14158572015-06-13 03:37:08 -0700179 }
180 }
Amin Hassani55c75412019-10-07 11:20:39 -0700181 for (const AnnotatedOperation& aop : part.aops) {
182 *partition->add_operations() = aop.op;
183 }
Tianjiee9156ec2020-08-11 11:13:54 -0700184 for (const auto& merge_op : part.cow_merge_sequence) {
185 *partition->add_merge_operations() = merge_op;
186 }
187
Amin Hassani55c75412019-10-07 11:20:39 -0700188 if (part.old_info.has_size() || part.old_info.has_hash())
189 *(partition->mutable_old_partition_info()) = part.old_info;
190 if (part.new_info.has_size() || part.new_info.has_hash())
191 *(partition->mutable_new_partition_info()) = part.new_info;
Alex Deymo14158572015-06-13 03:37:08 -0700192 }
193
194 // Signatures appear at the end of the blobs. Note the offset in the
Amin Hassani55c75412019-10-07 11:20:39 -0700195 // |manifest_|.
Sen Jiang644f6182015-10-06 16:45:57 -0700196 uint64_t signature_blob_length = 0;
Alex Deymo14158572015-06-13 03:37:08 -0700197 if (!private_key_path.empty()) {
Amin Hassani232f8f92019-01-14 16:15:31 -0800198 TEST_AND_RETURN_FALSE(PayloadSigner::SignatureBlobLength(
Sen Jiang9b2f1782019-01-24 14:27:50 -0800199 {private_key_path}, &signature_blob_length));
Sen Jiang3e728fe2015-11-05 11:37:23 -0800200 PayloadSigner::AddSignatureToManifest(
Kelvin Zhangb0b9c202020-07-24 16:02:09 -0400201 next_blob_offset, signature_blob_length, &manifest_);
Alex Deymo14158572015-06-13 03:37:08 -0700202 }
Kelvin Zhangf041a9d2021-10-06 18:58:39 -0700203 WritePayload(payload_file,
204 ordered_blobs_file.path(),
205 private_key_path,
206 major_version_,
207 manifest_,
208 metadata_size_out);
Alex Deymo14158572015-06-13 03:37:08 -0700209
Kelvin Zhangf041a9d2021-10-06 18:58:39 -0700210 ReportPayloadUsage(*metadata_size_out);
211 return true;
212}
Alex Deymo14158572015-06-13 03:37:08 -0700213
Kelvin Zhangf041a9d2021-10-06 18:58:39 -0700214bool PayloadFile::WritePayload(const std::string& payload_file,
215 const std::string& ordered_blobs_file,
216 const std::string& private_key_path,
217 uint64_t major_version_,
218 const DeltaArchiveManifest& manifest,
219 uint64_t* metadata_size_out) {
220 std::string serialized_manifest;
221
222 TEST_AND_RETURN_FALSE(manifest.SerializeToString(&serialized_manifest));
Sen Jiangaef1c6f2015-10-07 10:05:32 -0700223 uint64_t metadata_size =
224 sizeof(kDeltaMagic) + 2 * sizeof(uint64_t) + serialized_manifest.size();
Alex Deymo14158572015-06-13 03:37:08 -0700225 LOG(INFO) << "Writing final delta file header...";
226 DirectFileWriter writer;
227 TEST_AND_RETURN_FALSE_ERRNO(writer.Open(payload_file.c_str(),
228 O_WRONLY | O_CREAT | O_TRUNC,
229 0644) == 0);
230 ScopedFileWriterCloser writer_closer(&writer);
231
232 // Write header
Alex Deymo95699a92016-12-08 19:43:01 -0800233 TEST_AND_RETURN_FALSE_ERRNO(writer.Write(kDeltaMagic, sizeof(kDeltaMagic)));
Alex Deymo14158572015-06-13 03:37:08 -0700234
235 // Write major version number
Sen Jiang46e9b172015-08-31 14:11:01 -0700236 TEST_AND_RETURN_FALSE(WriteUint64AsBigEndian(&writer, major_version_));
Alex Deymo14158572015-06-13 03:37:08 -0700237
238 // Write protobuf length
Amin Hassani232f8f92019-01-14 16:15:31 -0800239 TEST_AND_RETURN_FALSE(
240 WriteUint64AsBigEndian(&writer, serialized_manifest.size()));
Alex Deymo14158572015-06-13 03:37:08 -0700241
Amin Hassani55c75412019-10-07 11:20:39 -0700242 // Metadata signature has the same size as payload signature, because they
243 // are both the same kind of signature for the same kind of hash.
Kelvin Zhangf041a9d2021-10-06 18:58:39 -0700244 const auto signature_blob_length = manifest.signatures_size();
245 // Adding a new scope here so code down below can't access
246 // metadata_signature_size, as the integer is in big endian, not host
247 // endianess.
248 {
249 const uint32_t metadata_signature_size = htobe32(signature_blob_length);
250 TEST_AND_RETURN_FALSE_ERRNO(writer.Write(&metadata_signature_size,
251 sizeof(metadata_signature_size)));
252 metadata_size += sizeof(metadata_signature_size);
253 }
Sen Jiangf4bb3e62015-09-29 11:12:09 -0700254
Alex Deymo14158572015-06-13 03:37:08 -0700255 // Write protobuf
256 LOG(INFO) << "Writing final delta file protobuf... "
257 << serialized_manifest.size();
Alex Deymo95699a92016-12-08 19:43:01 -0800258 TEST_AND_RETURN_FALSE_ERRNO(
259 writer.Write(serialized_manifest.data(), serialized_manifest.size()));
Alex Deymo14158572015-06-13 03:37:08 -0700260
Sen Jiang644f6182015-10-06 16:45:57 -0700261 // Write metadata signature blob.
Amin Hassani55c75412019-10-07 11:20:39 -0700262 if (!private_key_path.empty()) {
Sen Jiang9b2f1782019-01-24 14:27:50 -0800263 brillo::Blob metadata_hash;
Amin Hassani232f8f92019-01-14 16:15:31 -0800264 TEST_AND_RETURN_FALSE(HashCalculator::RawHashOfFile(
265 payload_file, metadata_size, &metadata_hash));
Sen Jiang9b2f1782019-01-24 14:27:50 -0800266 string metadata_signature;
267 TEST_AND_RETURN_FALSE(PayloadSigner::SignHashWithKeys(
268 metadata_hash, {private_key_path}, &metadata_signature));
Alex Deymo95699a92016-12-08 19:43:01 -0800269 TEST_AND_RETURN_FALSE_ERRNO(
270 writer.Write(metadata_signature.data(), metadata_signature.size()));
Sen Jiang644f6182015-10-06 16:45:57 -0700271 }
272
Amin Hassani55c75412019-10-07 11:20:39 -0700273 // Append the data blobs.
Alex Deymo14158572015-06-13 03:37:08 -0700274 LOG(INFO) << "Writing final delta file data blobs...";
Kelvin Zhangf041a9d2021-10-06 18:58:39 -0700275 int blobs_fd = open(ordered_blobs_file.c_str(), O_RDONLY, 0);
Alex Deymo14158572015-06-13 03:37:08 -0700276 ScopedFdCloser blobs_fd_closer(&blobs_fd);
277 TEST_AND_RETURN_FALSE(blobs_fd >= 0);
278 for (;;) {
279 vector<char> buf(1024 * 1024);
280 ssize_t rc = read(blobs_fd, buf.data(), buf.size());
281 if (0 == rc) {
282 // EOF
283 break;
284 }
285 TEST_AND_RETURN_FALSE_ERRNO(rc > 0);
Alex Deymo95699a92016-12-08 19:43:01 -0800286 TEST_AND_RETURN_FALSE_ERRNO(writer.Write(buf.data(), rc));
Alex Deymo14158572015-06-13 03:37:08 -0700287 }
Sen Jiang644f6182015-10-06 16:45:57 -0700288 // Write payload signature blob.
Alex Deymo14158572015-06-13 03:37:08 -0700289 if (!private_key_path.empty()) {
290 LOG(INFO) << "Signing the update...";
Sen Jiang9b2f1782019-01-24 14:27:50 -0800291 string signature;
Alex Deymo14158572015-06-13 03:37:08 -0700292 TEST_AND_RETURN_FALSE(PayloadSigner::SignPayload(
293 payload_file,
Sen Jiang9b2f1782019-01-24 14:27:50 -0800294 {private_key_path},
Sen Jiang720df3e2015-10-01 13:10:44 -0700295 metadata_size,
Kelvin Zhangf041a9d2021-10-06 18:58:39 -0700296 signature_blob_length,
297 metadata_size + signature_blob_length + manifest.signatures_offset(),
Sen Jiang9b2f1782019-01-24 14:27:50 -0800298 &signature));
Alex Deymo95699a92016-12-08 19:43:01 -0800299 TEST_AND_RETURN_FALSE_ERRNO(
Sen Jiang9b2f1782019-01-24 14:27:50 -0800300 writer.Write(signature.data(), signature.size()));
Alex Deymo14158572015-06-13 03:37:08 -0700301 }
Kelvin Zhangf041a9d2021-10-06 18:58:39 -0700302 if (metadata_size_out) {
303 *metadata_size_out = metadata_size;
304 }
Alex Deymo14158572015-06-13 03:37:08 -0700305 return true;
306}
307
Amin Hassani232f8f92019-01-14 16:15:31 -0800308bool PayloadFile::ReorderDataBlobs(const string& data_blobs_path,
309 const string& new_data_blobs_path) {
Alex Deymo14158572015-06-13 03:37:08 -0700310 int in_fd = open(data_blobs_path.c_str(), O_RDONLY, 0);
311 TEST_AND_RETURN_FALSE_ERRNO(in_fd >= 0);
312 ScopedFdCloser in_fd_closer(&in_fd);
313
314 DirectFileWriter writer;
Alex Deymo95699a92016-12-08 19:43:01 -0800315 int rc = writer.Open(
316 new_data_blobs_path.c_str(), O_WRONLY | O_TRUNC | O_CREAT, 0644);
317 if (rc != 0) {
318 PLOG(ERROR) << "Error creating " << new_data_blobs_path;
319 return false;
320 }
Alex Deymo14158572015-06-13 03:37:08 -0700321 ScopedFileWriterCloser writer_closer(&writer);
322 uint64_t out_file_size = 0;
323
Alex Deymoa4073ef2016-03-22 23:40:53 -0700324 for (auto& part : part_vec_) {
Sen Jiangb9ef4912015-09-21 15:06:13 -0700325 for (AnnotatedOperation& aop : part.aops) {
Alex Deymo14158572015-06-13 03:37:08 -0700326 if (!aop.op.has_data_offset())
327 continue;
328 CHECK(aop.op.has_data_length());
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700329 brillo::Blob buf(aop.op.data_length());
Alex Deymo14158572015-06-13 03:37:08 -0700330 ssize_t rc = pread(in_fd, buf.data(), buf.size(), aop.op.data_offset());
331 TEST_AND_RETURN_FALSE(rc == static_cast<ssize_t>(buf.size()));
332
333 // Add the hash of the data blobs for this operation
334 TEST_AND_RETURN_FALSE(AddOperationHash(&aop.op, buf));
335
336 aop.op.set_data_offset(out_file_size);
Alex Deymo95699a92016-12-08 19:43:01 -0800337 TEST_AND_RETURN_FALSE_ERRNO(writer.Write(buf.data(), buf.size()));
Alex Deymo14158572015-06-13 03:37:08 -0700338 out_file_size += buf.size();
339 }
340 }
341 return true;
342}
343
Alex Deymoa12ee112015-08-12 22:19:32 -0700344bool PayloadFile::AddOperationHash(InstallOperation* op,
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700345 const brillo::Blob& buf) {
Sen Jiang2703ef42017-03-16 13:36:21 -0700346 brillo::Blob hash;
347 TEST_AND_RETURN_FALSE(HashCalculator::RawHashOfData(buf, &hash));
Alex Deymo14158572015-06-13 03:37:08 -0700348 op->set_data_sha256_hash(hash.data(), hash.size());
349 return true;
350}
351
352void PayloadFile::ReportPayloadUsage(uint64_t metadata_size) const {
Simon Glass3d32f852017-06-28 16:38:11 -0600353 std::map<DeltaObject, int> object_counts;
Alex Deymo14158572015-06-13 03:37:08 -0700354 off_t total_size = 0;
Sen Jiangf23bf922018-11-01 18:26:07 -0700355 int total_op = 0;
Alex Deymo14158572015-06-13 03:37:08 -0700356
Sen Jiangb9ef4912015-09-21 15:06:13 -0700357 for (const auto& part : part_vec_) {
Sen Jianga91195d2018-10-25 15:15:38 -0700358 string part_prefix = "<" + part.name + ">:";
Sen Jiangb9ef4912015-09-21 15:06:13 -0700359 for (const AnnotatedOperation& aop : part.aops) {
Sen Jianga91195d2018-10-25 15:15:38 -0700360 DeltaObject delta(
361 part_prefix + aop.name, aop.op.type(), aop.op.data_length());
Simon Glass3d32f852017-06-28 16:38:11 -0600362 object_counts[delta]++;
Alex Deymo14158572015-06-13 03:37:08 -0700363 total_size += aop.op.data_length();
364 }
Sen Jiangf23bf922018-11-01 18:26:07 -0700365 total_op += part.aops.size();
Alex Deymo14158572015-06-13 03:37:08 -0700366 }
367
Simon Glass3d32f852017-06-28 16:38:11 -0600368 object_counts[DeltaObject("<manifest-metadata>", -1, metadata_size)] = 1;
Alex Deymo14158572015-06-13 03:37:08 -0700369 total_size += metadata_size;
370
Sen Jianga91195d2018-10-25 15:15:38 -0700371 constexpr char kFormatString[] = "%6.2f%% %10jd %-13s %s %d\n";
Simon Glass3d32f852017-06-28 16:38:11 -0600372 for (const auto& object_count : object_counts) {
373 const DeltaObject& object = object_count.first;
Sen Jianga91195d2018-10-25 15:15:38 -0700374 // Use printf() instead of LOG(INFO) because timestamp makes it difficult to
375 // compare two reports.
Sen Jiangcebb6882019-02-26 16:23:28 +0800376 printf(kFormatString,
377 object.size * 100.0 / total_size,
378 object.size,
379 (object.type >= 0
380 ? InstallOperationTypeName(
381 static_cast<InstallOperation::Type>(object.type))
382 : "-"),
383 object.name.c_str(),
384 object_count.second);
Alex Deymo14158572015-06-13 03:37:08 -0700385 }
Sen Jiangf23bf922018-11-01 18:26:07 -0700386 printf(kFormatString, 100.0, total_size, "", "<total>", total_op);
387 fflush(stdout);
Alex Deymo14158572015-06-13 03:37:08 -0700388}
389
Alex Deymo14158572015-06-13 03:37:08 -0700390} // namespace chromeos_update_engine