| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium 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_DIFF_GENERATOR_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "update_engine/graph_types.h" | 11 #include "update_engine/graph_types.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // from T rather than the blocks in the edge. Modify A to depend on X, | 118 // from T rather than the blocks in the edge. Modify A to depend on X, |
| 119 // but not on B. Free space is found by looking in 'blocks'. | 119 // but not on B. Free space is found by looking in 'blocks'. |
| 120 // Returns true on success. | 120 // Returns true on success. |
| 121 static bool CutEdges(Graph* graph, | 121 static bool CutEdges(Graph* graph, |
| 122 const std::set<Edge>& edges, | 122 const std::set<Edge>& edges, |
| 123 std::vector<CutEdgeVertexes>* out_cuts); | 123 std::vector<CutEdgeVertexes>* out_cuts); |
| 124 | 124 |
| 125 // Stores all Extents in 'extents' into 'out'. | 125 // Stores all Extents in 'extents' into 'out'. |
| 126 static void StoreExtents(const std::vector<Extent>& extents, | 126 static void StoreExtents(const std::vector<Extent>& extents, |
| 127 google::protobuf::RepeatedPtrField<Extent>* out); | 127 google::protobuf::RepeatedPtrField<Extent>* out); |
| 128 | 128 |
| 129 // Creates all the edges for the graph. Writers of a block point to | 129 // Creates all the edges for the graph. Writers of a block point to |
| 130 // readers of the same block. This is because for an edge A->B, B | 130 // readers of the same block. This is because for an edge A->B, B |
| 131 // must complete before A executes. | 131 // must complete before A executes. |
| 132 static void CreateEdges(Graph* graph, const std::vector<Block>& blocks); | 132 static void CreateEdges(Graph* graph, const std::vector<Block>& blocks); |
| 133 | 133 |
| 134 // Given a topologically sorted graph |op_indexes| and |graph|, alters | 134 // Given a topologically sorted graph |op_indexes| and |graph|, alters |
| 135 // |op_indexes| to move all the full operations to the end of the vector. | 135 // |op_indexes| to move all the full operations to the end of the vector. |
| 136 // Full operations should not be depended on, so this is safe. | 136 // Full operations should not be depended on, so this is safe. |
| 137 static void MoveFullOpsToBack(Graph* graph, | 137 static void MoveFullOpsToBack(Graph* graph, |
| 138 std::vector<Vertex::Index>* op_indexes); | 138 std::vector<Vertex::Index>* op_indexes); |
| 139 | 139 |
| 140 // Sorts the vector |cuts| by its |cuts[].old_dest| member. Order is | 140 // Sorts the vector |cuts| by its |cuts[].old_dest| member. Order is |
| 141 // determined by the order of elements in op_indexes. | 141 // determined by the order of elements in op_indexes. |
| 142 static void SortCutsByTopoOrder(std::vector<Vertex::Index>& op_indexes, | 142 static void SortCutsByTopoOrder(std::vector<Vertex::Index>& op_indexes, |
| 143 std::vector<CutEdgeVertexes>* cuts); | 143 std::vector<CutEdgeVertexes>* cuts); |
| 144 | 144 |
| 145 // Returns true iff there are no extents in the graph that refer to temp | 145 // Returns true iff there are no extents in the graph that refer to temp |
| 146 // blocks. Temp blocks are in the range [kTempBlockStart, kSparseHole). | 146 // blocks. Temp blocks are in the range [kTempBlockStart, kSparseHole). |
| 147 static bool NoTempBlocksRemain(const Graph& graph); | 147 static bool NoTempBlocksRemain(const Graph& graph); |
| 148 | 148 |
| 149 // Install operations in the manifest may reference data blobs, which | 149 // Install operations in the manifest may reference data blobs, which |
| 150 // are in data_blobs_path. This function creates a new data blobs file | 150 // are in data_blobs_path. This function creates a new data blobs file |
| 151 // with the data blobs in the same order as the referencing install | 151 // with the data blobs in the same order as the referencing install |
| 152 // operations in the manifest. E.g. if manifest[0] has a data blob | 152 // operations in the manifest. E.g. if manifest[0] has a data blob |
| 153 // "X" at offset 1, manifest[1] has a data blob "Y" at offset 0, | 153 // "X" at offset 1, manifest[1] has a data blob "Y" at offset 0, |
| 154 // and data_blobs_path's file contains "YX", new_data_blobs_path | 154 // and data_blobs_path's file contains "YX", new_data_blobs_path |
| 155 // will set to be a file that contains "XY". | 155 // will set to be a file that contains "XY". |
| 156 static bool ReorderDataBlobs(DeltaArchiveManifest* manifest, | 156 static bool ReorderDataBlobs(DeltaArchiveManifest* manifest, |
| 157 const std::string& data_blobs_path, | 157 const std::string& data_blobs_path, |
| 158 const std::string& new_data_blobs_path); | 158 const std::string& new_data_blobs_path); |
| 159 | 159 |
| 160 // Handles allocation of temp blocks to a cut edge by converting the | 160 // Handles allocation of temp blocks to a cut edge by converting the |
| 161 // dest node to a full op. This removes the need for temp blocks, but | 161 // dest node to a full op. This removes the need for temp blocks, but |
| 162 // comes at the cost of a worse compression ratio. | 162 // comes at the cost of a worse compression ratio. |
| 163 // For example, say we have A->B->A. It would first be cut to form: | 163 // For example, say we have A->B->A. It would first be cut to form: |
| 164 // A->B->N<-A, where N copies blocks to temp space. If there are no | 164 // A->B->N<-A, where N copies blocks to temp space. If there are no |
| 165 // temp blocks, this function can be called to convert it to the form: | 165 // temp blocks, this function can be called to convert it to the form: |
| 166 // A->B. Now, A is a full operation. | 166 // A->B. Now, A is a full operation. |
| 167 static bool ConvertCutToFullOp(Graph* graph, | 167 static bool ConvertCutToFullOp(Graph* graph, |
| 168 const CutEdgeVertexes& cut, | 168 const CutEdgeVertexes& cut, |
| 169 const std::string& new_root, | 169 const std::string& new_root, |
| 170 int data_fd, | 170 int data_fd, |
| 171 off_t* data_file_size); | 171 off_t* data_file_size); |
| 172 | 172 |
| 173 // Takes |op_indexes|, which is effectively a mapping from order in | 173 // Takes |op_indexes|, which is effectively a mapping from order in |
| 174 // which the op is performed -> graph vertex index, and produces the | 174 // which the op is performed -> graph vertex index, and produces the |
| 175 // reverse: a mapping from graph vertex index -> op_indexes index. | 175 // reverse: a mapping from graph vertex index -> op_indexes index. |
| 176 static void GenerateReverseTopoOrderMap( | 176 static void GenerateReverseTopoOrderMap( |
| 177 std::vector<Vertex::Index>& op_indexes, | 177 std::vector<Vertex::Index>& op_indexes, |
| 178 std::vector<std::vector<Vertex::Index>::size_type>* reverse_op_indexes); | 178 std::vector<std::vector<Vertex::Index>::size_type>* reverse_op_indexes); |
| 179 | 179 |
| 180 // Takes a |graph|, which has edges that must be cut, as listed in | 180 // Takes a |graph|, which has edges that must be cut, as listed in |
| 181 // |cuts|. Cuts the edges. Maintains a list in which the operations | 181 // |cuts|. Cuts the edges. Maintains a list in which the operations |
| 182 // will be performed (in |op_indexes|) and the reverse (in | 182 // will be performed (in |op_indexes|) and the reverse (in |
| 183 // |reverse_op_indexes|). Cutting edges requires scratch space, and | 183 // |reverse_op_indexes|). Cutting edges requires scratch space, and |
| 184 // if insufficient scratch is found, the file is reread and will be | 184 // if insufficient scratch is found, the file is reread and will be |
| 185 // send down (either as REPLACE or REPLACE_BZ). Returns true on | 185 // send down (either as REPLACE or REPLACE_BZ). Returns true on |
| 186 // success. | 186 // success. |
| 187 static bool AssignTempBlocks( | 187 static bool AssignTempBlocks( |
| 188 Graph* graph, | 188 Graph* graph, |
| 189 const std::string& new_root, | 189 const std::string& new_root, |
| 190 int data_fd, | 190 int data_fd, |
| 191 off_t* data_file_size, | 191 off_t* data_file_size, |
| 192 std::vector<Vertex::Index>* op_indexes, | 192 std::vector<Vertex::Index>* op_indexes, |
| 193 std::vector<std::vector<Vertex::Index>::size_type>* reverse_op_indexes, | 193 std::vector<std::vector<Vertex::Index>::size_type>* reverse_op_indexes, |
| 194 std::vector<CutEdgeVertexes>& cuts); | 194 std::vector<CutEdgeVertexes>& cuts); |
| 195 | 195 |
| 196 // Given a new rootfs and kernel (|new_image|, |new_kernel_part|), | 196 // Given a new rootfs and kernel (|new_image|, |new_kernel_part|), Reads them |
| 197 // Reads them sequentially, creating a full update of chunk_size chunks. | 197 // sequentially, creating a full update of chunk_size chunks. Populates |
| 198 // Populates |graph|, |kernel_ops|, and |final_order|, with data | 198 // |graph|, |kernel_ops|, and |final_order|, with data about the update |
| 199 // about the update operations, and writes relevant data to |fd|, | 199 // operations, and writes relevant data to |fd|, updating |data_file_size| as |
| 200 // updating |data_file_size| as it does. | 200 // it does. Only the first |image_size| bytes are read from |new_image| |
| 201 // assuming that this is the actual file system. |
| 201 static bool ReadFullUpdateFromDisk( | 202 static bool ReadFullUpdateFromDisk( |
| 202 Graph* graph, | 203 Graph* graph, |
| 203 const std::string& new_kernel_part, | 204 const std::string& new_kernel_part, |
| 204 const std::string& new_image, | 205 const std::string& new_image, |
| 206 off_t image_size, |
| 205 int fd, | 207 int fd, |
| 206 off_t* data_file_size, | 208 off_t* data_file_size, |
| 207 off_t chunk_size, | 209 off_t chunk_size, |
| 208 std::vector<DeltaArchiveManifest_InstallOperation>* kernel_ops, | 210 std::vector<DeltaArchiveManifest_InstallOperation>* kernel_ops, |
| 209 std::vector<Vertex::Index>* final_order); | 211 std::vector<Vertex::Index>* final_order); |
| 210 | 212 |
| 211 private: | 213 private: |
| 212 // This should never be constructed | 214 // This should never be constructed |
| 213 DISALLOW_IMPLICIT_CONSTRUCTORS(DeltaDiffGenerator); | 215 DISALLOW_IMPLICIT_CONSTRUCTORS(DeltaDiffGenerator); |
| 214 }; | 216 }; |
| 215 | 217 |
| 216 extern const char* const kBsdiffPath; | 218 extern const char* const kBsdiffPath; |
| 217 extern const char* const kBspatchPath; | 219 extern const char* const kBspatchPath; |
| 218 extern const char* const kDeltaMagic; | 220 extern const char* const kDeltaMagic; |
| 219 | 221 |
| 220 }; // namespace chromeos_update_engine | 222 }; // namespace chromeos_update_engine |
| 221 | 223 |
| 222 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ | 224 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_DELTA_DIFF_GENERATOR_H__ |
| OLD | NEW |