root / hw / 9pfs / virtio-9p.h @ ff06030f
History | View | Annotate | Download (9.6 kB)
1 |
#ifndef _QEMU_VIRTIO_9P_H
|
---|---|
2 |
#define _QEMU_VIRTIO_9P_H
|
3 |
|
4 |
#include <sys/types.h> |
5 |
#include <dirent.h> |
6 |
#include <sys/time.h> |
7 |
#include <utime.h> |
8 |
#include "hw/virtio.h" |
9 |
#include "fsdev/file-op-9p.h" |
10 |
|
11 |
/* The feature bitmap for virtio 9P */
|
12 |
/* The mount point is specified in a config variable */
|
13 |
#define VIRTIO_9P_MOUNT_TAG 0 |
14 |
|
15 |
enum {
|
16 |
P9_TLERROR = 6,
|
17 |
P9_RLERROR, |
18 |
P9_TSTATFS = 8,
|
19 |
P9_RSTATFS, |
20 |
P9_TLOPEN = 12,
|
21 |
P9_RLOPEN, |
22 |
P9_TLCREATE = 14,
|
23 |
P9_RLCREATE, |
24 |
P9_TSYMLINK = 16,
|
25 |
P9_RSYMLINK, |
26 |
P9_TMKNOD = 18,
|
27 |
P9_RMKNOD, |
28 |
P9_TRENAME = 20,
|
29 |
P9_RRENAME, |
30 |
P9_TREADLINK = 22,
|
31 |
P9_RREADLINK, |
32 |
P9_TGETATTR = 24,
|
33 |
P9_RGETATTR, |
34 |
P9_TSETATTR = 26,
|
35 |
P9_RSETATTR, |
36 |
P9_TXATTRWALK = 30,
|
37 |
P9_RXATTRWALK, |
38 |
P9_TXATTRCREATE = 32,
|
39 |
P9_RXATTRCREATE, |
40 |
P9_TREADDIR = 40,
|
41 |
P9_RREADDIR, |
42 |
P9_TFSYNC = 50,
|
43 |
P9_RFSYNC, |
44 |
P9_TLOCK = 52,
|
45 |
P9_RLOCK, |
46 |
P9_TGETLOCK = 54,
|
47 |
P9_RGETLOCK, |
48 |
P9_TLINK = 70,
|
49 |
P9_RLINK, |
50 |
P9_TMKDIR = 72,
|
51 |
P9_RMKDIR, |
52 |
P9_TVERSION = 100,
|
53 |
P9_RVERSION, |
54 |
P9_TAUTH = 102,
|
55 |
P9_RAUTH, |
56 |
P9_TATTACH = 104,
|
57 |
P9_RATTACH, |
58 |
P9_TERROR = 106,
|
59 |
P9_RERROR, |
60 |
P9_TFLUSH = 108,
|
61 |
P9_RFLUSH, |
62 |
P9_TWALK = 110,
|
63 |
P9_RWALK, |
64 |
P9_TOPEN = 112,
|
65 |
P9_ROPEN, |
66 |
P9_TCREATE = 114,
|
67 |
P9_RCREATE, |
68 |
P9_TREAD = 116,
|
69 |
P9_RREAD, |
70 |
P9_TWRITE = 118,
|
71 |
P9_RWRITE, |
72 |
P9_TCLUNK = 120,
|
73 |
P9_RCLUNK, |
74 |
P9_TREMOVE = 122,
|
75 |
P9_RREMOVE, |
76 |
P9_TSTAT = 124,
|
77 |
P9_RSTAT, |
78 |
P9_TWSTAT = 126,
|
79 |
P9_RWSTAT, |
80 |
}; |
81 |
|
82 |
|
83 |
/* qid.types */
|
84 |
enum {
|
85 |
P9_QTDIR = 0x80,
|
86 |
P9_QTAPPEND = 0x40,
|
87 |
P9_QTEXCL = 0x20,
|
88 |
P9_QTMOUNT = 0x10,
|
89 |
P9_QTAUTH = 0x08,
|
90 |
P9_QTTMP = 0x04,
|
91 |
P9_QTSYMLINK = 0x02,
|
92 |
P9_QTLINK = 0x01,
|
93 |
P9_QTFILE = 0x00,
|
94 |
}; |
95 |
|
96 |
enum p9_proto_version {
|
97 |
V9FS_PROTO_2000U = 0x01,
|
98 |
V9FS_PROTO_2000L = 0x02,
|
99 |
}; |
100 |
|
101 |
#define P9_NOTAG (u16)(~0) |
102 |
#define P9_NOFID (u32)(~0) |
103 |
#define P9_MAXWELEM 16 |
104 |
static inline const char *rpath(FsContext *ctx, const char *path, char *buffer) |
105 |
{ |
106 |
snprintf(buffer, PATH_MAX, "%s/%s", ctx->fs_root, path);
|
107 |
return buffer;
|
108 |
} |
109 |
|
110 |
/*
|
111 |
* ample room for Twrite/Rread header
|
112 |
* size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
|
113 |
*/
|
114 |
#define P9_IOHDRSZ 24 |
115 |
|
116 |
typedef struct V9fsPDU V9fsPDU; |
117 |
struct V9fsState;
|
118 |
|
119 |
struct V9fsPDU
|
120 |
{ |
121 |
uint32_t size; |
122 |
uint16_t tag; |
123 |
uint8_t id; |
124 |
VirtQueueElement elem; |
125 |
struct V9fsState *s;
|
126 |
QLIST_ENTRY(V9fsPDU) next; |
127 |
}; |
128 |
|
129 |
|
130 |
/* FIXME
|
131 |
* 1) change user needs to set groups and stuff
|
132 |
*/
|
133 |
|
134 |
/* from Linux's linux/virtio_9p.h */
|
135 |
|
136 |
/* The ID for virtio console */
|
137 |
#define VIRTIO_ID_9P 9 |
138 |
#define MAX_REQ 128 |
139 |
#define MAX_TAG_LEN 32 |
140 |
|
141 |
#define BUG_ON(cond) assert(!(cond))
|
142 |
|
143 |
typedef struct V9fsFidState V9fsFidState; |
144 |
|
145 |
typedef struct V9fsString |
146 |
{ |
147 |
int16_t size; |
148 |
char *data;
|
149 |
} V9fsString; |
150 |
|
151 |
typedef struct V9fsQID |
152 |
{ |
153 |
int8_t type; |
154 |
int32_t version; |
155 |
int64_t path; |
156 |
} V9fsQID; |
157 |
|
158 |
typedef struct V9fsStat |
159 |
{ |
160 |
int16_t size; |
161 |
int16_t type; |
162 |
int32_t dev; |
163 |
V9fsQID qid; |
164 |
int32_t mode; |
165 |
int32_t atime; |
166 |
int32_t mtime; |
167 |
int64_t length; |
168 |
V9fsString name; |
169 |
V9fsString uid; |
170 |
V9fsString gid; |
171 |
V9fsString muid; |
172 |
/* 9p2000.u */
|
173 |
V9fsString extension; |
174 |
int32_t n_uid; |
175 |
int32_t n_gid; |
176 |
int32_t n_muid; |
177 |
} V9fsStat; |
178 |
|
179 |
enum {
|
180 |
P9_FID_NONE = 0,
|
181 |
P9_FID_FILE, |
182 |
P9_FID_DIR, |
183 |
P9_FID_XATTR, |
184 |
}; |
185 |
|
186 |
typedef struct V9fsXattr |
187 |
{ |
188 |
int64_t copied_len; |
189 |
int64_t len; |
190 |
void *value;
|
191 |
V9fsString name; |
192 |
int flags;
|
193 |
} V9fsXattr; |
194 |
|
195 |
struct V9fsFidState
|
196 |
{ |
197 |
int fid_type;
|
198 |
int32_t fid; |
199 |
V9fsString path; |
200 |
union {
|
201 |
int fd;
|
202 |
DIR *dir; |
203 |
V9fsXattr xattr; |
204 |
} fs; |
205 |
uid_t uid; |
206 |
V9fsFidState *next; |
207 |
}; |
208 |
|
209 |
typedef struct V9fsState |
210 |
{ |
211 |
VirtIODevice vdev; |
212 |
VirtQueue *vq; |
213 |
V9fsPDU pdus[MAX_REQ]; |
214 |
QLIST_HEAD(, V9fsPDU) free_list; |
215 |
V9fsFidState *fid_list; |
216 |
FileOperations *ops; |
217 |
FsContext ctx; |
218 |
uint16_t tag_len; |
219 |
uint8_t *tag; |
220 |
size_t config_size; |
221 |
enum p9_proto_version proto_version;
|
222 |
int32_t msize; |
223 |
} V9fsState; |
224 |
|
225 |
typedef struct V9fsCreateState { |
226 |
V9fsPDU *pdu; |
227 |
size_t offset; |
228 |
V9fsFidState *fidp; |
229 |
V9fsQID qid; |
230 |
int32_t perm; |
231 |
int8_t mode; |
232 |
struct stat stbuf;
|
233 |
V9fsString name; |
234 |
V9fsString extension; |
235 |
V9fsString fullname; |
236 |
int iounit;
|
237 |
} V9fsCreateState; |
238 |
|
239 |
typedef struct V9fsLcreateState { |
240 |
V9fsPDU *pdu; |
241 |
size_t offset; |
242 |
V9fsFidState *fidp; |
243 |
V9fsQID qid; |
244 |
int32_t iounit; |
245 |
struct stat stbuf;
|
246 |
V9fsString name; |
247 |
V9fsString fullname; |
248 |
} V9fsLcreateState; |
249 |
|
250 |
typedef struct V9fsStatState { |
251 |
V9fsPDU *pdu; |
252 |
size_t offset; |
253 |
V9fsStat v9stat; |
254 |
V9fsFidState *fidp; |
255 |
struct stat stbuf;
|
256 |
} V9fsStatState; |
257 |
|
258 |
typedef struct V9fsStatDotl { |
259 |
uint64_t st_result_mask; |
260 |
V9fsQID qid; |
261 |
uint32_t st_mode; |
262 |
uint32_t st_uid; |
263 |
uint32_t st_gid; |
264 |
uint64_t st_nlink; |
265 |
uint64_t st_rdev; |
266 |
uint64_t st_size; |
267 |
uint64_t st_blksize; |
268 |
uint64_t st_blocks; |
269 |
uint64_t st_atime_sec; |
270 |
uint64_t st_atime_nsec; |
271 |
uint64_t st_mtime_sec; |
272 |
uint64_t st_mtime_nsec; |
273 |
uint64_t st_ctime_sec; |
274 |
uint64_t st_ctime_nsec; |
275 |
uint64_t st_btime_sec; |
276 |
uint64_t st_btime_nsec; |
277 |
uint64_t st_gen; |
278 |
uint64_t st_data_version; |
279 |
} V9fsStatDotl; |
280 |
|
281 |
typedef struct V9fsStatStateDotl { |
282 |
V9fsPDU *pdu; |
283 |
size_t offset; |
284 |
V9fsStatDotl v9stat_dotl; |
285 |
struct stat stbuf;
|
286 |
} V9fsStatStateDotl; |
287 |
|
288 |
|
289 |
typedef struct V9fsWalkState { |
290 |
V9fsPDU *pdu; |
291 |
size_t offset; |
292 |
uint16_t nwnames; |
293 |
int name_idx;
|
294 |
V9fsQID *qids; |
295 |
V9fsFidState *fidp; |
296 |
V9fsFidState *newfidp; |
297 |
V9fsString path; |
298 |
V9fsString *wnames; |
299 |
struct stat stbuf;
|
300 |
} V9fsWalkState; |
301 |
|
302 |
typedef struct V9fsOpenState { |
303 |
V9fsPDU *pdu; |
304 |
size_t offset; |
305 |
int32_t mode; |
306 |
V9fsFidState *fidp; |
307 |
V9fsQID qid; |
308 |
struct stat stbuf;
|
309 |
int iounit;
|
310 |
} V9fsOpenState; |
311 |
|
312 |
typedef struct V9fsReadState { |
313 |
V9fsPDU *pdu; |
314 |
size_t offset; |
315 |
int32_t count; |
316 |
int32_t total; |
317 |
int64_t off; |
318 |
V9fsFidState *fidp; |
319 |
struct iovec iov[128]; /* FIXME: bad, bad, bad */ |
320 |
struct iovec *sg;
|
321 |
off_t dir_pos; |
322 |
struct dirent *dent;
|
323 |
struct stat stbuf;
|
324 |
V9fsString name; |
325 |
V9fsStat v9stat; |
326 |
int32_t len; |
327 |
int32_t cnt; |
328 |
int32_t max_count; |
329 |
} V9fsReadState; |
330 |
|
331 |
typedef struct V9fsWriteState { |
332 |
V9fsPDU *pdu; |
333 |
size_t offset; |
334 |
int32_t len; |
335 |
int32_t count; |
336 |
int32_t total; |
337 |
int64_t off; |
338 |
V9fsFidState *fidp; |
339 |
struct iovec iov[128]; /* FIXME: bad, bad, bad */ |
340 |
struct iovec *sg;
|
341 |
int cnt;
|
342 |
} V9fsWriteState; |
343 |
|
344 |
typedef struct V9fsRemoveState { |
345 |
V9fsPDU *pdu; |
346 |
size_t offset; |
347 |
V9fsFidState *fidp; |
348 |
} V9fsRemoveState; |
349 |
|
350 |
typedef struct V9fsWstatState |
351 |
{ |
352 |
V9fsPDU *pdu; |
353 |
size_t offset; |
354 |
int16_t unused; |
355 |
V9fsStat v9stat; |
356 |
V9fsFidState *fidp; |
357 |
struct stat stbuf;
|
358 |
} V9fsWstatState; |
359 |
|
360 |
typedef struct V9fsSymlinkState |
361 |
{ |
362 |
V9fsPDU *pdu; |
363 |
size_t offset; |
364 |
V9fsString name; |
365 |
V9fsString symname; |
366 |
V9fsString fullname; |
367 |
V9fsFidState *dfidp; |
368 |
V9fsQID qid; |
369 |
struct stat stbuf;
|
370 |
} V9fsSymlinkState; |
371 |
|
372 |
typedef struct V9fsIattr |
373 |
{ |
374 |
int32_t valid; |
375 |
int32_t mode; |
376 |
int32_t uid; |
377 |
int32_t gid; |
378 |
int64_t size; |
379 |
int64_t atime_sec; |
380 |
int64_t atime_nsec; |
381 |
int64_t mtime_sec; |
382 |
int64_t mtime_nsec; |
383 |
} V9fsIattr; |
384 |
|
385 |
typedef struct V9fsSetattrState |
386 |
{ |
387 |
V9fsPDU *pdu; |
388 |
size_t offset; |
389 |
V9fsIattr v9iattr; |
390 |
V9fsFidState *fidp; |
391 |
} V9fsSetattrState; |
392 |
|
393 |
struct virtio_9p_config
|
394 |
{ |
395 |
/* number of characters in tag */
|
396 |
uint16_t tag_len; |
397 |
/* Variable size tag name */
|
398 |
uint8_t tag[0];
|
399 |
} __attribute__((packed)); |
400 |
|
401 |
typedef struct V9fsStatfs |
402 |
{ |
403 |
uint32_t f_type; |
404 |
uint32_t f_bsize; |
405 |
uint64_t f_blocks; |
406 |
uint64_t f_bfree; |
407 |
uint64_t f_bavail; |
408 |
uint64_t f_files; |
409 |
uint64_t f_ffree; |
410 |
uint64_t fsid_val; |
411 |
uint32_t f_namelen; |
412 |
} V9fsStatfs; |
413 |
|
414 |
typedef struct V9fsStatfsState { |
415 |
V9fsPDU *pdu; |
416 |
size_t offset; |
417 |
int32_t fid; |
418 |
V9fsStatfs v9statfs; |
419 |
V9fsFidState *fidp; |
420 |
struct statfs stbuf;
|
421 |
} V9fsStatfsState; |
422 |
|
423 |
typedef struct V9fsMkState { |
424 |
V9fsPDU *pdu; |
425 |
size_t offset; |
426 |
V9fsQID qid; |
427 |
struct stat stbuf;
|
428 |
V9fsString name; |
429 |
V9fsString fullname; |
430 |
} V9fsMkState; |
431 |
|
432 |
typedef struct V9fsRenameState { |
433 |
V9fsPDU *pdu; |
434 |
V9fsFidState *fidp; |
435 |
size_t offset; |
436 |
int32_t newdirfid; |
437 |
V9fsString name; |
438 |
} V9fsRenameState; |
439 |
|
440 |
typedef struct V9fsXattrState |
441 |
{ |
442 |
V9fsPDU *pdu; |
443 |
size_t offset; |
444 |
V9fsFidState *file_fidp; |
445 |
V9fsFidState *xattr_fidp; |
446 |
V9fsString name; |
447 |
int64_t size; |
448 |
int flags;
|
449 |
void *value;
|
450 |
} V9fsXattrState; |
451 |
|
452 |
#define P9_LOCK_SUCCESS 0 |
453 |
#define P9_LOCK_BLOCKED 1 |
454 |
#define P9_LOCK_ERROR 2 |
455 |
#define P9_LOCK_GRACE 3 |
456 |
|
457 |
#define P9_LOCK_FLAGS_BLOCK 1 |
458 |
#define P9_LOCK_FLAGS_RECLAIM 2 |
459 |
|
460 |
typedef struct V9fsFlock |
461 |
{ |
462 |
uint8_t type; |
463 |
uint32_t flags; |
464 |
uint64_t start; /* absolute offset */
|
465 |
uint64_t length; |
466 |
uint32_t proc_id; |
467 |
V9fsString client_id; |
468 |
} V9fsFlock; |
469 |
|
470 |
typedef struct V9fsLockState |
471 |
{ |
472 |
V9fsPDU *pdu; |
473 |
size_t offset; |
474 |
int8_t status; |
475 |
struct stat stbuf;
|
476 |
V9fsFidState *fidp; |
477 |
V9fsFlock *flock; |
478 |
} V9fsLockState; |
479 |
|
480 |
typedef struct V9fsGetlock |
481 |
{ |
482 |
uint8_t type; |
483 |
uint64_t start; /* absolute offset */
|
484 |
uint64_t length; |
485 |
uint32_t proc_id; |
486 |
V9fsString client_id; |
487 |
} V9fsGetlock; |
488 |
|
489 |
typedef struct V9fsGetlockState |
490 |
{ |
491 |
V9fsPDU *pdu; |
492 |
size_t offset; |
493 |
struct stat stbuf;
|
494 |
V9fsFidState *fidp; |
495 |
V9fsGetlock *glock; |
496 |
} V9fsGetlockState; |
497 |
|
498 |
typedef struct V9fsReadLinkState |
499 |
{ |
500 |
V9fsPDU *pdu; |
501 |
size_t offset; |
502 |
V9fsString target; |
503 |
} V9fsReadLinkState; |
504 |
|
505 |
size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, |
506 |
size_t offset, size_t size, int pack);
|
507 |
|
508 |
static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count, |
509 |
size_t offset, size_t size) |
510 |
{ |
511 |
return pdu_packunpack(dst, sg, sg_count, offset, size, 0); |
512 |
} |
513 |
|
514 |
extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq); |
515 |
|
516 |
#endif
|