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