Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "update_engine/filesystem_copier_action.h" |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 6 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 7 | #include <sys/stat.h> |
| 8 | #include <sys/types.h> |
| 9 | #include <errno.h> |
| 10 | #include <fcntl.h> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 11 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 12 | #include <algorithm> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 13 | #include <cstdlib> |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 14 | #include <map> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 17 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 18 | #include <gio/gio.h> |
| 19 | #include <gio/gunixinputstream.h> |
| 20 | #include <gio/gunixoutputstream.h> |
| 21 | #include <glib.h> |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 22 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 23 | #include "update_engine/filesystem_iterator.h" |
| 24 | #include "update_engine/subprocess.h" |
| 25 | #include "update_engine/utils.h" |
| 26 | |
Andrew de los Reyes | 4fe15d0 | 2009-12-10 19:01:36 -0800 | [diff] [blame] | 27 | using std::map; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 28 | using std::min; |
| 29 | using std::string; |
| 30 | using std::vector; |
| 31 | |
| 32 | namespace chromeos_update_engine { |
| 33 | |
| 34 | namespace { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 35 | const off_t kCopyFileBufferSize = 128 * 1024; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 36 | } // namespace {} |
| 37 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 38 | FilesystemCopierAction::FilesystemCopierAction( |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 39 | bool copying_kernel_install_path, |
| 40 | bool verify_hash) |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 41 | : copying_kernel_install_path_(copying_kernel_install_path), |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 42 | verify_hash_(verify_hash), |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 43 | src_stream_(NULL), |
| 44 | dst_stream_(NULL), |
| 45 | read_done_(false), |
| 46 | failed_(false), |
| 47 | cancelled_(false), |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 48 | filesystem_size_(kint64max) { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 49 | // A lot of code works on the implicit assumption that processing is done on |
| 50 | // exactly 2 ping-pong buffers. |
| 51 | COMPILE_ASSERT(arraysize(buffer_) == 2 && |
| 52 | arraysize(buffer_state_) == 2 && |
| 53 | arraysize(buffer_valid_size_) == 2 && |
| 54 | arraysize(canceller_) == 2, |
| 55 | ping_pong_buffers_not_two); |
| 56 | for (int i = 0; i < 2; ++i) { |
| 57 | buffer_state_[i] = kBufferStateEmpty; |
| 58 | buffer_valid_size_[i] = 0; |
| 59 | canceller_[i] = NULL; |
| 60 | } |
| 61 | } |
| 62 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 63 | void FilesystemCopierAction::PerformAction() { |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 64 | // Will tell the ActionProcessor we've failed if we return. |
| 65 | ScopedActionCompleter abort_action_completer(processor_, this); |
| 66 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 67 | if (!HasInputObject()) { |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 68 | LOG(ERROR) << "FilesystemCopierAction missing input object."; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | install_plan_ = GetInputObject(); |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 72 | if (!verify_hash_ && |
| 73 | (install_plan_.is_resume || install_plan_.is_full_update)) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 74 | // No copy or hash verification needed. Done! |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame] | 75 | LOG(INFO) << "filesystem copying skipped: " |
| 76 | << (install_plan_.is_resume ? "resumed" : "full") << " update"; |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 77 | if (HasOutputPipe()) |
| 78 | SetOutputObject(install_plan_); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 79 | abort_action_completer.set_code(kErrorCodeSuccess); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 83 | const string destination = copying_kernel_install_path_ ? |
| 84 | install_plan_.kernel_install_path : |
| 85 | install_plan_.install_path; |
| 86 | string source = verify_hash_ ? destination : copy_source_; |
Andrew de los Reyes | f918517 | 2010-05-03 11:07:05 -0700 | [diff] [blame] | 87 | if (source.empty()) { |
| 88 | source = copying_kernel_install_path_ ? |
| 89 | utils::BootKernelDevice(utils::BootDevice()) : |
| 90 | utils::BootDevice(); |
| 91 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 92 | int src_fd = open(source.c_str(), O_RDONLY); |
| 93 | if (src_fd < 0) { |
| 94 | PLOG(ERROR) << "Unable to open " << source << " for reading:"; |
| 95 | return; |
| 96 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 97 | |
| 98 | if (!verify_hash_) { |
| 99 | int dst_fd = open(destination.c_str(), |
| 100 | O_WRONLY | O_TRUNC | O_CREAT, |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 101 | 0644); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 102 | if (dst_fd < 0) { |
| 103 | close(src_fd); |
| 104 | PLOG(ERROR) << "Unable to open " << install_plan_.install_path |
| 105 | << " for writing:"; |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | dst_stream_ = g_unix_output_stream_new(dst_fd, TRUE); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 112 | DetermineFilesystemSize(src_fd); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 113 | src_stream_ = g_unix_input_stream_new(src_fd, TRUE); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 114 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 115 | for (int i = 0; i < 2; i++) { |
| 116 | buffer_[i].resize(kCopyFileBufferSize); |
| 117 | canceller_[i] = g_cancellable_new(); |
| 118 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 119 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 120 | // Start the first read. |
| 121 | SpawnAsyncActions(); |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 122 | |
| 123 | abort_action_completer.set_should_complete(false); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void FilesystemCopierAction::TerminateProcessing() { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 127 | for (int i = 0; i < 2; i++) { |
| 128 | if (canceller_[i]) { |
| 129 | g_cancellable_cancel(canceller_[i]); |
| 130 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
Ben Chan | 2add7d7 | 2012-10-08 19:28:37 -0700 | [diff] [blame] | 134 | bool FilesystemCopierAction::IsCleanupPending() const { |
| 135 | return (src_stream_ != NULL); |
| 136 | } |
| 137 | |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 138 | void FilesystemCopierAction::Cleanup(ErrorCode code) { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 139 | for (int i = 0; i < 2; i++) { |
| 140 | g_object_unref(canceller_[i]); |
| 141 | canceller_[i] = NULL; |
| 142 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 143 | g_object_unref(src_stream_); |
| 144 | src_stream_ = NULL; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 145 | if (dst_stream_) { |
| 146 | g_object_unref(dst_stream_); |
| 147 | dst_stream_ = NULL; |
| 148 | } |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 149 | if (cancelled_) |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 150 | return; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 151 | if (code == kErrorCodeSuccess && HasOutputPipe()) |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 152 | SetOutputObject(install_plan_); |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 153 | processor_->ActionComplete(this, code); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 156 | void FilesystemCopierAction::AsyncReadReadyCallback(GObject *source_object, |
| 157 | GAsyncResult *res) { |
| 158 | int index = buffer_state_[0] == kBufferStateReading ? 0 : 1; |
| 159 | CHECK(buffer_state_[index] == kBufferStateReading); |
| 160 | |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 161 | GError* error = NULL; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 162 | CHECK(canceller_[index]); |
| 163 | cancelled_ = g_cancellable_is_cancelled(canceller_[index]) == TRUE; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 164 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 165 | ssize_t bytes_read = g_input_stream_read_finish(src_stream_, res, &error); |
| 166 | if (bytes_read < 0) { |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 167 | LOG(ERROR) << "Read failed: " << utils::GetAndFreeGError(&error); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 168 | failed_ = true; |
| 169 | buffer_state_[index] = kBufferStateEmpty; |
| 170 | } else if (bytes_read == 0) { |
| 171 | read_done_ = true; |
| 172 | buffer_state_[index] = kBufferStateEmpty; |
| 173 | } else { |
| 174 | buffer_valid_size_[index] = bytes_read; |
| 175 | buffer_state_[index] = kBufferStateFull; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 176 | filesystem_size_ -= bytes_read; |
| 177 | } |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 178 | SpawnAsyncActions(); |
| 179 | |
| 180 | if (bytes_read > 0) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 181 | // If read_done_ is set, SpawnAsyncActions may finalize the hash so the hash |
| 182 | // update below would happen too late. |
| 183 | CHECK(!read_done_); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 184 | if (!hasher_.Update(buffer_[index].data(), bytes_read)) { |
| 185 | LOG(ERROR) << "Unable to update the hash."; |
| 186 | failed_ = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 187 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 188 | if (verify_hash_) { |
| 189 | buffer_state_[index] = kBufferStateEmpty; |
| 190 | } |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 191 | } |
| 192 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 193 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 194 | void FilesystemCopierAction::StaticAsyncReadReadyCallback( |
| 195 | GObject *source_object, |
| 196 | GAsyncResult *res, |
| 197 | gpointer user_data) { |
| 198 | reinterpret_cast<FilesystemCopierAction*>(user_data)-> |
| 199 | AsyncReadReadyCallback(source_object, res); |
| 200 | } |
| 201 | |
| 202 | void FilesystemCopierAction::AsyncWriteReadyCallback(GObject *source_object, |
| 203 | GAsyncResult *res) { |
| 204 | int index = buffer_state_[0] == kBufferStateWriting ? 0 : 1; |
| 205 | CHECK(buffer_state_[index] == kBufferStateWriting); |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 206 | buffer_state_[index] = kBufferStateEmpty; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 207 | |
| 208 | GError* error = NULL; |
| 209 | CHECK(canceller_[index]); |
| 210 | cancelled_ = g_cancellable_is_cancelled(canceller_[index]) == TRUE; |
| 211 | |
| 212 | ssize_t bytes_written = g_output_stream_write_finish(dst_stream_, |
| 213 | res, |
| 214 | &error); |
Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 215 | |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 216 | if (bytes_written < static_cast<ssize_t>(buffer_valid_size_[index])) { |
| 217 | if (bytes_written < 0) { |
Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 218 | LOG(ERROR) << "Write error: " << utils::GetAndFreeGError(&error); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 219 | } else { |
Gilad Arnold | 6dbbd39 | 2012-07-10 16:19:11 -0700 | [diff] [blame] | 220 | LOG(ERROR) << "Wrote too few bytes: " << bytes_written |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 221 | << " < " << buffer_valid_size_[index]; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 222 | } |
Gilad Arnold | 581c2ea | 2012-07-19 12:33:49 -0700 | [diff] [blame] | 223 | failed_ = true; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | SpawnAsyncActions(); |
| 227 | } |
| 228 | |
| 229 | void FilesystemCopierAction::StaticAsyncWriteReadyCallback( |
| 230 | GObject *source_object, |
| 231 | GAsyncResult *res, |
| 232 | gpointer user_data) { |
| 233 | reinterpret_cast<FilesystemCopierAction*>(user_data)-> |
| 234 | AsyncWriteReadyCallback(source_object, res); |
| 235 | } |
| 236 | |
| 237 | void FilesystemCopierAction::SpawnAsyncActions() { |
| 238 | bool reading = false; |
| 239 | bool writing = false; |
| 240 | for (int i = 0; i < 2; i++) { |
| 241 | if (buffer_state_[i] == kBufferStateReading) { |
| 242 | reading = true; |
| 243 | } |
| 244 | if (buffer_state_[i] == kBufferStateWriting) { |
| 245 | writing = true; |
| 246 | } |
| 247 | } |
| 248 | if (failed_ || cancelled_) { |
| 249 | if (!reading && !writing) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 250 | Cleanup(kErrorCodeError); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 251 | } |
| 252 | return; |
| 253 | } |
| 254 | for (int i = 0; i < 2; i++) { |
| 255 | if (!reading && !read_done_ && buffer_state_[i] == kBufferStateEmpty) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 256 | int64_t bytes_to_read = std::min(static_cast<int64_t>(buffer_[0].size()), |
| 257 | filesystem_size_); |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 258 | g_input_stream_read_async( |
| 259 | src_stream_, |
| 260 | buffer_[i].data(), |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 261 | bytes_to_read, |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 262 | G_PRIORITY_DEFAULT, |
| 263 | canceller_[i], |
| 264 | &FilesystemCopierAction::StaticAsyncReadReadyCallback, |
| 265 | this); |
| 266 | reading = true; |
| 267 | buffer_state_[i] = kBufferStateReading; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 268 | } else if (!writing && !verify_hash_ && |
| 269 | buffer_state_[i] == kBufferStateFull) { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 270 | g_output_stream_write_async( |
| 271 | dst_stream_, |
| 272 | buffer_[i].data(), |
| 273 | buffer_valid_size_[i], |
| 274 | G_PRIORITY_DEFAULT, |
| 275 | canceller_[i], |
| 276 | &FilesystemCopierAction::StaticAsyncWriteReadyCallback, |
| 277 | this); |
| 278 | writing = true; |
| 279 | buffer_state_[i] = kBufferStateWriting; |
| 280 | } |
| 281 | } |
| 282 | if (!reading && !writing) { |
| 283 | // We're done! |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 284 | ErrorCode code = kErrorCodeSuccess; |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 285 | if (hasher_.Finalize()) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 286 | LOG(INFO) << "Hash: " << hasher_.hash(); |
| 287 | if (verify_hash_) { |
| 288 | if (copying_kernel_install_path_) { |
| 289 | if (install_plan_.kernel_hash != hasher_.raw_hash()) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 290 | code = kErrorCodeNewKernelVerificationError; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 291 | LOG(ERROR) << "New kernel verification failed."; |
| 292 | } |
| 293 | } else { |
| 294 | if (install_plan_.rootfs_hash != hasher_.raw_hash()) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 295 | code = kErrorCodeNewRootfsVerificationError; |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 296 | LOG(ERROR) << "New rootfs verification failed."; |
| 297 | } |
| 298 | } |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 299 | } else { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 300 | if (copying_kernel_install_path_) { |
| 301 | install_plan_.kernel_hash = hasher_.raw_hash(); |
| 302 | } else { |
| 303 | install_plan_.rootfs_hash = hasher_.raw_hash(); |
| 304 | } |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 305 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 306 | } else { |
Darin Petkov | c2e4a7d | 2010-12-02 14:47:06 -0800 | [diff] [blame] | 307 | LOG(ERROR) << "Unable to finalize the hash."; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 308 | code = kErrorCodeError; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 309 | } |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 310 | Cleanup(code); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 311 | } |
Andrew de los Reyes | c702078 | 2010-04-28 10:46:04 -0700 | [diff] [blame] | 312 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 313 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 314 | void FilesystemCopierAction::DetermineFilesystemSize(int fd) { |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 315 | if (verify_hash_) { |
| 316 | filesystem_size_ = copying_kernel_install_path_ ? |
| 317 | install_plan_.kernel_size : install_plan_.rootfs_size; |
| 318 | LOG(INFO) << "Filesystem size: " << filesystem_size_; |
| 319 | return; |
| 320 | } |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 321 | filesystem_size_ = kint64max; |
| 322 | int block_count = 0, block_size = 0; |
| 323 | if (!copying_kernel_install_path_ && |
| 324 | utils::GetFilesystemSizeFromFD(fd, &block_count, &block_size)) { |
| 325 | filesystem_size_ = static_cast<int64_t>(block_count) * block_size; |
| 326 | LOG(INFO) << "Filesystem size: " << filesystem_size_ << " bytes (" |
| 327 | << block_count << "x" << block_size << ")."; |
| 328 | } |
| 329 | } |
| 330 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 331 | } // namespace chromeos_update_engine |