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