puffs_msgif.h revision 1.13 1 /* $NetBSD: puffs_msgif.h,v 1.13 2006/12/29 15:38:37 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2005, 2006 Antti Kantee. All Rights Reserved.
5 *
6 * Development of this software was supported by the
7 * Google Summer of Code program and the Ulla Tuominen Foundation.
8 * The Google SoC project was mentored by Bill Studenmund.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the company nor the name of the author may be used to
19 * endorse or promote products derived from this software without specific
20 * prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #ifndef _PUFFS_MSGIF_H_
36 #define _PUFFS_MSGIF_H_
37
38 #include <sys/param.h>
39 #include <sys/time.h>
40 #include <sys/ioccom.h>
41 #include <sys/uio.h>
42 #include <sys/vnode.h>
43 #include <sys/ucred.h>
44 #include <sys/statvfs.h>
45 #include <sys/dirent.h>
46 #include <sys/fcntl.h>
47
48 #define PUFFSOP_VFS 1
49 #define PUFFSOP_VN 2
50 #define PUFFSOPFLAG_FAF 0x10 /* fire-and-forget */
51
52 #define PUFFSOP_OPCMASK 0x03
53 #define PUFFSOP_OPCLASS(a) ((a) & PUFFSOP_OPCMASK)
54 #define PUFFSOP_WANTREPLY(a) (((a) & PUFFSOPFLAG_FAF) == 0)
55
56 /* XXX: we don't need everything */
57 enum {
58 PUFFS_VFS_MOUNT, PUFFS_VFS_START, PUFFS_VFS_UNMOUNT,
59 PUFFS_VFS_ROOT, PUFFS_VFS_STATVFS, PUFFS_VFS_SYNC,
60 PUFFS_VFS_VGET, PUFFS_VFS_FHTOVP, PUFFS_VFS_VPTOFH,
61 PUFFS_VFS_INIT, PUFFS_VFS_DONE, PUFFS_VFS_SNAPSHOT,
62 PUFFS_VFS_EXTATTCTL
63 };
64 #define PUFFS_VFS_MAX PUFFS_VFS_EXTATTCTL
65
66 /* moreXXX: we don't need everything here either */
67 enum {
68 PUFFS_VN_LOOKUP, PUFFS_VN_CREATE, PUFFS_VN_MKNOD,
69 PUFFS_VN_OPEN, PUFFS_VN_CLOSE, PUFFS_VN_ACCESS,
70 PUFFS_VN_GETATTR, PUFFS_VN_SETATTR, PUFFS_VN_READ,
71 PUFFS_VN_WRITE, PUFFS_VN_IOCTL, PUFFS_VN_FCNTL,
72 PUFFS_VN_POLL, PUFFS_VN_KQFILTER, PUFFS_VN_REVOKE,
73 PUFFS_VN_MMAP, PUFFS_VN_FSYNC, PUFFS_VN_SEEK,
74 PUFFS_VN_REMOVE, PUFFS_VN_LINK, PUFFS_VN_RENAME,
75 PUFFS_VN_MKDIR, PUFFS_VN_RMDIR, PUFFS_VN_SYMLINK,
76 PUFFS_VN_READDIR, PUFFS_VN_READLINK, PUFFS_VN_ABORTOP,
77 PUFFS_VN_INACTIVE, PUFFS_VN_RECLAIM, PUFFS_VN_LOCK,
78 PUFFS_VN_UNLOCK, PUFFS_VN_BMAP, PUFFS_VN_STRATEGY,
79 PUFFS_VN_PRINT, PUFFS_VN_ISLOCKED, PUFFS_VN_PATHCONF,
80 PUFFS_VN_ADVLOCK, PUFFS_VN_LEASE, PUFFS_VN_WHITEOUT,
81 PUFFS_VN_GETPAGES, PUFFS_VN_PUTPAGES, PUFFS_VN_GETEXTATTR,
82 PUFFS_VN_LISTEXTATTR, PUFFS_VN_OPENEXTATTR, PUFFS_VN_DELETEEXTATTR,
83 PUFFS_VN_SETEXTATTR
84 };
85 #define PUFFS_VN_MAX PUFFS_VN_SETEXTATTR
86
87 #define PUFFSVERSION 0 /* meaning: *NO* versioning yet */
88 #define PUFFSNAMESIZE 32
89 struct puffs_args {
90 int pa_vers;
91 int pa_fd;
92 uint32_t pa_flags;
93 size_t pa_maxreqlen;
94 char pa_name[PUFFSNAMESIZE]; /* name for puffs type */
95 uint8_t pa_vnopmask[PUFFS_VN_MAX];
96 };
97 #define PUFFS_KFLAG_ALLOWCTL 0x01 /* ioctl/fcntl commands allowed */
98 #define PUFFS_KFLAG_NOCACHE 0x02 /* flush page cache immediately */
99 #define PUFFS_KFLAG_ALLOPS 0x04 /* ignore pa_vnopmask, send all */
100 #define PUFFS_KFLAG_MASK 0x07
101
102 /*
103 * This is the device minor number for the cloning device. Make it
104 * a high number "just in case", even though we don't want to open
105 * any specific devices currently.
106 */
107 #define PUFFS_CLONER 0x7ffff
108
109 struct puffs_reqh_get {
110 void *phg_buf; /* user buffer */
111 size_t phg_buflen; /* user buffer length */
112
113 int phg_nops; /* max ops user wants / number delivered */
114 int phg_more; /* advisory: more ops available? */
115 };
116
117 struct puffs_reqh_put {
118 int php_nops; /* ops available / ops handled */
119
120 /* these describe the first request */
121 uint64_t php_id; /* request id */
122 void *php_buf; /* user buffer address */
123 size_t php_buflen; /* user buffer length, hdr NOT incl. */
124 };
125
126 /*
127 * The requests work as follows:
128 *
129 * + GETOP: When fetching operations from the kernel, the user server
130 * supplies a flat buffer into which operations are written.
131 * The number of operations written to the buffer is
132 * MIN(prhg_nops, requests waiting, space in buffer).
133 *
134 * Operations follow each other and each one is described
135 * by the puffs_req structure, which is immediately followed
136 * by the aligned request data buffer in preq_buf. The next
137 * puffs_req can be found at preq + preq_buflen.
138 *
139 * Visually, the server should expect:
140 *
141 * |<-- preq_buflen -->|
142 * ---------------------------------------------------------------
143 * |hdr| buffer |align|hdr| buffer |hdr| .... |buffer| |
144 * ---------------------------------------------------------------
145 * ^ start ^ unaligned ^ aligned ^ always aligned
146 *
147 * The server is allowed to modify the contents of the buffers.
148 * Since the headers are the same size for both get and put, it
149 * is possible to handle all operations simply by doing in-place
150 * modification. Where more input is expected that what was put
151 * out, the kernel leaves a hole in the buffer. This hole size
152 * is derived from the operational semantics known by the vnode
153 * layer. The hole size is included in preq_buflen. The
154 * amount of relevant information in the buffer is call-specific
155 * and can be deduced by the server from the call type.
156 *
157 * + PUTOP: When returning the results of an operation to the kernel, the
158 * user server is allowed to input results in a scatter-gather
159 * fashion. Each request is made up of a header and the buffer.
160 * The header describes the *NEXT* request for copyin, *NOT* the
161 * current one. The first request is described in puffs_reqh_put
162 * and the last one is left uninterpreted. This is to halve the
163 * amount of copyin's required.
164 *
165 * Fans of my ascii art, rejoice:
166 * /-------------------->| preq_buflen |
167 * ---^----------------------------------------------------------
168 * |hdr|buffer| empty spaces |hdr| buffer | |
169 * --v-----------------------^-v---------------------------------
170 * \------- preq_buf -----/ \------- preq_buf ....
171 *
172 * This scheme also allows for better in-place modification of the
173 * request buffer when handling requests. The vision is that
174 * operations which can be immediately satisfied will be edited
175 * in-place while ones which can't will be left blank. Also,
176 * requests from async operations which have been satisfied
177 * meanwhile can be included.
178 *
179 * The total number of operations is given by the ioctl control
180 * structure puffs_reqh. The values in the header in the final
181 * are not used.
182 */
183 struct puffs_req {
184 uint64_t preq_id; /* get: cur, put: next */
185
186 union u {
187 struct {
188 uint8_t opclass; /* cur */
189 uint8_t optype; /* cur */
190
191 /*
192 * preq_cookie is the node cookie associated with
193 * the request. It always maps 1:1 to a vnode
194 * and could map to a userspace struct puffs_node.
195 * The cookie usually describes the first
196 * vnode argument of the VOP_POP() in question.
197 */
198
199 void *cookie; /* cur */
200 } out;
201 struct {
202 int rv; /* cur */
203 void *buf; /* next */
204 } in;
205 } u;
206
207 size_t preq_buflen; /* get: cur, put: next */
208 /*
209 * the following helper pads the struct size to md alignment
210 * multiple (should size_t not cut it). it makes sure that
211 * whatever comes after this struct is aligned
212 */
213 uint8_t preq_buf[0] __aligned(ALIGNBYTES+1);
214 };
215 #define preq_opclass u.out.opclass
216 #define preq_optype u.out.optype
217 #define preq_cookie u.out.cookie
218 #define preq_rv u.in.rv
219 #define preq_nextbuf u.in.buf
220
221 /*
222 * Some operations have unknown size requirements. So as the first
223 * stab at handling it, do an extra bounce between the kernel and
224 * userspace.
225 */
226 struct puffs_sizeop {
227 uint64_t pso_reqid;
228
229 uint8_t *pso_userbuf;
230 size_t pso_bufsize;
231 };
232
233 /*
234 * Credentials for an operation. Can be either struct uucred for
235 * ops called from a credential context or NOCRED/FSCRED for ops
236 * called from within the kernel. It is up to the implementation
237 * if it makes a difference between these two and the super-user.
238 */
239 struct puffs_cred {
240 struct uucred pcr_uuc;
241 uint8_t pcr_type;
242 uint8_t pcr_internal;
243 };
244 #define PUFFCRED_TYPE_UUC 1
245 #define PUFFCRED_TYPE_INTERNAL 2
246
247 #define PUFFCRED_CRED_NOCRED 1
248 #define PUFFCRED_CRED_FSCRED 2
249
250
251 #define PUFFSSTARTOP _IOWR('p', 1, struct puffs_startreq)
252 #define PUFFSGETOP _IOWR('p', 2, struct puffs_reqh_get)
253 #define PUFFSPUTOP _IOWR('p', 3, struct puffs_reqh_put)
254 #define PUFFSSIZEOP _IOWR('p', 4, struct puffs_sizeop)
255
256 /*
257 * 4x MAXPHYS is the max size the system will attempt to copy,
258 * else treated as garbage
259 */
260 #define PUFFS_REQ_MAXSIZE 4*MAXPHYS
261 #define PUFFS_REQSTRUCT_MAX 4096 /* XXX: approxkludge */
262
263 #define PUFFS_TOMOVE(a,b) (MIN((a), b->pmp_req_maxsize - PUFFS_REQSTRUCT_MAX))
264
265 /* puffs struct componentname built by kernel */
266 struct puffs_kcn {
267 /* args */
268 u_long pkcn_nameiop; /* namei operation */
269 u_long pkcn_flags; /* flags */
270 pid_t pkcn_pid; /* caller pid */
271 struct puffs_cred pkcn_cred; /* caller creds */
272
273 char pkcn_name[MAXPATHLEN+1]; /* nul-terminated path component */
274 long pkcn_namelen;
275 };
276
277 /*
278 * XXX: figure out what to do with these, copied from namei.h for now
279 */
280 #define PUFFSLOOKUP_LOOKUP 0 /* perform name lookup only */
281 #define PUFFSLOOKUP_CREATE 1 /* setup for file creation */
282 #define PUFFSLOOKUP_DELETE 2 /* setup for file deletion */
283 #define PUFFSLOOKUP_RENAME 3 /* setup for file renaming */
284 #define PUFFSLOOKUP_OPMASK 3 /* mask for operation */
285
286 #define PUFFSLOOKUP_FOLLOW 0x04 /* follow symlinks */
287 #define PUFFSLOOKUP_NOFOLLOW 0x08 /* don't follow symlinks */
288 #define PUFFSLOOKUP_OPTIONS 0x0c
289
290 /*
291 * Next come the individual requests. They are all subclassed from
292 * puffs_req and contain request-specific fields in addition. Note
293 * that there are some requests which have to handle arbitrary-length
294 * buffers.
295 *
296 * The division is the following: puffs_req is to be touched only
297 * by generic routines while the other stuff is supposed to be
298 * modified only by specific routines.
299 */
300
301 struct puffs_startreq {
302 struct puffs_req psr_pr;
303
304 void *psr_cookie; /* IN: root node cookie */
305 struct statvfs psr_sb; /* IN: statvfs buffer */
306 };
307
308 /*
309 * aux structures for vfs operations.
310 */
311 struct puffs_vfsreq_unmount {
312 struct puffs_req pvfsr_pr;
313
314 int pvfsr_flags;
315 pid_t pvfsr_pid;
316 };
317
318 struct puffs_vfsreq_statvfs {
319 struct puffs_req pvfsr_pr;
320
321 struct statvfs pvfsr_sb;
322 pid_t pvfsr_pid;
323 };
324
325 struct puffs_vfsreq_sync {
326 struct puffs_req pvfsr_pr;
327
328 struct puffs_cred pvfsr_cred;
329 pid_t pvfsr_pid;
330 int pvfsr_waitfor;
331 };
332
333 /*
334 * aux structures for vnode operations.
335 */
336
337 struct puffs_vnreq_lookup {
338 struct puffs_req pvn_pr;
339
340 struct puffs_kcn pvnr_cn; /* OUT */
341 void *pvnr_newnode; /* IN */
342 enum vtype pvnr_vtype; /* IN */
343 voff_t pvnr_size; /* IN */
344 dev_t pvnr_rdev; /* IN */
345 };
346
347 struct puffs_vnreq_create {
348 struct puffs_req pvn_pr;
349
350 struct puffs_kcn pvnr_cn; /* OUT */
351 struct vattr pvnr_va; /* OUT */
352 void *pvnr_newnode; /* IN */
353 };
354
355 struct puffs_vnreq_mknod {
356 struct puffs_req pvn_pr;
357
358 struct puffs_kcn pvnr_cn; /* OUT */
359 struct vattr pvnr_va; /* OUT */
360 void *pvnr_newnode; /* IN */
361 };
362
363 struct puffs_vnreq_open {
364 struct puffs_req pvn_pr;
365
366 struct puffs_cred pvnr_cred; /* OUT */
367 pid_t pvnr_pid; /* OUT */
368 int pvnr_mode; /* OUT */
369 };
370
371 struct puffs_vnreq_close {
372 struct puffs_req pvn_pr;
373
374 struct puffs_cred pvnr_cred; /* OUT */
375 pid_t pvnr_pid; /* OUT */
376 int pvnr_fflag; /* OUT */
377 };
378
379 struct puffs_vnreq_access {
380 struct puffs_req pvn_pr;
381
382 struct puffs_cred pvnr_cred; /* OUT */
383 pid_t pvnr_pid; /* OUT */
384 int pvnr_mode; /* OUT */
385 };
386
387 #define puffs_vnreq_setattr puffs_vnreq_setgetattr
388 #define puffs_vnreq_getattr puffs_vnreq_setgetattr
389 struct puffs_vnreq_setgetattr {
390 struct puffs_req pvn_pr;
391
392 struct puffs_cred pvnr_cred; /* OUT */
393 struct vattr pvnr_va; /* IN/OUT (op depend) */
394 pid_t pvnr_pid; /* OUT */
395 };
396
397 #define puffs_vnreq_read puffs_vnreq_readwrite
398 #define puffs_vnreq_write puffs_vnreq_readwrite
399 struct puffs_vnreq_readwrite {
400 struct puffs_req pvn_pr;
401
402 struct puffs_cred pvnr_cred; /* OUT */
403 off_t pvnr_offset; /* OUT */
404 size_t pvnr_resid; /* IN/OUT */
405 int pvnr_ioflag; /* OUT */
406
407 uint8_t pvnr_data[0]; /* IN/OUT (wr/rd) */
408 };
409
410 #define puffs_vnreq_ioctl puffs_vnreq_fcnioctl
411 #define puffs_vnreq_fcntl puffs_vnreq_fcnioctl
412 struct puffs_vnreq_fcnioctl {
413 struct puffs_req pvn_pr;
414
415 struct puffs_cred pvnr_cred;
416 u_long pvnr_command;
417 pid_t pvnr_pid;
418 int pvnr_fflag;
419
420 void *pvnr_data;
421 size_t pvnr_datalen;
422 int pvnr_copyback;
423 };
424
425 struct puffs_vnreq_poll {
426 struct puffs_req pvn_pr;
427
428 int pvnr_events; /* OUT */
429 pid_t pvnr_pid; /* OUT */
430 };
431
432 struct puffs_vnreq_revoke {
433 struct puffs_req pvn_pr;
434
435 int pvnr_flags; /* OUT */
436 };
437
438 struct puffs_vnreq_fsync {
439 struct puffs_req pvn_pr;
440
441 struct puffs_cred pvnr_cred; /* OUT */
442 off_t pvnr_offlo; /* OUT */
443 off_t pvnr_offhi; /* OUT */
444 pid_t pvnr_pid; /* OUT */
445 int pvnr_flags; /* OUT */
446 };
447
448 struct puffs_vnreq_seek {
449 struct puffs_req pvn_pr;
450
451 struct puffs_cred pvnr_cred; /* OUT */
452 off_t pvnr_oldoff; /* OUT */
453 off_t pvnr_newoff; /* OUT */
454 };
455
456 struct puffs_vnreq_remove {
457 struct puffs_req pvn_pr;
458
459 struct puffs_kcn pvnr_cn; /* OUT */
460 void *pvnr_cookie_targ; /* OUT */
461 };
462
463 struct puffs_vnreq_mkdir {
464 struct puffs_req pvn_pr;
465
466 struct puffs_kcn pvnr_cn; /* OUT */
467 struct vattr pvnr_va; /* OUT */
468 void *pvnr_newnode; /* IN */
469 };
470
471 struct puffs_vnreq_rmdir {
472 struct puffs_req pvn_pr;
473
474 struct puffs_kcn pvnr_cn; /* OUT */
475 void *pvnr_cookie_targ; /* OUT */
476 };
477
478 struct puffs_vnreq_link {
479 struct puffs_req pvn_pr;
480
481 struct puffs_kcn pvnr_cn; /* OUT */
482 void *pvnr_cookie_targ; /* OUT */
483 };
484
485 struct puffs_vnreq_rename {
486 struct puffs_req pvn_pr;
487
488 struct puffs_kcn pvnr_cn_src; /* OUT */
489 struct puffs_kcn pvnr_cn_targ; /* OUT */
490 void *pvnr_cookie_src; /* OUT */
491 void *pvnr_cookie_targ; /* OUT */
492 void *pvnr_cookie_targdir; /* OUT */
493 };
494
495 struct puffs_vnreq_symlink {
496 struct puffs_req pvn_pr;
497
498 struct puffs_kcn pvnr_cn; /* OUT */
499 struct vattr pvnr_va; /* OUT */
500 void *pvnr_newnode; /* IN */
501 char pvnr_link[MAXPATHLEN]; /* OUT */
502 };
503
504 struct puffs_vnreq_readdir {
505 struct puffs_req pvn_pr;
506
507 struct puffs_cred pvnr_cred; /* OUT */
508 off_t pvnr_offset; /* IN/OUT */
509 size_t pvnr_resid; /* IN/OUT */
510
511 struct dirent pvnr_dent[0]; /* IN */
512 };
513
514 struct puffs_vnreq_readlink {
515 struct puffs_req pvn_pr;
516
517 struct puffs_cred pvnr_cred; /* OUT */
518 size_t pvnr_linklen; /* IN */
519 char pvnr_link[MAXPATHLEN]; /* IN, XXX */
520 };
521
522 struct puffs_vnreq_reclaim {
523 struct puffs_req pvn_pr;
524
525 pid_t pvnr_pid; /* OUT */
526 };
527
528 struct puffs_vnreq_inactive {
529 struct puffs_req pvn_pr;
530
531 pid_t pvnr_pid; /* OUT */
532 int pvnr_backendrefs; /* IN */
533 };
534
535 struct puffs_vnreq_print {
536 struct puffs_req pvn_pr;
537
538 /* empty */
539 };
540
541 struct puffs_vnreq_pathconf {
542 struct puffs_req pvn_pr;
543
544 int pvnr_name; /* OUT */
545 int pvnr_retval; /* IN */
546 };
547
548 struct puffs_vnreq_advlock {
549 struct puffs_req pvn_pr;
550
551 struct flock pvnr_fl; /* OUT */
552 void *pvnr_id; /* OUT */
553 int pvnr_op; /* OUT */
554 int pvnr_flags; /* OUT */
555 };
556
557 struct puffs_vnreq_mmap {
558 struct puffs_req pvn_pr;
559
560 int pvnr_fflags; /* OUT */
561 struct puffs_cred pvnr_cred; /* OUT */
562 pid_t pvnr_pid; /* OUT */
563 };
564
565 /* notyet */
566 #if 0
567 struct puffs_vnreq_kqfilter { };
568 struct puffs_vnreq_islocked { };
569 struct puffs_vnreq_lease { };
570 #endif
571 struct puffs_vnreq_getpages { };
572 struct puffs_vnreq_putpages { };
573 struct puffs_vnreq_getextattr { };
574 struct puffs_vnreq_setextattr { };
575 struct puffs_vnreq_listextattr { };
576
577 #ifdef _KERNEL
578 #define PUFFS_VFSREQ(a) \
579 struct puffs_vfsreq_##a a##_arg; \
580 memset(&a##_arg, 0, sizeof(struct puffs_vfsreq_##a))
581
582 #define PUFFS_VNREQ(a) \
583 struct puffs_vnreq_##a a##_arg; \
584 memset(&a##_arg, 0, sizeof(struct puffs_vnreq_##a))
585 #endif
586
587 #endif /* _PUFFS_MSGIF_H_ */
588