X-Git-Url: http://git.openwrt.org/?p=project%2Ffstools.git;a=blobdiff_plain;f=block.c;h=9e530f1a93b8e729cf9aeadfd508bd261928070a;hp=66dcf9c09294285481fcc7c341e7f05d8cbe727c;hb=d1f1f2b38fa1e7b594bd005e563679a40e4d7e95;hpb=fb0700f0fdfc4bec220203d31df87be2b4ccc467 diff --git a/block.c b/block.c index 66dcf9c..9e530f1 100644 --- a/block.c +++ b/block.c @@ -575,23 +575,6 @@ static void cache_load(int mtd) } -static int print_block_uci(struct probe_info *pr) -{ - if (!strcmp(pr->type, "swap")) { - printf("config 'swap'\n"); - } else { - printf("config 'mount'\n"); - printf("\toption\ttarget\t'/mnt/%s'\n", basename(pr->dev)); - } - if (pr->uuid) - printf("\toption\tuuid\t'%s'\n", pr->uuid); - else - printf("\toption\tdevice\t'%s'\n", pr->dev); - printf("\toption\tenabled\t'0'\n\n"); - - return 0; -} - static struct device* find_block_device(char *uuid, char *label, char *path) { struct device *dev; @@ -704,6 +687,30 @@ static char* find_mount_point(char *block) return point; } +static int print_block_uci(struct probe_info *pr) +{ + if (!strcmp(pr->type, "swap")) { + printf("config 'swap'\n"); + } else { + char *mp = find_mount_point(pr->dev); + + printf("config 'mount'\n"); + if (mp) { + printf("\toption\ttarget\t'%s'\n", mp); + free(mp); + } else { + printf("\toption\ttarget\t'/mnt/%s'\n", basename(pr->dev)); + } + } + if (pr->uuid) + printf("\toption\tuuid\t'%s'\n", pr->uuid); + else + printf("\toption\tdevice\t'%s'\n", pr->dev); + printf("\toption\tenabled\t'0'\n\n"); + + return 0; +} + static int print_block_info(struct probe_info *pr) { static char *mp; @@ -1065,6 +1072,7 @@ static int mount_device(struct device *dev, int type) { struct mount *m; struct probe_info *pr; + struct stat st; char _target[32]; char *target; char *device; @@ -1087,17 +1095,21 @@ static int mount_device(struct device *dev, int type) return 0; } - mp = find_mount_point(pr->dev); - if (mp && (type != TYPE_HOTPLUG)) { - ULOG_ERR("%s is already mounted on %s\n", pr->dev, mp); - free(mp); - return -1; - } - m = dev->m; if (m && m->extroot) return -1; + mp = find_mount_point(pr->dev); + if (mp) { + if (m && m->type == TYPE_MOUNT && strcmp(m->target, mp)) { + ULOG_ERR("%s is already mounted on %s\n", pr->dev, mp); + err = -1; + } else + err = 0; + free(mp); + return err; + } + if (type == TYPE_HOTPLUG) blockd_notify(device, m, pr); @@ -1143,6 +1155,8 @@ static int mount_device(struct device *dev, int type) check_filesystem(pr); mkdir_p(target); + if (!lstat(target, &st) && S_ISLNK(st.st_mode)) + unlink(target); err = handle_mount(pr->dev, target, pr->type, m); if (err) { @@ -1188,30 +1202,47 @@ static int umount_device(char *path, int type, bool all) static int mount_action(char *action, char *device, int type) { + struct device *the_dev, *dev; char path[32]; if (!action || !device) return -1; - snprintf(path, sizeof(path), "/dev/%s", device); + + if (config_load(NULL)) + return -1; + cache_load(0); + + the_dev = find_block_device(NULL, NULL, device); if (!strcmp(action, "remove")) { if (type == TYPE_HOTPLUG) blockd_notify(device, NULL, NULL); - umount_device(path, type, true); - + if (!the_dev || !the_dev->m || the_dev->m->type != TYPE_MOUNT) { + snprintf(path, sizeof(path), "/dev/%s", device); + umount_device(path, type, true); + } else + vlist_for_element_to_last_reverse(&devices, the_dev, dev, node) + if (dev->m && dev->m->type == TYPE_MOUNT) + umount_device(dev->pr->dev, type, true); return 0; - } else if (strcmp(action, "add")) { - ULOG_ERR("Unkown action %s\n", action); - - return -1; + } else if (!strcmp(action, "add")) { + if (!the_dev) + return -1; + if (the_dev->m && the_dev->m->type == TYPE_MOUNT) { + vlist_for_first_to_element(&devices, the_dev, dev, node) { + if (dev->m && dev->m->type == TYPE_MOUNT) { + int err = mount_device(dev, type); + if (err) + return err; + } + } + return 0; + } else + return mount_device(the_dev, type); } - - if (config_load(NULL)) - return -1; - cache_load(0); - - return mount_device(find_block_device(NULL, NULL, path), type); + ULOG_ERR("Unkown action %s\n", action); + return -1; } static int main_hotplug(int argc, char **argv) @@ -1515,7 +1546,7 @@ static int mount_extroot(char *cfg) ULOG_INFO("extroot: device not present, retrying in %u seconds\n", delay_root); sleep(delay_root); make_devs(); - cache_load(0); + cache_load(1); dev = find_block_device(m->uuid, m->label, m->device); } if (dev) {