summaryrefslogtreecommitdiffstats
path: root/adb/remount_service.c
diff options
context:
space:
mode:
Diffstat (limited to 'adb/remount_service.c')
-rw-r--r--adb/remount_service.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/adb/remount_service.c b/adb/remount_service.c
index 3a4535e..72d15a1 100644
--- a/adb/remount_service.c
+++ b/adb/remount_service.c
@@ -29,6 +29,7 @@
static int system_ro = 1;
+static int vendor_ro = 1;
/* Returns the device used to mount a directory in /proc/mounts */
static char *find_mount(const char *dir)
@@ -67,18 +68,27 @@ static char *find_mount(const char *dir)
return NULL;
}
+static int hasVendorPartition()
+{
+ struct stat info;
+ if (!lstat("/vendor", &info))
+ if ((info.st_mode & S_IFMT) == S_IFDIR)
+ return true;
+ return false;
+}
+
/* Init mounts /system as read only, remount to enable writes. */
-static int remount_system()
+static int remount(const char* dir, int* dir_ro)
{
char *dev;
int fd;
int OFF = 0;
- if (system_ro == 0) {
+ if (dir_ro == 0) {
return 0;
}
- dev = find_mount("/system");
+ dev = find_mount(dir);
if (!dev)
return -1;
@@ -90,11 +100,11 @@ static int remount_system()
ioctl(fd, BLKROSET, &OFF);
adb_close(fd);
- system_ro = mount(dev, "/system", "none", MS_REMOUNT, NULL);
+ *dir_ro = mount(dev, dir, "none", MS_REMOUNT, NULL);
free(dev);
- return system_ro;
+ return *dir_ro;
}
static void write_string(int fd, const char* str)
@@ -104,14 +114,23 @@ static void write_string(int fd, const char* str)
void remount_service(int fd, void *cookie)
{
- int ret = remount_system();
+ char buffer[200];
+ if (remount("/system", &system_ro)) {
+ snprintf(buffer, sizeof(buffer), "remount of system failed: %s\n",strerror(errno));
+ write_string(fd, buffer);
+ }
+
+ if (hasVendorPartition()) {
+ if (remount("/vendor", &vendor_ro)) {
+ snprintf(buffer, sizeof(buffer), "remount of vendor failed: %s\n",strerror(errno));
+ write_string(fd, buffer);
+ }
+ }
- if (!ret)
- write_string(fd, "remount succeeded\n");
+ if (!system_ro && (!vendor_ro || !hasVendorPartition()))
+ write_string(fd, "remount succeeded\n");
else {
- char buffer[200];
- snprintf(buffer, sizeof(buffer), "remount failed: %s\n", strerror(errno));
- write_string(fd, buffer);
+ write_string(fd, "remount failed\n");
}
adb_close(fd);