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