Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 53667c41 authored by Dan Albert's avatar Dan Albert Committed by Gerrit Code Review
Browse files

Merge "Revert "adb: support /oem partition""

parents cfa966e3 6084a012
Loading
Loading
Loading
Loading
+25 −42
Original line number Diff line number Diff line
@@ -43,8 +43,7 @@
static int do_cmd(transport_type ttype, const char* serial, const char *cmd, ...);

int find_sync_dirs(const char *srcarg,
        char **system_srcdir_out, char **data_srcdir_out, char **vendor_srcdir_out,
        char **oem_srcdir_out);
        char **android_srcdir_out, char **data_srcdir_out, char **vendor_srcdir_out);
int install_app(transport_type transport, const char* serial, int argc,
                const char** argv);
int install_multiple_app(transport_type transport, const char* serial, int argc,
@@ -207,7 +206,7 @@ void help()
        "  adb get-serialno             - prints: <serial-number>\n"
        "  adb get-devpath              - prints: <device-path>\n"
        "  adb status-window            - continuously print device status for a specified device\n"
        "  adb remount                  - remounts the /system, /vendor (if present) and /oem (if present) partitions on the device read-write\n"
        "  adb remount                  - remounts the /system and /vendor (if present) partitions on the device read-write\n"
        "  adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program\n"
        "  adb reboot-bootloader        - reboots the device into the bootloader\n"
        "  adb root                     - restarts the adbd daemon with root permissions\n"
@@ -223,9 +222,9 @@ void help()
        "adb sync notes: adb sync [ <directory> ]\n"
        "  <localdir> can be interpreted in several ways:\n"
        "\n"
        "  - If <directory> is not specified, /system, /vendor (if present), /oem (if present) and /data partitions will be updated.\n"
        "  - If <directory> is not specified, /system, /vendor (if present), and /data partitions will be updated.\n"
        "\n"
        "  - If it is \"system\", \"vendor\", \"oem\" or \"data\", only the corresponding partition\n"
        "  - If it is \"system\", \"vendor\" or \"data\", only the corresponding partition\n"
        "    is updated.\n"
        "\n"
        "environmental variables:\n"
@@ -1634,8 +1633,7 @@ int adb_commandline(int argc, const char **argv)
    }
    else if (!strcmp(argv[0], "sync")) {
        const char* srcarg;
        char *system_srcpath, *data_srcpath, *vendor_srcpath, *oem_srcpath;

        char *android_srcpath, *data_srcpath, *vendor_srcpath;
        int listonly = 0;

        int ret;
@@ -1655,22 +1653,18 @@ int adb_commandline(int argc, const char **argv)
        } else {
            return usage();
        }
        ret = find_sync_dirs(srcarg, &system_srcpath, &data_srcpath, &vendor_srcpath,
                &oem_srcpath);
        ret = find_sync_dirs(srcarg, &android_srcpath, &data_srcpath, &vendor_srcpath);
        if (ret != 0) return usage();

        if (system_srcpath != NULL)
            ret = do_sync_sync(system_srcpath, "/system", listonly);
        if (android_srcpath != NULL)
            ret = do_sync_sync(android_srcpath, "/system", listonly);
        if (ret == 0 && vendor_srcpath != NULL)
            ret = do_sync_sync(vendor_srcpath, "/vendor", listonly);
        if(ret == 0 && oem_srcpath != NULL)
            ret = do_sync_sync(oem_srcpath, "/oem", listonly);
        if (ret == 0 && data_srcpath != NULL)
            ret = do_sync_sync(data_srcpath, "/data", listonly);

        free(system_srcpath);
        free(android_srcpath);
        free(vendor_srcpath);
        free(oem_srcpath);
        free(data_srcpath);
        return ret;
    }
@@ -1776,60 +1770,49 @@ static int do_cmd(transport_type ttype, const char* serial, const char *cmd, ...
}

int find_sync_dirs(const char *srcarg,
        char **system_srcdir_out, char **data_srcdir_out, char **vendor_srcdir_out,
        char **oem_srcdir_out)
        char **android_srcdir_out, char **data_srcdir_out, char **vendor_srcdir_out)
{
    char *system_srcdir = NULL, *data_srcdir = NULL, *vendor_srcdir = NULL, *oem_srcdir = NULL;
    char *android_srcdir = NULL, *data_srcdir = NULL, *vendor_srcdir = NULL;
    struct stat st;

    if(srcarg == NULL) {
        system_srcdir = product_file("system");
        android_srcdir = product_file("system");
        data_srcdir = product_file("data");
        vendor_srcdir = product_file("vendor");
        oem_srcdir = product_file("oem");
        // Check if vendor partition exists.
        /* Check if vendor partition exists */
        if (lstat(vendor_srcdir, &st) || !S_ISDIR(st.st_mode))
            vendor_srcdir = NULL;
        // Check if oem partition exists.
        if (lstat(oem_srcdir, &st) || !S_ISDIR(st.st_mode))
            oem_srcdir = NULL;
    } else {
        // srcarg may be "data", "system", "vendor", "oem" or NULL.
        // If srcarg is NULL, then all partitions are synced.
        /* srcarg may be "data", "system" or NULL.
         * if srcarg is NULL, then both data and system are synced
         */
        if(strcmp(srcarg, "system") == 0) {
            system_srcdir = product_file("system");
            android_srcdir = product_file("system");
        } else if(strcmp(srcarg, "data") == 0) {
            data_srcdir = product_file("data");
        } else if(strcmp(srcarg, "vendor") == 0) {
            vendor_srcdir = product_file("vendor");
        } else if(strcmp(srcarg, "oem") == 0) {
            oem_srcdir = product_file("oem");
        } else {
            // It's not "system", "data", "vendor", or "oem".
            /* It's not "system", "vendor", or "data".
             */
            return 1;
        }
    }

    if(system_srcdir_out != NULL)
        *system_srcdir_out = system_srcdir;
    if(android_srcdir_out != NULL)
        *android_srcdir_out = android_srcdir;
    else
        free(system_srcdir);
        free(android_srcdir);

    if(vendor_srcdir_out != NULL)
        *vendor_srcdir_out = vendor_srcdir;
    else
        free(vendor_srcdir);

    if(oem_srcdir_out != NULL)
        *oem_srcdir_out = oem_srcdir;
    else
        free(oem_srcdir);

    if(data_srcdir_out != NULL)
            *data_srcdir_out = data_srcdir;
        else
            free(data_srcdir);

    return 0;
}

+11 −7
Original line number Diff line number Diff line
@@ -33,11 +33,15 @@
#include "file_sync_service.h"
#include "private/android_filesystem_config.h"

static bool should_use_fs_config(const char* path) {
    // TODO: use fs_config to configure permissions on /data.
    return strncmp("/system/", path, strlen("/system/")) == 0 ||
           strncmp("/vendor/", path, strlen("/vendor/")) == 0 ||
           strncmp("/oem/", path, strlen("/oem/")) == 0;
/* TODO: use fs_config to configure permissions on /data */
static bool is_on_system(const char *name) {
    const char *SYSTEM = "/system/";
    return (strncmp(SYSTEM, name, strlen(SYSTEM)) == 0);
}

static bool is_on_vendor(const char *name) {
    const char *VENDOR = "/vendor/";
    return (strncmp(VENDOR, name, strlen(VENDOR)) == 0);
}

static int mkdirs(char *name)
@@ -55,7 +59,7 @@ static int mkdirs(char *name)
        x = adb_dirstart(x);
        if(x == 0) return 0;
        *x = 0;
        if (should_use_fs_config(name)) {
        if (is_on_system(name) || is_on_vendor(name)) {
            fs_config(name, 1, &uid, &gid, &mode, &cap);
        }
        ret = adb_mkdir(name, mode);
@@ -364,7 +368,7 @@ static int do_send(int s, char *path, char *buffer)
    if(*tmp == '/') {
        tmp++;
    }
    if (should_use_fs_config(path)) {
    if (is_on_system(path) || is_on_vendor(path)) {
        fs_config(tmp, 0, &uid, &gid, &mode, &cap);
    }
    return handle_send_file(s, path, uid, gid, mode, buffer, do_unlink);
+64 −45
Original line number Diff line number Diff line
@@ -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));
}

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;
static int hasVendorPartition()
{
    struct stat info;
    if (!lstat("/vendor", &info))
        if ((info.st_mode & S_IFMT) == S_IFDIR)
          return true;
    return false;
}

    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;
/* 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;
    }
  return true;

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