| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "update_engine/delta_performer.h" | 5 #include "update_engine/delta_performer.h" |
| 6 | 6 |
| 7 #include <endian.h> | 7 #include <endian.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 139 |
| 140 bool DeltaPerformer::OpenKernel(const char* kernel_path) { | 140 bool DeltaPerformer::OpenKernel(const char* kernel_path) { |
| 141 int err; | 141 int err; |
| 142 bool success = OpenFile(kernel_path, &kernel_fd_, &err); | 142 bool success = OpenFile(kernel_path, &kernel_fd_, &err); |
| 143 if (success) | 143 if (success) |
| 144 kernel_path_ = kernel_path; | 144 kernel_path_ = kernel_path; |
| 145 return success; | 145 return success; |
| 146 } | 146 } |
| 147 | 147 |
| 148 int DeltaPerformer::Close() { | 148 int DeltaPerformer::Close() { |
| 149 if (!buffer_.empty()) { | |
| 150 LOG(ERROR) << "Called Close() while buffer not empty!"; | |
| 151 return -1; | |
| 152 } | |
| 153 int err = 0; | 149 int err = 0; |
| 154 if (close(kernel_fd_) == -1) { | 150 if (close(kernel_fd_) == -1) { |
| 155 err = errno; | 151 err = errno; |
| 156 PLOG(ERROR) << "Unable to close kernel fd:"; | 152 PLOG(ERROR) << "Unable to close kernel fd:"; |
| 157 } | 153 } |
| 158 if (close(fd_) == -1) { | 154 if (close(fd_) == -1) { |
| 159 err = errno; | 155 err = errno; |
| 160 PLOG(ERROR) << "Unable to close rootfs fd:"; | 156 PLOG(ERROR) << "Unable to close rootfs fd:"; |
| 161 } | 157 } |
| 162 LOG_IF(ERROR, !hash_calculator_.Finalize()) << "Unable to finalize the hash."; | 158 LOG_IF(ERROR, !hash_calculator_.Finalize()) << "Unable to finalize the hash."; |
| 163 fd_ = -2; // Set so that isn't not valid AND calls to Open() will fail. | 159 fd_ = -2; // Set to invalid so that calls to Open() will fail. |
| 164 path_ = ""; | 160 path_ = ""; |
| 161 if (!buffer_.empty()) { |
| 162 LOG(ERROR) << "Called Close() while buffer not empty!"; |
| 163 if (err >= 0) { |
| 164 err = 1; |
| 165 } |
| 166 } |
| 165 return -err; | 167 return -err; |
| 166 } | 168 } |
| 167 | 169 |
| 168 namespace { | 170 namespace { |
| 169 | 171 |
| 170 void LogPartitionInfoHash(const PartitionInfo& info, const string& tag) { | 172 void LogPartitionInfoHash(const PartitionInfo& info, const string& tag) { |
| 171 string sha256; | 173 string sha256; |
| 172 if (OmahaHashCalculator::Base64Encode(info.hash().data(), | 174 if (OmahaHashCalculator::Base64Encode(info.hash().data(), |
| 173 info.hash().size(), | 175 info.hash().size(), |
| 174 &sha256)) { | 176 &sha256)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 194 | 196 |
| 195 // Wrapper around write. Returns bytes written on success or | 197 // Wrapper around write. Returns bytes written on success or |
| 196 // -errno on error. | 198 // -errno on error. |
| 197 // This function performs as many actions as it can, given the amount of | 199 // This function performs as many actions as it can, given the amount of |
| 198 // data received thus far. | 200 // data received thus far. |
| 199 ssize_t DeltaPerformer::Write(const void* bytes, size_t count) { | 201 ssize_t DeltaPerformer::Write(const void* bytes, size_t count) { |
| 200 const char* c_bytes = reinterpret_cast<const char*>(bytes); | 202 const char* c_bytes = reinterpret_cast<const char*>(bytes); |
| 201 buffer_.insert(buffer_.end(), c_bytes, c_bytes + count); | 203 buffer_.insert(buffer_.end(), c_bytes, c_bytes + count); |
| 202 | 204 |
| 203 if (!manifest_valid_) { | 205 if (!manifest_valid_) { |
| 204 // See if we have enough bytes for the manifest yet | |
| 205 if (buffer_.size() < strlen(kDeltaMagic) + | 206 if (buffer_.size() < strlen(kDeltaMagic) + |
| 206 kDeltaVersionLength + kDeltaProtobufLengthLength) { | 207 kDeltaVersionLength + kDeltaProtobufLengthLength) { |
| 207 // Don't have enough bytes to even know the protobuf length | 208 // Don't have enough bytes to know the protobuf length. |
| 208 return count; | 209 return count; |
| 209 } | 210 } |
| 211 if (memcmp(buffer_.data(), kDeltaMagic, strlen(kDeltaMagic)) != 0) { |
| 212 LOG(ERROR) << "Bad payload format -- invalid delta magic."; |
| 213 return -EINVAL; |
| 214 } |
| 210 uint64_t protobuf_length; | 215 uint64_t protobuf_length; |
| 211 COMPILE_ASSERT(sizeof(protobuf_length) == kDeltaProtobufLengthLength, | 216 COMPILE_ASSERT(sizeof(protobuf_length) == kDeltaProtobufLengthLength, |
| 212 protobuf_length_size_mismatch); | 217 protobuf_length_size_mismatch); |
| 213 memcpy(&protobuf_length, | 218 memcpy(&protobuf_length, |
| 214 &buffer_[strlen(kDeltaMagic) + kDeltaVersionLength], | 219 &buffer_[strlen(kDeltaMagic) + kDeltaVersionLength], |
| 215 kDeltaProtobufLengthLength); | 220 kDeltaProtobufLengthLength); |
| 216 protobuf_length = be64toh(protobuf_length); // switch big endian to host | 221 protobuf_length = be64toh(protobuf_length); // switch big endian to host |
| 217 if (buffer_.size() < strlen(kDeltaMagic) + kDeltaVersionLength + | 222 if (buffer_.size() < strlen(kDeltaMagic) + kDeltaVersionLength + |
| 218 kDeltaProtobufLengthLength + protobuf_length) { | 223 kDeltaProtobufLengthLength + protobuf_length) { |
| 219 return count; | 224 return count; |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { | 749 if (prefs_->GetInt64(kPrefsResumedUpdateFailures, &resumed_update_failures)) { |
| 745 resumed_update_failures++; | 750 resumed_update_failures++; |
| 746 } else { | 751 } else { |
| 747 resumed_update_failures = 1; | 752 resumed_update_failures = 1; |
| 748 } | 753 } |
| 749 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); | 754 prefs_->SetInt64(kPrefsResumedUpdateFailures, resumed_update_failures); |
| 750 return true; | 755 return true; |
| 751 } | 756 } |
| 752 | 757 |
| 753 } // namespace chromeos_update_engine | 758 } // namespace chromeos_update_engine |
| OLD | NEW |