blob: 4efbe41b75db84069e5d323f0aa70d52e3c974a5 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2012 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//
Allie Woodeb9e6d82015-04-17 13:55:30 -070016
Alex Deymo39910dc2015-11-09 17:04:30 -080017#include "update_engine/payload_consumer/filesystem_verifier_action.h"
Allie Woodeb9e6d82015-04-17 13:55:30 -070018
19#include <errno.h>
20#include <fcntl.h>
21#include <sys/stat.h>
22#include <sys/types.h>
Kelvin Zhangec205cf2020-09-28 13:23:40 -040023#include <unistd.h>
Allie Woodeb9e6d82015-04-17 13:55:30 -070024
25#include <algorithm>
26#include <cstdlib>
Kelvin Zhangec205cf2020-09-28 13:23:40 -040027#include <memory>
Allie Woodeb9e6d82015-04-17 13:55:30 -070028#include <string>
Kelvin Zhangec205cf2020-09-28 13:23:40 -040029#include <utility>
Allie Woodeb9e6d82015-04-17 13:55:30 -070030
Alex Deymo20c99202015-07-09 16:14:16 -070031#include <base/bind.h>
Tianjie24f96092020-06-30 12:26:25 -070032#include <base/strings/string_util.h>
Kelvin Zhangec205cf2020-09-28 13:23:40 -040033#include <brillo/data_encoding.h>
34#include <brillo/message_loops/message_loop.h>
35#include <brillo/streams/file_stream.h>
Allie Woodeb9e6d82015-04-17 13:55:30 -070036
Alex Deymo39910dc2015-11-09 17:04:30 -080037#include "update_engine/common/utils.h"
Kelvin Zhangec205cf2020-09-28 13:23:40 -040038#include "update_engine/payload_consumer/file_descriptor.h"
Allie Woodeb9e6d82015-04-17 13:55:30 -070039
Sen Jiang2703ef42017-03-16 13:36:21 -070040using brillo::data_encoding::Base64Encode;
Allie Woodeb9e6d82015-04-17 13:55:30 -070041using std::string;
42
Kelvin Zhang7f925672021-03-15 13:37:40 -040043// On a partition with verity enabled, we expect to see the following format:
44// ===================================================
45// Normal Filesystem Data
46// (this should take most of the space, like over 90%)
47// ===================================================
48// Hash tree
49// ~0.8% (e.g. 16M for 2GB image)
50// ===================================================
51// FEC data
52// ~0.8%
53// ===================================================
54// Footer
55// 4K
56// ===================================================
57
58// For OTA that doesn't do on device verity computation, hash tree and fec data
59// are written during DownloadAction as a regular InstallOp, so no special
60// handling needed, we can just read the entire partition in 1 go.
61
62// Verity enabled case: Only Normal FS data is written during download action.
63// When hasing the entire partition, we will need to build the hash tree, write
64// it to disk, then build FEC, and write it to disk. Therefore, it is important
65// that we finish writing hash tree before we attempt to read & hash it. The
66// same principal applies to FEC data.
67
68// |verity_writer_| handles building and
69// writing of FEC/HashTree, we just need to be careful when reading.
70// Specifically, we must stop at beginning of Hash tree, let |verity_writer_|
71// write both hash tree and FEC, then continue reading the remaining part of
72// partition.
73
Allie Woodeb9e6d82015-04-17 13:55:30 -070074namespace chromeos_update_engine {
75
76namespace {
Alex Deymo20c99202015-07-09 16:14:16 -070077const off_t kReadFileBufferSize = 128 * 1024;
Allie Woodeb9e6d82015-04-17 13:55:30 -070078} // namespace
79
Allie Woodeb9e6d82015-04-17 13:55:30 -070080void FilesystemVerifierAction::PerformAction() {
81 // Will tell the ActionProcessor we've failed if we return.
82 ScopedActionCompleter abort_action_completer(processor_, this);
83
84 if (!HasInputObject()) {
85 LOG(ERROR) << "FilesystemVerifierAction missing input object.";
86 return;
87 }
88 install_plan_ = GetInputObject();
89
Alex Deymoe5e5fe92015-10-05 09:28:19 -070090 if (install_plan_.partitions.empty()) {
91 LOG(INFO) << "No partitions to verify.";
Allie Woodeb9e6d82015-04-17 13:55:30 -070092 if (HasOutputPipe())
93 SetOutputObject(install_plan_);
94 abort_action_completer.set_code(ErrorCode::kSuccess);
95 return;
96 }
Jae Hoon Kim50504d62020-04-23 14:32:38 -070097 install_plan_.Dump();
Alex Deymoe5e5fe92015-10-05 09:28:19 -070098 StartPartitionHashing();
Allie Woodeb9e6d82015-04-17 13:55:30 -070099 abort_action_completer.set_should_complete(false);
100}
101
102void FilesystemVerifierAction::TerminateProcessing() {
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400103 brillo::MessageLoop::current()->CancelTask(pending_task_id_);
Alex Deymo20c99202015-07-09 16:14:16 -0700104 cancelled_ = true;
105 Cleanup(ErrorCode::kSuccess); // error code is ignored if canceled_ is true.
Allie Woodeb9e6d82015-04-17 13:55:30 -0700106}
107
Allie Woodeb9e6d82015-04-17 13:55:30 -0700108void FilesystemVerifierAction::Cleanup(ErrorCode code) {
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400109 read_fd_.reset();
110 write_fd_.reset();
Alex Deymo20c99202015-07-09 16:14:16 -0700111 // This memory is not used anymore.
112 buffer_.clear();
113
Allie Woodeb9e6d82015-04-17 13:55:30 -0700114 if (cancelled_)
115 return;
116 if (code == ErrorCode::kSuccess && HasOutputPipe())
117 SetOutputObject(install_plan_);
Kelvin Zhang70eef232020-06-12 20:32:40 +0000118 UpdateProgress(1.0);
Allie Woodeb9e6d82015-04-17 13:55:30 -0700119 processor_->ActionComplete(this, code);
120}
121
Kelvin Zhang70eef232020-06-12 20:32:40 +0000122void FilesystemVerifierAction::UpdateProgress(double progress) {
123 if (delegate_ != nullptr) {
124 delegate_->OnVerifyProgressUpdate(progress);
125 }
126}
127
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400128bool FilesystemVerifierAction::InitializeFdVABC() {
129 const InstallPlan::Partition& partition =
130 install_plan_.partitions[partition_index_];
131
Kelvin Zhang21a49912021-03-12 14:28:33 -0500132 read_fd_ =
133 dynamic_control_->OpenCowFd(partition.name, partition.source_path, true);
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400134 if (!read_fd_) {
135 LOG(ERROR) << "OpenCowReader(" << partition.name << ", "
136 << partition.source_path << ") failed.";
137 return false;
138 }
139 partition_size_ = partition.target_size;
140 // TODO(b/173432386): Support Verity writes for VABC.
141 CHECK_EQ(partition.fec_size, 0U);
142 CHECK_EQ(partition.hash_tree_size, 0U);
143 return true;
144}
145
146bool FilesystemVerifierAction::InitializeFd(const std::string& part_path) {
147 read_fd_ = FileDescriptorPtr(new EintrSafeFileDescriptor());
148 if (!read_fd_->Open(part_path.c_str(), O_RDONLY)) {
149 LOG(ERROR) << "Unable to open " << part_path << " for reading.";
150 return false;
151 }
152
153 // Can't re-use |read_fd_|, as verity writer may call `seek` to modify state
154 // of a file descriptor.
155 if (ShouldWriteVerity()) {
156 write_fd_ = FileDescriptorPtr(new EintrSafeFileDescriptor());
157 if (!write_fd_->Open(part_path.c_str(), O_RDWR)) {
158 LOG(ERROR) << "Unable to open " << part_path << " for Read/Write.";
159 return false;
160 }
161 }
162 return true;
163}
164
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700165void FilesystemVerifierAction::StartPartitionHashing() {
166 if (partition_index_ == install_plan_.partitions.size()) {
Tianjie24f96092020-06-30 12:26:25 -0700167 if (!install_plan_.untouched_dynamic_partitions.empty()) {
168 LOG(INFO) << "Verifying extents of untouched dynamic partitions ["
169 << base::JoinString(install_plan_.untouched_dynamic_partitions,
170 ", ")
171 << "]";
172 if (!dynamic_control_->VerifyExtentsForUntouchedPartitions(
173 install_plan_.source_slot,
174 install_plan_.target_slot,
175 install_plan_.untouched_dynamic_partitions)) {
176 Cleanup(ErrorCode::kFilesystemVerifierError);
177 return;
178 }
179 }
180
Sen Jianga35896c2016-05-25 11:08:41 -0700181 Cleanup(ErrorCode::kSuccess);
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700182 return;
183 }
Sen Jiang57f91802017-11-14 17:42:13 -0800184 const InstallPlan::Partition& partition =
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700185 install_plan_.partitions[partition_index_];
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700186 string part_path;
Sen Jiangfef85fd2016-03-25 15:32:49 -0700187 switch (verifier_step_) {
188 case VerifierStep::kVerifySourceHash:
Sen Jiange6e4bb92016-04-05 14:59:12 -0700189 part_path = partition.source_path;
Sen Jiang57f91802017-11-14 17:42:13 -0800190 partition_size_ = partition.source_size;
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700191 break;
Sen Jiangfef85fd2016-03-25 15:32:49 -0700192 case VerifierStep::kVerifyTargetHash:
Sen Jiange6e4bb92016-04-05 14:59:12 -0700193 part_path = partition.target_path;
Sen Jiang57f91802017-11-14 17:42:13 -0800194 partition_size_ = partition.target_size;
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700195 break;
196 }
Yifan Hong537802d2018-08-15 13:15:42 -0700197
Yifan Hong537802d2018-08-15 13:15:42 -0700198 LOG(INFO) << "Hashing partition " << partition_index_ << " ("
199 << partition.name << ") on device " << part_path;
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400200 auto success = false;
Kelvin Zhang06188352021-02-10 13:21:47 -0500201 if (dynamic_control_->UpdateUsesSnapshotCompression() &&
Kelvin Zhangebd115e2021-03-08 16:10:25 -0500202 verifier_step_ == VerifierStep::kVerifyTargetHash &&
203 dynamic_control_->IsDynamicPartition(partition.name,
204 install_plan_.target_slot)) {
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400205 success = InitializeFdVABC();
206 } else {
207 if (part_path.empty()) {
208 if (partition_size_ == 0) {
209 LOG(INFO) << "Skip hashing partition " << partition_index_ << " ("
210 << partition.name << ") because size is 0.";
211 partition_index_++;
212 StartPartitionHashing();
213 return;
214 }
215 LOG(ERROR) << "Cannot hash partition " << partition_index_ << " ("
216 << partition.name
217 << ") because its device path cannot be determined.";
218 Cleanup(ErrorCode::kFilesystemVerifierError);
219 return;
220 }
221 success = InitializeFd(part_path);
222 }
223 if (!success) {
Sen Jiang57f91802017-11-14 17:42:13 -0800224 Cleanup(ErrorCode::kFilesystemVerifierError);
225 return;
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700226 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700227 buffer_.resize(kReadFileBufferSize);
Sen Jiang57f91802017-11-14 17:42:13 -0800228 hasher_ = std::make_unique<HashCalculator>();
229
230 offset_ = 0;
Kelvin Zhang7f925672021-03-15 13:37:40 -0400231 filesystem_data_end_ = partition_size_;
232 CHECK_LE(partition.hash_tree_offset, partition.fec_offset)
233 << " Hash tree is expected to come before FEC data";
234 if (partition.hash_tree_offset != 0) {
235 filesystem_data_end_ = partition.hash_tree_offset;
236 } else if (partition.fec_offset != 0) {
237 filesystem_data_end_ = partition.fec_offset;
238 }
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400239 if (ShouldWriteVerity()) {
Kelvin Zhang7f925672021-03-15 13:37:40 -0400240 if (!verity_writer_->Init(partition)) {
Sen Jiang57f91802017-11-14 17:42:13 -0800241 Cleanup(ErrorCode::kVerityCalculationError);
242 return;
243 }
244 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700245
246 // Start the first read.
Kelvin Zhang7f925672021-03-15 13:37:40 -0400247 ScheduleFileSystemRead();
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700248}
249
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400250bool FilesystemVerifierAction::ShouldWriteVerity() {
251 const InstallPlan::Partition& partition =
252 install_plan_.partitions[partition_index_];
253 return verifier_step_ == VerifierStep::kVerifyTargetHash &&
254 install_plan_.write_verity &&
255 (partition.hash_tree_size > 0 || partition.fec_size > 0);
256}
257
Kelvin Zhang7f925672021-03-15 13:37:40 -0400258void FilesystemVerifierAction::ReadVerityAndFooter() {
259 if (ShouldWriteVerity()) {
260 if (!verity_writer_->Finalize(read_fd_, write_fd_)) {
261 LOG(ERROR) << "Failed to write hashtree/FEC data.";
262 Cleanup(ErrorCode::kFilesystemVerifierError);
263 return;
264 }
265 }
266 auto bytes_to_read = partition_size_ - filesystem_data_end_;
267 // Since we handed our |read_fd_| to verity_writer_ during |Finalize()| call,
268 // fd's position could have been changed. Re-seek.
269 read_fd_->Seek(filesystem_data_end_, SEEK_SET);
270 while (bytes_to_read > 0) {
271 const auto read_size = std::min<size_t>(buffer_.size(), bytes_to_read);
272 auto bytes_read = read_fd_->Read(buffer_.data(), read_size);
273 if (bytes_read <= 0) {
274 PLOG(ERROR) << "Failed to read hash tree " << bytes_read;
275 Cleanup(ErrorCode::kFilesystemVerifierError);
276 return;
277 }
278 if (!hasher_->Update(buffer_.data(), bytes_read)) {
279 LOG(ERROR) << "Unable to update the hash.";
280 Cleanup(ErrorCode::kError);
281 return;
282 }
283 bytes_to_read -= bytes_read;
284 }
285 FinishPartitionHashing();
286}
Sen Jiang57f91802017-11-14 17:42:13 -0800287
Kelvin Zhang7f925672021-03-15 13:37:40 -0400288void FilesystemVerifierAction::ScheduleFileSystemRead() {
Sen Jiang57f91802017-11-14 17:42:13 -0800289 // We can only start reading anything past |hash_tree_offset| after we have
290 // already read all the data blocks that the hash tree covers. The same
291 // applies to FEC.
Kelvin Zhang7f925672021-03-15 13:37:40 -0400292
293 size_t bytes_to_read = std::min(static_cast<uint64_t>(buffer_.size()),
294 filesystem_data_end_ - offset_);
Alex Deymob9e8e262015-08-03 20:23:03 -0700295 if (!bytes_to_read) {
Kelvin Zhang7f925672021-03-15 13:37:40 -0400296 ReadVerityAndFooter();
Allie Woodeb9e6d82015-04-17 13:55:30 -0700297 return;
298 }
299
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400300 auto bytes_read = read_fd_->Read(buffer_.data(), bytes_to_read);
301 if (bytes_read < 0) {
Alex Deymob9e8e262015-08-03 20:23:03 -0700302 LOG(ERROR) << "Unable to schedule an asynchronous read from the stream.";
303 Cleanup(ErrorCode::kError);
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400304 } else {
305 // We could just invoke |OnReadDoneCallback()|, it works. But |PostTask|
306 // is used so that users can cancel updates.
307 pending_task_id_ = brillo::MessageLoop::current()->PostTask(
308 base::Bind(&FilesystemVerifierAction::OnReadDone,
309 base::Unretained(this),
310 bytes_read));
Allie Woodeb9e6d82015-04-17 13:55:30 -0700311 }
312}
313
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400314void FilesystemVerifierAction::OnReadDone(size_t bytes_read) {
Sen Jiang57f91802017-11-14 17:42:13 -0800315 if (cancelled_) {
316 Cleanup(ErrorCode::kError);
317 return;
318 }
Alex Deymob9e8e262015-08-03 20:23:03 -0700319 if (bytes_read == 0) {
Sen Jiang57f91802017-11-14 17:42:13 -0800320 LOG(ERROR) << "Failed to read the remaining " << partition_size_ - offset_
321 << " bytes from partition "
322 << install_plan_.partitions[partition_index_].name;
323 Cleanup(ErrorCode::kFilesystemVerifierError);
324 return;
325 }
326
327 if (!hasher_->Update(buffer_.data(), bytes_read)) {
328 LOG(ERROR) << "Unable to update the hash.";
329 Cleanup(ErrorCode::kError);
330 return;
331 }
332
Kelvin Zhang70eef232020-06-12 20:32:40 +0000333 // WE don't consider sizes of each partition. Every partition
334 // has the same length on progress bar.
335 // TODO(zhangkelvin) Take sizes of each partition into account
336
337 UpdateProgress(
338 (static_cast<double>(offset_) / partition_size_ + partition_index_) /
339 install_plan_.partitions.size());
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400340 if (ShouldWriteVerity()) {
Sen Jiang57f91802017-11-14 17:42:13 -0800341 if (!verity_writer_->Update(offset_, buffer_.data(), bytes_read)) {
Kelvin Zhang7f925672021-03-15 13:37:40 -0400342 LOG(ERROR) << "Unable to update verity";
Sen Jiang57f91802017-11-14 17:42:13 -0800343 Cleanup(ErrorCode::kVerityCalculationError);
Alex Deymob9e8e262015-08-03 20:23:03 -0700344 return;
345 }
346 }
347
Sen Jiang57f91802017-11-14 17:42:13 -0800348 offset_ += bytes_read;
Kelvin Zhang7f925672021-03-15 13:37:40 -0400349 if (offset_ == filesystem_data_end_) {
350 ReadVerityAndFooter();
Sen Jiang57f91802017-11-14 17:42:13 -0800351 return;
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700352 }
Sen Jiang57f91802017-11-14 17:42:13 -0800353
Kelvin Zhang7f925672021-03-15 13:37:40 -0400354 ScheduleFileSystemRead();
Alex Deymob9e8e262015-08-03 20:23:03 -0700355}
356
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700357void FilesystemVerifierAction::FinishPartitionHashing() {
358 if (!hasher_->Finalize()) {
Alex Deymob9e8e262015-08-03 20:23:03 -0700359 LOG(ERROR) << "Unable to finalize the hash.";
Sen Jiang57f91802017-11-14 17:42:13 -0800360 Cleanup(ErrorCode::kError);
361 return;
Alex Deymob9e8e262015-08-03 20:23:03 -0700362 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700363 InstallPlan::Partition& partition =
364 install_plan_.partitions[partition_index_];
Sen Jiang2703ef42017-03-16 13:36:21 -0700365 LOG(INFO) << "Hash of " << partition.name << ": "
366 << Base64Encode(hasher_->raw_hash());
Alex Deymob9e8e262015-08-03 20:23:03 -0700367
Sen Jiangfef85fd2016-03-25 15:32:49 -0700368 switch (verifier_step_) {
369 case VerifierStep::kVerifyTargetHash:
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700370 if (partition.target_hash != hasher_->raw_hash()) {
371 LOG(ERROR) << "New '" << partition.name
372 << "' partition verification failed.";
Sen Jiangcdd52062017-05-18 15:33:10 -0700373 if (partition.source_hash.empty()) {
374 // No need to verify source if it is a full payload.
Sen Jiang57f91802017-11-14 17:42:13 -0800375 Cleanup(ErrorCode::kNewRootfsVerificationError);
376 return;
Sen Jiangcdd52062017-05-18 15:33:10 -0700377 }
Sen Jiangfef85fd2016-03-25 15:32:49 -0700378 // If we have not verified source partition yet, now that the target
Sen Jiang65566a32016-04-06 13:35:36 -0700379 // partition does not match, and it's not a full payload, we need to
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400380 // switch to kVerifySourceHash step to check if it's because the
381 // source partition does not match either.
Sen Jiangfef85fd2016-03-25 15:32:49 -0700382 verifier_step_ = VerifierStep::kVerifySourceHash;
Sen Jiang1ad42ad2015-11-17 15:04:02 -0800383 } else {
384 partition_index_++;
Allie Woodeb9e6d82015-04-17 13:55:30 -0700385 }
386 break;
Sen Jiangfef85fd2016-03-25 15:32:49 -0700387 case VerifierStep::kVerifySourceHash:
Sen Jiang1ad42ad2015-11-17 15:04:02 -0800388 if (partition.source_hash != hasher_->raw_hash()) {
389 LOG(ERROR) << "Old '" << partition.name
390 << "' partition verification failed.";
Sen Jiangfef85fd2016-03-25 15:32:49 -0700391 LOG(ERROR) << "This is a server-side error due to mismatched delta"
392 << " update image!";
393 LOG(ERROR) << "The delta I've been given contains a " << partition.name
394 << " delta update that must be applied over a "
395 << partition.name << " with a specific checksum, but the "
396 << partition.name
397 << " we're starting with doesn't have that checksum! This"
398 " means that the delta I've been given doesn't match my"
399 " existing system. The "
400 << partition.name << " partition I have has hash: "
Sen Jiang2703ef42017-03-16 13:36:21 -0700401 << Base64Encode(hasher_->raw_hash())
Sen Jiangfef85fd2016-03-25 15:32:49 -0700402 << " but the update expected me to have "
Sen Jiang2703ef42017-03-16 13:36:21 -0700403 << Base64Encode(partition.source_hash) << " .";
Sen Jiangfef85fd2016-03-25 15:32:49 -0700404 LOG(INFO) << "To get the checksum of the " << partition.name
405 << " partition run this command: dd if="
406 << partition.source_path
407 << " bs=1M count=" << partition.source_size
408 << " iflag=count_bytes 2>/dev/null | openssl dgst -sha256 "
409 "-binary | openssl base64";
410 LOG(INFO) << "To get the checksum of partitions in a bin file, "
411 << "run: .../src/scripts/sha256_partitions.sh .../file.bin";
Sen Jiang57f91802017-11-14 17:42:13 -0800412 Cleanup(ErrorCode::kDownloadStateInitializationError);
413 return;
Sen Jiang1ad42ad2015-11-17 15:04:02 -0800414 }
Sen Jianga35896c2016-05-25 11:08:41 -0700415 // The action will skip kVerifySourceHash step if target partition hash
416 // matches, if we are in this step, it means target hash does not match,
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400417 // and now that the source partition hash matches, we should set the
418 // error code to reflect the error in target partition. We only need to
419 // verify the source partition which the target hash does not match, the
420 // rest of the partitions don't matter.
Sen Jiang57f91802017-11-14 17:42:13 -0800421 Cleanup(ErrorCode::kNewRootfsVerificationError);
422 return;
Allie Woodeb9e6d82015-04-17 13:55:30 -0700423 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700424 // Start hashing the next partition, if any.
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700425 hasher_.reset();
426 buffer_.clear();
Kelvin Zhangec205cf2020-09-28 13:23:40 -0400427 if (read_fd_) {
428 read_fd_.reset();
429 }
430 if (write_fd_) {
431 write_fd_.reset();
432 }
Alex Deymoe5e5fe92015-10-05 09:28:19 -0700433 StartPartitionHashing();
Allie Woodeb9e6d82015-04-17 13:55:30 -0700434}
435
436} // namespace chromeos_update_engine