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