Statistics
| Branch: | Revision:

root / hw / virtio-9p.h @ b67592ea

History | View | Annotate | Download (7.4 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_TLCREATE = 14,
19
    P9_RLCREATE,
20
    P9_TSYMLINK = 16,
21
    P9_RSYMLINK,
22
    P9_TMKNOD = 18,
23
    P9_RMKNOD,
24
    P9_TGETATTR = 24,
25
    P9_RGETATTR,
26
    P9_TSETATTR = 26,
27
    P9_RSETATTR,
28
    P9_TREADDIR = 40,
29
    P9_RREADDIR,
30
    P9_TLINK = 70,
31
    P9_RLINK,
32
    P9_TMKDIR = 72,
33
    P9_RMKDIR,
34
    P9_TVERSION = 100,
35
    P9_RVERSION,
36
    P9_TAUTH = 102,
37
    P9_RAUTH,
38
    P9_TATTACH = 104,
39
    P9_RATTACH,
40
    P9_TERROR = 106,
41
    P9_RERROR,
42
    P9_TFLUSH = 108,
43
    P9_RFLUSH,
44
    P9_TWALK = 110,
45
    P9_RWALK,
46
    P9_TOPEN = 112,
47
    P9_ROPEN,
48
    P9_TCREATE = 114,
49
    P9_RCREATE,
50
    P9_TREAD = 116,
51
    P9_RREAD,
52
    P9_TWRITE = 118,
53
    P9_RWRITE,
54
    P9_TCLUNK = 120,
55
    P9_RCLUNK,
56
    P9_TREMOVE = 122,
57
    P9_RREMOVE,
58
    P9_TSTAT = 124,
59
    P9_RSTAT,
60
    P9_TWSTAT = 126,
61
    P9_RWSTAT,
62
};
63

    
64

    
65
/* qid.types */
66
enum {
67
    P9_QTDIR = 0x80,
68
    P9_QTAPPEND = 0x40,
69
    P9_QTEXCL = 0x20,
70
    P9_QTMOUNT = 0x10,
71
    P9_QTAUTH = 0x08,
72
    P9_QTTMP = 0x04,
73
    P9_QTSYMLINK = 0x02,
74
    P9_QTLINK = 0x01,
75
    P9_QTFILE = 0x00,
76
};
77

    
78
enum p9_proto_version {
79
    V9FS_PROTO_2000U = 0x01,
80
    V9FS_PROTO_2000L = 0x02,
81
};
82

    
83
#define P9_NOTAG    (u16)(~0)
84
#define P9_NOFID    (u32)(~0)
85
#define P9_MAXWELEM 16
86

    
87
/*
88
 * ample room for Twrite/Rread header
89
 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
90
 */
91
#define P9_IOHDRSZ 24
92

    
93
typedef struct V9fsPDU V9fsPDU;
94

    
95
struct V9fsPDU
96
{
97
    uint32_t size;
98
    uint16_t tag;
99
    uint8_t id;
100
    VirtQueueElement elem;
101
    QLIST_ENTRY(V9fsPDU) next;
102
};
103

    
104

    
105
/* FIXME
106
 * 1) change user needs to set groups and stuff
107
 */
108

    
109
/* from Linux's linux/virtio_9p.h */
110

    
111
/* The ID for virtio console */
112
#define VIRTIO_ID_9P    9
113
#define MAX_REQ         128
114
#define MAX_TAG_LEN     32
115

    
116
#define BUG_ON(cond) assert(!(cond))
117

    
118
typedef struct V9fsFidState V9fsFidState;
119

    
120
typedef struct V9fsString
121
{
122
    int16_t size;
123
    char *data;
124
} V9fsString;
125

    
126
typedef struct V9fsQID
127
{
128
    int8_t type;
129
    int32_t version;
130
    int64_t path;
131
} V9fsQID;
132

    
133
typedef struct V9fsStat
134
{
135
    int16_t size;
136
    int16_t type;
137
    int32_t dev;
138
    V9fsQID qid;
139
    int32_t mode;
140
    int32_t atime;
141
    int32_t mtime;
142
    int64_t length;
143
    V9fsString name;
144
    V9fsString uid;
145
    V9fsString gid;
146
    V9fsString muid;
147
    /* 9p2000.u */
148
    V9fsString extension;
149
   int32_t n_uid;
150
    int32_t n_gid;
151
    int32_t n_muid;
152
} V9fsStat;
153

    
154
struct V9fsFidState
155
{
156
    int32_t fid;
157
    V9fsString path;
158
    int fd;
159
    DIR *dir;
160
    uid_t uid;
161
    V9fsFidState *next;
162
};
163

    
164
typedef struct V9fsState
165
{
166
    VirtIODevice vdev;
167
    VirtQueue *vq;
168
    V9fsPDU pdus[MAX_REQ];
169
    QLIST_HEAD(, V9fsPDU) free_list;
170
    V9fsFidState *fid_list;
171
    FileOperations *ops;
172
    FsContext ctx;
173
    uint16_t tag_len;
174
    uint8_t *tag;
175
    size_t config_size;
176
    enum p9_proto_version proto_version;
177
    int32_t msize;
178
} V9fsState;
179

    
180
typedef struct V9fsCreateState {
181
    V9fsPDU *pdu;
182
    size_t offset;
183
    V9fsFidState *fidp;
184
    V9fsQID qid;
185
    int32_t perm;
186
    int8_t mode;
187
    struct stat stbuf;
188
    V9fsString name;
189
    V9fsString extension;
190
    V9fsString fullname;
191
    int iounit;
192
} V9fsCreateState;
193

    
194
typedef struct V9fsLcreateState {
195
    V9fsPDU *pdu;
196
    size_t offset;
197
    V9fsFidState *fidp;
198
    V9fsQID qid;
199
    int32_t iounit;
200
    struct stat stbuf;
201
    V9fsString name;
202
    V9fsString fullname;
203
} V9fsLcreateState;
204

    
205
typedef struct V9fsStatState {
206
    V9fsPDU *pdu;
207
    size_t offset;
208
    V9fsStat v9stat;
209
    V9fsFidState *fidp;
210
    struct stat stbuf;
211
} V9fsStatState;
212

    
213
typedef struct V9fsStatDotl {
214
    uint64_t st_result_mask;
215
    V9fsQID qid;
216
    uint32_t st_mode;
217
    uint32_t st_uid;
218
    uint32_t st_gid;
219
    uint64_t st_nlink;
220
    uint64_t st_rdev;
221
    uint64_t st_size;
222
    uint64_t st_blksize;
223
    uint64_t st_blocks;
224
    uint64_t st_atime_sec;
225
    uint64_t st_atime_nsec;
226
    uint64_t st_mtime_sec;
227
    uint64_t st_mtime_nsec;
228
    uint64_t st_ctime_sec;
229
    uint64_t st_ctime_nsec;
230
    uint64_t st_btime_sec;
231
    uint64_t st_btime_nsec;
232
    uint64_t st_gen;
233
    uint64_t st_data_version;
234
} V9fsStatDotl;
235

    
236
typedef struct V9fsStatStateDotl {
237
    V9fsPDU *pdu;
238
    size_t offset;
239
    V9fsStatDotl v9stat_dotl;
240
    struct stat stbuf;
241
} V9fsStatStateDotl;
242

    
243

    
244
typedef struct V9fsWalkState {
245
    V9fsPDU *pdu;
246
    size_t offset;
247
    int16_t nwnames;
248
    int name_idx;
249
    V9fsQID *qids;
250
    V9fsFidState *fidp;
251
    V9fsFidState *newfidp;
252
    V9fsString path;
253
    V9fsString *wnames;
254
    struct stat stbuf;
255
} V9fsWalkState;
256

    
257
typedef struct V9fsOpenState {
258
    V9fsPDU *pdu;
259
    size_t offset;
260
    int8_t mode;
261
    V9fsFidState *fidp;
262
    V9fsQID qid;
263
    struct stat stbuf;
264
    int iounit;
265
} V9fsOpenState;
266

    
267
typedef struct V9fsReadState {
268
    V9fsPDU *pdu;
269
    size_t offset;
270
    int32_t count;
271
    int32_t total;
272
    int64_t off;
273
    V9fsFidState *fidp;
274
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
275
    struct iovec *sg;
276
    off_t dir_pos;
277
    struct dirent *dent;
278
    struct stat stbuf;
279
    V9fsString name;
280
    V9fsStat v9stat;
281
    int32_t len;
282
    int32_t cnt;
283
    int32_t max_count;
284
} V9fsReadState;
285

    
286
typedef struct V9fsWriteState {
287
    V9fsPDU *pdu;
288
    size_t offset;
289
    int32_t len;
290
    int32_t count;
291
    int32_t total;
292
    int64_t off;
293
    V9fsFidState *fidp;
294
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
295
    struct iovec *sg;
296
    int cnt;
297
} V9fsWriteState;
298

    
299
typedef struct V9fsRemoveState {
300
    V9fsPDU *pdu;
301
    size_t offset;
302
    V9fsFidState *fidp;
303
} V9fsRemoveState;
304

    
305
typedef struct V9fsWstatState
306
{
307
    V9fsPDU *pdu;
308
    size_t offset;
309
    int16_t unused;
310
    V9fsStat v9stat;
311
    V9fsFidState *fidp;
312
    struct stat stbuf;
313
    V9fsString nname;
314
} V9fsWstatState;
315

    
316
typedef struct V9fsSymlinkState
317
{
318
    V9fsPDU *pdu;
319
    size_t offset;
320
    V9fsString name;
321
    V9fsString symname;
322
    V9fsString fullname;
323
    V9fsFidState *dfidp;
324
    V9fsQID qid;
325
    struct stat stbuf;
326
} V9fsSymlinkState;
327

    
328
typedef struct V9fsIattr
329
{
330
    int32_t valid;
331
    int32_t mode;
332
    int32_t uid;
333
    int32_t gid;
334
    int64_t size;
335
    int64_t atime_sec;
336
    int64_t atime_nsec;
337
    int64_t mtime_sec;
338
    int64_t mtime_nsec;
339
} V9fsIattr;
340

    
341
typedef struct V9fsSetattrState
342
{
343
    V9fsPDU *pdu;
344
    size_t offset;
345
    V9fsIattr v9iattr;
346
    V9fsFidState *fidp;
347
} V9fsSetattrState;
348

    
349
struct virtio_9p_config
350
{
351
    /* number of characters in tag */
352
    uint16_t tag_len;
353
    /* Variable size tag name */
354
    uint8_t tag[0];
355
} __attribute__((packed));
356

    
357
typedef struct V9fsStatfs
358
{
359
    uint32_t f_type;
360
    uint32_t f_bsize;
361
    uint64_t f_blocks;
362
    uint64_t f_bfree;
363
    uint64_t f_bavail;
364
    uint64_t f_files;
365
    uint64_t f_ffree;
366
    uint64_t fsid_val;
367
    uint32_t f_namelen;
368
} V9fsStatfs;
369

    
370
typedef struct V9fsStatfsState {
371
    V9fsPDU *pdu;
372
    size_t offset;
373
    int32_t fid;
374
    V9fsStatfs v9statfs;
375
    V9fsFidState *fidp;
376
    struct statfs stbuf;
377
} V9fsStatfsState;
378

    
379
typedef struct V9fsMkState {
380
    V9fsPDU *pdu;
381
    size_t offset;
382
    V9fsQID qid;
383
    struct stat stbuf;
384
    V9fsString name;
385
    V9fsString fullname;
386
} V9fsMkState;
387

    
388
extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
389
                            size_t offset, size_t size, int pack);
390

    
391
static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
392
                        size_t offset, size_t size)
393
{
394
    return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
395
}
396

    
397
#endif