Fix disable-verity when the underlying block device is RO
If verity is enabled and the underlying block device is marked
read-only, disable-verity fails. We cannot use the existing code
for enable-verity to make the device writable as the device in
/proc/mounts will be the verity device instead of the underlying
device we want to change. This change makes the correct device
writable when altering verity state.
Change-Id: I423ee50fb34d78cff2fe843318b9081c03c5142d
diff --git a/adb/remount_service.c b/adb/remount_service.c
index 9746f9a..2479f88 100644
--- a/adb/remount_service.c
+++ b/adb/remount_service.c
@@ -79,14 +79,12 @@
return false;
}
-static int make_block_device_writable(const char* dir)
+int make_block_device_writable(const char* dev)
{
- char *dev = 0;
int fd = -1;
int OFF = 0;
int rc = -1;
- dev = find_mount(dir);
if (!dev)
goto errout;
@@ -104,36 +102,27 @@
if (fd >= 0) {
adb_close(fd);
}
-
- if (dev) {
- free(dev);
- }
return rc;
}
/* Init mounts /system as read only, remount to enable writes. */
static int remount(const char* dir, int* dir_ro)
{
- char *dev;
-
- if (dir_ro == 0) {
- return 0;
- }
-
- if (make_block_device_writable(dir)) {
- return -1;
- }
+ char *dev = 0;
+ int rc = -1;
dev = find_mount(dir);
- if (!dev)
- return -1;
+ if (!dev || make_block_device_writable(dev)) {
+ goto errout;
+ }
- *dir_ro = mount(dev, dir, "none", MS_REMOUNT, NULL);
+ rc = mount(dev, dir, "none", MS_REMOUNT, NULL);
+ *dir_ro = rc;
+errout:
free(dev);
-
- return *dir_ro;
+ return rc;
}
static void write_string(int fd, const char* str)
@@ -141,28 +130,6 @@
writex(fd, str, strlen(str));
}
-int make_system_and_vendor_block_devices_writable(int fd)
-{
- char buffer[200];
- if (make_block_device_writable("/system")) {
- snprintf(buffer, sizeof(buffer),
- "Failed to make system block device writable %s\n",
- strerror(errno));
- write_string(fd, buffer);
- return -1;
- }
-
- if (hasVendorPartition() && make_block_device_writable("/vendor")) {
- snprintf(buffer, sizeof(buffer),
- "Failed to make vendor block device writable: %s\n",
- strerror(errno));
- write_string(fd, buffer);
- return -1;
- }
-
- return 0;
-}
-
void remount_service(int fd, void *cookie)
{
char buffer[200];