]>
git.proxmox.com Git - mirror_qemu.git/blob - hw/virtio-9p-local.c
f6781ca2af2b3fe93e08e2b32cdf0dc3bc6ef899
2 * Virtio 9p Posix callback
4 * Copyright IBM, Corp. 2010
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #include "virtio-9p.h"
15 #include <arpa/inet.h>
18 #include <sys/socket.h>
21 static const char *rpath(FsContext
*ctx
, const char *path
)
23 /* FIXME: so wrong... */
24 static char buffer
[4096];
25 snprintf(buffer
, sizeof(buffer
), "%s/%s", ctx
->fs_root
, path
);
29 static int local_lstat(FsContext
*ctx
, const char *path
, struct stat
*stbuf
)
31 return lstat(rpath(ctx
, path
), stbuf
);
34 static int local_setuid(FsContext
*ctx
, uid_t uid
)
39 static uid_t cur_uid
= -1;
55 if (getgrouplist(pw
->pw_name
, pw
->pw_gid
, groups
, &ngroups
) == -1) {
59 if (setgroups(ngroups
, groups
)) {
63 if (setregid(-1, pw
->pw_gid
)) {
67 if (setreuid(-1, uid
)) {
76 static ssize_t
local_readlink(FsContext
*ctx
, const char *path
,
77 char *buf
, size_t bufsz
)
79 return readlink(rpath(ctx
, path
), buf
, bufsz
);
82 static int local_close(FsContext
*ctx
, int fd
)
87 static int local_closedir(FsContext
*ctx
, DIR *dir
)
92 static int local_open(FsContext
*ctx
, const char *path
, int flags
)
94 return open(rpath(ctx
, path
), flags
);
97 static DIR *local_opendir(FsContext
*ctx
, const char *path
)
99 return opendir(rpath(ctx
, path
));
102 static void local_rewinddir(FsContext
*ctx
, DIR *dir
)
104 return rewinddir(dir
);
107 static off_t
local_telldir(FsContext
*ctx
, DIR *dir
)
112 static struct dirent
*local_readdir(FsContext
*ctx
, DIR *dir
)
117 static void local_seekdir(FsContext
*ctx
, DIR *dir
, off_t off
)
119 return seekdir(dir
, off
);
122 static ssize_t
local_readv(FsContext
*ctx
, int fd
, const struct iovec
*iov
,
125 return readv(fd
, iov
, iovcnt
);
128 static off_t
local_lseek(FsContext
*ctx
, int fd
, off_t offset
, int whence
)
130 return lseek(fd
, offset
, whence
);
133 static ssize_t
local_writev(FsContext
*ctx
, int fd
, const struct iovec
*iov
,
136 return writev(fd
, iov
, iovcnt
);
139 static int local_chmod(FsContext
*ctx
, const char *path
, mode_t mode
)
141 return chmod(rpath(ctx
, path
), mode
);
144 static int local_mknod(FsContext
*ctx
, const char *path
, mode_t mode
, dev_t dev
)
146 return mknod(rpath(ctx
, path
), mode
, dev
);
149 static int local_mksock(FsContext
*ctx2
, const char *path
)
151 struct sockaddr_un addr
;
154 addr
.sun_family
= AF_UNIX
;
155 snprintf(addr
.sun_path
, 108, "%s", rpath(ctx2
, path
));
157 s
= socket(PF_UNIX
, SOCK_STREAM
, 0);
162 if (bind(s
, (struct sockaddr
*)&addr
, sizeof(addr
))) {
171 static int local_mkdir(FsContext
*ctx
, const char *path
, mode_t mode
)
173 return mkdir(rpath(ctx
, path
), mode
);
176 static int local_fstat(FsContext
*ctx
, int fd
, struct stat
*stbuf
)
178 return fstat(fd
, stbuf
);
181 static int local_open2(FsContext
*ctx
, const char *path
, int flags
, mode_t mode
)
183 return open(rpath(ctx
, path
), flags
, mode
);
186 static int local_symlink(FsContext
*ctx
, const char *oldpath
,
189 return symlink(oldpath
, rpath(ctx
, newpath
));
192 static int local_link(FsContext
*ctx
, const char *oldpath
, const char *newpath
)
194 char *tmp
= qemu_strdup(rpath(ctx
, oldpath
));
201 err
= link(tmp
, rpath(ctx
, newpath
));
215 FileOperations local_ops
= {
216 .lstat
= local_lstat
,
217 .setuid
= local_setuid
,
218 .readlink
= local_readlink
,
219 .close
= local_close
,
220 .closedir
= local_closedir
,
222 .opendir
= local_opendir
,
223 .rewinddir
= local_rewinddir
,
224 .telldir
= local_telldir
,
225 .readdir
= local_readdir
,
226 .seekdir
= local_seekdir
,
227 .readv
= local_readv
,
228 .lseek
= local_lseek
,
229 .writev
= local_writev
,
230 .chmod
= local_chmod
,
231 .mknod
= local_mknod
,
232 .mksock
= local_mksock
,
233 .mkdir
= local_mkdir
,
234 .fstat
= local_fstat
,
235 .open2
= local_open2
,
236 .symlink
= local_symlink
,