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