rename - change name of file or directory
[qemu.git] / hw / virtio-9p.h
blob4d179b7feee62d8e48a5513aebc45bf917e72892
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_TLCREATE = 14,
19 P9_RLCREATE,
20 P9_TSYMLINK = 16,
21 P9_RSYMLINK,
22 P9_TMKNOD = 18,
23 P9_RMKNOD,
24 P9_TRENAME = 20,
25 P9_RRENAME,
26 P9_TGETATTR = 24,
27 P9_RGETATTR,
28 P9_TSETATTR = 26,
29 P9_RSETATTR,
30 P9_TREADDIR = 40,
31 P9_RREADDIR,
32 P9_TLINK = 70,
33 P9_RLINK,
34 P9_TMKDIR = 72,
35 P9_RMKDIR,
36 P9_TVERSION = 100,
37 P9_RVERSION,
38 P9_TAUTH = 102,
39 P9_RAUTH,
40 P9_TATTACH = 104,
41 P9_RATTACH,
42 P9_TERROR = 106,
43 P9_RERROR,
44 P9_TFLUSH = 108,
45 P9_RFLUSH,
46 P9_TWALK = 110,
47 P9_RWALK,
48 P9_TOPEN = 112,
49 P9_ROPEN,
50 P9_TCREATE = 114,
51 P9_RCREATE,
52 P9_TREAD = 116,
53 P9_RREAD,
54 P9_TWRITE = 118,
55 P9_RWRITE,
56 P9_TCLUNK = 120,
57 P9_RCLUNK,
58 P9_TREMOVE = 122,
59 P9_RREMOVE,
60 P9_TSTAT = 124,
61 P9_RSTAT,
62 P9_TWSTAT = 126,
63 P9_RWSTAT,
67 /* qid.types */
68 enum {
69 P9_QTDIR = 0x80,
70 P9_QTAPPEND = 0x40,
71 P9_QTEXCL = 0x20,
72 P9_QTMOUNT = 0x10,
73 P9_QTAUTH = 0x08,
74 P9_QTTMP = 0x04,
75 P9_QTSYMLINK = 0x02,
76 P9_QTLINK = 0x01,
77 P9_QTFILE = 0x00,
80 enum p9_proto_version {
81 V9FS_PROTO_2000U = 0x01,
82 V9FS_PROTO_2000L = 0x02,
85 #define P9_NOTAG (u16)(~0)
86 #define P9_NOFID (u32)(~0)
87 #define P9_MAXWELEM 16
90 * ample room for Twrite/Rread header
91 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
93 #define P9_IOHDRSZ 24
95 typedef struct V9fsPDU V9fsPDU;
97 struct V9fsPDU
99 uint32_t size;
100 uint16_t tag;
101 uint8_t id;
102 VirtQueueElement elem;
103 QLIST_ENTRY(V9fsPDU) next;
107 /* FIXME
108 * 1) change user needs to set groups and stuff
111 /* from Linux's linux/virtio_9p.h */
113 /* The ID for virtio console */
114 #define VIRTIO_ID_9P 9
115 #define MAX_REQ 128
116 #define MAX_TAG_LEN 32
118 #define BUG_ON(cond) assert(!(cond))
120 typedef struct V9fsFidState V9fsFidState;
122 typedef struct V9fsString
124 int16_t size;
125 char *data;
126 } V9fsString;
128 typedef struct V9fsQID
130 int8_t type;
131 int32_t version;
132 int64_t path;
133 } V9fsQID;
135 typedef struct V9fsStat
137 int16_t size;
138 int16_t type;
139 int32_t dev;
140 V9fsQID qid;
141 int32_t mode;
142 int32_t atime;
143 int32_t mtime;
144 int64_t length;
145 V9fsString name;
146 V9fsString uid;
147 V9fsString gid;
148 V9fsString muid;
149 /* 9p2000.u */
150 V9fsString extension;
151 int32_t n_uid;
152 int32_t n_gid;
153 int32_t n_muid;
154 } V9fsStat;
156 struct V9fsFidState
158 int32_t fid;
159 V9fsString path;
160 int fd;
161 DIR *dir;
162 uid_t uid;
163 V9fsFidState *next;
166 typedef struct V9fsState
168 VirtIODevice vdev;
169 VirtQueue *vq;
170 V9fsPDU pdus[MAX_REQ];
171 QLIST_HEAD(, V9fsPDU) free_list;
172 V9fsFidState *fid_list;
173 FileOperations *ops;
174 FsContext ctx;
175 uint16_t tag_len;
176 uint8_t *tag;
177 size_t config_size;
178 enum p9_proto_version proto_version;
179 int32_t msize;
180 } V9fsState;
182 typedef struct V9fsCreateState {
183 V9fsPDU *pdu;
184 size_t offset;
185 V9fsFidState *fidp;
186 V9fsQID qid;
187 int32_t perm;
188 int8_t mode;
189 struct stat stbuf;
190 V9fsString name;
191 V9fsString extension;
192 V9fsString fullname;
193 int iounit;
194 } V9fsCreateState;
196 typedef struct V9fsLcreateState {
197 V9fsPDU *pdu;
198 size_t offset;
199 V9fsFidState *fidp;
200 V9fsQID qid;
201 int32_t iounit;
202 struct stat stbuf;
203 V9fsString name;
204 V9fsString fullname;
205 } V9fsLcreateState;
207 typedef struct V9fsStatState {
208 V9fsPDU *pdu;
209 size_t offset;
210 V9fsStat v9stat;
211 V9fsFidState *fidp;
212 struct stat stbuf;
213 } V9fsStatState;
215 typedef struct V9fsStatDotl {
216 uint64_t st_result_mask;
217 V9fsQID qid;
218 uint32_t st_mode;
219 uint32_t st_uid;
220 uint32_t st_gid;
221 uint64_t st_nlink;
222 uint64_t st_rdev;
223 uint64_t st_size;
224 uint64_t st_blksize;
225 uint64_t st_blocks;
226 uint64_t st_atime_sec;
227 uint64_t st_atime_nsec;
228 uint64_t st_mtime_sec;
229 uint64_t st_mtime_nsec;
230 uint64_t st_ctime_sec;
231 uint64_t st_ctime_nsec;
232 uint64_t st_btime_sec;
233 uint64_t st_btime_nsec;
234 uint64_t st_gen;
235 uint64_t st_data_version;
236 } V9fsStatDotl;
238 typedef struct V9fsStatStateDotl {
239 V9fsPDU *pdu;
240 size_t offset;
241 V9fsStatDotl v9stat_dotl;
242 struct stat stbuf;
243 } V9fsStatStateDotl;
246 typedef struct V9fsWalkState {
247 V9fsPDU *pdu;
248 size_t offset;
249 int16_t nwnames;
250 int name_idx;
251 V9fsQID *qids;
252 V9fsFidState *fidp;
253 V9fsFidState *newfidp;
254 V9fsString path;
255 V9fsString *wnames;
256 struct stat stbuf;
257 } V9fsWalkState;
259 typedef struct V9fsOpenState {
260 V9fsPDU *pdu;
261 size_t offset;
262 int8_t mode;
263 V9fsFidState *fidp;
264 V9fsQID qid;
265 struct stat stbuf;
266 int iounit;
267 } V9fsOpenState;
269 typedef struct V9fsReadState {
270 V9fsPDU *pdu;
271 size_t offset;
272 int32_t count;
273 int32_t total;
274 int64_t off;
275 V9fsFidState *fidp;
276 struct iovec iov[128]; /* FIXME: bad, bad, bad */
277 struct iovec *sg;
278 off_t dir_pos;
279 struct dirent *dent;
280 struct stat stbuf;
281 V9fsString name;
282 V9fsStat v9stat;
283 int32_t len;
284 int32_t cnt;
285 int32_t max_count;
286 } V9fsReadState;
288 typedef struct V9fsWriteState {
289 V9fsPDU *pdu;
290 size_t offset;
291 int32_t len;
292 int32_t count;
293 int32_t total;
294 int64_t off;
295 V9fsFidState *fidp;
296 struct iovec iov[128]; /* FIXME: bad, bad, bad */
297 struct iovec *sg;
298 int cnt;
299 } V9fsWriteState;
301 typedef struct V9fsRemoveState {
302 V9fsPDU *pdu;
303 size_t offset;
304 V9fsFidState *fidp;
305 } V9fsRemoveState;
307 typedef struct V9fsWstatState
309 V9fsPDU *pdu;
310 size_t offset;
311 int16_t unused;
312 V9fsStat v9stat;
313 V9fsFidState *fidp;
314 struct stat stbuf;
315 } V9fsWstatState;
317 typedef struct V9fsSymlinkState
319 V9fsPDU *pdu;
320 size_t offset;
321 V9fsString name;
322 V9fsString symname;
323 V9fsString fullname;
324 V9fsFidState *dfidp;
325 V9fsQID qid;
326 struct stat stbuf;
327 } V9fsSymlinkState;
329 typedef struct V9fsIattr
331 int32_t valid;
332 int32_t mode;
333 int32_t uid;
334 int32_t gid;
335 int64_t size;
336 int64_t atime_sec;
337 int64_t atime_nsec;
338 int64_t mtime_sec;
339 int64_t mtime_nsec;
340 } V9fsIattr;
342 typedef struct V9fsSetattrState
344 V9fsPDU *pdu;
345 size_t offset;
346 V9fsIattr v9iattr;
347 V9fsFidState *fidp;
348 } V9fsSetattrState;
350 struct virtio_9p_config
352 /* number of characters in tag */
353 uint16_t tag_len;
354 /* Variable size tag name */
355 uint8_t tag[0];
356 } __attribute__((packed));
358 typedef struct V9fsStatfs
360 uint32_t f_type;
361 uint32_t f_bsize;
362 uint64_t f_blocks;
363 uint64_t f_bfree;
364 uint64_t f_bavail;
365 uint64_t f_files;
366 uint64_t f_ffree;
367 uint64_t fsid_val;
368 uint32_t f_namelen;
369 } V9fsStatfs;
371 typedef struct V9fsStatfsState {
372 V9fsPDU *pdu;
373 size_t offset;
374 int32_t fid;
375 V9fsStatfs v9statfs;
376 V9fsFidState *fidp;
377 struct statfs stbuf;
378 } V9fsStatfsState;
380 typedef struct V9fsMkState {
381 V9fsPDU *pdu;
382 size_t offset;
383 V9fsQID qid;
384 struct stat stbuf;
385 V9fsString name;
386 V9fsString fullname;
387 } V9fsMkState;
389 typedef struct V9fsRenameState {
390 V9fsPDU *pdu;
391 V9fsFidState *fidp;
392 size_t offset;
393 int32_t newdirfid;
394 V9fsString name;
395 } V9fsRenameState;
397 extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
398 size_t offset, size_t size, int pack);
400 static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
401 size_t offset, size_t size)
403 return pdu_packunpack(dst, sg, sg_count, offset, size, 0);
406 #endif