puffs_msgif.h revision 1.5 1 /* $NetBSD: puffs_msgif.h,v 1.5 2006/11/07 22:10:18 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 enum {
57 PUFFS_VFS_MOUNT, PUFFS_VFS_START, PUFFS_VFS_UNMOUNT,
58 PUFFS_VFS_ROOT, PUFFS_VFS_STATVFS, PUFFS_VFS_SYNC,
59 PUFFS_VFS_VGET, PUFFS_VFS_FHTOVP, PUFFS_VFS_VPTOFH,
60 PUFFS_VFS_INIT, PUFFS_VFS_DONE, PUFFS_VFS_SNAPSHOT,
61 PUFFS_VFS_EXTATTCTL
62 };
63 #define PUFFS_VFS_MAX PUFFS_VFS_EXTATTCTL
64
65 enum {
66 PUFFS_VN_LOOKUP, PUFFS_VN_CREATE, PUFFS_VN_MKNOD,
67 PUFFS_VN_OPEN, PUFFS_VN_CLOSE, PUFFS_VN_ACCESS,
68 PUFFS_VN_GETATTR, PUFFS_VN_SETATTR, PUFFS_VN_READ,
69 PUFFS_VN_WRITE, PUFFS_VN_IOCTL, PUFFS_VN_FCNTL,
70 PUFFS_VN_POLL, PUFFS_VN_KQFILTER, PUFFS_VN_REVOKE,
71 PUFFS_VN_MMAP, PUFFS_VN_FSYNC, PUFFS_VN_SEEK,
72 PUFFS_VN_REMOVE, PUFFS_VN_LINK, PUFFS_VN_RENAME,
73 PUFFS_VN_MKDIR, PUFFS_VN_RMDIR, PUFFS_VN_SYMLINK,
74 PUFFS_VN_READDIR, PUFFS_VN_READLINK, PUFFS_VN_ABORTOP,
75 PUFFS_VN_INACTIVE, PUFFS_VN_RECLAIM, PUFFS_VN_LOCK,
76 PUFFS_VN_UNLOCK, PUFFS_VN_BMAP, PUFFS_VN_STRATEGY,
77 PUFFS_VN_PRINT, PUFFS_VN_ISLOCKED, PUFFS_VN_PATHCONF,
78 PUFFS_VN_ADVLOCK, PUFFS_VN_LEASE, PUFFS_VN_WHITEOUT,
79 PUFFS_VN_GETPAGES, PUFFS_VN_PUTPAGES, PUFFS_VN_GETEXTATTR,
80 PUFFS_VN_LISTEXTATTR, PUFFS_VN_OPENEXTATTR, PUFFS_VN_DELETEEXTATTR,
81 PUFFS_VN_SETEXTATTR
82 };
83 #define PUFFS_VN_MAX PUFFS_VN_SETEXTATTR
84
85 #define PUFFSVERSION 0 /* meaning: *NO* versioning yet */
86 #define PUFFSNAMESIZE 32
87 struct puffs_args {
88 int pa_vers;
89 int pa_fd;
90 unsigned int pa_flags;
91 size_t pa_maxreqlen;
92 char pa_name[PUFFSNAMESIZE]; /* name for puffs type */
93 };
94 #define PUFFS_FLAG_ALLOWCTL 0x01 /* ioctl/fcntl commands allowed */
95 #define PUFFS_FLAG_MASK 0x01
96
97 /*
98 * This is the device minor number for the cloning device. Make it
99 * a high number "just in case", even though we don't want to open
100 * any specific devices currently.
101 */
102 #define PUFFS_CLONER 0x7ffff
103
104 /*
105 * This is the structure that travels on the user-kernel interface.
106 * It is used to deliver ops to the user server and bring the results back
107 */
108 struct puffs_req {
109 uint64_t preq_id; /* OUT/IN */
110 uint8_t preq_opclass; /* OUT */
111 uint8_t preq_optype; /* OUT */
112
113 int preq_rv; /* IN */
114
115 /*
116 * preq_cookie is the node cookie associated with the request.
117 * It always maps 1:1 to a vnode and should map to a userspace
118 * struct puffs_node. The cookie usually describes the first
119 * vnode argument of the VOP_POP() in question.
120 */
121 void *preq_cookie; /* OUT */
122
123 /* these come in from userspace twice (getop and putop) */
124 void *preq_aux; /* IN/IN */
125 size_t preq_auxlen; /* IN/IN */
126 };
127
128 #define PUFFS_REQFLAG_ADJBUF 0x01
129
130 /*
131 * Some operations have unknown size requirements. So as the first
132 * stab at handling it, do an extra bounce between the kernel and
133 * userspace.
134 */
135 struct puffs_sizeop {
136 uint64_t pso_reqid;
137
138 uint8_t *pso_userbuf;
139 size_t pso_bufsize;
140 };
141
142 /*
143 * Credentials for an operation. Can be either struct uucred for
144 * ops called from a credential context or NOCRED/FSCRED for ops
145 * called from within the kernel. It is up to the implementation
146 * if it makes a difference between these two and the super-user.
147 */
148 struct puffs_cred {
149 struct uucred pcr_uuc;
150 uint8_t pcr_type;
151 uint8_t pcr_internal;
152 };
153 #define PUFFCRED_TYPE_UUC 1
154 #define PUFFCRED_TYPE_INTERNAL 2
155
156 #define PUFFCRED_CRED_NOCRED 1
157 #define PUFFCRED_CRED_FSCRED 2
158
159
160 #define PUFFSGETOP _IOWR('p', 1, struct puffs_req)
161 #define PUFFSPUTOP _IOWR('p', 2, struct puffs_req)
162 #define PUFFSSIZEOP _IOWR('p', 3, struct puffs_sizeop)
163 #define PUFFSMOUNTOP _IOWR('p', 4, struct puffs_vfsreq_start)
164
165 /*
166 * 4x MAXPHYS is the max size the system will attempt to copy,
167 * else treated as garbage
168 */
169 #define PUFFS_REQ_MAXSIZE 4*MAXPHYS
170 #define PUFFS_REQSTRUCT_MAX 4096 /* XXX: approxkludge */
171
172 #define PUFFS_TOMOVE(a,b) (MIN((a), b->pmp_req_maxsize - PUFFS_REQSTRUCT_MAX))
173
174 /* puffs struct componentname, for userspace */
175 struct puffs_cn {
176 /* args */
177 u_long pcn_nameiop; /* namei operation */
178 u_long pcn_flags; /* flags */
179 pid_t pcn_pid; /* caller pid */
180 struct puffs_cred pcn_cred; /* caller creds */
181
182 /* shared */
183 char pcn_name[MAXPATHLEN]; /* path to lookup */
184 long pcn_namelen; /* length of path */
185 };
186
187 /*
188 * XXX: figure out what to do with these, copied from namei.h for now
189 */
190 #define PUFFSLOOKUP_LOOKUP 0 /* perform name lookup only */
191 #define PUFFSLOOKUP_CREATE 1 /* setup for file creation */
192 #define PUFFSLOOKUP_DELETE 2 /* setup for file deletion */
193 #define PUFFSLOOKUP_RENAME 3 /* setup for file renaming */
194 #define PUFFSLOOKUP_OPMASK 3 /* mask for operation */
195
196 #define PUFFSLOOKUP_FOLLOW 0x04 /* follow symlinks */
197 #define PUFFSLOOKUP_NOFOLLOW 0x08 /* don't follow symlinks */
198 #define PUFFSLOOKUP_OPTIONS 0x0c
199
200 struct puffs_vfsreq_start {
201 fsid_t psr_fsidx; /* fsid value */
202 void *psr_cookie; /* root node cookie */
203 };
204
205 /*
206 * aux structures for vfs operations.
207 */
208 struct puffs_vfsreq_unmount {
209 int pvfsr_flags;
210 pid_t pvfsr_pid;
211 };
212
213 struct puffs_vfsreq_statvfs {
214 struct statvfs pvfsr_sb;
215 pid_t pvfsr_pid;
216 };
217
218 struct puffs_vfsreq_sync {
219 struct puffs_cred pvfsr_cred;
220 pid_t pvfsr_pid;
221 int pvfsr_waitfor;
222 };
223
224 /*
225 * aux structures for vnode operations.
226 */
227
228 struct puffs_vnreq_lookup {
229 struct puffs_cn pvnr_cn; /* OUT */
230 void *pvnr_newnode; /* IN */
231 enum vtype pvnr_vtype; /* IN */
232 voff_t pvnr_size; /* IN */
233 dev_t pvnr_rdev; /* IN */
234 };
235
236 struct puffs_vnreq_create {
237 struct puffs_cn pvnr_cn; /* OUT */
238 struct vattr pvnr_va; /* OUT */
239 void *pvnr_newnode; /* IN */
240 };
241
242 struct puffs_vnreq_mknod {
243 struct puffs_cn pvnr_cn; /* OUT */
244 struct vattr pvnr_va; /* OUT */
245 void *pvnr_newnode; /* IN */
246 };
247
248 struct puffs_vnreq_open {
249 struct puffs_cred pvnr_cred; /* OUT */
250 pid_t pvnr_pid; /* OUT */
251 int pvnr_mode; /* OUT */
252 };
253
254 struct puffs_vnreq_close {
255 struct puffs_cred pvnr_cred; /* OUT */
256 pid_t pvnr_pid; /* OUT */
257 int pvnr_fflag; /* OUT */
258 };
259
260 struct puffs_vnreq_access {
261 struct puffs_cred pvnr_cred; /* OUT */
262 pid_t pvnr_pid; /* OUT */
263 int pvnr_mode; /* OUT */
264 };
265
266 #define puffs_vnreq_setattr puffs_vnreq_setgetattr
267 #define puffs_vnreq_getattr puffs_vnreq_setgetattr
268 struct puffs_vnreq_setgetattr {
269 struct puffs_cred pvnr_cred; /* OUT */
270 struct vattr pvnr_va; /* IN/OUT (op depend) */
271 pid_t pvnr_pid; /* OUT */
272 };
273
274 #define puffs_vnreq_read puffs_vnreq_readwrite
275 #define puffs_vnreq_write puffs_vnreq_readwrite
276 struct puffs_vnreq_readwrite {
277 struct puffs_cred pvnr_cred; /* OUT */
278 off_t pvnr_offset; /* OUT */
279 size_t pvnr_resid; /* IN/OUT */
280 int pvnr_ioflag; /* OUT */
281
282 uint8_t pvnr_data[0]; /* IN/OUT (wr/rd) */
283 };
284
285 #define puffs_vnreq_ioctl puffs_vnreq_fcnioctl
286 #define puffs_vnreq_fcntl puffs_vnreq_fcnioctl
287 struct puffs_vnreq_fcnioctl {
288 struct puffs_cred pvnr_cred;
289 u_long pvnr_command;
290 pid_t pvnr_pid;
291 int pvnr_fflag;
292
293 void *pvnr_data;
294 size_t pvnr_datalen;
295 int pvnr_copyback;
296 };
297
298 struct puffs_vnreq_poll {
299 int pvnr_events; /* OUT */
300 pid_t pvnr_pid; /* OUT */
301 };
302
303 struct puffs_vnreq_revoke {
304 int pvnr_flags; /* OUT */
305 };
306
307 struct puffs_vnreq_fsync {
308 struct puffs_cred pvnr_cred; /* OUT */
309 off_t pvnr_offlo; /* OUT */
310 off_t pvnr_offhi; /* OUT */
311 pid_t pvnr_pid; /* OUT */
312 int pvnr_flags; /* OUT */
313 };
314
315 struct puffs_vnreq_seek {
316 struct puffs_cred pvnr_cred; /* OUT */
317 off_t pvnr_oldoff; /* OUT */
318 off_t pvnr_newoff; /* OUT */
319 };
320
321 struct puffs_vnreq_remove {
322 struct puffs_cn pvnr_cn; /* OUT */
323 void *pvnr_cookie_targ; /* OUT */
324 };
325
326 struct puffs_vnreq_mkdir {
327 struct puffs_cn pvnr_cn; /* OUT */
328 struct vattr pvnr_va; /* OUT */
329 void *pvnr_newnode; /* IN */
330 };
331
332 struct puffs_vnreq_rmdir {
333 struct puffs_cn pvnr_cn; /* OUT */
334 void *pvnr_cookie_targ; /* OUT */
335 };
336
337 struct puffs_vnreq_link {
338 struct puffs_cn pvnr_cn; /* OUT */
339 void *pvnr_cookie_targ; /* OUT */
340 };
341
342 struct puffs_vnreq_rename {
343 struct puffs_cn pvnr_cn_src; /* OUT */
344 struct puffs_cn pvnr_cn_targ; /* OUT */
345 void *pvnr_cookie_src; /* OUT */
346 void *pvnr_cookie_targ; /* OUT */
347 void *pvnr_cookie_targdir; /* OUT */
348 };
349
350 struct puffs_vnreq_symlink {
351 struct puffs_cn pvnr_cn; /* OUT */
352 struct vattr pvnr_va; /* OUT */
353 void *pvnr_newnode; /* IN */
354 char pvnr_link[MAXPATHLEN]; /* OUT */
355 };
356
357 struct puffs_vnreq_readdir {
358 struct puffs_cred pvnr_cred; /* OUT */
359 off_t pvnr_offset; /* IN/OUT */
360 size_t pvnr_resid; /* IN/OUT */
361
362 struct dirent pvnr_dent[0]; /* IN */
363 };
364
365 struct puffs_vnreq_readlink {
366 struct puffs_cred pvnr_cred; /* OUT */
367 size_t pvnr_linklen; /* IN */
368 char pvnr_link[MAXPATHLEN]; /* IN, XXX */
369 };
370
371 struct puffs_vnreq_reclaim {
372 pid_t pvnr_pid; /* OUT */
373 };
374
375 struct puffs_vnreq_inactive {
376 pid_t pvnr_pid; /* OUT */
377 int pvnr_backendrefs; /* IN */
378 };
379
380 /* XXX: get rid of alltogether */
381 struct puffs_vnreq_print {
382 /* empty */
383 };
384
385 struct puffs_vnreq_pathconf {
386 int pvnr_name; /* OUT */
387 int pvnr_retval; /* IN */
388 };
389
390 struct puffs_vnreq_advlock {
391 struct flock pvnr_fl; /* OUT */
392 void *pvnr_id; /* OUT */
393 int pvnr_op; /* OUT */
394 int pvnr_flags; /* OUT */
395 };
396
397 /* notyet */
398 #if 0
399 struct puffs_vnreq_kqfilter { };
400 struct puffs_vnreq_islocked { };
401 struct puffs_vnreq_lease { };
402 #endif
403 struct puffs_vnreq_getpages { };
404 struct puffs_vnreq_putpages { };
405 struct puffs_vnreq_mmap { };
406 struct puffs_vnreq_getextattr { };
407 struct puffs_vnreq_setextattr { };
408 struct puffs_vnreq_listextattr { };
409
410 #ifdef _KERNEL
411 #define PUFFS_VFSREQ(a) \
412 struct puffs_vfsreq_##a a##_arg; \
413 memset(&a##_arg, 0, sizeof(struct puffs_vfsreq_##a))
414
415 #define PUFFS_VNREQ(a) \
416 struct puffs_vnreq_##a a##_arg; \
417 memset(&a##_arg, 0, sizeof(struct puffs_vnreq_##a))
418 #endif
419
420 #endif /* _PUFFS_MSGIF_H_ */
421