am 32933ff5: am dc4fa7f6: Merge "Fix "adb remount" for when the root directory is in system.img"

* commit '32933ff511a4b63f60543c97e2fc3b47ea465d1a':
  Fix "adb remount" for when the root directory is in system.img
This commit is contained in:
Daniel Rosenberg 2015-07-08 20:37:27 +00:00 committed by Android Git Automerger
commit a5b671d0e3
1 changed files with 34 additions and 2 deletions

View File

@ -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");