[V4] virtio-9p: readdir implementation for 9p2000.L
[qemu/stefanha.git] / hw / virtio-9p.h
blob9773659bb00338fba502c8a40c786af1372ee878
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_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,
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,
64 enum p9_proto_version {
65 V9FS_PROTO_2000U = 0x01,
66 V9FS_PROTO_2000L = 0x02,
69 #define P9_NOTAG (u16)(~0)
70 #define P9_NOFID (u32)(~0)
71 #define P9_MAXWELEM 16
73 typedef struct V9fsPDU V9fsPDU;
75 struct V9fsPDU
77 uint32_t size;
78 uint16_t tag;
79 uint8_t id;
80 VirtQueueElement elem;
81 QLIST_ENTRY(V9fsPDU) next;
85 /* FIXME
86 * 1) change user needs to set groups and stuff
89 /* from Linux's linux/virtio_9p.h */
91 /* The ID for virtio console */
92 #define VIRTIO_ID_9P 9
93 #define MAX_REQ 128
94 #define MAX_TAG_LEN 32
96 #define BUG_ON(cond) assert(!(cond))
98 typedef struct V9fsFidState V9fsFidState;
100 typedef struct V9fsString
102 int16_t size;
103 char *data;
104 } V9fsString;
106 typedef struct V9fsQID
108 int8_t type;
109 int32_t version;
110 int64_t path;
111 } V9fsQID;
113 typedef struct V9fsStat
115 int16_t size;
116 int16_t type;
117 int32_t dev;
118 V9fsQID qid;
119 int32_t mode;
120 int32_t atime;
121 int32_t mtime;
122 int64_t length;
123 V9fsString name;
124 V9fsString uid;
125 V9fsString gid;
126 V9fsString muid;
127 /* 9p2000.u */
128 V9fsString extension;
129 int32_t n_uid;
130 int32_t n_gid;
131 int32_t n_muid;
132 } V9fsStat;
134 struct V9fsFidState
136 int32_t fid;
137 V9fsString path;
138 int fd;
139 DIR *dir;
140 uid_t uid;
141 V9fsFidState *next;
144 typedef struct V9fsState
146 VirtIODevice vdev;
147 VirtQueue *vq;
148 V9fsPDU pdus[MAX_REQ];
149 QLIST_HEAD(, V9fsPDU) free_list;
150 V9fsFidState *fid_list;
151 FileOperations *ops;
152 FsContext ctx;
153 uint16_t tag_len;
154 uint8_t *tag;
155 size_t config_size;
156 enum p9_proto_version proto_version;
157 } V9fsState;
159 typedef struct V9fsCreateState {
160 V9fsPDU *pdu;
161 size_t offset;
162 V9fsFidState *fidp;
163 V9fsQID qid;
164 int32_t perm;
165 int8_t mode;
166 struct stat stbuf;
167 V9fsString name;
168 V9fsString extension;
169 V9fsString fullname;
170 } V9fsCreateState;
172 typedef struct V9fsStatState {
173 V9fsPDU *pdu;
174 size_t offset;
175 V9fsStat v9stat;
176 V9fsFidState *fidp;
177 struct stat stbuf;
178 } V9fsStatState;
180 typedef struct V9fsWalkState {
181 V9fsPDU *pdu;
182 size_t offset;
183 int16_t nwnames;
184 int name_idx;
185 V9fsQID *qids;
186 V9fsFidState *fidp;
187 V9fsFidState *newfidp;
188 V9fsString path;
189 V9fsString *wnames;
190 struct stat stbuf;
191 } V9fsWalkState;
193 typedef struct V9fsOpenState {
194 V9fsPDU *pdu;
195 size_t offset;
196 int8_t mode;
197 V9fsFidState *fidp;
198 V9fsQID qid;
199 struct stat stbuf;
200 } V9fsOpenState;
202 typedef struct V9fsReadState {
203 V9fsPDU *pdu;
204 size_t offset;
205 int32_t count;
206 int32_t total;
207 int64_t off;
208 V9fsFidState *fidp;
209 struct iovec iov[128]; /* FIXME: bad, bad, bad */
210 struct iovec *sg;
211 off_t dir_pos;
212 struct dirent *dent;
213 struct stat stbuf;
214 V9fsString name;
215 V9fsStat v9stat;
216 int32_t len;
217 int32_t cnt;
218 int32_t max_count;
219 } V9fsReadState;
221 typedef struct V9fsWriteState {
222 V9fsPDU *pdu;
223 size_t offset;
224 int32_t len;
225 int32_t count;
226 int32_t total;
227 int64_t off;
228 V9fsFidState *fidp;
229 struct iovec iov[128]; /* FIXME: bad, bad, bad */
230 struct iovec *sg;
231 int cnt;
232 } V9fsWriteState;
234 typedef struct V9fsRemoveState {
235 V9fsPDU *pdu;
236 size_t offset;
237 V9fsFidState *fidp;
238 } V9fsRemoveState;
240 typedef struct V9fsWstatState
242 V9fsPDU *pdu;
243 size_t offset;
244 int16_t unused;
245 V9fsStat v9stat;
246 V9fsFidState *fidp;
247 struct stat stbuf;
248 V9fsString nname;
249 } V9fsWstatState;
251 struct virtio_9p_config
253 /* number of characters in tag */
254 uint16_t tag_len;
255 /* Variable size tag name */
256 uint8_t tag[0];
257 } __attribute__((packed));
259 typedef struct V9fsStatfs
261 uint32_t f_type;
262 uint32_t f_bsize;
263 uint64_t f_blocks;
264 uint64_t f_bfree;
265 uint64_t f_bavail;
266 uint64_t f_files;
267 uint64_t f_ffree;
268 uint64_t fsid_val;
269 uint32_t f_namelen;
270 } V9fsStatfs;
272 typedef struct V9fsStatfsState {
273 V9fsPDU *pdu;
274 size_t offset;
275 int32_t fid;
276 V9fsStatfs v9statfs;
277 V9fsFidState *fidp;
278 struct statfs stbuf;
279 } V9fsStatfsState;
281 extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
282 size_t offset, size_t size, int pack);
284 static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
285 size_t offset, size_t size)
287 return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
290 #endif