Statistics
| Branch: | Revision:

root / hw / virtio-9p.h @ 10b468bd

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_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_TXATTRCREATE = 32,
35
    P9_RXATTRCREATE,
36
    P9_TREADDIR = 40,
37
    P9_RREADDIR,
38
    P9_TLINK = 70,
39
    P9_RLINK,
40
    P9_TMKDIR = 72,
41
    P9_RMKDIR,
42
    P9_TVERSION = 100,
43
    P9_RVERSION,
44
    P9_TAUTH = 102,
45
    P9_RAUTH,
46
    P9_TATTACH = 104,
47
    P9_RATTACH,
48
    P9_TERROR = 106,
49
    P9_RERROR,
50
    P9_TFLUSH = 108,
51
    P9_RFLUSH,
52
    P9_TWALK = 110,
53
    P9_RWALK,
54
    P9_TOPEN = 112,
55
    P9_ROPEN,
56
    P9_TCREATE = 114,
57
    P9_RCREATE,
58
    P9_TREAD = 116,
59
    P9_RREAD,
60
    P9_TWRITE = 118,
61
    P9_RWRITE,
62
    P9_TCLUNK = 120,
63
    P9_RCLUNK,
64
    P9_TREMOVE = 122,
65
    P9_RREMOVE,
66
    P9_TSTAT = 124,
67
    P9_RSTAT,
68
    P9_TWSTAT = 126,
69
    P9_RWSTAT,
70
};
71

    
72

    
73
/* qid.types */
74
enum {
75
    P9_QTDIR = 0x80,
76
    P9_QTAPPEND = 0x40,
77
    P9_QTEXCL = 0x20,
78
    P9_QTMOUNT = 0x10,
79
    P9_QTAUTH = 0x08,
80
    P9_QTTMP = 0x04,
81
    P9_QTSYMLINK = 0x02,
82
    P9_QTLINK = 0x01,
83
    P9_QTFILE = 0x00,
84
};
85

    
86
enum p9_proto_version {
87
    V9FS_PROTO_2000U = 0x01,
88
    V9FS_PROTO_2000L = 0x02,
89
};
90

    
91
#define P9_NOTAG    (u16)(~0)
92
#define P9_NOFID    (u32)(~0)
93
#define P9_MAXWELEM 16
94

    
95
/*
96
 * ample room for Twrite/Rread header
97
 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
98
 */
99
#define P9_IOHDRSZ 24
100

    
101
typedef struct V9fsPDU V9fsPDU;
102

    
103
struct V9fsPDU
104
{
105
    uint32_t size;
106
    uint16_t tag;
107
    uint8_t id;
108
    VirtQueueElement elem;
109
    QLIST_ENTRY(V9fsPDU) next;
110
};
111

    
112

    
113
/* FIXME
114
 * 1) change user needs to set groups and stuff
115
 */
116

    
117
/* from Linux's linux/virtio_9p.h */
118

    
119
/* The ID for virtio console */
120
#define VIRTIO_ID_9P    9
121
#define MAX_REQ         128
122
#define MAX_TAG_LEN     32
123

    
124
#define BUG_ON(cond) assert(!(cond))
125

    
126
typedef struct V9fsFidState V9fsFidState;
127

    
128
typedef struct V9fsString
129
{
130
    int16_t size;
131
    char *data;
132
} V9fsString;
133

    
134
typedef struct V9fsQID
135
{
136
    int8_t type;
137
    int32_t version;
138
    int64_t path;
139
} V9fsQID;
140

    
141
typedef struct V9fsStat
142
{
143
    int16_t size;
144
    int16_t type;
145
    int32_t dev;
146
    V9fsQID qid;
147
    int32_t mode;
148
    int32_t atime;
149
    int32_t mtime;
150
    int64_t length;
151
    V9fsString name;
152
    V9fsString uid;
153
    V9fsString gid;
154
    V9fsString muid;
155
    /* 9p2000.u */
156
    V9fsString extension;
157
   int32_t n_uid;
158
    int32_t n_gid;
159
    int32_t n_muid;
160
} V9fsStat;
161

    
162
enum {
163
    P9_FID_NONE = 0,
164
    P9_FID_FILE,
165
    P9_FID_DIR,
166
    P9_FID_XATTR,
167
};
168

    
169
typedef struct V9fsXattr
170
{
171
    int64_t copied_len;
172
    int64_t len;
173
    void *value;
174
    V9fsString name;
175
    int flags;
176
} V9fsXattr;
177

    
178
struct V9fsFidState
179
{
180
    int fid_type;
181
    int32_t fid;
182
    V9fsString path;
183
    union {
184
        int fd;
185
        DIR *dir;
186
        V9fsXattr xattr;
187
    } fs;
188
    uid_t uid;
189
    V9fsFidState *next;
190
};
191

    
192
typedef struct V9fsState
193
{
194
    VirtIODevice vdev;
195
    VirtQueue *vq;
196
    V9fsPDU pdus[MAX_REQ];
197
    QLIST_HEAD(, V9fsPDU) free_list;
198
    V9fsFidState *fid_list;
199
    FileOperations *ops;
200
    FsContext ctx;
201
    uint16_t tag_len;
202
    uint8_t *tag;
203
    size_t config_size;
204
    enum p9_proto_version proto_version;
205
    int32_t msize;
206
} V9fsState;
207

    
208
typedef struct V9fsCreateState {
209
    V9fsPDU *pdu;
210
    size_t offset;
211
    V9fsFidState *fidp;
212
    V9fsQID qid;
213
    int32_t perm;
214
    int8_t mode;
215
    struct stat stbuf;
216
    V9fsString name;
217
    V9fsString extension;
218
    V9fsString fullname;
219
    int iounit;
220
} V9fsCreateState;
221

    
222
typedef struct V9fsLcreateState {
223
    V9fsPDU *pdu;
224
    size_t offset;
225
    V9fsFidState *fidp;
226
    V9fsQID qid;
227
    int32_t iounit;
228
    struct stat stbuf;
229
    V9fsString name;
230
    V9fsString fullname;
231
} V9fsLcreateState;
232

    
233
typedef struct V9fsStatState {
234
    V9fsPDU *pdu;
235
    size_t offset;
236
    V9fsStat v9stat;
237
    V9fsFidState *fidp;
238
    struct stat stbuf;
239
} V9fsStatState;
240

    
241
typedef struct V9fsStatDotl {
242
    uint64_t st_result_mask;
243
    V9fsQID qid;
244
    uint32_t st_mode;
245
    uint32_t st_uid;
246
    uint32_t st_gid;
247
    uint64_t st_nlink;
248
    uint64_t st_rdev;
249
    uint64_t st_size;
250
    uint64_t st_blksize;
251
    uint64_t st_blocks;
252
    uint64_t st_atime_sec;
253
    uint64_t st_atime_nsec;
254
    uint64_t st_mtime_sec;
255
    uint64_t st_mtime_nsec;
256
    uint64_t st_ctime_sec;
257
    uint64_t st_ctime_nsec;
258
    uint64_t st_btime_sec;
259
    uint64_t st_btime_nsec;
260
    uint64_t st_gen;
261
    uint64_t st_data_version;
262
} V9fsStatDotl;
263

    
264
typedef struct V9fsStatStateDotl {
265
    V9fsPDU *pdu;
266
    size_t offset;
267
    V9fsStatDotl v9stat_dotl;
268
    struct stat stbuf;
269
} V9fsStatStateDotl;
270

    
271

    
272
typedef struct V9fsWalkState {
273
    V9fsPDU *pdu;
274
    size_t offset;
275
    int16_t nwnames;
276
    int name_idx;
277
    V9fsQID *qids;
278
    V9fsFidState *fidp;
279
    V9fsFidState *newfidp;
280
    V9fsString path;
281
    V9fsString *wnames;
282
    struct stat stbuf;
283
} V9fsWalkState;
284

    
285
typedef struct V9fsOpenState {
286
    V9fsPDU *pdu;
287
    size_t offset;
288
    int32_t mode;
289
    V9fsFidState *fidp;
290
    V9fsQID qid;
291
    struct stat stbuf;
292
    int iounit;
293
} V9fsOpenState;
294

    
295
typedef struct V9fsReadState {
296
    V9fsPDU *pdu;
297
    size_t offset;
298
    int32_t count;
299
    int32_t total;
300
    int64_t off;
301
    V9fsFidState *fidp;
302
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
303
    struct iovec *sg;
304
    off_t dir_pos;
305
    struct dirent *dent;
306
    struct stat stbuf;
307
    V9fsString name;
308
    V9fsStat v9stat;
309
    int32_t len;
310
    int32_t cnt;
311
    int32_t max_count;
312
} V9fsReadState;
313

    
314
typedef struct V9fsWriteState {
315
    V9fsPDU *pdu;
316
    size_t offset;
317
    int32_t len;
318
    int32_t count;
319
    int32_t total;
320
    int64_t off;
321
    V9fsFidState *fidp;
322
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
323
    struct iovec *sg;
324
    int cnt;
325
} V9fsWriteState;
326

    
327
typedef struct V9fsRemoveState {
328
    V9fsPDU *pdu;
329
    size_t offset;
330
    V9fsFidState *fidp;
331
} V9fsRemoveState;
332

    
333
typedef struct V9fsWstatState
334
{
335
    V9fsPDU *pdu;
336
    size_t offset;
337
    int16_t unused;
338
    V9fsStat v9stat;
339
    V9fsFidState *fidp;
340
    struct stat stbuf;
341
} V9fsWstatState;
342

    
343
typedef struct V9fsSymlinkState
344
{
345
    V9fsPDU *pdu;
346
    size_t offset;
347
    V9fsString name;
348
    V9fsString symname;
349
    V9fsString fullname;
350
    V9fsFidState *dfidp;
351
    V9fsQID qid;
352
    struct stat stbuf;
353
} V9fsSymlinkState;
354

    
355
typedef struct V9fsIattr
356
{
357
    int32_t valid;
358
    int32_t mode;
359
    int32_t uid;
360
    int32_t gid;
361
    int64_t size;
362
    int64_t atime_sec;
363
    int64_t atime_nsec;
364
    int64_t mtime_sec;
365
    int64_t mtime_nsec;
366
} V9fsIattr;
367

    
368
typedef struct V9fsSetattrState
369
{
370
    V9fsPDU *pdu;
371
    size_t offset;
372
    V9fsIattr v9iattr;
373
    V9fsFidState *fidp;
374
} V9fsSetattrState;
375

    
376
struct virtio_9p_config
377
{
378
    /* number of characters in tag */
379
    uint16_t tag_len;
380
    /* Variable size tag name */
381
    uint8_t tag[0];
382
} __attribute__((packed));
383

    
384
typedef struct V9fsStatfs
385
{
386
    uint32_t f_type;
387
    uint32_t f_bsize;
388
    uint64_t f_blocks;
389
    uint64_t f_bfree;
390
    uint64_t f_bavail;
391
    uint64_t f_files;
392
    uint64_t f_ffree;
393
    uint64_t fsid_val;
394
    uint32_t f_namelen;
395
} V9fsStatfs;
396

    
397
typedef struct V9fsStatfsState {
398
    V9fsPDU *pdu;
399
    size_t offset;
400
    int32_t fid;
401
    V9fsStatfs v9statfs;
402
    V9fsFidState *fidp;
403
    struct statfs stbuf;
404
} V9fsStatfsState;
405

    
406
typedef struct V9fsMkState {
407
    V9fsPDU *pdu;
408
    size_t offset;
409
    V9fsQID qid;
410
    struct stat stbuf;
411
    V9fsString name;
412
    V9fsString fullname;
413
} V9fsMkState;
414

    
415
typedef struct V9fsRenameState {
416
    V9fsPDU *pdu;
417
    V9fsFidState *fidp;
418
    size_t offset;
419
    int32_t newdirfid;
420
    V9fsString name;
421
} V9fsRenameState;
422

    
423
typedef struct V9fsXattrState
424
{
425
    V9fsPDU *pdu;
426
    size_t offset;
427
    V9fsFidState *file_fidp;
428
    V9fsFidState *xattr_fidp;
429
    V9fsString name;
430
    int64_t size;
431
    int flags;
432
    void *value;
433
} V9fsXattrState;
434

    
435
extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
436
                            size_t offset, size_t size, int pack);
437

    
438
static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
439
                        size_t offset, size_t size)
440
{
441
    return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
442
}
443

    
444
#endif