summaryrefslogtreecommitdiffstats
path: root/applypatch/include
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-06-20 09:30:48 +0200
committerTao Bao <tbao@google.com>2018-08-31 18:21:15 +0200
commit5609bc8b34745b70d18916aa3b74f3272648e490 (patch)
tree048e988c79cb22a71dae3e951f41457d8f24f62f /applypatch/include
parentMerge "Enable c++17 in recovery_defaults." (diff)
downloadandroid_bootable_recovery-5609bc8b34745b70d18916aa3b74f3272648e490.tar
android_bootable_recovery-5609bc8b34745b70d18916aa3b74f3272648e490.tar.gz
android_bootable_recovery-5609bc8b34745b70d18916aa3b74f3272648e490.tar.bz2
android_bootable_recovery-5609bc8b34745b70d18916aa3b74f3272648e490.tar.lz
android_bootable_recovery-5609bc8b34745b70d18916aa3b74f3272648e490.tar.xz
android_bootable_recovery-5609bc8b34745b70d18916aa3b74f3272648e490.tar.zst
android_bootable_recovery-5609bc8b34745b70d18916aa3b74f3272648e490.zip
Diffstat (limited to 'applypatch/include')
-rw-r--r--applypatch/include/applypatch/applypatch.h85
1 files changed, 47 insertions, 38 deletions
diff --git a/applypatch/include/applypatch/applypatch.h b/applypatch/include/applypatch/applypatch.h
index cf65f3f22..70eee1c16 100644
--- a/applypatch/include/applypatch/applypatch.h
+++ b/applypatch/include/applypatch/applypatch.h
@@ -21,6 +21,7 @@
#include <functional>
#include <memory>
+#include <ostream>
#include <string>
#include <vector>
@@ -44,44 +45,52 @@ int ShowLicenses();
// digest or be of the form "<digest>:<anything>". Returns 0 on success, or -1 on any error.
int ParseSha1(const std::string& str, uint8_t* digest);
-// Applies binary patches to eMMC target files in a way that is safe (the original file is not
-// touched until we have the desired replacement for it) and idempotent (it's okay to run this
-// program multiple times).
-//
-// - If the SHA-1 hash of 'target_filename' is 'target_sha1_string', does nothing and returns
-// successfully.
-//
-// - Otherwise, if the SHA-1 hash of 'source_filename' is one of the entries in 'patch_sha1s', the
-// corresponding patch from 'patch_data' (which must be a VAL_BLOB) is applied to produce a new
-// file (the type of patch is automatically detected from the blob data). If that new file has
-// SHA-1 hash 'target_sha1_str', moves it to replace 'target_filename', and exits successfully.
-// Note that if 'source_filename' and 'target_filename' are not the same, 'source_filename' is
-// NOT deleted on success. 'target_filename' may be the string "-" to mean
-// "the same as 'source_filename'".
-//
-// - Otherwise, or if any error is encountered, exits with non-zero status.
-//
-// 'source_filename' must refer to an eMMC partition to read the source data. See the comments for
-// the LoadPartitionContents() function for the format of such a filename. 'target_size' has become
-// obsolete since we have dropped the support for patching non-eMMC targets (eMMC targets have the
-// size embedded in the filename).
-int applypatch(const char* source_filename, const char* target_filename,
- const char* target_sha1_str, size_t target_size,
- const std::vector<std::string>& patch_sha1s,
- const std::vector<std::unique_ptr<Value>>& patch_data, const Value* bonus_data);
-
-// Returns 0 if the contents of the eMMC target or the cached file match any of the given SHA-1's.
-// Returns nonzero otherwise. 'filename' must refer to an eMMC partition target. It would only use
-// 'sha1s' to find a match on /cache if the hashes embedded in the filename fail to match.
-int applypatch_check(const std::string& filename, const std::vector<std::string>& sha1s);
-
-// Flashes a given image to the eMMC target partition. It verifies the target cheksum first, and
-// will return if target already has the desired hash. Otherwise it checks the checksum of the
-// given source image before flashing, and verifies the target partition afterwards.
-// 'target_filename' must refer to an eMMC partition, of the form "EMMC:<device>:<size>:<hash>".
-// The function is idempotent. Returns zero on success.
-int applypatch_flash(const char* source_filename, const char* target_filename,
- const char* target_sha1_str, size_t target_size);
+struct Partition {
+ Partition() = default;
+
+ Partition(const std::string& name, size_t size, const std::string& hash)
+ : name(name), size(size), hash(hash) {}
+
+ // Parses and returns the given string into a Partition object. The input string is of the form
+ // "EMMC:<device>:<size>:<hash>". Returns the parsed Partition, or an empty object on error.
+ static Partition Parse(const std::string& partition, std::string* err);
+
+ std::string ToString() const;
+
+ // Returns whether the current Partition object is valid.
+ explicit operator bool() const {
+ return !name.empty();
+ }
+
+ std::string name;
+ size_t size;
+ std::string hash;
+};
+
+std::ostream& operator<<(std::ostream& os, const Partition& partition);
+
+// Applies the given 'patch' to the 'source' Partition, verifies then writes the patching result to
+// the 'target' Partition. While patching, it will backup the data on the source partition to
+// /cache, so that the patching could be resumed on interruption even if both of the source and
+// target partitions refer to the same device. The function is idempotent if called multiple times.
+// An optional arg 'bonus' can be provided, if the patch was generated with a bonus output.
+// Returns the patching result.
+bool PatchPartition(const Partition& target, const Partition& source, const Value& patch,
+ const Value* bonus);
+
+// Returns whether the contents of the eMMC target or the cached file match the embedded hash.
+// It will look for the backup on /cache if the given partition doesn't match the checksum.
+bool PatchPartitionCheck(const Partition& target, const Partition& source);
+
+// Checks whether the contents of the given partition has the desired hash. It will NOT look for
+// the backup on /cache if the given partition doesn't have the expected checksum.
+bool CheckPartition(const Partition& target);
+
+// Flashes a given image in 'source_filename' to the eMMC target partition. It verifies the target
+// checksum first, and will return if target already has the desired hash. Otherwise it checks the
+// checksum of the given source image, flashes, and verifies the target partition afterwards. The
+// function is idempotent. Returns the flashing result.
+bool FlashPartition(const Partition& target, const std::string& source_filename);
// Reads a file into memory; stores the file contents and associated metadata in *file. Returns 0
// on success, or -1 on error.