Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/vfscore: Fix warnings in automount.c #1398

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 20 additions & 7 deletions lib/vfscore/automount.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#include <uk/plat/memory.h>
#include <sys/stat.h>
#include <vfscore/mount.h>
#if CONFIG_LIBVFSCORE_AUTOMOUNT || CONFIG_LIBVFSCORE_AUTOUNMOUNT
#include <devfs/device.h>
#endif
#include <errno.h>
#include <uk/config.h>
#include <uk/arch/types.h>
Expand Down Expand Up @@ -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);
Expand All @@ -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, '/');
Expand All @@ -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;
}

Expand Down Expand Up @@ -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))
Expand Down