diff options
author | Dan Albert <danalbert@google.com> | 2015-03-16 21:35:53 +0000 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2015-03-16 21:35:53 +0000 |
commit | 6084a0124f868c7ec43f6c415a27a168f27ff694 (patch) | |
tree | 06e375320e4c8b9967a1fe660edcea2503fac277 /adb/remount_service.cpp | |
parent | 81416fdb186070fe4db3ca5fed2e713a4eecaac1 (diff) | |
download | system_core-6084a0124f868c7ec43f6c415a27a168f27ff694.zip system_core-6084a0124f868c7ec43f6c415a27a168f27ff694.tar.gz system_core-6084a0124f868c7ec43f6c415a27a168f27ff694.tar.bz2 |
Revert "adb: support /oem partition"
This is broken on userdebug builds, and it isn't completely clear why. The declaration for make_block-device_writable in adb.h wasn't updated to match the definition (which uses a std::string instead of a char*). adb.h is currently extern "C", and it isn't clear why this is only broken for userdebug, so I'd like to revert while we investigate.
This reverts commit 81416fdb186070fe4db3ca5fed2e713a4eecaac1.
Change-Id: I47f321574f9f21052e2c7332e8b0f6ef9ab98277
Diffstat (limited to 'adb/remount_service.cpp')
-rw-r--r-- | adb/remount_service.cpp | 109 |
1 files changed, 64 insertions, 45 deletions
diff --git a/adb/remount_service.cpp b/adb/remount_service.cpp index a83d5b1..414b316 100644 --- a/adb/remount_service.cpp +++ b/adb/remount_service.cpp @@ -23,8 +23,6 @@ #include <sys/mount.h> #include <unistd.h> -#include <string> - #include "sysdeps.h" #define TRACE_TAG TRACE_ADB @@ -34,10 +32,10 @@ static int system_ro = 1; static int vendor_ro = 1; -static int oem_ro = 1; /* Returns the device used to mount a directory in /proc/mounts */ -static std::string find_mount(const char *dir) { +static char *find_mount(const char *dir) +{ FILE* fp; struct mntent* mentry; char* device = NULL; @@ -47,7 +45,7 @@ static std::string find_mount(const char *dir) { } while ((mentry = getmntent(fp)) != NULL) { if (strcmp(dir, mentry->mnt_dir) == 0) { - device = mentry->mnt_fsname; + device = strdup(mentry->mnt_fsname); break; } } @@ -55,53 +53,64 @@ static std::string find_mount(const char *dir) { return device; } -static bool has_partition(const char* path) { - struct stat sb; - return (lstat(path, &sb) == 0 && S_ISDIR(sb.st_mode)); +static int hasVendorPartition() +{ + struct stat info; + if (!lstat("/vendor", &info)) + if ((info.st_mode & S_IFMT) == S_IFDIR) + return true; + return false; } -int make_block_device_writable(const std::string& dev) { - int fd = unix_open(dev.c_str(), O_RDONLY | O_CLOEXEC); - if (fd == -1) { - return -1; - } - - int result = -1; +int make_block_device_writable(const char* dev) +{ + int fd = -1; int OFF = 0; - if (!ioctl(fd, BLKROSET, &OFF)) { - result = 0; + int rc = -1; + + if (!dev) + goto errout; + + fd = unix_open(dev, O_RDONLY | O_CLOEXEC); + if (fd < 0) + goto errout; + + if (ioctl(fd, BLKROSET, &OFF)) { + goto errout; } - adb_close(fd); - return result; + rc = 0; + +errout: + if (fd >= 0) { + adb_close(fd); + } + return rc; } -// Init mounts /system as read only, remount to enable writes. -static int remount(const char* dir, int* dir_ro) { - std::string dev(find_mount(dir)); - if (dev.empty() || make_block_device_writable(dev)) { - return -1; +/* Init mounts /system as read only, remount to enable writes. */ +static int remount(const char* dir, int* dir_ro) +{ + char *dev = 0; + int rc = -1; + + dev = find_mount(dir); + + if (!dev || make_block_device_writable(dev)) { + goto errout; } - int rc = mount(dev.c_str(), dir, "none", MS_REMOUNT, NULL); + rc = mount(dev, dir, "none", MS_REMOUNT, NULL); *dir_ro = rc; - return rc; -} -static bool remount_partition(int fd, const char* partition, int* ro) { - if (!has_partition(partition)) { - return true; - } - if (remount(partition, ro)) { - char buf[200]; - snprintf(buf, sizeof(buf), "remount of %s failed: %s\n", partition, strerror(errno)); - WriteStringFully(fd, buf); - return false; - } - return true; +errout: + free(dev); + return rc; } -void remount_service(int fd, void* cookie) { +void remount_service(int fd, void *cookie) +{ + char buffer[200]; char prop_buf[PROPERTY_VALUE_MAX]; if (getuid() != 0) { @@ -124,7 +133,6 @@ void remount_service(int fd, void* cookie) { if (system_verified || vendor_verified) { // Allow remount but warn of likely bad effects bool both = system_verified && vendor_verified; - char buffer[200]; snprintf(buffer, sizeof(buffer), "dm_verity is enabled on the %s%s%s partition%s.\n", system_verified ? "system" : "", @@ -139,12 +147,23 @@ void remount_service(int fd, void* cookie) { WriteStringFully(fd, buffer); } - bool success = true; - success &= remount_partition(fd, "/system", &system_ro); - success &= remount_partition(fd, "/vendor", &vendor_ro); - success &= remount_partition(fd, "/oem", &oem_ro); + if (remount("/system", &system_ro)) { + snprintf(buffer, sizeof(buffer), "remount of system failed: %s\n",strerror(errno)); + WriteStringFully(fd, buffer); + } + + if (hasVendorPartition()) { + if (remount("/vendor", &vendor_ro)) { + snprintf(buffer, sizeof(buffer), "remount of vendor failed: %s\n",strerror(errno)); + WriteStringFully(fd, buffer); + } + } - WriteStringFully(fd, success ? "remount succeeded\n" : "remount failed\n"); + if (!system_ro && (!vendor_ro || !hasVendorPartition())) + WriteStringFully(fd, "remount succeeded\n"); + else { + WriteStringFully(fd, "remount failed\n"); + } adb_close(fd); } |