X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=block.c;h=860a95cead30e087d2241794e15611d658b07806;hb=0828095b1600fe19dc1112fbcde84a3cbfa8b2b5;hp=d0fce7e866e40f96776b33fcd022b20c9e7fd974;hpb=267dd987b1aec750f8839d1d8d8c2f80d9f1107e;p=project%2Fubox.git diff --git a/block.c b/block.c index d0fce7e..860a95c 100644 --- a/block.c +++ b/block.c @@ -137,6 +137,14 @@ static char *blobmsg_get_strdup(struct blob_attr *attr) return strdup(blobmsg_get_string(attr)); } +static char *blobmsg_get_basename(struct blob_attr *attr) +{ + if (!attr) + return NULL; + + return strdup(basename(blobmsg_get_string(attr))); +} + static int mount_add(struct uci_section *s) { struct blob_attr *tb[__MOUNT_MAX] = { 0 }; @@ -158,7 +166,7 @@ static int mount_add(struct uci_section *s) m->label = blobmsg_get_strdup(tb[MOUNT_LABEL]); m->target = blobmsg_get_strdup(tb[MOUNT_TARGET]); m->options = blobmsg_get_strdup(tb[MOUNT_OPTIONS]); - m->device = blobmsg_get_strdup(tb[MOUNT_DEVICE]); + m->device = blobmsg_get_basename(tb[MOUNT_DEVICE]); m->overlay = m->extroot = 0; if (m->target && !strcmp(m->target, "/")) m->extroot = 1; @@ -191,7 +199,7 @@ static int swap_add(struct uci_section *s) memset(m, 0, sizeof(struct mount)); m->type = TYPE_SWAP; m->uuid = blobmsg_get_strdup(tb[SWAP_UUID]); - m->device = blobmsg_get_strdup(tb[SWAP_DEVICE]); + m->device = blobmsg_get_basename(tb[SWAP_DEVICE]); if (tb[SWAP_PRIO]) m->prio = blobmsg_get_u32(tb[SWAP_PRIO]); if (m->prio) @@ -319,7 +327,7 @@ static int _cache_load(const char *path) struct blkid_struct_probe *pr = malloc(sizeof(struct blkid_struct_probe)); memset(pr, 0, sizeof(struct blkid_struct_probe)); probe_block(gl.gl_pathv[j], pr); - if (pr->err) + if (pr->err || !pr->id) free(pr); else list_add_tail(&pr->list, &devices); @@ -336,6 +344,10 @@ static void cache_load(int mtd) _cache_load("/dev/mtdblock*"); _cache_load("/dev/mmcblk*"); _cache_load("/dev/sd*"); + _cache_load("/dev/sdc*"); + _cache_load("/dev/hd*"); + _cache_load("/dev/md*"); + _cache_load("/dev/mapper/*"); } static int print_block_info(struct blkid_struct_probe *pr) @@ -369,7 +381,7 @@ static int print_block_uci(struct blkid_struct_probe *pr) if (pr->uuid[0]) printf("\toption\tuuid\t'%s'\n", pr->uuid); else - printf("\toption\tdevice\t'%s'\n", basename(pr->dev)); + printf("\toption\tdevice\t'%s'\n", pr->dev); printf("\toption\tenabled\t'0'\n\n"); return 0; @@ -448,11 +460,10 @@ static void check_filesystem(struct blkid_struct_probe *pr) return; } - if (stat(e2fsck, &statbuf) < 0) - return; - - if (!(statbuf.st_mode & S_IXUSR)) + if (stat(e2fsck, &statbuf) < 0) { + fprintf(stderr, "check_filesystem: %s not found\n", e2fsck); return; + } pid = fork(); if (!pid) { @@ -460,18 +471,23 @@ static void check_filesystem(struct blkid_struct_probe *pr) exit(-1); } else if (pid > 0) { int status; + waitpid(pid, &status, 0); + if (WEXITSTATUS(status)) + fprintf(stderr, "check_filesystem: %s returned %d\n", e2fsck, WEXITSTATUS(status)); } } static int mount_device(struct blkid_struct_probe *pr, int hotplug) { struct mount *m; - char *device = basename(pr->dev); + char *device; if (!pr) return -1; + device = basename(pr->dev); + if (!strcmp(pr->id->name, "swap")) { if (hotplug && !auto_swap) return -1; @@ -702,6 +718,8 @@ static int mount_extroot(char *cfg) if (!pr && delay_root){ fprintf(stderr, "extroot: is not ready yet, retrying in %ui seconds\n", delay_root); sleep(delay_root); + mkblkdev(); + cache_load(0); pr = find_block_info(m->uuid, m->label, NULL); } if (pr) {