Revision c494dd6f hw/virtio-9p-local.c
b/hw/virtio-9p-local.c | ||
---|---|---|
12 | 12 |
*/ |
13 | 13 |
#include "virtio.h" |
14 | 14 |
#include "virtio-9p.h" |
15 |
#include <arpa/inet.h> |
|
15 | 16 |
#include <pwd.h> |
16 | 17 |
#include <grp.h> |
18 |
#include <sys/socket.h> |
|
19 |
#include <sys/un.h> |
|
17 | 20 |
|
18 | 21 |
static const char *rpath(FsContext *ctx, const char *path) |
19 | 22 |
{ |
... | ... | |
133 | 136 |
return writev(fd, iov, iovcnt); |
134 | 137 |
} |
135 | 138 |
|
139 |
static int local_chmod(FsContext *ctx, const char *path, mode_t mode) |
|
140 |
{ |
|
141 |
return chmod(rpath(ctx, path), mode); |
|
142 |
} |
|
143 |
|
|
144 |
static int local_mknod(FsContext *ctx, const char *path, mode_t mode, dev_t dev) |
|
145 |
{ |
|
146 |
return mknod(rpath(ctx, path), mode, dev); |
|
147 |
} |
|
148 |
|
|
149 |
static int local_mksock(FsContext *ctx2, const char *path) |
|
150 |
{ |
|
151 |
struct sockaddr_un addr; |
|
152 |
int s; |
|
153 |
|
|
154 |
addr.sun_family = AF_UNIX; |
|
155 |
snprintf(addr.sun_path, 108, "%s", rpath(ctx2, path)); |
|
156 |
|
|
157 |
s = socket(PF_UNIX, SOCK_STREAM, 0); |
|
158 |
if (s == -1) { |
|
159 |
return -1; |
|
160 |
} |
|
161 |
|
|
162 |
if (bind(s, (struct sockaddr *)&addr, sizeof(addr))) { |
|
163 |
close(s); |
|
164 |
return -1; |
|
165 |
} |
|
166 |
|
|
167 |
close(s); |
|
168 |
return 0; |
|
169 |
} |
|
170 |
|
|
171 |
static int local_mkdir(FsContext *ctx, const char *path, mode_t mode) |
|
172 |
{ |
|
173 |
return mkdir(rpath(ctx, path), mode); |
|
174 |
} |
|
175 |
|
|
176 |
static int local_fstat(FsContext *ctx, int fd, struct stat *stbuf) |
|
177 |
{ |
|
178 |
return fstat(fd, stbuf); |
|
179 |
} |
|
180 |
|
|
181 |
static int local_open2(FsContext *ctx, const char *path, int flags, mode_t mode) |
|
182 |
{ |
|
183 |
return open(rpath(ctx, path), flags, mode); |
|
184 |
} |
|
185 |
|
|
186 |
static int local_symlink(FsContext *ctx, const char *oldpath, |
|
187 |
const char *newpath) |
|
188 |
{ |
|
189 |
return symlink(oldpath, rpath(ctx, newpath)); |
|
190 |
} |
|
191 |
|
|
192 |
static int local_link(FsContext *ctx, const char *oldpath, const char *newpath) |
|
193 |
{ |
|
194 |
char *tmp = qemu_strdup(rpath(ctx, oldpath)); |
|
195 |
int err, serrno = 0; |
|
196 |
|
|
197 |
if (tmp == NULL) { |
|
198 |
return -ENOMEM; |
|
199 |
} |
|
200 |
|
|
201 |
err = link(tmp, rpath(ctx, newpath)); |
|
202 |
if (err == -1) { |
|
203 |
serrno = errno; |
|
204 |
} |
|
205 |
|
|
206 |
qemu_free(tmp); |
|
207 |
|
|
208 |
if (err == -1) { |
|
209 |
errno = serrno; |
|
210 |
} |
|
211 |
|
|
212 |
return err; |
|
213 |
} |
|
214 |
|
|
136 | 215 |
FileOperations local_ops = { |
137 | 216 |
.lstat = local_lstat, |
138 | 217 |
.setuid = local_setuid, |
... | ... | |
148 | 227 |
.readv = local_readv, |
149 | 228 |
.lseek = local_lseek, |
150 | 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, |
|
237 |
.link = local_link, |
|
151 | 238 |
}; |
Also available in: Unified diff