blob: 0be86661222d4999c7703f1cc36a2799ce2e690c [file] [log] [blame]
Alex Deymo14158572015-06-13 03:37:08 -07001// Copyright 2015 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 UPDATE_ENGINE_PAYLOAD_GENERATOR_DELTA_DIFF_UTILS_H_
6#define UPDATE_ENGINE_PAYLOAD_GENERATOR_DELTA_DIFF_UTILS_H_
7
8#include <string>
9#include <vector>
10
11#include <chromeos/secure_blob.h>
12
13#include "update_engine/payload_generator/annotated_operation.h"
Alex Deymo14158572015-06-13 03:37:08 -070014#include "update_engine/payload_generator/payload_generation_config.h"
15#include "update_engine/update_metadata.pb.h"
16
17namespace chromeos_update_engine {
18
19namespace diff_utils {
20
Alex Deymob42b98d2015-07-06 17:42:38 -070021// Create operations in |aops| to produce all the blocks in the |new_part|
22// partition using the filesystem opened in that PartitionConfig.
23// It uses the files reported by the filesystem in |old_part| and the data
24// blocks in that partition (if available) to determine the best way to compress
25// the new files (REPLACE, REPLACE_BZ, COPY, BSDIFF) and writes any necessary
26// data to the end of |data_fd| updating |data_file_size| accordingly.
27bool DeltaReadPartition(std::vector<AnnotatedOperation>* aops,
28 const PartitionConfig& old_part,
29 const PartitionConfig& new_part,
30 off_t chunk_blocks,
31 int data_fd,
32 off_t* data_file_size,
33 bool skip_block_0,
34 bool src_ops_allowed);
Alex Deymo14158572015-06-13 03:37:08 -070035
36// For a given file |name| append operations to |aops| to produce it in the
37// |new_part|. The file will be split in chunks of |chunk_blocks| blocks each
38// or treated as a single chunk if |chunk_blocks| is -1. The file data is
39// stored in |new_part| in the blocks described by |new_extents| and, if it
40// exists, the old version exists in |old_part| in the blocks described by
41// |old_extents|. The operations added to |aops| reference the data blob
42// in the file |data_fd|, which has length *data_file_size. *data_file_size is
43// updated appropriately. Returns true on success.
44bool DeltaReadFile(std::vector<AnnotatedOperation>* aops,
45 const std::string& old_part,
46 const std::string& new_part,
47 const std::vector<Extent>& old_extents,
48 const std::vector<Extent>& new_extents,
49 const std::string& name,
50 off_t chunk_blocks,
51 int data_fd,
52 off_t* data_file_size,
53 bool src_ops_allowed);
54
55// Reads the blocks |old_extents| from |old_part| (if it exists) and the
56// |new_extents| from |new_part| and determines the smallest way to encode
57// this |new_extents| for the diff. It stores necessary data in |out_data| and
58// fills in |out_op|. If there's no change in old and new files, it creates a
59// MOVE operation. If there is a change, the smallest of REPLACE, REPLACE_BZ,
60// or BSDIFF wins. |new_extents| must not be empty.
61// If |src_ops_allowed| is true, it will emit SOURCE_COPY and SOURCE_BSDIFF
62// operations instead of MOVE and BSDIFF, respectively.
63// Returns true on success.
64bool ReadExtentsToDiff(const std::string& old_part,
65 const std::string& new_part,
66 const std::vector<Extent>& old_extents,
67 const std::vector<Extent>& new_extents,
68 bool bsdiff_allowed,
69 chromeos::Blob* out_data,
70 DeltaArchiveManifest_InstallOperation* out_op,
71 bool src_ops_allowed);
72
Alex Deymo14158572015-06-13 03:37:08 -070073// Runs the bsdiff tool on two files and returns the resulting delta in
74// |out|. Returns true on success.
75bool BsdiffFiles(const std::string& old_file,
76 const std::string& new_file,
77 chromeos::Blob* out);
78
79// Returns true if |op| is a no-op operation that doesn't do any useful work
80// (e.g., a move operation that copies blocks onto themselves).
81bool IsNoopOperation(const DeltaArchiveManifest_InstallOperation& op);
82
83// Filters all the operations that are no-op, maintaining the relative order
84// of the rest of the operations.
85void FilterNoopOperations(std::vector<AnnotatedOperation>* ops);
86
87bool InitializePartitionInfo(const PartitionConfig& partition,
88 PartitionInfo* info);
89
90} // namespace diff_utils
91
92} // namespace chromeos_update_engine
93
94#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_DELTA_DIFF_UTILS_H_