root / hw / virtio-9p.h @ fac4f111
History | View | Annotate | Download (4.8 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_TVERSION = 100,
|
17 |
P9_RVERSION, |
18 |
P9_TAUTH = 102,
|
19 |
P9_RAUTH, |
20 |
P9_TATTACH = 104,
|
21 |
P9_RATTACH, |
22 |
P9_TERROR = 106,
|
23 |
P9_RERROR, |
24 |
P9_TFLUSH = 108,
|
25 |
P9_RFLUSH, |
26 |
P9_TWALK = 110,
|
27 |
P9_RWALK, |
28 |
P9_TOPEN = 112,
|
29 |
P9_ROPEN, |
30 |
P9_TCREATE = 114,
|
31 |
P9_RCREATE, |
32 |
P9_TREAD = 116,
|
33 |
P9_RREAD, |
34 |
P9_TWRITE = 118,
|
35 |
P9_RWRITE, |
36 |
P9_TCLUNK = 120,
|
37 |
P9_RCLUNK, |
38 |
P9_TREMOVE = 122,
|
39 |
P9_RREMOVE, |
40 |
P9_TSTAT = 124,
|
41 |
P9_RSTAT, |
42 |
P9_TWSTAT = 126,
|
43 |
P9_RWSTAT, |
44 |
}; |
45 |
|
46 |
|
47 |
/* qid.types */
|
48 |
enum {
|
49 |
P9_QTDIR = 0x80,
|
50 |
P9_QTAPPEND = 0x40,
|
51 |
P9_QTEXCL = 0x20,
|
52 |
P9_QTMOUNT = 0x10,
|
53 |
P9_QTAUTH = 0x08,
|
54 |
P9_QTTMP = 0x04,
|
55 |
P9_QTSYMLINK = 0x02,
|
56 |
P9_QTLINK = 0x01,
|
57 |
P9_QTFILE = 0x00,
|
58 |
}; |
59 |
|
60 |
#define P9_NOTAG (u16)(~0) |
61 |
#define P9_NOFID (u32)(~0) |
62 |
#define P9_MAXWELEM 16 |
63 |
|
64 |
typedef struct V9fsPDU V9fsPDU; |
65 |
|
66 |
struct V9fsPDU
|
67 |
{ |
68 |
uint32_t size; |
69 |
uint16_t tag; |
70 |
uint8_t id; |
71 |
VirtQueueElement elem; |
72 |
QLIST_ENTRY(V9fsPDU) next; |
73 |
}; |
74 |
|
75 |
|
76 |
/* FIXME
|
77 |
* 1) change user needs to set groups and stuff
|
78 |
*/
|
79 |
|
80 |
/* from Linux's linux/virtio_9p.h */
|
81 |
|
82 |
/* The ID for virtio console */
|
83 |
#define VIRTIO_ID_9P 9 |
84 |
#define MAX_REQ 128 |
85 |
#define MAX_TAG_LEN 32 |
86 |
|
87 |
#define BUG_ON(cond) assert(!(cond))
|
88 |
|
89 |
typedef struct V9fsFidState V9fsFidState; |
90 |
|
91 |
typedef struct V9fsString |
92 |
{ |
93 |
int16_t size; |
94 |
char *data;
|
95 |
} V9fsString; |
96 |
|
97 |
typedef struct V9fsQID |
98 |
{ |
99 |
int8_t type; |
100 |
int32_t version; |
101 |
int64_t path; |
102 |
} V9fsQID; |
103 |
|
104 |
typedef struct V9fsStat |
105 |
{ |
106 |
int16_t size; |
107 |
int16_t type; |
108 |
int32_t dev; |
109 |
V9fsQID qid; |
110 |
int32_t mode; |
111 |
int32_t atime; |
112 |
int32_t mtime; |
113 |
int64_t length; |
114 |
V9fsString name; |
115 |
V9fsString uid; |
116 |
V9fsString gid; |
117 |
V9fsString muid; |
118 |
/* 9p2000.u */
|
119 |
V9fsString extension; |
120 |
int32_t n_uid; |
121 |
int32_t n_gid; |
122 |
int32_t n_muid; |
123 |
} V9fsStat; |
124 |
|
125 |
struct V9fsFidState
|
126 |
{ |
127 |
int32_t fid; |
128 |
V9fsString path; |
129 |
int fd;
|
130 |
DIR *dir; |
131 |
uid_t uid; |
132 |
V9fsFidState *next; |
133 |
}; |
134 |
|
135 |
typedef struct V9fsState |
136 |
{ |
137 |
VirtIODevice vdev; |
138 |
VirtQueue *vq; |
139 |
V9fsPDU pdus[MAX_REQ]; |
140 |
QLIST_HEAD(, V9fsPDU) free_list; |
141 |
V9fsFidState *fid_list; |
142 |
FileOperations *ops; |
143 |
FsContext ctx; |
144 |
uint16_t tag_len; |
145 |
uint8_t *tag; |
146 |
size_t config_size; |
147 |
} V9fsState; |
148 |
|
149 |
typedef struct V9fsCreateState { |
150 |
V9fsPDU *pdu; |
151 |
size_t offset; |
152 |
V9fsFidState *fidp; |
153 |
V9fsQID qid; |
154 |
int32_t perm; |
155 |
int8_t mode; |
156 |
struct stat stbuf;
|
157 |
V9fsString name; |
158 |
V9fsString extension; |
159 |
V9fsString fullname; |
160 |
} V9fsCreateState; |
161 |
|
162 |
typedef struct V9fsStatState { |
163 |
V9fsPDU *pdu; |
164 |
size_t offset; |
165 |
V9fsStat v9stat; |
166 |
V9fsFidState *fidp; |
167 |
struct stat stbuf;
|
168 |
} V9fsStatState; |
169 |
|
170 |
typedef struct V9fsWalkState { |
171 |
V9fsPDU *pdu; |
172 |
size_t offset; |
173 |
int16_t nwnames; |
174 |
int name_idx;
|
175 |
V9fsQID *qids; |
176 |
V9fsFidState *fidp; |
177 |
V9fsFidState *newfidp; |
178 |
V9fsString path; |
179 |
V9fsString *wnames; |
180 |
struct stat stbuf;
|
181 |
} V9fsWalkState; |
182 |
|
183 |
typedef struct V9fsOpenState { |
184 |
V9fsPDU *pdu; |
185 |
size_t offset; |
186 |
int8_t mode; |
187 |
V9fsFidState *fidp; |
188 |
V9fsQID qid; |
189 |
struct stat stbuf;
|
190 |
} V9fsOpenState; |
191 |
|
192 |
typedef struct V9fsReadState { |
193 |
V9fsPDU *pdu; |
194 |
size_t offset; |
195 |
int32_t count; |
196 |
int32_t total; |
197 |
int64_t off; |
198 |
V9fsFidState *fidp; |
199 |
struct iovec iov[128]; /* FIXME: bad, bad, bad */ |
200 |
struct iovec *sg;
|
201 |
off_t dir_pos; |
202 |
struct dirent *dent;
|
203 |
struct stat stbuf;
|
204 |
V9fsString name; |
205 |
V9fsStat v9stat; |
206 |
int32_t len; |
207 |
int32_t cnt; |
208 |
int32_t max_count; |
209 |
} V9fsReadState; |
210 |
|
211 |
typedef struct V9fsWriteState { |
212 |
V9fsPDU *pdu; |
213 |
size_t offset; |
214 |
int32_t len; |
215 |
int32_t count; |
216 |
int32_t total; |
217 |
int64_t off; |
218 |
V9fsFidState *fidp; |
219 |
struct iovec iov[128]; /* FIXME: bad, bad, bad */ |
220 |
struct iovec *sg;
|
221 |
int cnt;
|
222 |
} V9fsWriteState; |
223 |
|
224 |
typedef struct V9fsRemoveState { |
225 |
V9fsPDU *pdu; |
226 |
size_t offset; |
227 |
V9fsFidState *fidp; |
228 |
} V9fsRemoveState; |
229 |
|
230 |
typedef struct V9fsWstatState |
231 |
{ |
232 |
V9fsPDU *pdu; |
233 |
size_t offset; |
234 |
int16_t unused; |
235 |
V9fsStat v9stat; |
236 |
V9fsFidState *fidp; |
237 |
struct stat stbuf;
|
238 |
V9fsString nname; |
239 |
} V9fsWstatState; |
240 |
|
241 |
struct virtio_9p_config
|
242 |
{ |
243 |
/* number of characters in tag */
|
244 |
uint16_t tag_len; |
245 |
/* Variable size tag name */
|
246 |
uint8_t tag[0];
|
247 |
} __attribute__((packed)); |
248 |
|
249 |
extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, |
250 |
size_t offset, size_t size, int pack);
|
251 |
|
252 |
static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count, |
253 |
size_t offset, size_t size) |
254 |
{ |
255 |
return pdu_packunpack(dst, sg, sg_count, offset, size, 0); |
256 |
} |
257 |
|
258 |
#endif
|