}
-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;
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;
{
struct mount *m;
struct probe_info *pr;
+ struct stat st;
char _target[32];
char *target;
char *device;
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);
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) {
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)
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) {