Statistics
| Branch: | Revision:

root / hw / virtio-9p.h @ 5268cecc

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_TVERSION = 100,
33
    P9_RVERSION,
34
    P9_TAUTH = 102,
35
    P9_RAUTH,
36
    P9_TATTACH = 104,
37
    P9_RATTACH,
38
    P9_TERROR = 106,
39
    P9_RERROR,
40
    P9_TFLUSH = 108,
41
    P9_RFLUSH,
42
    P9_TWALK = 110,
43
    P9_RWALK,
44
    P9_TOPEN = 112,
45
    P9_ROPEN,
46
    P9_TCREATE = 114,
47
    P9_RCREATE,
48
    P9_TREAD = 116,
49
    P9_RREAD,
50
    P9_TWRITE = 118,
51
    P9_RWRITE,
52
    P9_TCLUNK = 120,
53
    P9_RCLUNK,
54
    P9_TREMOVE = 122,
55
    P9_RREMOVE,
56
    P9_TSTAT = 124,
57
    P9_RSTAT,
58
    P9_TWSTAT = 126,
59
    P9_RWSTAT,
60
};
61

    
62

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

    
76
enum p9_proto_version {
77
    V9FS_PROTO_2000U = 0x01,
78
    V9FS_PROTO_2000L = 0x02,
79
};
80

    
81
#define P9_NOTAG    (u16)(~0)
82
#define P9_NOFID    (u32)(~0)
83
#define P9_MAXWELEM 16
84

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

    
91
typedef struct V9fsPDU V9fsPDU;
92

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

    
102

    
103
/* FIXME
104
 * 1) change user needs to set groups and stuff
105
 */
106

    
107
/* from Linux's linux/virtio_9p.h */
108

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

    
114
#define BUG_ON(cond) assert(!(cond))
115

    
116
typedef struct V9fsFidState V9fsFidState;
117

    
118
typedef struct V9fsString
119
{
120
    int16_t size;
121
    char *data;
122
} V9fsString;
123

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

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

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

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

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

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

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

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

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

    
241

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
395
#endif