summaryrefslogtreecommitdiffstats
path: root/updater
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--updater/commands.cpp51
-rw-r--r--updater/include/private/commands.h67
2 files changed, 118 insertions, 0 deletions
diff --git a/updater/commands.cpp b/updater/commands.cpp
index 017086323..aed63369c 100644
--- a/updater/commands.cpp
+++ b/updater/commands.cpp
@@ -401,3 +401,54 @@ std::ostream& operator<<(std::ostream& os, const SourceInfo& source) {
}
return os;
}
+
+TransferList TransferList::Parse(const std::string& transfer_list_str, std::string* err) {
+ TransferList result{};
+
+ std::vector<std::string> lines = android::base::Split(transfer_list_str, "\n");
+ if (lines.size() < kTransferListHeaderLines) {
+ *err = android::base::StringPrintf("too few lines in the transfer list [%zu]", lines.size());
+ return TransferList{};
+ }
+
+ // First line in transfer list is the version number.
+ if (!android::base::ParseInt(lines[0], &result.version_, 3, 4)) {
+ *err = "unexpected transfer list version ["s + lines[0] + "]";
+ return TransferList{};
+ }
+
+ // Second line in transfer list is the total number of blocks we expect to write.
+ if (!android::base::ParseUint(lines[1], &result.total_blocks_)) {
+ *err = "unexpected block count ["s + lines[1] + "]";
+ return TransferList{};
+ }
+
+ // Third line is how many stash entries are needed simultaneously.
+ if (!android::base::ParseUint(lines[2], &result.stash_max_entries_)) {
+ return TransferList{};
+ }
+
+ // Fourth line is the maximum number of blocks that will be stashed simultaneously.
+ if (!android::base::ParseUint(lines[3], &result.stash_max_blocks_)) {
+ *err = "unexpected maximum stash blocks ["s + lines[3] + "]";
+ return TransferList{};
+ }
+
+ // Subsequent lines are all individual transfer commands.
+ for (size_t i = kTransferListHeaderLines; i < lines.size(); i++) {
+ const std::string& line = lines[i];
+ if (line.empty()) continue;
+
+ size_t cmdindex = i - kTransferListHeaderLines;
+ std::string parsing_error;
+ Command command = Command::Parse(line, cmdindex, &parsing_error);
+ if (!command) {
+ *err = android::base::StringPrintf("Failed to parse command %zu [%s]: %s", cmdindex,
+ line.c_str(), parsing_error.c_str());
+ return TransferList{};
+ }
+ result.commands_.push_back(command);
+ }
+
+ return result;
+}
diff --git a/updater/include/private/commands.h b/updater/include/private/commands.h
index 521289780..79f915434 100644
--- a/updater/include/private/commands.h
+++ b/updater/include/private/commands.h
@@ -406,3 +406,70 @@ class Command {
};
std::ostream& operator<<(std::ostream& os, const Command& command);
+
+// TransferList represents the info for a transfer list, which is parsed from input text lines
+// containing commands to transfer data from one place to another on the target partition.
+//
+// The creator of the transfer list will guarantee that no block is read (i.e., used as the source
+// for a patch or move) after it has been written.
+//
+// The creator will guarantee that a given stash is loaded (with a stash command) before it's used
+// in a move/bsdiff/imgdiff command.
+//
+// Within one command the source and target ranges may overlap so in general we need to read the
+// entire source into memory before writing anything to the target blocks.
+//
+// All the patch data is concatenated into one patch_data file in the update package. It must be
+// stored uncompressed because we memory-map it in directly from the archive. (Since patches are
+// already compressed, we lose very little by not compressing their concatenation.)
+//
+// Commands that read data from the partition (i.e. move/bsdiff/imgdiff/stash) have one or more
+// additional hashes before the range parameters, which are used to check if the command has
+// already been completed and verify the integrity of the source data.
+class TransferList {
+ public:
+ // Number of header lines.
+ static constexpr size_t kTransferListHeaderLines = 4;
+
+ TransferList() = default;
+
+ // Parses the given input string and returns a TransferList object. Sets error message if any.
+ static TransferList Parse(const std::string& transfer_list_str, std::string* err);
+
+ int version() const {
+ return version_;
+ }
+
+ size_t total_blocks() const {
+ return total_blocks_;
+ }
+
+ size_t stash_max_entries() const {
+ return stash_max_entries_;
+ }
+
+ size_t stash_max_blocks() const {
+ return stash_max_blocks_;
+ }
+
+ const std::vector<Command>& commands() const {
+ return commands_;
+ }
+
+ // Returns whether the TransferList is valid.
+ constexpr explicit operator bool() const {
+ return version_ != 0;
+ }
+
+ private:
+ // BBOTA version.
+ int version_{ 0 };
+ // Total number of blocks to be written in this transfer.
+ size_t total_blocks_;
+ // Maximum number of stashes that exist at the same time.
+ size_t stash_max_entries_;
+ // Maximum number of blocks to be stashed.
+ size_t stash_max_blocks_;
+ // Commands in this transfer.
+ std::vector<Command> commands_;
+};