aboutsummaryrefslogtreecommitdiff
path: root/hw/9pfs/9p-util.c
diff options
context:
space:
mode:
authorGreg Kurz <groug@kaod.org>2017-05-25 10:30:14 +0200
committerGreg Kurz <groug@kaod.org>2017-05-25 10:30:14 +0200
commit3dbcf27334b6c41e74a476b55d76f60df1c4007b (patch)
tree4fda76c5b7b96a449362455813968bedddffdd3f /hw/9pfs/9p-util.c
parentf57f5878578af19f72344439154234c6d6ba8ccc (diff)
9pfs: local: simplify file opening
The logic to open a path currently sits between local_open_nofollow() and the relative_openat_nofollow() helper, which has no other user. For the sake of clarity, this patch moves all the code of the helper into its unique caller. While here we also: - drop the code to skip leading "/" because the backend isn't supposed to pass anything but relative paths without consecutive slashes. The assert() is kept because we really don't want a buggy backend to pass an absolute path to openat(). - use strchrnul() to get a simpler code. This is ok since virtfs is for linux+glibc hosts only. - don't dup() the initial directory and add an assert() to ensure we don't return the global mountfd to the caller. BTW, this would mean that the caller passed an empty path, which isn't supposed to happen either. Signed-off-by: Greg Kurz <groug@kaod.org> Reviewed-by: Eric Blake <eblake@redhat.com> [groug: fixed typos in changelog]
Diffstat (limited to 'hw/9pfs/9p-util.c')
-rw-r--r--hw/9pfs/9p-util.c43
1 files changed, 0 insertions, 43 deletions
diff --git a/hw/9pfs/9p-util.c b/hw/9pfs/9p-util.c
index fdb4d57376..f709c27a1f 100644
--- a/hw/9pfs/9p-util.c
+++ b/hw/9pfs/9p-util.c
@@ -14,49 +14,6 @@
#include "qemu/xattr.h"
#include "9p-util.h"
-int relative_openat_nofollow(int dirfd, const char *path, int flags,
- mode_t mode)
-{
- int fd;
-
- fd = dup(dirfd);
- if (fd == -1) {
- return -1;
- }
-
- while (*path) {
- const char *c;
- int next_fd;
- char *head;
-
- /* Only relative paths without consecutive slashes */
- assert(path[0] != '/');
-
- head = g_strdup(path);
- c = strchr(path, '/');
- if (c) {
- head[c - path] = 0;
- next_fd = openat_dir(fd, head);
- } else {
- next_fd = openat_file(fd, head, flags, mode);
- }
- g_free(head);
- if (next_fd == -1) {
- close_preserve_errno(fd);
- return -1;
- }
- close(fd);
- fd = next_fd;
-
- if (!c) {
- break;
- }
- path = c + 1;
- }
-
- return fd;
-}
-
ssize_t fgetxattrat_nofollow(int dirfd, const char *filename, const char *name,
void *value, size_t size)
{