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