SYSTEM_ROOT -> get_system_root
Add a get_system_root() function in roots.cpp
which returns / or /system based on fstab.
This factors out the 'if' check from recovery.cpp
and fsck_unshare_blocks.cpp.
Test: boot recovery, mount system
Bug: 118634720
Change-Id: If4947cba3a3f08dbe695fd2b50a9354cd302ee03
diff --git a/fsck_unshare_blocks.cpp b/fsck_unshare_blocks.cpp
index 684958e..b653d13 100644
--- a/fsck_unshare_blocks.cpp
+++ b/fsck_unshare_blocks.cpp
@@ -40,7 +40,6 @@
static constexpr const char* SYSTEM_E2FSCK_BIN = "/system/bin/e2fsck_static";
static constexpr const char* TMP_E2FSCK_BIN = "/tmp/e2fsck.bin";
-static constexpr const char* SYSTEM_ROOT = "/system";
static bool copy_file(const char* source, const char* dest) {
android::base::unique_fd source_fd(open(source, O_RDONLY));
@@ -121,14 +120,10 @@
std::vector<std::string> partitions = { "/odm", "/oem", "/product", "/vendor" };
// Temporarily mount system so we can copy e2fsck_static.
- bool mounted = false;
- if (volume_for_mount_point(SYSTEM_ROOT) == nullptr) {
- mounted = ensure_path_mounted_at("/", "/mnt/system") != -1;
- partitions.push_back("/");
- } else {
- mounted = ensure_path_mounted_at(SYSTEM_ROOT, "/mnt/system") != -1;
- partitions.push_back(SYSTEM_ROOT);
- }
+ std::string system_root = get_system_root();
+ bool mounted = ensure_path_mounted_at(system_root.c_str(), "/mnt/system");
+ partitions.push_back(system_root);
+
if (!mounted) {
LOG(ERROR) << "Failed to mount system image.";
return false;