Statistics
| Branch: | Revision:

root / hw / virtio-9p.h @ 5e94c103

History | View | Annotate | Download (5.6 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_TREADDIR = 40,
19
    P9_RREADDIR,
20
    P9_TVERSION = 100,
21
    P9_RVERSION,
22
    P9_TAUTH = 102,
23
    P9_RAUTH,
24
    P9_TATTACH = 104,
25
    P9_RATTACH,
26
    P9_TERROR = 106,
27
    P9_RERROR,
28
    P9_TFLUSH = 108,
29
    P9_RFLUSH,
30
    P9_TWALK = 110,
31
    P9_RWALK,
32
    P9_TOPEN = 112,
33
    P9_ROPEN,
34
    P9_TCREATE = 114,
35
    P9_RCREATE,
36
    P9_TREAD = 116,
37
    P9_RREAD,
38
    P9_TWRITE = 118,
39
    P9_RWRITE,
40
    P9_TCLUNK = 120,
41
    P9_RCLUNK,
42
    P9_TREMOVE = 122,
43
    P9_RREMOVE,
44
    P9_TSTAT = 124,
45
    P9_RSTAT,
46
    P9_TWSTAT = 126,
47
    P9_RWSTAT,
48
};
49

    
50

    
51
/* qid.types */
52
enum {
53
    P9_QTDIR = 0x80,
54
    P9_QTAPPEND = 0x40,
55
    P9_QTEXCL = 0x20,
56
    P9_QTMOUNT = 0x10,
57
    P9_QTAUTH = 0x08,
58
    P9_QTTMP = 0x04,
59
    P9_QTSYMLINK = 0x02,
60
    P9_QTLINK = 0x01,
61
    P9_QTFILE = 0x00,
62
};
63

    
64
enum p9_proto_version {
65
    V9FS_PROTO_2000U = 0x01,
66
    V9FS_PROTO_2000L = 0x02,
67
};
68

    
69
#define P9_NOTAG    (u16)(~0)
70
#define P9_NOFID    (u32)(~0)
71
#define P9_MAXWELEM 16
72

    
73
/*
74
 * ample room for Twrite/Rread header
75
 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
76
 */
77
#define P9_IOHDRSZ 24
78

    
79
typedef struct V9fsPDU V9fsPDU;
80

    
81
struct V9fsPDU
82
{
83
    uint32_t size;
84
    uint16_t tag;
85
    uint8_t id;
86
    VirtQueueElement elem;
87
    QLIST_ENTRY(V9fsPDU) next;
88
};
89

    
90

    
91
/* FIXME
92
 * 1) change user needs to set groups and stuff
93
 */
94

    
95
/* from Linux's linux/virtio_9p.h */
96

    
97
/* The ID for virtio console */
98
#define VIRTIO_ID_9P    9
99
#define MAX_REQ         128
100
#define MAX_TAG_LEN     32
101

    
102
#define BUG_ON(cond) assert(!(cond))
103

    
104
typedef struct V9fsFidState V9fsFidState;
105

    
106
typedef struct V9fsString
107
{
108
    int16_t size;
109
    char *data;
110
} V9fsString;
111

    
112
typedef struct V9fsQID
113
{
114
    int8_t type;
115
    int32_t version;
116
    int64_t path;
117
} V9fsQID;
118

    
119
typedef struct V9fsStat
120
{
121
    int16_t size;
122
    int16_t type;
123
    int32_t dev;
124
    V9fsQID qid;
125
    int32_t mode;
126
    int32_t atime;
127
    int32_t mtime;
128
    int64_t length;
129
    V9fsString name;
130
    V9fsString uid;
131
    V9fsString gid;
132
    V9fsString muid;
133
    /* 9p2000.u */
134
    V9fsString extension;
135
   int32_t n_uid;
136
    int32_t n_gid;
137
    int32_t n_muid;
138
} V9fsStat;
139

    
140
struct V9fsFidState
141
{
142
    int32_t fid;
143
    V9fsString path;
144
    int fd;
145
    DIR *dir;
146
    uid_t uid;
147
    V9fsFidState *next;
148
};
149

    
150
typedef struct V9fsState
151
{
152
    VirtIODevice vdev;
153
    VirtQueue *vq;
154
    V9fsPDU pdus[MAX_REQ];
155
    QLIST_HEAD(, V9fsPDU) free_list;
156
    V9fsFidState *fid_list;
157
    FileOperations *ops;
158
    FsContext ctx;
159
    uint16_t tag_len;
160
    uint8_t *tag;
161
    size_t config_size;
162
    enum p9_proto_version proto_version;
163
    int32_t msize;
164
} V9fsState;
165

    
166
typedef struct V9fsCreateState {
167
    V9fsPDU *pdu;
168
    size_t offset;
169
    V9fsFidState *fidp;
170
    V9fsQID qid;
171
    int32_t perm;
172
    int8_t mode;
173
    struct stat stbuf;
174
    V9fsString name;
175
    V9fsString extension;
176
    V9fsString fullname;
177
    int iounit;
178
} V9fsCreateState;
179

    
180
typedef struct V9fsStatState {
181
    V9fsPDU *pdu;
182
    size_t offset;
183
    V9fsStat v9stat;
184
    V9fsFidState *fidp;
185
    struct stat stbuf;
186
} V9fsStatState;
187

    
188
typedef struct V9fsWalkState {
189
    V9fsPDU *pdu;
190
    size_t offset;
191
    int16_t nwnames;
192
    int name_idx;
193
    V9fsQID *qids;
194
    V9fsFidState *fidp;
195
    V9fsFidState *newfidp;
196
    V9fsString path;
197
    V9fsString *wnames;
198
    struct stat stbuf;
199
} V9fsWalkState;
200

    
201
typedef struct V9fsOpenState {
202
    V9fsPDU *pdu;
203
    size_t offset;
204
    int8_t mode;
205
    V9fsFidState *fidp;
206
    V9fsQID qid;
207
    struct stat stbuf;
208
    int iounit;
209
} V9fsOpenState;
210

    
211
typedef struct V9fsReadState {
212
    V9fsPDU *pdu;
213
    size_t offset;
214
    int32_t count;
215
    int32_t total;
216
    int64_t off;
217
    V9fsFidState *fidp;
218
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
219
    struct iovec *sg;
220
    off_t dir_pos;
221
    struct dirent *dent;
222
    struct stat stbuf;
223
    V9fsString name;
224
    V9fsStat v9stat;
225
    int32_t len;
226
    int32_t cnt;
227
    int32_t max_count;
228
} V9fsReadState;
229

    
230
typedef struct V9fsWriteState {
231
    V9fsPDU *pdu;
232
    size_t offset;
233
    int32_t len;
234
    int32_t count;
235
    int32_t total;
236
    int64_t off;
237
    V9fsFidState *fidp;
238
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
239
    struct iovec *sg;
240
    int cnt;
241
} V9fsWriteState;
242

    
243
typedef struct V9fsRemoveState {
244
    V9fsPDU *pdu;
245
    size_t offset;
246
    V9fsFidState *fidp;
247
} V9fsRemoveState;
248

    
249
typedef struct V9fsWstatState
250
{
251
    V9fsPDU *pdu;
252
    size_t offset;
253
    int16_t unused;
254
    V9fsStat v9stat;
255
    V9fsFidState *fidp;
256
    struct stat stbuf;
257
    V9fsString nname;
258
} V9fsWstatState;
259

    
260
struct virtio_9p_config
261
{
262
    /* number of characters in tag */
263
    uint16_t tag_len;
264
    /* Variable size tag name */
265
    uint8_t tag[0];
266
} __attribute__((packed));
267

    
268
typedef struct V9fsStatfs
269
{
270
    uint32_t f_type;
271
    uint32_t f_bsize;
272
    uint64_t f_blocks;
273
    uint64_t f_bfree;
274
    uint64_t f_bavail;
275
    uint64_t f_files;
276
    uint64_t f_ffree;
277
    uint64_t fsid_val;
278
    uint32_t f_namelen;
279
} V9fsStatfs;
280

    
281
typedef struct V9fsStatfsState {
282
    V9fsPDU *pdu;
283
    size_t offset;
284
    int32_t fid;
285
    V9fsStatfs v9statfs;
286
    V9fsFidState *fidp;
287
    struct statfs stbuf;
288
} V9fsStatfsState;
289

    
290
extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
291
                            size_t offset, size_t size, int pack);
292

    
293
static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
294
                        size_t offset, size_t size)
295
{
296
    return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
297
}
298

    
299
#endif