update_engine: Add fds for the source partitions.

Add new fds for the source partition, one for the rootfs and another for
the kernel. These are opened if we have a delta update with minor
version 2.

This change also adds support for changing the minor versions in tests.
There is a new private member, supported_minor_version_, which defaults
to kSupportedMinorPayloadVersion. It is set in the unit tests with calls
to SetSupportedVersion.

BUG=chromium:463573
TEST=`FEATURES=test emerge-link update_engine`

Change-Id: Ib988c91eb450b2499c615ae65b271691dfd9c651
Reviewed-on: https://chromium-review.googlesource.com/260950
Trybot-Ready: Allie Wood <alliewood@chromium.org>
Tested-by: Allie Wood <alliewood@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Allie Wood <alliewood@chromium.org>
diff --git a/delta_performer.h b/delta_performer.h
index eed24cb..fd234a2 100644
--- a/delta_performer.h
+++ b/delta_performer.h
@@ -24,6 +24,12 @@
 
 namespace chromeos_update_engine {
 
+// The minor version used by the in-place delta generator algorithm.
+extern const uint32_t kInPlaceMinorPayloadVersion;
+
+// The minor version used by the A to B delta generator algorithm.
+extern const uint32_t kSourceMinorPayloadVersion;
+
 class PrefsInterface;
 
 // This class performs the actions in a delta update synchronously. The delta
@@ -65,6 +71,8 @@
         install_plan_(install_plan),
         fd_(nullptr),
         kernel_fd_(nullptr),
+        source_fd_(nullptr),
+        source_kernel_fd_(nullptr),
         manifest_parsed_(false),
         manifest_valid_(false),
         metadata_size_(0),
@@ -79,12 +87,19 @@
         overall_progress_(0),
         last_progress_chunk_(0),
         forced_progress_log_wait_(
-            base::TimeDelta::FromSeconds(kProgressLogTimeoutSeconds)) {}
+            base::TimeDelta::FromSeconds(kProgressLogTimeoutSeconds)),
+        supported_minor_version_(kSupportedMinorPayloadVersion) {}
 
   // Opens the kernel. Should be called before or after Open(), but before
   // Write(). The kernel file will be close()d when Close() is called.
   bool OpenKernel(const char* kernel_path);
 
+  // Opens the source partition. The file will be closed when Close() is called.
+  bool OpenSourceRootfs(const std::string& kernel_path);
+
+  // Opens the source kernel. The file will be closed when Close() is called.
+  bool OpenSourceKernel(const std::string& source_kernel_path);
+
   // flags and mode ignored. Once Close()d, a DeltaPerformer can't be
   // Open()ed again.
   int Open(const char* path, int flags, mode_t mode) override;
@@ -186,6 +201,10 @@
   // Returns true on success.
   bool GetManifest(DeltaArchiveManifest* out_manifest_p) const;
 
+  // Returns the delta minor version. If this value is defined in the manifest,
+  // it returns that value, otherwise it returns the default value.
+  uint32_t GetMinorVersion() const;
+
  private:
   friend class DeltaPerformerTest;
   FRIEND_TEST(DeltaPerformerTest, IsIdempotentOperationTest);
@@ -300,9 +319,15 @@
   // File descriptor of open device.
   FileDescriptorPtr fd_;
 
-  // File descriptor of the kernel device
+  // File descriptor of the kernel device.
   FileDescriptorPtr kernel_fd_;
 
+  // File descriptor of the source device.
+  FileDescriptorPtr source_fd_;
+
+  // File descriptor of the source kernel device.
+  FileDescriptorPtr source_kernel_fd_;
+
   std::string path_;  // Path that fd_ refers to.
   std::string kernel_path_;  // Path that kernel_fd_ refers to.
 
@@ -359,6 +384,9 @@
   const base::TimeDelta forced_progress_log_wait_;
   base::Time forced_progress_log_time_;
 
+  // The delta minor payload version supported by DeltaPerformer.
+  uint32_t supported_minor_version_;
+
   DISALLOW_COPY_AND_ASSIGN(DeltaPerformer);
 };