Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Remove MTD cruft from init.
Browse files Browse the repository at this point in the history
Bug: http://b/29250988
Change-Id: I38ab263192944e4ff291fd91b25db163a8848d75
  • Loading branch information
enh-google committed Jun 25, 2016
1 parent aa9f371 commit 3195116
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 107 deletions.
17 changes: 1 addition & 16 deletions init/builtins.cpp
Expand Up @@ -382,22 +382,7 @@ static int do_mount(const std::vector<std::string>& args) {
source = args[2].c_str();
target = args[3].c_str();

if (!strncmp(source, "mtd@", 4)) {
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)) {
if (!strncmp(source, "loop@", 5)) {
int mode, loop, fd;
struct loop_info info;

Expand Down
2 changes: 0 additions & 2 deletions init/readme.txt
Expand Up @@ -311,8 +311,6 @@ mount_all <fstab> [ <path> ]*

mount <type> <device> <dir> [ <flag> ]* [<options>]
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", ...
<options> include "barrier=1", "noauto_da_alloc", "discard", ... as
a comma separated string, eg: barrier=1,noauto_da_alloc
Expand Down
23 changes: 7 additions & 16 deletions init/ueventd.cpp
Expand Up @@ -119,22 +119,13 @@ void set_device_permission(int nargs, char **args)
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);
char *wildcard_chr = strchr(name, '*');
if ((name[len - 1] == '*') &&
(wildcard_chr == (name + len - 1))) {
prefix = 1;
name[len - 1] = '\0';
} else if (wildcard_chr) {
wildcard = 1;
}
int len = strlen(name);
char *wildcard_chr = strchr(name, '*');
if ((name[len - 1] == '*') && (wildcard_chr == (name + len - 1))) {
prefix = 1;
name[len - 1] = '\0';
} else if (wildcard_chr) {
wildcard = 1;
}

perm = strtol(args[1], &endptr, 8);
Expand Down
72 changes: 0 additions & 72 deletions init/util.cpp
Expand Up @@ -199,78 +199,6 @@ int write_file(const char* path, const char* content) {
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() {
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
Expand Down
1 change: 0 additions & 1 deletion init/util.h
Expand Up @@ -27,7 +27,6 @@

#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,
uid_t uid, gid_t gid, const char *socketcon);

Expand Down

0 comments on commit 3195116

Please sign in to comment.