Statistics
| Branch: | Revision:

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

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

    
48

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

    
62
enum p9_proto_version {
63
    V9FS_PROTO_2000U = 0x01,
64
    V9FS_PROTO_2000L = 0x02,
65
};
66

    
67
#define P9_NOTAG    (u16)(~0)
68
#define P9_NOFID    (u32)(~0)
69
#define P9_MAXWELEM 16
70

    
71
typedef struct V9fsPDU V9fsPDU;
72

    
73
struct V9fsPDU
74
{
75
    uint32_t size;
76
    uint16_t tag;
77
    uint8_t id;
78
    VirtQueueElement elem;
79
    QLIST_ENTRY(V9fsPDU) next;
80
};
81

    
82

    
83
/* FIXME
84
 * 1) change user needs to set groups and stuff
85
 */
86

    
87
/* from Linux's linux/virtio_9p.h */
88

    
89
/* The ID for virtio console */
90
#define VIRTIO_ID_9P    9
91
#define MAX_REQ         128
92
#define MAX_TAG_LEN     32
93

    
94
#define BUG_ON(cond) assert(!(cond))
95

    
96
typedef struct V9fsFidState V9fsFidState;
97

    
98
typedef struct V9fsString
99
{
100
    int16_t size;
101
    char *data;
102
} V9fsString;
103

    
104
typedef struct V9fsQID
105
{
106
    int8_t type;
107
    int32_t version;
108
    int64_t path;
109
} V9fsQID;
110

    
111
typedef struct V9fsStat
112
{
113
    int16_t size;
114
    int16_t type;
115
    int32_t dev;
116
    V9fsQID qid;
117
    int32_t mode;
118
    int32_t atime;
119
    int32_t mtime;
120
    int64_t length;
121
    V9fsString name;
122
    V9fsString uid;
123
    V9fsString gid;
124
    V9fsString muid;
125
    /* 9p2000.u */
126
    V9fsString extension;
127
   int32_t n_uid;
128
    int32_t n_gid;
129
    int32_t n_muid;
130
} V9fsStat;
131

    
132
struct V9fsFidState
133
{
134
    int32_t fid;
135
    V9fsString path;
136
    int fd;
137
    DIR *dir;
138
    uid_t uid;
139
    V9fsFidState *next;
140
};
141

    
142
typedef struct V9fsState
143
{
144
    VirtIODevice vdev;
145
    VirtQueue *vq;
146
    V9fsPDU pdus[MAX_REQ];
147
    QLIST_HEAD(, V9fsPDU) free_list;
148
    V9fsFidState *fid_list;
149
    FileOperations *ops;
150
    FsContext ctx;
151
    uint16_t tag_len;
152
    uint8_t *tag;
153
    size_t config_size;
154
    enum p9_proto_version proto_version;
155
} V9fsState;
156

    
157
typedef struct V9fsCreateState {
158
    V9fsPDU *pdu;
159
    size_t offset;
160
    V9fsFidState *fidp;
161
    V9fsQID qid;
162
    int32_t perm;
163
    int8_t mode;
164
    struct stat stbuf;
165
    V9fsString name;
166
    V9fsString extension;
167
    V9fsString fullname;
168
} V9fsCreateState;
169

    
170
typedef struct V9fsStatState {
171
    V9fsPDU *pdu;
172
    size_t offset;
173
    V9fsStat v9stat;
174
    V9fsFidState *fidp;
175
    struct stat stbuf;
176
} V9fsStatState;
177

    
178
typedef struct V9fsWalkState {
179
    V9fsPDU *pdu;
180
    size_t offset;
181
    int16_t nwnames;
182
    int name_idx;
183
    V9fsQID *qids;
184
    V9fsFidState *fidp;
185
    V9fsFidState *newfidp;
186
    V9fsString path;
187
    V9fsString *wnames;
188
    struct stat stbuf;
189
} V9fsWalkState;
190

    
191
typedef struct V9fsOpenState {
192
    V9fsPDU *pdu;
193
    size_t offset;
194
    int8_t mode;
195
    V9fsFidState *fidp;
196
    V9fsQID qid;
197
    struct stat stbuf;
198
} V9fsOpenState;
199

    
200
typedef struct V9fsReadState {
201
    V9fsPDU *pdu;
202
    size_t offset;
203
    int32_t count;
204
    int32_t total;
205
    int64_t off;
206
    V9fsFidState *fidp;
207
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
208
    struct iovec *sg;
209
    off_t dir_pos;
210
    struct dirent *dent;
211
    struct stat stbuf;
212
    V9fsString name;
213
    V9fsStat v9stat;
214
    int32_t len;
215
    int32_t cnt;
216
    int32_t max_count;
217
} V9fsReadState;
218

    
219
typedef struct V9fsWriteState {
220
    V9fsPDU *pdu;
221
    size_t offset;
222
    int32_t len;
223
    int32_t count;
224
    int32_t total;
225
    int64_t off;
226
    V9fsFidState *fidp;
227
    struct iovec iov[128]; /* FIXME: bad, bad, bad */
228
    struct iovec *sg;
229
    int cnt;
230
} V9fsWriteState;
231

    
232
typedef struct V9fsRemoveState {
233
    V9fsPDU *pdu;
234
    size_t offset;
235
    V9fsFidState *fidp;
236
} V9fsRemoveState;
237

    
238
typedef struct V9fsWstatState
239
{
240
    V9fsPDU *pdu;
241
    size_t offset;
242
    int16_t unused;
243
    V9fsStat v9stat;
244
    V9fsFidState *fidp;
245
    struct stat stbuf;
246
    V9fsString nname;
247
} V9fsWstatState;
248

    
249
struct virtio_9p_config
250
{
251
    /* number of characters in tag */
252
    uint16_t tag_len;
253
    /* Variable size tag name */
254
    uint8_t tag[0];
255
} __attribute__((packed));
256

    
257
typedef struct V9fsStatfs
258
{
259
    uint32_t f_type;
260
    uint32_t f_bsize;
261
    uint64_t f_blocks;
262
    uint64_t f_bfree;
263
    uint64_t f_bavail;
264
    uint64_t f_files;
265
    uint64_t f_ffree;
266
    uint64_t fsid_val;
267
    uint32_t f_namelen;
268
} V9fsStatfs;
269

    
270
typedef struct V9fsStatfsState {
271
    V9fsPDU *pdu;
272
    size_t offset;
273
    int32_t fid;
274
    V9fsStatfs v9statfs;
275
    V9fsFidState *fidp;
276
    struct statfs stbuf;
277
} V9fsStatfsState;
278

    
279
extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
280
                            size_t offset, size_t size, int pack);
281

    
282
static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
283
                        size_t offset, size_t size)
284
{
285
    return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
286
}
287

    
288
#endif