diff options
author | Daniel Rosenberg <drosen@google.com> | 2015-06-29 17:30:28 -0700 |
---|---|---|
committer | Daniel Rosenberg <drosen@google.com> | 2015-07-08 19:36:19 +0000 |
commit | d6eba89f83a4028a4b25e44dc0f8bc59dd6ad70a (patch) | |
tree | 8b5b1bf8c1e546371e3bbb7e88f37ae245e8fc23 /adb/remount_service.cpp | |
parent | c9aeae27403db86e1ec30c953f1d0fd6ae63b184 (diff) | |
download | core-d6eba89f83a4028a4b25e44dc0f8bc59dd6ad70a.tar.gz core-d6eba89f83a4028a4b25e44dc0f8bc59dd6ad70a.tar.bz2 core-d6eba89f83a4028a4b25e44dc0f8bc59dd6ad70a.zip |
Fix "adb remount" for when the root directory is in system.img
When the root directory has been built into system.img, it is
mounted at /.
Change-Id: If01d12efeaa53b4ae59e801a6e9b802a9ae5882d
Diffstat (limited to 'adb/remount_service.cpp')
-rw-r--r-- | adb/remount_service.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/adb/remount_service.cpp b/adb/remount_service.cpp index 3a4d2da7b..28932636d 100644 --- a/adb/remount_service.cpp +++ b/adb/remount_service.cpp @@ -33,9 +33,12 @@ #include "adb_io.h" #include "adb_utils.h" #include "cutils/properties.h" +#include "fs_mgr.h" + +const std::string kFstab_Prefix = "/fstab."; // Returns the device used to mount a directory in /proc/mounts. -static std::string find_mount(const char* dir) { +static std::string find_proc_mount(const char* dir) { std::unique_ptr<FILE, int(*)(FILE*)> fp(setmntent("/proc/mounts", "r"), endmntent); if (!fp) { return ""; @@ -50,6 +53,29 @@ static std::string find_mount(const char* dir) { return ""; } +// Returns the device used to mount a directory in the fstab. +static std::string find_fstab_mount(const char* dir) { + char propbuf[PROPERTY_VALUE_MAX]; + + property_get("ro.hardware", propbuf, ""); + std::string fstab_filename = kFstab_Prefix + propbuf; + struct fstab* fstab = fs_mgr_read_fstab(fstab_filename.c_str()); + struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, dir); + std::string dev = rec ? std::string(rec->blk_device) : ""; + fs_mgr_free_fstab(fstab); + return dev; +} + +// The proc entry for / is full of lies, so check fstab instead. +// /proc/mounts lists rootfs and /dev/root, neither of which is what we want. +static std::string find_mount(const char* dir) { + if (strcmp(dir, "/") == 0) { + return find_fstab_mount(dir); + } else { + return find_proc_mount(dir); + } +} + bool make_block_device_writable(const std::string& dev) { int fd = unix_open(dev.c_str(), O_RDONLY | O_CLOEXEC); if (fd == -1) { @@ -112,7 +138,13 @@ void remount_service(int fd, void* cookie) { } bool success = true; - success &= remount_partition(fd, "/system"); + property_get("ro.build.system_root_image", prop_buf, ""); + bool system_root = !strcmp(prop_buf, "true"); + if (system_root) { + success &= remount_partition(fd, "/"); + } else { + success &= remount_partition(fd, "/system"); + } success &= remount_partition(fd, "/vendor"); success &= remount_partition(fd, "/oem"); |