{
FILE *fp = fopen("/proc/self/mountinfo", "r");
static char line[256];
- int len = strlen(block);
char *point = NULL, *pos, *tmp, *cpoint, *devname;
struct stat s;
int rstat;
*pos = '\0';
devname = tmp;
- if (!strncmp(block, devname, len)) {
+ if (!strcmp(block, devname)) {
point = strdup(cpoint);
break;
}
return err;
}
-static void blockd_notify(char *device, struct mount *m, struct probe_info *pr)
+static int blockd_notify(char *device, struct mount *m, struct probe_info *pr)
{
struct ubus_context *ctx = ubus_connect(NULL);
uint32_t id;
+ int err;
if (!ctx)
- return;
+ return -ENXIO;
if (!ubus_lookup_id(ctx, "block", &id)) {
struct blob_buf buf = { 0 };
blobmsg_add_u32(&buf, "remove", 1);
}
- ubus_invoke(ctx, id, "hotplug", buf.head, NULL, NULL, 3000);
+ err = ubus_invoke(ctx, id, "hotplug", buf.head, NULL, NULL, 3000);
+ } else {
+ err = -ENOENT;
}
ubus_free(ctx);
+
+ return err;
}
static int mount_device(struct probe_info *pr, int type)
handle_swapfiles(true);
- hotplug_call_mount("add", device);
+ if (type != TYPE_AUTOFS)
+ hotplug_call_mount("add", device);
return 0;
}
-static int umount_device(char *path)
+static int umount_device(char *path, int type)
{
char *mp;
int err;
if (!mp)
return -1;
- hotplug_call_mount("remove", basename(path));
+ if (type != TYPE_AUTOFS)
+ hotplug_call_mount("remove", basename(path));
err = umount2(mp, MNT_DETACH);
- if (err)
+ if (err) {
ULOG_ERR("unmounting %s (%s) failed (%d) - %m\n", path, mp,
errno);
- else
+ } else {
ULOG_INFO("unmounted %s (%s)\n", path, mp);
+ rmdir(mp);
+ }
free(mp);
return err;
if (type == TYPE_HOTPLUG)
blockd_notify(device, NULL, NULL);
- umount_device(path);
+ umount_device(path, type);
return 0;
} else if (strcmp(action, "add")) {
static int main_autofs(int argc, char **argv)
{
+ int err = 0;
+
if (argc < 3)
return -1;
cache_load(0);
list_for_each_entry(pr, &devices, list) {
- struct mount *m = find_block(pr->uuid, pr->label, NULL, NULL);
+ struct mount *m;
- if (m && m->autofs)
- mount_device(pr, TYPE_HOTPLUG);
- else
- blockd_notify(pr->dev, m, pr);
+ if (!strcmp(pr->type, "swap"))
+ continue;
+
+ m = find_block(pr->uuid, pr->label, NULL, NULL);
+ if (m && m->extroot)
+ continue;
+
+ blockd_notify(pr->dev, m, pr);
}
- return 0;
+ } else if (!strcmp(argv[2], "available")) {
+ err = hotplug_call_mount("add", argv[3]);
+ } else if (!strcmp(argv[2], "unavailable")) {
+ err = hotplug_call_mount("remove", argv[3]);
+ } else {
+ if (argc < 4)
+ return -EINVAL;
+
+ err = mount_action(argv[2], argv[3], TYPE_AUTOFS);
}
- if (argc < 4)
- return -EINVAL;
+ if (err) {
+ ULOG_ERR("autofs: \"%s\" action has failed: %d\n", argv[2], err);
+ }
- return mount_action(argv[2], argv[3], TYPE_AUTOFS);
+ return err;
}
static int find_block_mtd(char *name, char *part, int plen)
if (m && m->extroot)
continue;
- umount_device(pr->dev);
+ umount_device(pr->dev, TYPE_DEV);
}
return 0;