Revision be940c87
b/hw/file-op-9p.h | ||
---|---|---|
74 | 74 |
int (*rename)(FsContext *, const char *, const char *); |
75 | 75 |
int (*truncate)(FsContext *, const char *, off_t); |
76 | 76 |
int (*fsync)(FsContext *, int); |
77 |
int (*statfs)(FsContext *s, const char *path, struct statfs *stbuf); |
|
77 | 78 |
void *opaque; |
78 | 79 |
} FileOperations; |
79 | 80 |
#endif |
b/hw/virtio-9p-local.c | ||
---|---|---|
466 | 466 |
return fsync(fd); |
467 | 467 |
} |
468 | 468 |
|
469 |
static int local_statfs(FsContext *s, const char *path, struct statfs *stbuf) |
|
470 |
{ |
|
471 |
return statfs(rpath(s, path), stbuf); |
|
472 |
} |
|
473 |
|
|
469 | 474 |
FileOperations local_ops = { |
470 | 475 |
.lstat = local_lstat, |
471 | 476 |
.readlink = local_readlink, |
... | ... | |
493 | 498 |
.utime = local_utime, |
494 | 499 |
.remove = local_remove, |
495 | 500 |
.fsync = local_fsync, |
501 |
.statfs = local_statfs, |
|
496 | 502 |
}; |
b/hw/virtio-9p.c | ||
---|---|---|
2144 | 2144 |
qemu_free(vs); |
2145 | 2145 |
} |
2146 | 2146 |
|
2147 |
static int v9fs_do_statfs(V9fsState *s, V9fsString *path, struct statfs *stbuf) |
|
2148 |
{ |
|
2149 |
return s->ops->statfs(&s->ctx, path->data, stbuf); |
|
2150 |
} |
|
2151 |
|
|
2152 |
static void v9fs_statfs_post_statfs(V9fsState *s, V9fsStatfsState *vs, int err) |
|
2153 |
{ |
|
2154 |
if (err) { |
|
2155 |
err = -errno; |
|
2156 |
goto out; |
|
2157 |
} |
|
2158 |
|
|
2159 |
vs->v9statfs.f_type = vs->stbuf.f_type; |
|
2160 |
vs->v9statfs.f_bsize = vs->stbuf.f_bsize; |
|
2161 |
vs->v9statfs.f_blocks = vs->stbuf.f_blocks; |
|
2162 |
vs->v9statfs.f_bfree = vs->stbuf.f_bfree; |
|
2163 |
vs->v9statfs.f_bavail = vs->stbuf.f_bavail; |
|
2164 |
vs->v9statfs.f_files = vs->stbuf.f_files; |
|
2165 |
vs->v9statfs.f_ffree = vs->stbuf.f_ffree; |
|
2166 |
vs->v9statfs.fsid_val = (unsigned int) vs->stbuf.f_fsid.__val[0] | |
|
2167 |
(unsigned long long)vs->stbuf.f_fsid.__val[1] << 32; |
|
2168 |
vs->v9statfs.f_namelen = vs->stbuf.f_namelen; |
|
2169 |
|
|
2170 |
vs->offset += pdu_marshal(vs->pdu, vs->offset, "ddqqqqqqd", |
|
2171 |
vs->v9statfs.f_type, vs->v9statfs.f_bsize, vs->v9statfs.f_blocks, |
|
2172 |
vs->v9statfs.f_bfree, vs->v9statfs.f_bavail, vs->v9statfs.f_files, |
|
2173 |
vs->v9statfs.f_ffree, vs->v9statfs.fsid_val, |
|
2174 |
vs->v9statfs.f_namelen); |
|
2175 |
|
|
2176 |
out: |
|
2177 |
complete_pdu(s, vs->pdu, vs->offset); |
|
2178 |
qemu_free(vs); |
|
2179 |
} |
|
2180 |
|
|
2181 |
static void v9fs_statfs(V9fsState *s, V9fsPDU *pdu) |
|
2182 |
{ |
|
2183 |
V9fsStatfsState *vs; |
|
2184 |
ssize_t err = 0; |
|
2185 |
|
|
2186 |
vs = qemu_malloc(sizeof(*vs)); |
|
2187 |
vs->pdu = pdu; |
|
2188 |
vs->offset = 7; |
|
2189 |
|
|
2190 |
memset(&vs->v9statfs, 0, sizeof(vs->v9statfs)); |
|
2191 |
|
|
2192 |
pdu_unmarshal(vs->pdu, vs->offset, "d", &vs->fid); |
|
2193 |
|
|
2194 |
vs->fidp = lookup_fid(s, vs->fid); |
|
2195 |
if (vs->fidp == NULL) { |
|
2196 |
err = -ENOENT; |
|
2197 |
goto out; |
|
2198 |
} |
|
2199 |
|
|
2200 |
err = v9fs_do_statfs(s, &vs->fidp->path, &vs->stbuf); |
|
2201 |
v9fs_statfs_post_statfs(s, vs, err); |
|
2202 |
return; |
|
2203 |
|
|
2204 |
out: |
|
2205 |
complete_pdu(s, vs->pdu, err); |
|
2206 |
qemu_free(vs); |
|
2207 |
} |
|
2208 |
|
|
2147 | 2209 |
typedef void (pdu_handler_t)(V9fsState *s, V9fsPDU *pdu); |
2148 | 2210 |
|
2149 | 2211 |
static pdu_handler_t *pdu_handlers[] = { |
2212 |
[P9_TSTATFS] = v9fs_statfs, |
|
2150 | 2213 |
[P9_TVERSION] = v9fs_version, |
2151 | 2214 |
[P9_TATTACH] = v9fs_attach, |
2152 | 2215 |
[P9_TSTAT] = v9fs_stat, |
b/hw/virtio-9p.h | ||
---|---|---|
13 | 13 |
#define VIRTIO_9P_MOUNT_TAG 0 |
14 | 14 |
|
15 | 15 |
enum { |
16 |
P9_TSTATFS = 8, |
|
17 |
P9_RSTATFS, |
|
16 | 18 |
P9_TVERSION = 100, |
17 | 19 |
P9_RVERSION, |
18 | 20 |
P9_TAUTH = 102, |
... | ... | |
252 | 254 |
uint8_t tag[0]; |
253 | 255 |
} __attribute__((packed)); |
254 | 256 |
|
257 |
typedef struct V9fsStatfs |
|
258 |
{ |
|
259 |
uint32_t f_type; |
|
260 |
uint32_t f_bsize; |
|
261 |
uint64_t f_blocks; |
|
262 |
uint64_t f_bfree; |
|
263 |
uint64_t f_bavail; |
|
264 |
uint64_t f_files; |
|
265 |
uint64_t f_ffree; |
|
266 |
uint64_t fsid_val; |
|
267 |
uint32_t f_namelen; |
|
268 |
} V9fsStatfs; |
|
269 |
|
|
270 |
typedef struct V9fsStatfsState { |
|
271 |
V9fsPDU *pdu; |
|
272 |
size_t offset; |
|
273 |
int32_t fid; |
|
274 |
V9fsStatfs v9statfs; |
|
275 |
V9fsFidState *fidp; |
|
276 |
struct statfs stbuf; |
|
277 |
} V9fsStatfsState; |
|
278 |
|
|
255 | 279 |
extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, |
256 | 280 |
size_t offset, size_t size, int pack); |
257 | 281 |
|
Also available in: Unified diff