Upon source hash validation failure, log ext4 remount information

When source hash verification fails, check if the current partition
is an ext4 that has been remounted.
Log mount count and date.

Based on corresponding functionality in recovery.

Bug: 72074823
Test: manual - Confirm that remount count is present in the log when
      installing an update and the system has been remounted

Change-Id: I3cf12c9f93fa5ef9f73f0a1b6a795eb2a3e9335e
diff --git a/payload_consumer/delta_performer.cc b/payload_consumer/delta_performer.cc
index 7c94c71..6540675 100644
--- a/payload_consumer/delta_performer.cc
+++ b/payload_consumer/delta_performer.cc
@@ -50,6 +50,7 @@
 #include "update_engine/payload_consumer/extent_reader.h"
 #include "update_engine/payload_consumer/extent_writer.h"
 #include "update_engine/payload_consumer/file_descriptor_utils.h"
+#include "update_engine/payload_consumer/mount_history.h"
 #if USE_MTD
 #include "update_engine/payload_consumer/mtd_file_descriptor.h"
 #endif
@@ -1079,8 +1080,10 @@
 
 // Compare |calculated_hash| with source hash in |operation|, return false and
 // dump hash and set |error| if don't match.
+// |source_fd| is the file descriptor of the source partition.
 bool ValidateSourceHash(const brillo::Blob& calculated_hash,
                         const InstallOperation& operation,
+                        const FileDescriptorPtr source_fd,
                         ErrorCode* error) {
   brillo::Blob expected_source_hash(operation.src_sha256_hash().begin(),
                                     operation.src_sha256_hash().end());
@@ -1107,6 +1110,9 @@
     LOG(ERROR) << "Operation source (offset:size) in blocks: "
                << base::JoinString(source_extents, ",");
 
+    // Log remount history if this device is an ext4 partition.
+    LogMountHistory(source_fd);
+
     *error = ErrorCode::kDownloadStateInitializationError;
     return false;
   }
@@ -1131,7 +1137,8 @@
                                                      &source_hash));
 
   if (operation.has_src_sha256_hash()) {
-    TEST_AND_RETURN_FALSE(ValidateSourceHash(source_hash, operation, error));
+    TEST_AND_RETURN_FALSE(
+        ValidateSourceHash(source_hash, operation, source_fd_, error));
   }
 
   return true;
@@ -1217,8 +1224,8 @@
     total_blocks -= read_blocks;
   }
   TEST_AND_RETURN_FALSE(source_hasher.Finalize());
-  TEST_AND_RETURN_FALSE(
-      ValidateSourceHash(source_hasher.raw_hash(), operation, error));
+  TEST_AND_RETURN_FALSE(ValidateSourceHash(
+      source_hasher.raw_hash(), operation, source_fd_, error));
   return true;
 }