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

Commit cbeeeaef authored by Elliott Hughes's avatar Elliott Hughes Committed by android-build-merger
Browse files

Merge \\\\"Remove MTD cruft from init.\\\\" am: 90db709a am: 80744d86 am: 77b189ac

am: db62f10c

Change-Id: Ife58caa4905776992fe28374a51bf9048fdb9533
parents 2edd112f db62f10c
Loading
Loading
Loading
Loading
+1 −16
Original line number Original line Diff line number Diff line
@@ -401,22 +401,7 @@ static int do_mount(const std::vector<std::string>& args) {
    source = args[2].c_str();
    source = args[2].c_str();
    target = args[3].c_str();
    target = args[3].c_str();


    if (!strncmp(source, "mtd@", 4)) {
    if (!strncmp(source, "loop@", 5)) {
        n = mtd_name_to_number(source + 4);
        if (n < 0) {
            return -1;
        }

        snprintf(tmp, sizeof(tmp), "/dev/block/mtdblock%d", n);

        if (wait)
            wait_for_file(tmp, COMMAND_RETRY_TIMEOUT);
        if (mount(tmp, target, system, flags, options) < 0) {
            return -1;
        }

        goto exit_success;
    } else if (!strncmp(source, "loop@", 5)) {
        int mode, loop, fd;
        int mode, loop, fd;
        struct loop_info info;
        struct loop_info info;


+0 −2
Original line number Original line Diff line number Diff line
@@ -311,8 +311,6 @@ mount_all <fstab> [ <path> ]*


mount <type> <device> <dir> [ <flag> ]* [<options>]
mount <type> <device> <dir> [ <flag> ]* [<options>]
   Attempt to mount the named device at the directory <dir>
   Attempt to mount the named device at the directory <dir>
   <device> may be of the form mtd@name to specify a mtd block
   device by name.
   <flag>s include "ro", "rw", "remount", "noatime", ...
   <flag>s include "ro", "rw", "remount", "noatime", ...
   <options> include "barrier=1", "noauto_da_alloc", "discard", ... as
   <options> include "barrier=1", "noauto_da_alloc", "discard", ... as
   a comma separated string, eg: barrier=1,noauto_da_alloc
   a comma separated string, eg: barrier=1,noauto_da_alloc
+7 −16
Original line number Original line Diff line number Diff line
@@ -119,23 +119,14 @@ void set_device_permission(int nargs, char **args)
        return;
        return;
    }
    }


    /* If path starts with mtd@ lookup the mount number. */
    if (!strncmp(name, "mtd@", 4)) {
        int n = mtd_name_to_number(name + 4);
        if (n >= 0)
            asprintf(&tmp, "/dev/mtd/mtd%d", n);
        name = tmp;
    } else {
    int len = strlen(name);
    int len = strlen(name);
    char *wildcard_chr = strchr(name, '*');
    char *wildcard_chr = strchr(name, '*');
        if ((name[len - 1] == '*') &&
    if ((name[len - 1] == '*') && (wildcard_chr == (name + len - 1))) {
            (wildcard_chr == (name + len - 1))) {
        prefix = 1;
        prefix = 1;
        name[len - 1] = '\0';
        name[len - 1] = '\0';
    } else if (wildcard_chr) {
    } else if (wildcard_chr) {
        wildcard = 1;
        wildcard = 1;
    }
    }
    }


    perm = strtol(args[1], &endptr, 8);
    perm = strtol(args[1], &endptr, 8);
    if (!endptr || *endptr != '\0') {
    if (!endptr || *endptr != '\0') {
+0 −72
Original line number Original line Diff line number Diff line
@@ -199,78 +199,6 @@ int write_file(const char* path, const char* content) {
    return result;
    return result;
}
}


#define MAX_MTD_PARTITIONS 16

static struct {
    char name[16];
    int number;
} mtd_part_map[MAX_MTD_PARTITIONS];

static int mtd_part_count = -1;

static void find_mtd_partitions(void)
{
    int fd;
    char buf[1024];
    char *pmtdbufp;
    ssize_t pmtdsize;
    int r;

    fd = open("/proc/mtd", O_RDONLY|O_CLOEXEC);
    if (fd < 0)
        return;

    buf[sizeof(buf) - 1] = '\0';
    pmtdsize = read(fd, buf, sizeof(buf) - 1);
    pmtdbufp = buf;
    while (pmtdsize > 0) {
        int mtdnum, mtdsize, mtderasesize;
        char mtdname[16];
        mtdname[0] = '\0';
        mtdnum = -1;
        r = sscanf(pmtdbufp, "mtd%d: %x %x %15s",
                   &mtdnum, &mtdsize, &mtderasesize, mtdname);
        if ((r == 4) && (mtdname[0] == '"')) {
            char *x = strchr(mtdname + 1, '"');
            if (x) {
                *x = 0;
            }
            INFO("mtd partition %d, %s\n", mtdnum, mtdname + 1);
            if (mtd_part_count < MAX_MTD_PARTITIONS) {
                strcpy(mtd_part_map[mtd_part_count].name, mtdname + 1);
                mtd_part_map[mtd_part_count].number = mtdnum;
                mtd_part_count++;
            } else {
                ERROR("too many mtd partitions\n");
            }
        }
        while (pmtdsize > 0 && *pmtdbufp != '\n') {
            pmtdbufp++;
            pmtdsize--;
        }
        if (pmtdsize > 0) {
            pmtdbufp++;
            pmtdsize--;
        }
    }
    close(fd);
}

int mtd_name_to_number(const char *name)
{
    int n;
    if (mtd_part_count < 0) {
        mtd_part_count = 0;
        find_mtd_partitions();
    }
    for (n = 0; n < mtd_part_count; n++) {
        if (!strcmp(name, mtd_part_map[n].name)) {
            return mtd_part_map[n].number;
        }
    }
    return -1;
}

time_t gettime() {
time_t gettime() {
    timespec now;
    timespec now;
    clock_gettime(CLOCK_MONOTONIC, &now);
    clock_gettime(CLOCK_MONOTONIC, &now);
+0 −1
Original line number Original line Diff line number Diff line
@@ -27,7 +27,6 @@


#define COLDBOOT_DONE "/dev/.coldboot_done"
#define COLDBOOT_DONE "/dev/.coldboot_done"


int mtd_name_to_number(const char *name);
int create_socket(const char *name, int type, mode_t perm,
int create_socket(const char *name, int type, mode_t perm,
                  uid_t uid, gid_t gid, const char *socketcon);
                  uid_t uid, gid_t gid, const char *socketcon);