diff options
author | Daniel Golle <daniel@makrotopia.org> | 2021-07-17 23:13:27 +0100 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2021-07-18 03:38:26 +0100 |
commit | 59f7c11de7eb67def76e24b8f98c2db66d5518f2 (patch) | |
tree | 055feea3e0bda32c87ebb0023f2135272593870f | |
parent | cdc9939b071427cf2b35134481df27b4bd76dbfc (diff) | |
download | fstools-59f7c11de7eb67def76e24b8f98c2db66d5518f2.tar.gz |
blockd: create mountpoint parent folder if needed
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
-rw-r--r-- | blockd.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -209,7 +209,7 @@ static void device_mount_remove(struct ubus_context *ctx, struct device *device) static void device_mount_add(struct ubus_context *ctx, struct device *device) { struct stat st; - char *path; + char *path, *tmp; if (asprintf(&path, "/tmp/run/blockd/%s", device->name) == -1) exit(ENOMEM); @@ -220,6 +220,14 @@ static void device_mount_add(struct ubus_context *ctx, struct device *device) else if (S_ISDIR(st.st_mode)) rmdir(device->target); } + + tmp = strrchr(device->target, '/'); + if (tmp && tmp != device->target && tmp != &device->target[strlen(path)-1]) { + *tmp = '\0'; + mkdir_p(device->target, 0755); + *tmp = '/'; + } + if (symlink(path, device->target)) ULOG_ERR("failed to symlink %s->%s (%d) - %m\n", device->target, path, errno); else |