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