| 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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
| 7 | 7 |
| 8 #include <inttypes.h> | 8 #include <inttypes.h> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include <google/protobuf/repeated_field.h> | 10 #include <google/protobuf/repeated_field.h> |
| 11 #include "update_engine/file_writer.h" | 11 #include "update_engine/file_writer.h" |
| 12 #include "update_engine/update_metadata.pb.h" | 12 #include "update_engine/update_metadata.pb.h" |
| 13 | 13 |
| 14 namespace chromeos_update_engine { | 14 namespace chromeos_update_engine { |
| 15 | 15 |
| 16 // This class performs the actions in a delta update synchronously. The delta | 16 // This class performs the actions in a delta update synchronously. The delta |
| 17 // update itself should be passed in in chunks as it is received. | 17 // update itself should be passed in in chunks as it is received. |
| 18 | 18 |
| 19 class DeltaPerformer : public FileWriter { | 19 class DeltaPerformer : public FileWriter { |
| 20 public: | 20 public: |
| 21 DeltaPerformer() | 21 DeltaPerformer() |
| 22 : fd_(-1), | 22 : fd_(-1), |
| 23 kernel_fd_(-1), |
| 23 manifest_valid_(false), | 24 manifest_valid_(false), |
| 24 next_operation_(0), | 25 next_operation_num_(0), |
| 25 buffer_offset_(0), | 26 buffer_offset_(0), |
| 26 block_size_(0) {} | 27 block_size_(0) {} |
| 28 |
| 29 // Opens the kernel. Should be called before or after Open(), but before |
| 30 // Write(). The kernel file will be close()d when Close() is called. |
| 31 bool OpenKernel(const char* kernel_path); |
| 32 |
| 27 // flags and mode ignored. Once Close()d, a DeltaPerformer can't be | 33 // flags and mode ignored. Once Close()d, a DeltaPerformer can't be |
| 28 // Open()ed again. | 34 // Open()ed again. |
| 29 int Open(const char* path, int flags, mode_t mode); | 35 int Open(const char* path, int flags, mode_t mode); |
| 30 | 36 |
| 31 // Wrapper around write. Returns bytes written on success or | 37 // Wrapper around write. Returns bytes written on success or |
| 32 // -errno on error. | 38 // -errno on error. |
| 33 ssize_t Write(const void* bytes, size_t count); | 39 ssize_t Write(const void* bytes, size_t count); |
| 34 | 40 |
| 35 // Wrapper around close. Returns 0 on success or -errno on error. | 41 // Wrapper around close. Returns 0 on success or -errno on error. |
| 42 // Closes both 'path' given to Open() and the kernel path. |
| 36 int Close(); | 43 int Close(); |
| 37 | 44 |
| 38 // Converts an ordered collection of Extent objects which contain data of | 45 // Converts an ordered collection of Extent objects which contain data of |
| 39 // length full_length to a comma-separated string. For each Extent, the | 46 // length full_length to a comma-separated string. For each Extent, the |
| 40 // string will have the start offset and then the length in bytes. | 47 // string will have the start offset and then the length in bytes. |
| 41 // The length value of the last extent in the string may be short, since | 48 // The length value of the last extent in the string may be short, since |
| 42 // the full length of all extents in the string is capped to full_length. | 49 // the full length of all extents in the string is capped to full_length. |
| 43 // Also, an extent starting at kSparseHole, appears as -1 in the string. | 50 // Also, an extent starting at kSparseHole, appears as -1 in the string. |
| 44 // For example, if the Extents are {1, 1}, {4, 2}, {kSparseHole, 1}, | 51 // For example, if the Extents are {1, 1}, {4, 2}, {kSparseHole, 1}, |
| 45 // {0, 1}, block_size is 4096, and full_length is 5 * block_size - 13, | 52 // {0, 1}, block_size is 4096, and full_length is 5 * block_size - 13, |
| 46 // the resulting string will be: "4096:4096,16384:8192,-1:4096,0:4083" | 53 // the resulting string will be: "4096:4096,16384:8192,-1:4096,0:4083" |
| 47 static bool ExtentsToBsdiffPositionsString( | 54 static bool ExtentsToBsdiffPositionsString( |
| 48 const google::protobuf::RepeatedPtrField<Extent>& extents, | 55 const google::protobuf::RepeatedPtrField<Extent>& extents, |
| 49 uint64_t block_size, | 56 uint64_t block_size, |
| 50 uint64_t full_length, | 57 uint64_t full_length, |
| 51 std::string* positions_string); | 58 std::string* positions_string); |
| 52 | 59 |
| 53 private: | 60 private: |
| 54 // Returns true if enough of the delta file has been passed via Write() | 61 // Returns true if enough of the delta file has been passed via Write() |
| 55 // to be able to perform a given install operation. | 62 // to be able to perform a given install operation. |
| 56 bool CanPerformInstallOperation( | 63 bool CanPerformInstallOperation( |
| 57 const DeltaArchiveManifest_InstallOperation& operation); | 64 const DeltaArchiveManifest_InstallOperation& operation); |
| 58 | 65 |
| 59 // Returns true on success. | 66 // Returns true on success. |
| 60 bool PerformInstallOperation( | 67 bool PerformInstallOperation( |
| 61 const DeltaArchiveManifest_InstallOperation& operation); | 68 const DeltaArchiveManifest_InstallOperation& operation); |
| 62 | 69 |
| 63 // These perform a specific type of operation and return true on success. | 70 // These perform a specific type of operation and return true on success. |
| 64 bool PerformReplaceOperation( | 71 bool PerformReplaceOperation( |
| 65 const DeltaArchiveManifest_InstallOperation& operation); | 72 const DeltaArchiveManifest_InstallOperation& operation, |
| 73 bool is_kernel_partition); |
| 66 bool PerformMoveOperation( | 74 bool PerformMoveOperation( |
| 67 const DeltaArchiveManifest_InstallOperation& operation); | 75 const DeltaArchiveManifest_InstallOperation& operation, |
| 76 bool is_kernel_partition); |
| 68 bool PerformBsdiffOperation( | 77 bool PerformBsdiffOperation( |
| 69 const DeltaArchiveManifest_InstallOperation& operation); | 78 const DeltaArchiveManifest_InstallOperation& operation, |
| 79 bool is_kernel_partition); |
| 70 | 80 |
| 71 // File descriptor of open device. | 81 // File descriptor of open device. |
| 72 int fd_; | 82 int fd_; |
| 73 | 83 |
| 74 std::string path_; // Path that fd_ refers to | 84 // File descriptor of the kernel device |
| 85 int kernel_fd_; |
| 86 |
| 87 std::string path_; // Path that fd_ refers to. |
| 88 std::string kernel_path_; // Path that kernel_fd_ refers to. |
| 75 | 89 |
| 76 DeltaArchiveManifest manifest_; | 90 DeltaArchiveManifest manifest_; |
| 77 bool manifest_valid_; | 91 bool manifest_valid_; |
| 78 | 92 |
| 79 // Index of the next operation to perform in the manifest. | 93 // Index of the next operation to perform in the manifest. |
| 80 int next_operation_; | 94 int next_operation_num_; |
| 81 | 95 |
| 82 // buffer_ is a window of the data that's been downloaded. At first, | 96 // buffer_ is a window of the data that's been downloaded. At first, |
| 83 // it contains the beginning of the download, but after the protobuf | 97 // it contains the beginning of the download, but after the protobuf |
| 84 // has been downloaded and parsed, it contains a sliding window of | 98 // has been downloaded and parsed, it contains a sliding window of |
| 85 // data blobs. | 99 // data blobs. |
| 86 std::vector<char> buffer_; | 100 std::vector<char> buffer_; |
| 87 // Offset of buffer_ in the binary blobs section of the update. | 101 // Offset of buffer_ in the binary blobs section of the update. |
| 88 uint64_t buffer_offset_; | 102 uint64_t buffer_offset_; |
| 89 | 103 |
| 90 // The block size (parsed from the manifest). | 104 // The block size (parsed from the manifest). |
| 91 uint32_t block_size_; | 105 uint32_t block_size_; |
| 92 | 106 |
| 93 DISALLOW_COPY_AND_ASSIGN(DeltaPerformer); | 107 DISALLOW_COPY_AND_ASSIGN(DeltaPerformer); |
| 94 }; | 108 }; |
| 95 | 109 |
| 96 } // namespace chromeos_update_engine | 110 } // namespace chromeos_update_engine |
| 97 | 111 |
| 98 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ | 112 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_PERFORMER_H__ |
| OLD | NEW |