Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
| 7 | |
| 8 | #include <inttypes.h> |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 9 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 10 | #include <vector> |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 11 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 12 | #include <base/time.h> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 13 | #include <google/protobuf/repeated_field.h> |
Andrew de los Reyes | 353777c | 2010-10-08 10:34:30 -0700 | [diff] [blame] | 14 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 15 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 16 | #include "update_engine/file_writer.h" |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 17 | #include "update_engine/install_plan.h" |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 18 | #include "update_engine/omaha_hash_calculator.h" |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 19 | #include "update_engine/system_state.h" |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 20 | #include "update_engine/update_metadata.pb.h" |
| 21 | |
| 22 | namespace chromeos_update_engine { |
| 23 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 24 | class PrefsInterface; |
| 25 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 26 | // This class performs the actions in a delta update synchronously. The delta |
| 27 | // update itself should be passed in in chunks as it is received. |
| 28 | |
| 29 | class DeltaPerformer : public FileWriter { |
| 30 | public: |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 31 | enum MetadataParseResult { |
| 32 | kMetadataParseSuccess, |
| 33 | kMetadataParseError, |
| 34 | kMetadataParseInsufficientData, |
| 35 | }; |
| 36 | |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 37 | static const uint64_t kDeltaVersionSize; |
| 38 | static const uint64_t kDeltaManifestSizeSize; |
Darin Petkov | abc7bc0 | 2011-02-23 14:39:43 -0800 | [diff] [blame] | 39 | static const char kUpdatePayloadPublicKeyPath[]; |
| 40 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 41 | // Defines the granularity of progress logging in terms of how many "completed |
| 42 | // chunks" we want to report at the most. |
| 43 | static const unsigned kProgressLogMaxChunks; |
| 44 | // Defines a timeout since the last progress was logged after which we want to |
| 45 | // force another log message (even if the current chunk was not completed). |
| 46 | static const unsigned kProgressLogTimeoutSeconds; |
| 47 | // These define the relative weights (0-100) we give to the different work |
| 48 | // components associated with an update when computing an overall progress. |
| 49 | // Currently they include the download progress and the number of completed |
| 50 | // operations. They must add up to one hundred (100). |
| 51 | static const unsigned kProgressDownloadWeight; |
| 52 | static const unsigned kProgressOperationsWeight; |
| 53 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 54 | DeltaPerformer(PrefsInterface* prefs, |
| 55 | SystemState* system_state, |
| 56 | InstallPlan* install_plan) |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 57 | : prefs_(prefs), |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 58 | system_state_(system_state), |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 59 | install_plan_(install_plan), |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 60 | fd_(-1), |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 61 | kernel_fd_(-1), |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 62 | manifest_valid_(false), |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 63 | manifest_metadata_size_(0), |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 64 | next_operation_num_(0), |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 65 | buffer_offset_(0), |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 66 | last_updated_buffer_offset_(kuint64max), |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 67 | block_size_(0), |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 68 | public_key_path_(kUpdatePayloadPublicKeyPath), |
| 69 | total_bytes_received_(0), |
| 70 | num_rootfs_operations_(0), |
| 71 | num_total_operations_(0), |
| 72 | overall_progress_(0), |
| 73 | last_progress_chunk_(0), |
| 74 | forced_progress_log_wait_( |
| 75 | base::TimeDelta::FromSeconds(kProgressLogTimeoutSeconds)) {} |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 76 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 77 | // Opens the kernel. Should be called before or after Open(), but before |
| 78 | // Write(). The kernel file will be close()d when Close() is called. |
| 79 | bool OpenKernel(const char* kernel_path); |
| 80 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 81 | // flags and mode ignored. Once Close()d, a DeltaPerformer can't be |
| 82 | // Open()ed again. |
| 83 | int Open(const char* path, int flags, mode_t mode); |
| 84 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 85 | // FileWriter's Write implementation where caller doesn't care about |
| 86 | // error codes. |
| 87 | bool Write(const void* bytes, size_t count) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 88 | ErrorCode error; |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 89 | return Write(bytes, count, &error); |
| 90 | } |
| 91 | |
| 92 | // FileWriter's Write implementation that returns a more specific |error| code |
| 93 | // in case of failures in Write operation. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 94 | bool Write(const void* bytes, size_t count, ErrorCode *error); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 95 | |
| 96 | // Wrapper around close. Returns 0 on success or -errno on error. |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 97 | // Closes both 'path' given to Open() and the kernel path. |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 98 | int Close(); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 99 | |
| 100 | // Verifies the downloaded payload against the signed hash included in the |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 101 | // payload, against the update check hash (which is in base64 format) and |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 102 | // size using the public key and returns kErrorCodeSuccess on success, an |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 103 | // error code on failure. This method should be called after closing the |
| 104 | // stream. Note this method skips the signed hash check if the public key is |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 105 | // unavailable; it returns kErrorCodeSignedDeltaPayloadExpectedError if the |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 106 | // public key is available but the delta payload doesn't include a signature. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 107 | ErrorCode VerifyPayload(const std::string& update_check_response_hash, |
Andrew de los Reyes | 771e1bd | 2011-08-30 14:47:23 -0700 | [diff] [blame] | 108 | const uint64_t update_check_response_size); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 109 | |
Darin Petkov | 3aefa86 | 2010-12-07 14:45:00 -0800 | [diff] [blame] | 110 | // Reads from the update manifest the expected sizes and hashes of the target |
| 111 | // kernel and rootfs partitions. These values can be used for applied update |
| 112 | // hash verification. This method must be called after the update manifest has |
| 113 | // been parsed (e.g., after closing the stream). Returns true on success, and |
| 114 | // false on failure (e.g., when the values are not present in the update |
| 115 | // manifest). |
| 116 | bool GetNewPartitionInfo(uint64_t* kernel_size, |
| 117 | std::vector<char>* kernel_hash, |
| 118 | uint64_t* rootfs_size, |
| 119 | std::vector<char>* rootfs_hash); |
Darin Petkov | 2dd0109 | 2010-10-08 15:43:05 -0700 | [diff] [blame] | 120 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 121 | // Converts an ordered collection of Extent objects which contain data of |
| 122 | // length full_length to a comma-separated string. For each Extent, the |
| 123 | // string will have the start offset and then the length in bytes. |
| 124 | // The length value of the last extent in the string may be short, since |
| 125 | // the full length of all extents in the string is capped to full_length. |
| 126 | // Also, an extent starting at kSparseHole, appears as -1 in the string. |
| 127 | // For example, if the Extents are {1, 1}, {4, 2}, {kSparseHole, 1}, |
| 128 | // {0, 1}, block_size is 4096, and full_length is 5 * block_size - 13, |
| 129 | // the resulting string will be: "4096:4096,16384:8192,-1:4096,0:4083" |
| 130 | static bool ExtentsToBsdiffPositionsString( |
| 131 | const google::protobuf::RepeatedPtrField<Extent>& extents, |
| 132 | uint64_t block_size, |
| 133 | uint64_t full_length, |
| 134 | std::string* positions_string); |
| 135 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 136 | // Returns true if a previous update attempt can be continued based on the |
| 137 | // persistent preferences and the new update check response hash. |
| 138 | static bool CanResumeUpdate(PrefsInterface* prefs, |
| 139 | std::string update_check_response_hash); |
| 140 | |
| 141 | // Resets the persistent update progress state to indicate that an update |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 142 | // can't be resumed. Performs a quick update-in-progress reset if |quick| is |
| 143 | // true, otherwise resets all progress-related update state. Returns true on |
| 144 | // success, false otherwise. |
| 145 | static bool ResetUpdateProgress(PrefsInterface* prefs, bool quick); |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 146 | |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 147 | // Attempts to parse the update metadata starting from the beginning of |
| 148 | // |payload| into |manifest|. On success, sets |metadata_size| to the total |
| 149 | // metadata bytes (including the delta magic and metadata size fields), and |
| 150 | // returns kMetadataParseSuccess. Returns kMetadataParseInsufficientData if |
| 151 | // more data is needed to parse the complete metadata. Returns |
| 152 | // kMetadataParseError if the metadata can't be parsed given the payload. |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 153 | MetadataParseResult ParsePayloadMetadata( |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 154 | const std::vector<char>& payload, |
| 155 | DeltaArchiveManifest* manifest, |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 156 | uint64_t* metadata_size, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 157 | ErrorCode* error); |
Darin Petkov | 9574f7e | 2011-01-13 10:48:12 -0800 | [diff] [blame] | 158 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 159 | void set_public_key_path(const std::string& public_key_path) { |
| 160 | public_key_path_ = public_key_path; |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 163 | // Returns the byte offset at which the manifest protobuf begins in a |
| 164 | // payload. |
| 165 | static uint64_t GetManifestOffset(); |
| 166 | |
| 167 | // Returns the byte offset where the size of the manifest is stored in |
| 168 | // a payload. This offset precedes the actual start of the manifest |
| 169 | // that's returned by the GetManifestOffset method. |
| 170 | static uint64_t GetManifestSizeOffset(); |
| 171 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 172 | private: |
Andrew de los Reyes | 353777c | 2010-10-08 10:34:30 -0700 | [diff] [blame] | 173 | friend class DeltaPerformerTest; |
| 174 | FRIEND_TEST(DeltaPerformerTest, IsIdempotentOperationTest); |
| 175 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 176 | // Logs the progress of downloading/applying an update. |
| 177 | void LogProgress(const char* message_prefix); |
| 178 | |
| 179 | // Update overall progress metrics, log as necessary. |
| 180 | void UpdateOverallProgress(bool force_log, const char* message_prefix); |
| 181 | |
Andrew de los Reyes | 353777c | 2010-10-08 10:34:30 -0700 | [diff] [blame] | 182 | static bool IsIdempotentOperation( |
| 183 | const DeltaArchiveManifest_InstallOperation& op); |
| 184 | |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 185 | // Verifies that the expected source partition hashes (if present) match the |
| 186 | // hashes for the current partitions. Returns true if there're no expected |
| 187 | // hashes in the payload (e.g., if it's a new-style full update) or if the |
| 188 | // hashes match; returns false otherwise. |
| 189 | bool VerifySourcePartitions(); |
| 190 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 191 | // Returns true if enough of the delta file has been passed via Write() |
| 192 | // to be able to perform a given install operation. |
| 193 | bool CanPerformInstallOperation( |
| 194 | const DeltaArchiveManifest_InstallOperation& operation); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 195 | |
Gilad Arnold | 21504f0 | 2013-05-24 08:51:22 -0700 | [diff] [blame^] | 196 | // Checks the integrity of the payload manifest. Returns true upon success, |
| 197 | // false otherwise. |
| 198 | ErrorCode ValidateManifest(); |
| 199 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 200 | // Validates that the hash of the blobs corresponding to the given |operation| |
| 201 | // matches what's specified in the manifest in the payload. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 202 | // Returns kErrorCodeSuccess on match or a suitable error code otherwise. |
| 203 | ErrorCode ValidateOperationHash( |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 204 | const DeltaArchiveManifest_InstallOperation& operation); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 205 | |
| 206 | // Interprets the given |protobuf| as a DeltaArchiveManifest protocol buffer |
| 207 | // of the given protobuf_length and verifies that the signed hash of the |
Jay Srinivasan | f431870 | 2012-09-24 11:56:24 -0700 | [diff] [blame] | 208 | // metadata matches what's specified in the install plan from Omaha. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 209 | // Returns kErrorCodeSuccess on match or a suitable error code otherwise. |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 210 | // This method must be called before any part of the |protobuf| is parsed |
| 211 | // so that a man-in-the-middle attack on the SSL connection to the payload |
| 212 | // server doesn't exploit any vulnerability in the code that parses the |
| 213 | // protocol buffer. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 214 | ErrorCode ValidateMetadataSignature(const char* protobuf, |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 215 | uint64_t protobuf_length); |
| 216 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 217 | // Returns true on success. |
| 218 | bool PerformInstallOperation( |
| 219 | const DeltaArchiveManifest_InstallOperation& operation); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 220 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 221 | // These perform a specific type of operation and return true on success. |
| 222 | bool PerformReplaceOperation( |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 223 | const DeltaArchiveManifest_InstallOperation& operation, |
| 224 | bool is_kernel_partition); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 225 | bool PerformMoveOperation( |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 226 | const DeltaArchiveManifest_InstallOperation& operation, |
| 227 | bool is_kernel_partition); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 228 | bool PerformBsdiffOperation( |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 229 | const DeltaArchiveManifest_InstallOperation& operation, |
| 230 | bool is_kernel_partition); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 231 | |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 232 | // Returns true if the payload signature message has been extracted from |
| 233 | // |operation|, false otherwise. |
| 234 | bool ExtractSignatureMessage( |
| 235 | const DeltaArchiveManifest_InstallOperation& operation); |
| 236 | |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 237 | // Updates the hash calculator with |count| bytes at the head of |buffer_| and |
| 238 | // then discards them. |
| 239 | void DiscardBufferHeadBytes(size_t count); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 240 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 241 | // Checkpoints the update progress into persistent storage to allow this |
| 242 | // update attempt to be resumed after reboot. |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 243 | bool CheckpointUpdateProgress(); |
| 244 | |
Darin Petkov | 9b23057 | 2010-10-08 10:20:09 -0700 | [diff] [blame] | 245 | // Primes the required update state. Returns true if the update state was |
| 246 | // successfully initialized to a saved resume state or if the update is a new |
| 247 | // update. Returns false otherwise. |
| 248 | bool PrimeUpdateState(); |
| 249 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 250 | // Sends UMA statistics for the given error code. |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 251 | void SendUmaStat(ErrorCode code); |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 252 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 253 | // Update Engine preference store. |
| 254 | PrefsInterface* prefs_; |
| 255 | |
Jay Srinivasan | f057205 | 2012-10-23 18:12:56 -0700 | [diff] [blame] | 256 | // Global context of the system. |
| 257 | SystemState* system_state_; |
| 258 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 259 | // Install Plan based on Omaha Response. |
| 260 | InstallPlan* install_plan_; |
| 261 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 262 | // File descriptor of open device. |
| 263 | int fd_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 264 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 265 | // File descriptor of the kernel device |
| 266 | int kernel_fd_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 267 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 268 | std::string path_; // Path that fd_ refers to. |
| 269 | std::string kernel_path_; // Path that kernel_fd_ refers to. |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 270 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 271 | DeltaArchiveManifest manifest_; |
| 272 | bool manifest_valid_; |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 273 | uint64_t manifest_metadata_size_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 274 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 275 | // Index of the next operation to perform in the manifest. |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 276 | size_t next_operation_num_; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 277 | |
| 278 | // buffer_ is a window of the data that's been downloaded. At first, |
| 279 | // it contains the beginning of the download, but after the protobuf |
| 280 | // has been downloaded and parsed, it contains a sliding window of |
| 281 | // data blobs. |
| 282 | std::vector<char> buffer_; |
| 283 | // Offset of buffer_ in the binary blobs section of the update. |
| 284 | uint64_t buffer_offset_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 285 | |
Darin Petkov | 0406e40 | 2010-10-06 21:33:11 -0700 | [diff] [blame] | 286 | // Last |buffer_offset_| value updated as part of the progress update. |
| 287 | uint64_t last_updated_buffer_offset_; |
| 288 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 289 | // The block size (parsed from the manifest). |
| 290 | uint32_t block_size_; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 291 | |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 292 | // Calculates the payload hash. |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 293 | OmahaHashCalculator hash_calculator_; |
| 294 | |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame] | 295 | // Saves the signed hash context. |
| 296 | std::string signed_hash_context_; |
| 297 | |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 298 | // Signatures message blob extracted directly from the payload. |
| 299 | std::vector<char> signatures_message_data_; |
| 300 | |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 301 | // The public key to be used. Provided as a member so that tests can |
| 302 | // override with test keys. |
| 303 | std::string public_key_path_; |
Darin Petkov | 698d041 | 2010-10-13 10:59:44 -0700 | [diff] [blame] | 304 | |
Gilad Arnold | 8a86fa5 | 2013-01-15 12:35:05 -0800 | [diff] [blame] | 305 | // The number of bytes received so far, used for progress tracking. |
| 306 | size_t total_bytes_received_; |
| 307 | |
| 308 | // The number rootfs and total operations in a payload, once we know them. |
| 309 | size_t num_rootfs_operations_; |
| 310 | size_t num_total_operations_; |
| 311 | |
| 312 | // An overall progress counter, which should reflect both download progress |
| 313 | // and the ratio of applied operations. Range is 0-100. |
| 314 | unsigned overall_progress_; |
| 315 | |
| 316 | // The last progress chunk recorded. |
| 317 | unsigned last_progress_chunk_; |
| 318 | |
| 319 | // The timeout after which we should force emitting a progress log (constant), |
| 320 | // and the actual point in time for the next forced log to be emitted. |
| 321 | const base::TimeDelta forced_progress_log_wait_; |
| 322 | base::Time forced_progress_log_time_; |
| 323 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 324 | DISALLOW_COPY_AND_ASSIGN(DeltaPerformer); |
| 325 | }; |
| 326 | |
| 327 | } // namespace chromeos_update_engine |
| 328 | |
| 329 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |