9p-local.c (f57f5878578af19f72344439154234c6d6ba8ccc) 9p-local.c (3dbcf27334b6c41e74a476b55d76f60df1c4007b)
1/*
2 * 9p Posix callback
3 *
4 * Copyright IBM, Corp. 2010
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *

--- 39 unchanged lines hidden (view full) ---

48typedef struct {
49 int mountfd;
50} LocalData;
51
52int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags,
53 mode_t mode)
54{
55 LocalData *data = fs_ctx->private;
1/*
2 * 9p Posix callback
3 *
4 * Copyright IBM, Corp. 2010
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *

--- 39 unchanged lines hidden (view full) ---

48typedef struct {
49 int mountfd;
50} LocalData;
51
52int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags,
53 mode_t mode)
54{
55 LocalData *data = fs_ctx->private;
56 int fd = data->mountfd;
56
57
57 /* All paths are relative to the path data->mountfd points to */
58 while (*path == '/') {
59 path++;
58 while (*path && fd != -1) {
59 const char *c;
60 int next_fd;
61 char *head;
62
63 /* Only relative paths without consecutive slashes */
64 assert(*path != '/');
65
66 head = g_strdup(path);
67 c = strchrnul(path, '/');
68 if (*c) {
69 /* Intermediate path element */
70 head[c - path] = 0;
71 path = c + 1;
72 next_fd = openat_dir(fd, head);
73 } else {
74 /* Rightmost path element */
75 next_fd = openat_file(fd, head, flags, mode);
76 path = c;
77 }
78 g_free(head);
79 if (fd != data->mountfd) {
80 close_preserve_errno(fd);
81 }
82 fd = next_fd;
60 }
61
83 }
84
62 return relative_openat_nofollow(data->mountfd, path, flags, mode);
85 assert(fd != data->mountfd);
86 return fd;
63}
64
65int local_opendir_nofollow(FsContext *fs_ctx, const char *path)
66{
67 return local_open_nofollow(fs_ctx, path, O_DIRECTORY | O_RDONLY, 0);
68}
69
70static void renameat_preserve_errno(int odirfd, const char *opath, int ndirfd,

--- 1386 unchanged lines hidden ---
87}
88
89int local_opendir_nofollow(FsContext *fs_ctx, const char *path)
90{
91 return local_open_nofollow(fs_ctx, path, O_DIRECTORY | O_RDONLY, 0);
92}
93
94static void renameat_preserve_errno(int odirfd, const char *opath, int ndirfd,

--- 1386 unchanged lines hidden ---