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
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 @@
     }
     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 @@
     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;
-    }
-    adb_close(fd);
+    int rc = -1;
 
-    return result;
-}
+    if (!dev)
+        goto errout;
 
-// 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;
+    fd = unix_open(dev, O_RDONLY | O_CLOEXEC);
+    if (fd < 0)
+        goto errout;
+
+    if (ioctl(fd, BLKROSET, &OFF)) {
+        goto errout;
     }
 
-    int rc = mount(dev.c_str(), dir, "none", MS_REMOUNT, NULL);
-    *dir_ro = rc;
+    rc = 0;
+
+errout:
+    if (fd >= 0) {
+        adb_close(fd);
+    }
     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;
+/* 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;
+    }
+
+    rc = mount(dev, dir, "none", MS_REMOUNT, NULL);
+    *dir_ro = rc;
+
+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 @@
     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 @@
         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);
+    }
 
-    WriteStringFully(fd, success ? "remount succeeded\n" : "remount failed\n");
+    if (hasVendorPartition()) {
+        if (remount("/vendor", &vendor_ro)) {
+            snprintf(buffer, sizeof(buffer), "remount of vendor failed: %s\n",strerror(errno));
+            WriteStringFully(fd, buffer);
+        }
+    }
+
+    if (!system_ro && (!vendor_ro || !hasVendorPartition()))
+        WriteStringFully(fd, "remount succeeded\n");
+    else {
+        WriteStringFully(fd, "remount failed\n");
+    }
 
     adb_close(fd);
 }