Make non-volatile directory platform-specific.
update_engine daemon needs to persist files (such as the progress of
the update) in a non-volatile storage and also used to store a
marker file on a volatile storage to detect when update_engine is
restarted, likelly due to a crash.
This patch moves the non-volatile directory configuration to the
Hardware interface, making it platform-specific. It also replaces the
system rebooted detection using the boot_id provided by the kernel
instead of storing a file under /tmp. This implementation works both
on Chrome OS and Android.
Bug: 24074252
Test: FEATURES=test emerge-link update_engine; `mma`; deployed and tested manually on brillo.
Change-Id: I921d767982adebfd04eb12e08d8a157d9102d1e3
diff --git a/hardware_chromeos.cc b/hardware_chromeos.cc
index 888772d..d8c659a 100644
--- a/hardware_chromeos.cc
+++ b/hardware_chromeos.cc
@@ -37,13 +37,21 @@
namespace {
-static const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed";
+const char kOOBECompletedMarker[] = "/home/chronos/.oobe_completed";
+
+// The stateful directory used by update_engine to store powerwash-safe files.
+// The files stored here must be whitelisted in the powerwash scripts.
+const char kPowerwashSafeDirectory[] =
+ "/mnt/stateful_partition/unencrypted/preserve";
// The powerwash_count marker file contains the number of times the device was
// powerwashed. This value is incremented by the clobber-state script when
// a powerwash is performed.
-static const char kPowerwashCountMarker[] =
- "/mnt/stateful_partition/unencrypted/preserve/powerwash_count";
+const char kPowerwashCountMarker[] = "powerwash_count";
+
+// The stateful directory used by update_engine. This directory is wiped during
+// powerwash.
+const char kNonVolatileDirectory[] = "/var/lib/update_engine";
} // namespace
@@ -125,8 +133,10 @@
int HardwareChromeOS::GetPowerwashCount() const {
int powerwash_count;
+ base::FilePath marker_path = base::FilePath(kPowerwashSafeDirectory).Append(
+ kPowerwashCountMarker);
string contents;
- if (!utils::ReadFile(kPowerwashCountMarker, &contents))
+ if (!utils::ReadFile(marker_path.value(), &contents))
return -1;
base::TrimWhitespaceASCII(contents, base::TRIM_TRAILING, &contents);
if (!base::StringToInt(contents, &powerwash_count))
@@ -134,4 +144,14 @@
return powerwash_count;
}
+bool HardwareChromeOS::GetNonVolatileDirectory(base::FilePath* path) const {
+ *path = base::FilePath(kNonVolatileDirectory);
+ return true;
+}
+
+bool HardwareChromeOS::GetPowerwashSafeDirectory(base::FilePath* path) const {
+ *path = base::FilePath(kPowerwashSafeDirectory);
+ return true;
+}
+
} // namespace chromeos_update_engine