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