diff --git a/lib/vfscore/automount.c b/lib/vfscore/automount.c index 3a8cc68f24..cb7bd528ba 100644 --- a/lib/vfscore/automount.c +++ b/lib/vfscore/automount.c @@ -50,6 +50,9 @@ #include #include #include +#if CONFIG_LIBVFSCORE_AUTOMOUNT || CONFIG_LIBVFSCORE_AUTOUNMOUNT +#include +#endif #include #include #include @@ -563,9 +566,10 @@ static int vfscore_extract_volume(const struct vfscore_volume *vv) #endif /* CONFIG_LIBUKCPIO */ /* Handle `mkmp` Unikraft Mount Option */ -static int vfscore_ukopt_mkmp(char *path) +static int vfscore_ukopt_mkmp(const char *path) { char *pos, *prev_pos; + char *tmp_path; int rc; UK_ASSERT(path); @@ -577,7 +581,14 @@ static int vfscore_ukopt_mkmp(char *path) } uk_pr_debug(" mkmp: Ensure mount path \"%s\" exists\n", path); - pos = path; + tmp_path = strdup(path); + if (!tmp_path) + { + uk_pr_err("strdup failed with errno=%d\n", errno); + return -errno; + } + + pos = tmp_path; do { prev_pos = pos; pos = strchr(pos + 1, '/'); @@ -601,23 +612,24 @@ static int vfscore_ukopt_mkmp(char *path) (prev_pos[2] == '/' || prev_pos[2] == '\0') ))) { uk_pr_err("'.' or '..' are not supported in mount paths.\n"); + free(tmp_path); return -EINVAL; } /* mkdir() with S_IRWXU */ rc = mkdir(path, 0700); if (rc && errno != EEXIST) + { + free(tmp_path); return -errno; - - /* Restore current '/' */ - if (pos) - *pos = '/'; + } /* Handle paths with multiple `/` */ while (pos && pos[1] == '/') pos++; } while (pos); + free(tmp_path); return 0; } @@ -864,7 +876,8 @@ static void vfscore_autoumount(const struct uk_term_ctx *tctx __unused) int rc; uk_list_for_each_entry_reverse(mp, &mount_list, mnt_list) { - uk_pr_info("Unmounting %s (%p)...\n", mp->m_path, mp->m_dev); + uk_pr_info("Unmounting %s (%s)...\n", mp->m_path, + mp->m_dev ? mp->m_dev->name : "none"); /* For now, flags = 0 is enough. */ rc = VFS_UNMOUNT(mp, 0); if (unlikely(rc))