virtio-9p: getattr server implementation for 9P2000.L protocol.
[qemu.git] / hw / virtio-9p.h
blob1feed82a09e77b900ccc72581a8e1da41c27882f
1 #ifndef _QEMU_VIRTIO_9P_H
2 #define _QEMU_VIRTIO_9P_H
4 #include <sys/types.h>
5 #include <dirent.h>
6 #include <sys/time.h>
7 #include <utime.h>
9 #include "file-op-9p.h"
11 /* The feature bitmap for virtio 9P */
12 /* The mount point is specified in a config variable */
13 #define VIRTIO_9P_MOUNT_TAG 0
15 enum {
16 P9_TSTATFS = 8,
17 P9_RSTATFS,
18 P9_TGETATTR = 24,
19 P9_RGETATTR,
20 P9_TREADDIR = 40,
21 P9_RREADDIR,
22 P9_TVERSION = 100,
23 P9_RVERSION,
24 P9_TAUTH = 102,
25 P9_RAUTH,
26 P9_TATTACH = 104,
27 P9_RATTACH,
28 P9_TERROR = 106,
29 P9_RERROR,
30 P9_TFLUSH = 108,
31 P9_RFLUSH,
32 P9_TWALK = 110,
33 P9_RWALK,
34 P9_TOPEN = 112,
35 P9_ROPEN,
36 P9_TCREATE = 114,
37 P9_RCREATE,
38 P9_TREAD = 116,
39 P9_RREAD,
40 P9_TWRITE = 118,
41 P9_RWRITE,
42 P9_TCLUNK = 120,
43 P9_RCLUNK,
44 P9_TREMOVE = 122,
45 P9_RREMOVE,
46 P9_TSTAT = 124,
47 P9_RSTAT,
48 P9_TWSTAT = 126,
49 P9_RWSTAT,
53 /* qid.types */
54 enum {
55 P9_QTDIR = 0x80,
56 P9_QTAPPEND = 0x40,
57 P9_QTEXCL = 0x20,
58 P9_QTMOUNT = 0x10,
59 P9_QTAUTH = 0x08,
60 P9_QTTMP = 0x04,
61 P9_QTSYMLINK = 0x02,
62 P9_QTLINK = 0x01,
63 P9_QTFILE = 0x00,
66 enum p9_proto_version {
67 V9FS_PROTO_2000U = 0x01,
68 V9FS_PROTO_2000L = 0x02,
71 #define P9_NOTAG (u16)(~0)
72 #define P9_NOFID (u32)(~0)
73 #define P9_MAXWELEM 16
76 * ample room for Twrite/Rread header
77 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
79 #define P9_IOHDRSZ 24
81 typedef struct V9fsPDU V9fsPDU;
83 struct V9fsPDU
85 uint32_t size;
86 uint16_t tag;
87 uint8_t id;
88 VirtQueueElement elem;
89 QLIST_ENTRY(V9fsPDU) next;
93 /* FIXME
94 * 1) change user needs to set groups and stuff
97 /* from Linux's linux/virtio_9p.h */
99 /* The ID for virtio console */
100 #define VIRTIO_ID_9P 9
101 #define MAX_REQ 128
102 #define MAX_TAG_LEN 32
104 #define BUG_ON(cond) assert(!(cond))
106 typedef struct V9fsFidState V9fsFidState;
108 typedef struct V9fsString
110 int16_t size;
111 char *data;
112 } V9fsString;
114 typedef struct V9fsQID
116 int8_t type;
117 int32_t version;
118 int64_t path;
119 } V9fsQID;
121 typedef struct V9fsStat
123 int16_t size;
124 int16_t type;
125 int32_t dev;
126 V9fsQID qid;
127 int32_t mode;
128 int32_t atime;
129 int32_t mtime;
130 int64_t length;
131 V9fsString name;
132 V9fsString uid;
133 V9fsString gid;
134 V9fsString muid;
135 /* 9p2000.u */
136 V9fsString extension;
137 int32_t n_uid;
138 int32_t n_gid;
139 int32_t n_muid;
140 } V9fsStat;
142 struct V9fsFidState
144 int32_t fid;
145 V9fsString path;
146 int fd;
147 DIR *dir;
148 uid_t uid;
149 V9fsFidState *next;
152 typedef struct V9fsState
154 VirtIODevice vdev;
155 VirtQueue *vq;
156 V9fsPDU pdus[MAX_REQ];
157 QLIST_HEAD(, V9fsPDU) free_list;
158 V9fsFidState *fid_list;
159 FileOperations *ops;
160 FsContext ctx;
161 uint16_t tag_len;
162 uint8_t *tag;
163 size_t config_size;
164 enum p9_proto_version proto_version;
165 int32_t msize;
166 } V9fsState;
168 typedef struct V9fsCreateState {
169 V9fsPDU *pdu;
170 size_t offset;
171 V9fsFidState *fidp;
172 V9fsQID qid;
173 int32_t perm;
174 int8_t mode;
175 struct stat stbuf;
176 V9fsString name;
177 V9fsString extension;
178 V9fsString fullname;
179 int iounit;
180 } V9fsCreateState;
182 typedef struct V9fsStatState {
183 V9fsPDU *pdu;
184 size_t offset;
185 V9fsStat v9stat;
186 V9fsFidState *fidp;
187 struct stat stbuf;
188 } V9fsStatState;
190 typedef struct V9fsStatDotl {
191 uint64_t st_result_mask;
192 V9fsQID qid;
193 uint32_t st_mode;
194 uint32_t st_uid;
195 uint32_t st_gid;
196 uint64_t st_nlink;
197 uint64_t st_rdev;
198 uint64_t st_size;
199 uint64_t st_blksize;
200 uint64_t st_blocks;
201 uint64_t st_atime_sec;
202 uint64_t st_atime_nsec;
203 uint64_t st_mtime_sec;
204 uint64_t st_mtime_nsec;
205 uint64_t st_ctime_sec;
206 uint64_t st_ctime_nsec;
207 uint64_t st_btime_sec;
208 uint64_t st_btime_nsec;
209 uint64_t st_gen;
210 uint64_t st_data_version;
211 } V9fsStatDotl;
213 typedef struct V9fsStatStateDotl {
214 V9fsPDU *pdu;
215 size_t offset;
216 V9fsStatDotl v9stat_dotl;
217 struct stat stbuf;
218 } V9fsStatStateDotl;
221 typedef struct V9fsWalkState {
222 V9fsPDU *pdu;
223 size_t offset;
224 int16_t nwnames;
225 int name_idx;
226 V9fsQID *qids;
227 V9fsFidState *fidp;
228 V9fsFidState *newfidp;
229 V9fsString path;
230 V9fsString *wnames;
231 struct stat stbuf;
232 } V9fsWalkState;
234 typedef struct V9fsOpenState {
235 V9fsPDU *pdu;
236 size_t offset;
237 int8_t mode;
238 V9fsFidState *fidp;
239 V9fsQID qid;
240 struct stat stbuf;
241 int iounit;
242 } V9fsOpenState;
244 typedef struct V9fsReadState {
245 V9fsPDU *pdu;
246 size_t offset;
247 int32_t count;
248 int32_t total;
249 int64_t off;
250 V9fsFidState *fidp;
251 struct iovec iov[128]; /* FIXME: bad, bad, bad */
252 struct iovec *sg;
253 off_t dir_pos;
254 struct dirent *dent;
255 struct stat stbuf;
256 V9fsString name;
257 V9fsStat v9stat;
258 int32_t len;
259 int32_t cnt;
260 int32_t max_count;
261 } V9fsReadState;
263 typedef struct V9fsWriteState {
264 V9fsPDU *pdu;
265 size_t offset;
266 int32_t len;
267 int32_t count;
268 int32_t total;
269 int64_t off;
270 V9fsFidState *fidp;
271 struct iovec iov[128]; /* FIXME: bad, bad, bad */
272 struct iovec *sg;
273 int cnt;
274 } V9fsWriteState;
276 typedef struct V9fsRemoveState {
277 V9fsPDU *pdu;
278 size_t offset;
279 V9fsFidState *fidp;
280 } V9fsRemoveState;
282 typedef struct V9fsWstatState
284 V9fsPDU *pdu;
285 size_t offset;
286 int16_t unused;
287 V9fsStat v9stat;
288 V9fsFidState *fidp;
289 struct stat stbuf;
290 V9fsString nname;
291 } V9fsWstatState;
293 struct virtio_9p_config
295 /* number of characters in tag */
296 uint16_t tag_len;
297 /* Variable size tag name */
298 uint8_t tag[0];
299 } __attribute__((packed));
301 typedef struct V9fsStatfs
303 uint32_t f_type;
304 uint32_t f_bsize;
305 uint64_t f_blocks;
306 uint64_t f_bfree;
307 uint64_t f_bavail;
308 uint64_t f_files;
309 uint64_t f_ffree;
310 uint64_t fsid_val;
311 uint32_t f_namelen;
312 } V9fsStatfs;
314 typedef struct V9fsStatfsState {
315 V9fsPDU *pdu;
316 size_t offset;
317 int32_t fid;
318 V9fsStatfs v9statfs;
319 V9fsFidState *fidp;
320 struct statfs stbuf;
321 } V9fsStatfsState;
323 extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
324 size_t offset, size_t size, int pack);
326 static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
327 size_t offset, size_t size)
329 return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
332 #endif