Merge \"Remove MTD cruft from init.\"
am: 90db709a2f
Change-Id: I027708dd324000cbfad1a2a6e970f742db97bae5
This commit is contained in:
commit
80744d867f
5 changed files with 8 additions and 107 deletions
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -119,22 +119,13 @@ void set_device_permission(int nargs, char **args)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If path starts with mtd@ lookup the mount number. */
|
int len = strlen(name);
|
||||||
if (!strncmp(name, "mtd@", 4)) {
|
char *wildcard_chr = strchr(name, '*');
|
||||||
int n = mtd_name_to_number(name + 4);
|
if ((name[len - 1] == '*') && (wildcard_chr == (name + len - 1))) {
|
||||||
if (n >= 0)
|
prefix = 1;
|
||||||
asprintf(&tmp, "/dev/mtd/mtd%d", n);
|
name[len - 1] = '\0';
|
||||||
name = tmp;
|
} else if (wildcard_chr) {
|
||||||
} else {
|
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);
|
perm = strtol(args[1], &endptr, 8);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue