linux-user: convert ioctl(SIOCGIFCONF, ...) result.
[qemu/ar7.git] / hw / virtio-9p.h
blob2ae4ce7189c63d4adb767e9390e098ecde4787eb
1 #ifndef _QEMU_VIRTIO_9P_H
2 #define _QEMU_VIRTIO_9P_H
4 #include <sys/types.h>
5 #include <dirent.h>
6 #include <sys/time.h>
7 #include <utime.h>
9 #include "file-op-9p.h"
11 /* The feature bitmap for virtio 9P */
12 /* The mount point is specified in a config variable */
13 #define VIRTIO_9P_MOUNT_TAG 0
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,
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,
96 enum p9_proto_version {
97 V9FS_PROTO_2000U = 0x01,
98 V9FS_PROTO_2000L = 0x02,
101 #define P9_NOTAG (u16)(~0)
102 #define P9_NOFID (u32)(~0)
103 #define P9_MAXWELEM 16
106 * ample room for Twrite/Rread header
107 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
109 #define P9_IOHDRSZ 24
111 typedef struct V9fsPDU V9fsPDU;
113 struct V9fsPDU
115 uint32_t size;
116 uint16_t tag;
117 uint8_t id;
118 VirtQueueElement elem;
119 QLIST_ENTRY(V9fsPDU) next;
123 /* FIXME
124 * 1) change user needs to set groups and stuff
127 /* from Linux's linux/virtio_9p.h */
129 /* The ID for virtio console */
130 #define VIRTIO_ID_9P 9
131 #define MAX_REQ 128
132 #define MAX_TAG_LEN 32
134 #define BUG_ON(cond) assert(!(cond))
136 typedef struct V9fsFidState V9fsFidState;
138 typedef struct V9fsString
140 int16_t size;
141 char *data;
142 } V9fsString;
144 typedef struct V9fsQID
146 int8_t type;
147 int32_t version;
148 int64_t path;
149 } V9fsQID;
151 typedef struct V9fsStat
153 int16_t size;
154 int16_t type;
155 int32_t dev;
156 V9fsQID qid;
157 int32_t mode;
158 int32_t atime;
159 int32_t mtime;
160 int64_t length;
161 V9fsString name;
162 V9fsString uid;
163 V9fsString gid;
164 V9fsString muid;
165 /* 9p2000.u */
166 V9fsString extension;
167 int32_t n_uid;
168 int32_t n_gid;
169 int32_t n_muid;
170 } V9fsStat;
172 enum {
173 P9_FID_NONE = 0,
174 P9_FID_FILE,
175 P9_FID_DIR,
176 P9_FID_XATTR,
179 typedef struct V9fsXattr
181 int64_t copied_len;
182 int64_t len;
183 void *value;
184 V9fsString name;
185 int flags;
186 } V9fsXattr;
188 struct V9fsFidState
190 int fid_type;
191 int32_t fid;
192 V9fsString path;
193 union {
194 int fd;
195 DIR *dir;
196 V9fsXattr xattr;
197 } fs;
198 uid_t uid;
199 V9fsFidState *next;
202 typedef struct V9fsState
204 VirtIODevice vdev;
205 VirtQueue *vq;
206 V9fsPDU pdus[MAX_REQ];
207 QLIST_HEAD(, V9fsPDU) free_list;
208 V9fsFidState *fid_list;
209 FileOperations *ops;
210 FsContext ctx;
211 uint16_t tag_len;
212 uint8_t *tag;
213 size_t config_size;
214 enum p9_proto_version proto_version;
215 int32_t msize;
216 } V9fsState;
218 typedef struct V9fsCreateState {
219 V9fsPDU *pdu;
220 size_t offset;
221 V9fsFidState *fidp;
222 V9fsQID qid;
223 int32_t perm;
224 int8_t mode;
225 struct stat stbuf;
226 V9fsString name;
227 V9fsString extension;
228 V9fsString fullname;
229 int iounit;
230 } V9fsCreateState;
232 typedef struct V9fsLcreateState {
233 V9fsPDU *pdu;
234 size_t offset;
235 V9fsFidState *fidp;
236 V9fsQID qid;
237 int32_t iounit;
238 struct stat stbuf;
239 V9fsString name;
240 V9fsString fullname;
241 } V9fsLcreateState;
243 typedef struct V9fsStatState {
244 V9fsPDU *pdu;
245 size_t offset;
246 V9fsStat v9stat;
247 V9fsFidState *fidp;
248 struct stat stbuf;
249 } V9fsStatState;
251 typedef struct V9fsStatDotl {
252 uint64_t st_result_mask;
253 V9fsQID qid;
254 uint32_t st_mode;
255 uint32_t st_uid;
256 uint32_t st_gid;
257 uint64_t st_nlink;
258 uint64_t st_rdev;
259 uint64_t st_size;
260 uint64_t st_blksize;
261 uint64_t st_blocks;
262 uint64_t st_atime_sec;
263 uint64_t st_atime_nsec;
264 uint64_t st_mtime_sec;
265 uint64_t st_mtime_nsec;
266 uint64_t st_ctime_sec;
267 uint64_t st_ctime_nsec;
268 uint64_t st_btime_sec;
269 uint64_t st_btime_nsec;
270 uint64_t st_gen;
271 uint64_t st_data_version;
272 } V9fsStatDotl;
274 typedef struct V9fsStatStateDotl {
275 V9fsPDU *pdu;
276 size_t offset;
277 V9fsStatDotl v9stat_dotl;
278 struct stat stbuf;
279 } V9fsStatStateDotl;
282 typedef struct V9fsWalkState {
283 V9fsPDU *pdu;
284 size_t offset;
285 int16_t nwnames;
286 int name_idx;
287 V9fsQID *qids;
288 V9fsFidState *fidp;
289 V9fsFidState *newfidp;
290 V9fsString path;
291 V9fsString *wnames;
292 struct stat stbuf;
293 } V9fsWalkState;
295 typedef struct V9fsOpenState {
296 V9fsPDU *pdu;
297 size_t offset;
298 int32_t mode;
299 V9fsFidState *fidp;
300 V9fsQID qid;
301 struct stat stbuf;
302 int iounit;
303 } V9fsOpenState;
305 typedef struct V9fsReadState {
306 V9fsPDU *pdu;
307 size_t offset;
308 int32_t count;
309 int32_t total;
310 int64_t off;
311 V9fsFidState *fidp;
312 struct iovec iov[128]; /* FIXME: bad, bad, bad */
313 struct iovec *sg;
314 off_t dir_pos;
315 struct dirent *dent;
316 struct stat stbuf;
317 V9fsString name;
318 V9fsStat v9stat;
319 int32_t len;
320 int32_t cnt;
321 int32_t max_count;
322 } V9fsReadState;
324 typedef struct V9fsWriteState {
325 V9fsPDU *pdu;
326 size_t offset;
327 int32_t len;
328 int32_t count;
329 int32_t total;
330 int64_t off;
331 V9fsFidState *fidp;
332 struct iovec iov[128]; /* FIXME: bad, bad, bad */
333 struct iovec *sg;
334 int cnt;
335 } V9fsWriteState;
337 typedef struct V9fsRemoveState {
338 V9fsPDU *pdu;
339 size_t offset;
340 V9fsFidState *fidp;
341 } V9fsRemoveState;
343 typedef struct V9fsWstatState
345 V9fsPDU *pdu;
346 size_t offset;
347 int16_t unused;
348 V9fsStat v9stat;
349 V9fsFidState *fidp;
350 struct stat stbuf;
351 } V9fsWstatState;
353 typedef struct V9fsSymlinkState
355 V9fsPDU *pdu;
356 size_t offset;
357 V9fsString name;
358 V9fsString symname;
359 V9fsString fullname;
360 V9fsFidState *dfidp;
361 V9fsQID qid;
362 struct stat stbuf;
363 } V9fsSymlinkState;
365 typedef struct V9fsIattr
367 int32_t valid;
368 int32_t mode;
369 int32_t uid;
370 int32_t gid;
371 int64_t size;
372 int64_t atime_sec;
373 int64_t atime_nsec;
374 int64_t mtime_sec;
375 int64_t mtime_nsec;
376 } V9fsIattr;
378 typedef struct V9fsSetattrState
380 V9fsPDU *pdu;
381 size_t offset;
382 V9fsIattr v9iattr;
383 V9fsFidState *fidp;
384 } V9fsSetattrState;
386 struct virtio_9p_config
388 /* number of characters in tag */
389 uint16_t tag_len;
390 /* Variable size tag name */
391 uint8_t tag[0];
392 } __attribute__((packed));
394 typedef struct V9fsStatfs
396 uint32_t f_type;
397 uint32_t f_bsize;
398 uint64_t f_blocks;
399 uint64_t f_bfree;
400 uint64_t f_bavail;
401 uint64_t f_files;
402 uint64_t f_ffree;
403 uint64_t fsid_val;
404 uint32_t f_namelen;
405 } V9fsStatfs;
407 typedef struct V9fsStatfsState {
408 V9fsPDU *pdu;
409 size_t offset;
410 int32_t fid;
411 V9fsStatfs v9statfs;
412 V9fsFidState *fidp;
413 struct statfs stbuf;
414 } V9fsStatfsState;
416 typedef struct V9fsMkState {
417 V9fsPDU *pdu;
418 size_t offset;
419 V9fsQID qid;
420 struct stat stbuf;
421 V9fsString name;
422 V9fsString fullname;
423 } V9fsMkState;
425 typedef struct V9fsRenameState {
426 V9fsPDU *pdu;
427 V9fsFidState *fidp;
428 size_t offset;
429 int32_t newdirfid;
430 V9fsString name;
431 } V9fsRenameState;
433 typedef struct V9fsXattrState
435 V9fsPDU *pdu;
436 size_t offset;
437 V9fsFidState *file_fidp;
438 V9fsFidState *xattr_fidp;
439 V9fsString name;
440 int64_t size;
441 int flags;
442 void *value;
443 } V9fsXattrState;
445 #define P9_LOCK_SUCCESS 0
446 #define P9_LOCK_BLOCKED 1
447 #define P9_LOCK_ERROR 2
448 #define P9_LOCK_GRACE 3
450 #define P9_LOCK_FLAGS_BLOCK 1
451 #define P9_LOCK_FLAGS_RECLAIM 2
453 typedef struct V9fsFlock
455 uint8_t type;
456 uint32_t flags;
457 uint64_t start; /* absolute offset */
458 uint64_t length;
459 uint32_t proc_id;
460 V9fsString client_id;
461 } V9fsFlock;
463 typedef struct V9fsLockState
465 V9fsPDU *pdu;
466 size_t offset;
467 int8_t status;
468 struct stat stbuf;
469 V9fsFidState *fidp;
470 V9fsFlock *flock;
471 } V9fsLockState;
473 typedef struct V9fsGetlock
475 uint8_t type;
476 uint64_t start; /* absolute offset */
477 uint64_t length;
478 uint32_t proc_id;
479 V9fsString client_id;
480 } V9fsGetlock;
482 typedef struct V9fsGetlockState
484 V9fsPDU *pdu;
485 size_t offset;
486 struct stat stbuf;
487 V9fsFidState *fidp;
488 V9fsGetlock *glock;
489 } V9fsGetlockState;
491 typedef struct V9fsReadLinkState
493 V9fsPDU *pdu;
494 size_t offset;
495 V9fsString target;
496 } V9fsReadLinkState;
498 size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
499 size_t offset, size_t size, int pack);
501 static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
502 size_t offset, size_t size)
504 return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
507 #endif