puffs.c revision 1.34 1 /* $NetBSD: puffs.c,v 1.34 2007/04/11 21:04:51 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 #include <sys/cdefs.h>
36 #if !defined(lint)
37 __RCSID("$NetBSD: puffs.c,v 1.34 2007/04/11 21:04:51 pooka Exp $");
38 #endif /* !lint */
39
40 #include <sys/param.h>
41 #include <sys/mount.h>
42
43 #include <assert.h>
44 #include <err.h>
45 #include <errno.h>
46 #include <fcntl.h>
47 #include <mntopts.h>
48 #include <puffs.h>
49 #include <puffsdump.h>
50 #include <stdarg.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include <syslog.h>
55 #include <unistd.h>
56
57 #include "puffs_priv.h"
58
59 /* Most file systems want this for opts, so just give it to them */
60 const struct mntopt puffsmopts[] = {
61 MOPT_STDOPTS,
62 PUFFSMOPT_STD,
63 MOPT_NULL,
64 };
65
66 #define FILLOP(lower, upper) \
67 do { \
68 if (pops->puffs_node_##lower) \
69 opmask[PUFFS_VN_##upper] = 1; \
70 } while (/*CONSTCOND*/0)
71 static void
72 fillvnopmask(struct puffs_ops *pops, uint8_t *opmask)
73 {
74
75 memset(opmask, 0, PUFFS_VN_MAX);
76
77 FILLOP(create, CREATE);
78 FILLOP(mknod, MKNOD);
79 FILLOP(open, OPEN);
80 FILLOP(close, CLOSE);
81 FILLOP(access, ACCESS);
82 FILLOP(getattr, GETATTR);
83 FILLOP(setattr, SETATTR);
84 FILLOP(poll, POLL); /* XXX: not ready in kernel */
85 FILLOP(mmap, MMAP);
86 FILLOP(fsync, FSYNC);
87 FILLOP(seek, SEEK);
88 FILLOP(remove, REMOVE);
89 FILLOP(link, LINK);
90 FILLOP(rename, RENAME);
91 FILLOP(mkdir, MKDIR);
92 FILLOP(rmdir, RMDIR);
93 FILLOP(symlink, SYMLINK);
94 FILLOP(readdir, READDIR);
95 FILLOP(readlink, READLINK);
96 FILLOP(reclaim, RECLAIM);
97 FILLOP(inactive, INACTIVE);
98 FILLOP(print, PRINT);
99 FILLOP(read, READ);
100 FILLOP(write, WRITE);
101
102 /* XXX: not implemented in the kernel */
103 FILLOP(getextattr, GETEXTATTR);
104 FILLOP(setextattr, SETEXTATTR);
105 FILLOP(listextattr, LISTEXTATTR);
106 }
107 #undef FILLOP
108
109 int
110 puffs_getselectable(struct puffs_usermount *pu)
111 {
112
113 return pu->pu_fd;
114 }
115
116 int
117 puffs_setblockingmode(struct puffs_usermount *pu, int mode)
118 {
119 int x;
120
121 x = mode;
122 return ioctl(pu->pu_fd, FIONBIO, &x);
123 }
124
125 int
126 puffs_getstate(struct puffs_usermount *pu)
127 {
128
129 return pu->pu_state;
130 }
131
132 void
133 puffs_setstacksize(struct puffs_usermount *pu, size_t ss)
134 {
135
136 pu->pu_cc_stacksize = ss;
137 }
138
139 struct puffs_pathobj *
140 puffs_getrootpathobj(struct puffs_usermount *pu)
141 {
142 struct puffs_node *pnr;
143
144 pnr = pu->pu_pn_root;
145 if (pnr == NULL) {
146 errno = ENOENT;
147 return NULL;
148 }
149
150 return &pnr->pn_po;
151 }
152
153
154 void
155 puffs_set_pathbuild(struct puffs_usermount *pu, pu_pathbuild_fn fn)
156 {
157
158 pu->pu_pathbuild = fn;
159 }
160
161 void
162 puffs_set_pathtransform(struct puffs_usermount *pu, pu_pathtransform_fn fn)
163 {
164
165 pu->pu_pathtransform = fn;
166 }
167
168 void
169 puffs_set_pathcmp(struct puffs_usermount *pu, pu_pathcmp_fn fn)
170 {
171
172 pu->pu_pathcmp = fn;
173 }
174
175 void
176 puffs_set_pathfree(struct puffs_usermount *pu, pu_pathfree_fn fn)
177 {
178
179 pu->pu_pathfree = fn;
180 }
181
182 void
183 puffs_set_namemod(struct puffs_usermount *pu, pu_namemod_fn fn)
184 {
185
186 pu->pu_namemod = fn;
187 }
188
189 enum {PUFFCALL_ANSWER, PUFFCALL_IGNORE, PUFFCALL_AGAIN};
190
191 struct puffs_usermount *
192 _puffs_mount(int develv, struct puffs_ops *pops, const char *dir, int mntflags,
193 const char *puffsname, void *priv, uint32_t pflags, size_t maxreqlen)
194 {
195 struct puffs_args pargs;
196 struct puffs_usermount *pu;
197 int fd = 0;
198
199 if (develv != PUFFS_DEVEL_LIBVERSION) {
200 warnx("puffs_mount: mounting with lib version %d, need %d",
201 develv, PUFFS_DEVEL_LIBVERSION);
202 errno = EINVAL;
203 return NULL;
204 }
205
206 fd = open("/dev/puffs", O_RDONLY);
207 if (fd == -1)
208 return NULL;
209 if (fd <= 2)
210 warnx("puffs_mount: device fd %d (<= 2), sure this is "
211 "what you want?", fd);
212
213 pargs.pa_vers = PUFFSDEVELVERS | PUFFSVERSION;
214 pargs.pa_flags = PUFFS_FLAG_KERN(pflags);
215 pargs.pa_fd = fd;
216 pargs.pa_maxreqlen = maxreqlen;
217 fillvnopmask(pops, pargs.pa_vnopmask);
218 (void)strlcpy(pargs.pa_name, puffsname, sizeof(pargs.pa_name));
219
220 pu = malloc(sizeof(struct puffs_usermount));
221 if (!pu)
222 return NULL;
223
224 pu->pu_flags = pflags;
225 pu->pu_ops = *pops;
226 free(pops); /* XXX */
227 pu->pu_fd = fd;
228 pu->pu_privdata = priv;
229 pu->pu_cc_stacksize = PUFFS_CC_STACKSIZE_DEFAULT;
230 LIST_INIT(&pu->pu_pnodelst);
231
232 /* defaults for some user-settable translation functions */
233 pu->pu_cmap = NULL; /* identity translation */
234
235 pu->pu_pathbuild = puffs_stdpath_buildpath;
236 pu->pu_pathfree = puffs_stdpath_freepath;
237 pu->pu_pathcmp = puffs_stdpath_cmppath;
238 pu->pu_pathtransform = NULL;
239 pu->pu_namemod = NULL;
240
241 pu->pu_state = PUFFS_STATE_MOUNTING;
242
243 #if 1
244 /* XXXkludgehere */
245 /* kauth doesn't provide this service any longer */
246 if (geteuid() != 0)
247 mntflags |= MNT_NOSUID | MNT_NODEV;
248 #endif
249
250 if (mount(MOUNT_PUFFS, dir, mntflags, &pargs) == -1)
251 goto failfree;
252 pu->pu_maxreqlen = pargs.pa_maxreqlen;
253
254 return pu;
255
256 failfree:
257 /* can't unmount() from here for obvious reasons */
258 if (fd)
259 close(fd);
260 free(pu);
261 return NULL;
262 }
263
264 int
265 puffs_start(struct puffs_usermount *pu, void *rootcookie, struct statvfs *sbp)
266 {
267 struct puffs_startreq sreq;
268
269 memset(&sreq, 0, sizeof(struct puffs_startreq));
270 sreq.psr_cookie = rootcookie;
271 sreq.psr_sb = *sbp;
272
273 /* tell kernel we're flying */
274 if (ioctl(pu->pu_fd, PUFFSSTARTOP, &sreq) == -1)
275 return -1;
276
277 pu->pu_state = PUFFS_STATE_RUNNING;
278
279 return 0;
280 }
281
282 /*
283 * XXX: there's currently no clean way to request unmount from
284 * within the user server, so be very brutal about it.
285 */
286 /*ARGSUSED*/
287 int
288 puffs_exit(struct puffs_usermount *pu, int force)
289 {
290 struct puffs_node *pn, *pn_next;
291
292 force = 1; /* currently */
293
294 if (pu->pu_fd)
295 close(pu->pu_fd);
296
297 pn = LIST_FIRST(&pu->pu_pnodelst);
298 while (pn) {
299 pn_next = LIST_NEXT(pn, pn_entries);
300 puffs_pn_put(pn);
301 pn = pn_next;
302 }
303 free(pu);
304
305 return 0; /* always succesful for now, WILL CHANGE */
306 }
307
308 int
309 puffs_mainloop(struct puffs_usermount *pu, int flags)
310 {
311 struct puffs_getreq *pgr;
312 struct puffs_putreq *ppr;
313 int rv;
314
315 rv = -1;
316 pgr = puffs_req_makeget(pu, pu->pu_maxreqlen, 0);
317 if (pgr == NULL)
318 return -1;
319
320 ppr = puffs_req_makeput(pu);
321 if (ppr == NULL) {
322 puffs_req_destroyget(pgr);
323 return -1;
324 }
325
326 if ((flags & PUFFSLOOP_NODAEMON) == 0)
327 if (daemon(1, 0) == -1)
328 goto out;
329
330 /* XXX: should be a bit more robust with errors here */
331 while (puffs_getstate(pu) == PUFFS_STATE_RUNNING
332 || puffs_getstate(pu) == PUFFS_STATE_UNMOUNTING) {
333 puffs_req_resetput(ppr);
334
335 if (puffs_req_handle(pu, pgr, ppr, 0) == -1) {
336 rv = -1;
337 break;
338 }
339 if (puffs_req_putput(ppr) == -1) {
340 rv = -1;
341 break;
342 }
343 }
344
345 out:
346 puffs_req_destroyput(ppr);
347 puffs_req_destroyget(pgr);
348 return rv;
349 }
350
351 int
352 puffs_dopreq(struct puffs_usermount *pu, struct puffs_req *preq,
353 struct puffs_putreq *ppr)
354 {
355 struct puffs_cc *pcc;
356 int rv;
357
358 /*
359 * XXX: the structure is currently a mess. anyway, trap
360 * the cacheops here already, since they don't need a cc.
361 * I really should get around to revamping the operation
362 * dispatching code one of these days.
363 */
364 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_CACHE) {
365 struct puffs_cacheinfo *pci = (void *)preq;
366
367 if (pu->pu_ops.puffs_cache_write == NULL)
368 return 0;
369
370 pu->pu_ops.puffs_cache_write(pu, preq->preq_cookie,
371 pci->pcache_nruns, pci->pcache_runs);
372 }
373
374 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
375 puffsdump_req(preq);
376
377 pcc = puffs_cc_create(pu);
378
379 /* XXX: temporary kludging */
380 pcc->pcc_preq = malloc(preq->preq_buflen);
381 if (pcc->pcc_preq == NULL)
382 return -1;
383 (void) memcpy(pcc->pcc_preq, preq, preq->preq_buflen);
384
385 rv = puffs_docc(pcc, ppr);
386
387 if ((pcc->pcc_flags & PCC_DONE) == 0)
388 return 0;
389
390 return rv;
391 }
392
393 int
394 puffs_docc(struct puffs_cc *pcc, struct puffs_putreq *ppr)
395 {
396 struct puffs_usermount *pu = pcc->pcc_pu;
397 int rv;
398
399 assert((pcc->pcc_flags & PCC_DONE) == 0);
400
401 puffs_cc_continue(pcc);
402 rv = pcc->pcc_rv;
403
404 if ((pcc->pcc_flags & PCC_DONE) == 0)
405 rv = PUFFCALL_AGAIN;
406
407 /* check if we need to store this reply */
408 switch (rv) {
409 case PUFFCALL_ANSWER:
410 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
411 puffsdump_rv(pcc->pcc_preq);
412
413 puffs_req_putcc(ppr, pcc);
414 break;
415 case PUFFCALL_IGNORE:
416 puffs_cc_destroy(pcc);
417 break;
418 case PUFFCALL_AGAIN:
419 break;
420 default:
421 assert(/*CONSTCOND*/0);
422 }
423
424 return 0;
425 }
426
427 /* library private, but linked from callcontext.c */
428
429 void
430 puffs_calldispatcher(struct puffs_cc *pcc)
431 {
432 struct puffs_usermount *pu = pcc->pcc_pu;
433 struct puffs_ops *pops = &pu->pu_ops;
434 struct puffs_req *preq = pcc->pcc_preq;
435 void *auxbuf = preq; /* help with typecasting */
436 int error, rv, buildpath;
437
438 assert(pcc->pcc_flags & (PCC_ONCE | PCC_REALCC));
439
440 if (PUFFSOP_WANTREPLY(preq->preq_opclass))
441 rv = PUFFCALL_ANSWER;
442 else
443 rv = PUFFCALL_IGNORE;
444
445 buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
446
447 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
448 switch (preq->preq_optype) {
449 case PUFFS_VFS_UNMOUNT:
450 {
451 struct puffs_vfsreq_unmount *auxt = auxbuf;
452
453 pu->pu_state = PUFFS_STATE_UNMOUNTING;
454 error = pops->puffs_fs_unmount(pcc,
455 auxt->pvfsr_flags, auxt->pvfsr_pid);
456 if (!error)
457 pu->pu_state = PUFFS_STATE_UNMOUNTED;
458 else
459 pu->pu_state = PUFFS_STATE_RUNNING;
460 break;
461 }
462
463 case PUFFS_VFS_STATVFS:
464 {
465 struct puffs_vfsreq_statvfs *auxt = auxbuf;
466
467 error = pops->puffs_fs_statvfs(pcc,
468 &auxt->pvfsr_sb, auxt->pvfsr_pid);
469 break;
470 }
471
472 case PUFFS_VFS_SYNC:
473 {
474 struct puffs_vfsreq_sync *auxt = auxbuf;
475
476 error = pops->puffs_fs_sync(pcc,
477 auxt->pvfsr_waitfor, &auxt->pvfsr_cred,
478 auxt->pvfsr_pid);
479 break;
480 }
481
482 case PUFFS_VFS_FHTOVP:
483 {
484 struct puffs_vfsreq_fhtonode *auxt = auxbuf;
485
486 error = pops->puffs_fs_fhtonode(pcc, auxt->pvfsr_data,
487 auxt->pvfsr_dsize, &auxt->pvfsr_fhcookie,
488 &auxt->pvfsr_vtype, &auxt->pvfsr_size,
489 &auxt->pvfsr_rdev);
490
491 break;
492 }
493
494 case PUFFS_VFS_VPTOFH:
495 {
496 struct puffs_vfsreq_nodetofh *auxt = auxbuf;
497
498 error = pops->puffs_fs_nodetofh(pcc,
499 auxt->pvfsr_fhcookie, auxt->pvfsr_data,
500 &auxt->pvfsr_dsize);
501
502 break;
503 }
504
505 case PUFFS_VFS_SUSPEND:
506 {
507 struct puffs_vfsreq_suspend *auxt = auxbuf;
508
509 error = 0;
510 if (pops->puffs_fs_suspend == NULL)
511 break;
512
513 pops->puffs_fs_suspend(pcc, auxt->pvfsr_status);
514 break;
515 }
516
517 default:
518 /*
519 * I guess the kernel sees this one coming
520 */
521 error = EINVAL;
522 break;
523 }
524
525 /* XXX: audit return values */
526 /* XXX: sync with kernel */
527 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
528 switch (preq->preq_optype) {
529 case PUFFS_VN_LOOKUP:
530 {
531 struct puffs_vnreq_lookup *auxt = auxbuf;
532 struct puffs_cn pcn;
533
534 pcn.pcn_pkcnp = &auxt->pvnr_cn;
535 if (buildpath) {
536 error = puffs_path_pcnbuild(pu, &pcn,
537 preq->preq_cookie);
538 if (error)
539 break;
540 }
541
542 /* lookup *must* be present */
543 error = pops->puffs_node_lookup(pcc, preq->preq_cookie,
544 &auxt->pvnr_newnode, &auxt->pvnr_vtype,
545 &auxt->pvnr_size, &auxt->pvnr_rdev, &pcn);
546
547 if (buildpath) {
548 if (error) {
549 pu->pu_pathfree(pu, &pcn.pcn_po_full);
550 } else {
551 struct puffs_node *pn;
552
553 /*
554 * did we get a new node or a
555 * recycled node?
556 */
557 pn = PU_CMAP(pu, auxt->pvnr_newnode);
558 if (pn->pn_po.po_path == NULL)
559 pn->pn_po = pcn.pcn_po_full;
560 else
561 pu->pu_pathfree(pu,
562 &pcn.pcn_po_full);
563 }
564 }
565
566 break;
567 }
568
569 case PUFFS_VN_CREATE:
570 {
571 struct puffs_vnreq_create *auxt = auxbuf;
572 struct puffs_cn pcn;
573 if (pops->puffs_node_create == NULL) {
574 error = 0;
575 break;
576 }
577
578 pcn.pcn_pkcnp = &auxt->pvnr_cn;
579 if (buildpath) {
580 error = puffs_path_pcnbuild(pu, &pcn,
581 preq->preq_cookie);
582 if (error)
583 break;
584 }
585
586 error = pops->puffs_node_create(pcc,
587 preq->preq_cookie, &auxt->pvnr_newnode,
588 &pcn, &auxt->pvnr_va);
589
590 if (buildpath) {
591 if (error) {
592 pu->pu_pathfree(pu, &pcn.pcn_po_full);
593 } else {
594 struct puffs_node *pn;
595
596 pn = PU_CMAP(pu, auxt->pvnr_newnode);
597 pn->pn_po = pcn.pcn_po_full;
598 }
599 }
600
601 break;
602 }
603
604 case PUFFS_VN_MKNOD:
605 {
606 struct puffs_vnreq_mknod *auxt = auxbuf;
607 struct puffs_cn pcn;
608 if (pops->puffs_node_mknod == NULL) {
609 error = 0;
610 break;
611 }
612
613 pcn.pcn_pkcnp = &auxt->pvnr_cn;
614 if (buildpath) {
615 error = puffs_path_pcnbuild(pu, &pcn,
616 preq->preq_cookie);
617 if (error)
618 break;
619 }
620
621 error = pops->puffs_node_mknod(pcc,
622 preq->preq_cookie, &auxt->pvnr_newnode,
623 &pcn, &auxt->pvnr_va);
624
625 if (buildpath) {
626 if (error) {
627 pu->pu_pathfree(pu, &pcn.pcn_po_full);
628 } else {
629 struct puffs_node *pn;
630
631 pn = PU_CMAP(pu, auxt->pvnr_newnode);
632 pn->pn_po = pcn.pcn_po_full;
633 }
634 }
635
636 break;
637 }
638
639 case PUFFS_VN_OPEN:
640 {
641 struct puffs_vnreq_open *auxt = auxbuf;
642 if (pops->puffs_node_open == NULL) {
643 error = 0;
644 break;
645 }
646
647 error = pops->puffs_node_open(pcc,
648 preq->preq_cookie, auxt->pvnr_mode,
649 &auxt->pvnr_cred, auxt->pvnr_pid);
650 break;
651 }
652
653 case PUFFS_VN_CLOSE:
654 {
655 struct puffs_vnreq_close *auxt = auxbuf;
656 if (pops->puffs_node_close == NULL) {
657 error = 0;
658 break;
659 }
660
661 error = pops->puffs_node_close(pcc,
662 preq->preq_cookie, auxt->pvnr_fflag,
663 &auxt->pvnr_cred, auxt->pvnr_pid);
664 break;
665 }
666
667 case PUFFS_VN_ACCESS:
668 {
669 struct puffs_vnreq_access *auxt = auxbuf;
670 if (pops->puffs_node_access == NULL) {
671 error = 0;
672 break;
673 }
674
675 error = pops->puffs_node_access(pcc,
676 preq->preq_cookie, auxt->pvnr_mode,
677 &auxt->pvnr_cred, auxt->pvnr_pid);
678 break;
679 }
680
681 case PUFFS_VN_GETATTR:
682 {
683 struct puffs_vnreq_getattr *auxt = auxbuf;
684 if (pops->puffs_node_getattr == NULL) {
685 error = EOPNOTSUPP;
686 break;
687 }
688
689 error = pops->puffs_node_getattr(pcc,
690 preq->preq_cookie, &auxt->pvnr_va,
691 &auxt->pvnr_cred, auxt->pvnr_pid);
692 break;
693 }
694
695 case PUFFS_VN_SETATTR:
696 {
697 struct puffs_vnreq_setattr *auxt = auxbuf;
698 if (pops->puffs_node_setattr == NULL) {
699 error = EOPNOTSUPP;
700 break;
701 }
702
703 error = pops->puffs_node_setattr(pcc,
704 preq->preq_cookie, &auxt->pvnr_va,
705 &auxt->pvnr_cred, auxt->pvnr_pid);
706 break;
707 }
708
709 case PUFFS_VN_MMAP:
710 {
711 struct puffs_vnreq_mmap *auxt = auxbuf;
712 if (pops->puffs_node_mmap == NULL) {
713 error = 0;
714 break;
715 }
716
717 error = pops->puffs_node_mmap(pcc,
718 preq->preq_cookie, auxt->pvnr_fflags,
719 &auxt->pvnr_cred, auxt->pvnr_pid);
720 break;
721 }
722
723 case PUFFS_VN_FSYNC:
724 {
725 struct puffs_vnreq_fsync *auxt = auxbuf;
726 if (pops->puffs_node_fsync == NULL) {
727 error = 0;
728 break;
729 }
730
731 error = pops->puffs_node_fsync(pcc,
732 preq->preq_cookie, &auxt->pvnr_cred,
733 auxt->pvnr_flags, auxt->pvnr_offlo,
734 auxt->pvnr_offhi, auxt->pvnr_pid);
735 break;
736 }
737
738 case PUFFS_VN_SEEK:
739 {
740 struct puffs_vnreq_seek *auxt = auxbuf;
741 if (pops->puffs_node_seek == NULL) {
742 error = 0;
743 break;
744 }
745
746 error = pops->puffs_node_seek(pcc,
747 preq->preq_cookie, auxt->pvnr_oldoff,
748 auxt->pvnr_newoff, &auxt->pvnr_cred);
749 break;
750 }
751
752 case PUFFS_VN_REMOVE:
753 {
754 struct puffs_vnreq_remove *auxt = auxbuf;
755 struct puffs_cn pcn;
756 if (pops->puffs_node_remove == NULL) {
757 error = 0;
758 break;
759 }
760
761 pcn.pcn_pkcnp = &auxt->pvnr_cn;
762
763 error = pops->puffs_node_remove(pcc,
764 preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
765 break;
766 }
767
768 case PUFFS_VN_LINK:
769 {
770 struct puffs_vnreq_link *auxt = auxbuf;
771 struct puffs_cn pcn;
772 if (pops->puffs_node_link == NULL) {
773 error = 0;
774 break;
775 }
776
777 pcn.pcn_pkcnp = &auxt->pvnr_cn;
778 if (buildpath) {
779 error = puffs_path_pcnbuild(pu, &pcn,
780 preq->preq_cookie);
781 if (error)
782 break;
783 }
784
785 error = pops->puffs_node_link(pcc,
786 preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
787 if (buildpath)
788 pu->pu_pathfree(pu, &pcn.pcn_po_full);
789
790 break;
791 }
792
793 case PUFFS_VN_RENAME:
794 {
795 struct puffs_vnreq_rename *auxt = auxbuf;
796 struct puffs_cn pcn_src, pcn_targ;
797 struct puffs_node *pn_src;
798
799 if (pops->puffs_node_rename == NULL) {
800 error = 0;
801 break;
802 }
803
804 pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
805 pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
806 if (buildpath) {
807 pn_src = auxt->pvnr_cookie_src;
808 pcn_src.pcn_po_full = pn_src->pn_po;
809
810 error = puffs_path_pcnbuild(pu, &pcn_targ,
811 auxt->pvnr_cookie_targdir);
812 if (error)
813 break;
814 }
815
816 error = pops->puffs_node_rename(pcc,
817 preq->preq_cookie, auxt->pvnr_cookie_src,
818 &pcn_src, auxt->pvnr_cookie_targdir,
819 auxt->pvnr_cookie_targ, &pcn_targ);
820
821 if (buildpath) {
822 if (error) {
823 pu->pu_pathfree(pu,
824 &pcn_targ.pcn_po_full);
825 } else {
826 struct puffs_pathinfo pi;
827 struct puffs_pathobj po_old;
828
829 /* handle this node */
830 po_old = pn_src->pn_po;
831 pn_src->pn_po = pcn_targ.pcn_po_full;
832
833 if (pn_src->pn_va.va_type != VDIR) {
834 pu->pu_pathfree(pu, &po_old);
835 break;
836 }
837
838 /* handle all child nodes for DIRs */
839 pi.pi_old = &pcn_src.pcn_po_full;
840 pi.pi_new = &pcn_targ.pcn_po_full;
841
842 if (puffs_pn_nodewalk(pu,
843 puffs_path_prefixadj, &pi) != NULL)
844 error = ENOMEM;
845 pu->pu_pathfree(pu, &po_old);
846 }
847 }
848 break;
849 }
850
851 case PUFFS_VN_MKDIR:
852 {
853 struct puffs_vnreq_mkdir *auxt = auxbuf;
854 struct puffs_cn pcn;
855 if (pops->puffs_node_mkdir == NULL) {
856 error = 0;
857 break;
858 }
859
860 pcn.pcn_pkcnp = &auxt->pvnr_cn;
861 if (buildpath) {
862 error = puffs_path_pcnbuild(pu, &pcn,
863 preq->preq_cookie);
864 if (error)
865 break;
866 }
867
868 error = pops->puffs_node_mkdir(pcc,
869 preq->preq_cookie, &auxt->pvnr_newnode,
870 &pcn, &auxt->pvnr_va);
871
872 if (buildpath) {
873 if (error) {
874 pu->pu_pathfree(pu, &pcn.pcn_po_full);
875 } else {
876 struct puffs_node *pn;
877
878 pn = PU_CMAP(pu, auxt->pvnr_newnode);
879 pn->pn_po = pcn.pcn_po_full;
880 }
881 }
882
883 break;
884 }
885
886 case PUFFS_VN_RMDIR:
887 {
888 struct puffs_vnreq_rmdir *auxt = auxbuf;
889 struct puffs_cn pcn;
890 if (pops->puffs_node_rmdir == NULL) {
891 error = 0;
892 break;
893 }
894
895 pcn.pcn_pkcnp = &auxt->pvnr_cn;
896
897 error = pops->puffs_node_rmdir(pcc,
898 preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
899 break;
900 }
901
902 case PUFFS_VN_SYMLINK:
903 {
904 struct puffs_vnreq_symlink *auxt = auxbuf;
905 struct puffs_cn pcn;
906 if (pops->puffs_node_symlink == NULL) {
907 error = 0;
908 break;
909 }
910
911 pcn.pcn_pkcnp = &auxt->pvnr_cn;
912 if (buildpath) {
913 error = puffs_path_pcnbuild(pu, &pcn,
914 preq->preq_cookie);
915 if (error)
916 break;
917 }
918
919 error = pops->puffs_node_symlink(pcc,
920 preq->preq_cookie, &auxt->pvnr_newnode,
921 &pcn, &auxt->pvnr_va, auxt->pvnr_link);
922
923 if (buildpath) {
924 if (error) {
925 pu->pu_pathfree(pu, &pcn.pcn_po_full);
926 } else {
927 struct puffs_node *pn;
928
929 pn = PU_CMAP(pu, auxt->pvnr_newnode);
930 pn->pn_po = pcn.pcn_po_full;
931 }
932 }
933
934 break;
935 }
936
937 case PUFFS_VN_READDIR:
938 {
939 struct puffs_vnreq_readdir *auxt = auxbuf;
940 struct dirent *dent;
941 off_t *cookies;
942 size_t res;
943
944 if (pops->puffs_node_readdir == NULL) {
945 error = 0;
946 break;
947 }
948
949 if (auxt->pvnr_ncookies) {
950 /* LINTED: pvnr_data is __aligned() */
951 cookies = (off_t *)auxt->pvnr_data;
952 } else {
953 cookies = NULL;
954 }
955 /* LINTED: dentoff is aligned in the kernel */
956 dent = (struct dirent *)
957 (auxt->pvnr_data + auxt->pvnr_dentoff);
958
959 res = auxt->pvnr_resid;
960 error = pops->puffs_node_readdir(pcc,
961 preq->preq_cookie, dent, &auxt->pvnr_offset,
962 &auxt->pvnr_resid, &auxt->pvnr_cred,
963 &auxt->pvnr_eofflag, cookies, &auxt->pvnr_ncookies);
964
965 /* need to move a bit more */
966 preq->preq_buflen = sizeof(struct puffs_vnreq_readdir)
967 + auxt->pvnr_dentoff + (res - auxt->pvnr_resid);
968 break;
969 }
970
971 case PUFFS_VN_READLINK:
972 {
973 struct puffs_vnreq_readlink *auxt = auxbuf;
974 if (pops->puffs_node_readlink == NULL) {
975 error = EOPNOTSUPP;
976 break;
977 }
978
979 error = pops->puffs_node_readlink(pcc,
980 preq->preq_cookie, &auxt->pvnr_cred,
981 auxt->pvnr_link, &auxt->pvnr_linklen);
982 break;
983 }
984
985 case PUFFS_VN_RECLAIM:
986 {
987 struct puffs_vnreq_reclaim *auxt = auxbuf;
988 if (pops->puffs_node_reclaim == NULL) {
989 error = 0;
990 break;
991 }
992
993 error = pops->puffs_node_reclaim(pcc,
994 preq->preq_cookie, auxt->pvnr_pid);
995 break;
996 }
997
998 case PUFFS_VN_INACTIVE:
999 {
1000 struct puffs_vnreq_inactive *auxt = auxbuf;
1001 if (pops->puffs_node_inactive == NULL) {
1002 error = EOPNOTSUPP;
1003 break;
1004 }
1005
1006 error = pops->puffs_node_inactive(pcc,
1007 preq->preq_cookie, auxt->pvnr_pid,
1008 &auxt->pvnr_backendrefs);
1009 break;
1010 }
1011
1012 case PUFFS_VN_PATHCONF:
1013 {
1014 struct puffs_vnreq_pathconf *auxt = auxbuf;
1015 if (pops->puffs_node_pathconf == NULL) {
1016 error = 0;
1017 break;
1018 }
1019
1020 error = pops->puffs_node_pathconf(pcc,
1021 preq->preq_cookie, auxt->pvnr_name,
1022 &auxt->pvnr_retval);
1023 break;
1024 }
1025
1026 case PUFFS_VN_ADVLOCK:
1027 {
1028 struct puffs_vnreq_advlock *auxt = auxbuf;
1029 if (pops->puffs_node_advlock == NULL) {
1030 error = 0;
1031 break;
1032 }
1033
1034 error = pops->puffs_node_advlock(pcc,
1035 preq->preq_cookie, auxt->pvnr_id, auxt->pvnr_op,
1036 &auxt->pvnr_fl, auxt->pvnr_flags);
1037 break;
1038 }
1039
1040 case PUFFS_VN_PRINT:
1041 {
1042 if (pops->puffs_node_print == NULL) {
1043 error = 0;
1044 break;
1045 }
1046
1047 error = pops->puffs_node_print(pcc,
1048 preq->preq_cookie);
1049 break;
1050 }
1051
1052 case PUFFS_VN_READ:
1053 {
1054 struct puffs_vnreq_read *auxt = auxbuf;
1055 size_t res;
1056
1057 if (pops->puffs_node_read == NULL) {
1058 error = EIO;
1059 break;
1060 }
1061
1062 res = auxt->pvnr_resid;
1063 error = pops->puffs_node_read(pcc,
1064 preq->preq_cookie, auxt->pvnr_data,
1065 auxt->pvnr_offset, &auxt->pvnr_resid,
1066 &auxt->pvnr_cred, auxt->pvnr_ioflag);
1067
1068 /* need to move a bit more */
1069 preq->preq_buflen = sizeof(struct puffs_vnreq_read)
1070 + (res - auxt->pvnr_resid);
1071 break;
1072 }
1073
1074 case PUFFS_VN_WRITE:
1075 {
1076 struct puffs_vnreq_write *auxt = auxbuf;
1077
1078 if (pops->puffs_node_write == NULL) {
1079 error = EIO;
1080 break;
1081 }
1082
1083 error = pops->puffs_node_write(pcc,
1084 preq->preq_cookie, auxt->pvnr_data,
1085 auxt->pvnr_offset, &auxt->pvnr_resid,
1086 &auxt->pvnr_cred, auxt->pvnr_ioflag);
1087
1088 /* don't need to move data back to the kernel */
1089 preq->preq_buflen = sizeof(struct puffs_vnreq_write);
1090 break;
1091 }
1092
1093 /* holy bitrot, ryydman! */
1094 #if 0
1095 case PUFFS_VN_IOCTL:
1096 error = pops->puffs_node_ioctl1(pcc, preq->preq_cookie,
1097 (struct puffs_vnreq_ioctl *)auxbuf, &pop);
1098 if (error != 0)
1099 break;
1100 pop.pso_reqid = preq->preq_id;
1101
1102 /* let the kernel do it's intermediate duty */
1103 error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
1104 /*
1105 * XXX: I don't actually know what the correct
1106 * thing to do in case of an error is, so I'll
1107 * just ignore it for the time being.
1108 */
1109 error = pops->puffs_node_ioctl2(pcc, preq->preq_cookie,
1110 (struct puffs_vnreq_ioctl *)auxbuf, &pop);
1111 break;
1112
1113 case PUFFS_VN_FCNTL:
1114 error = pops->puffs_node_fcntl1(pcc, preq->preq_cookie,
1115 (struct puffs_vnreq_fcntl *)auxbuf, &pop);
1116 if (error != 0)
1117 break;
1118 pop.pso_reqid = preq->preq_id;
1119
1120 /* let the kernel do it's intermediate duty */
1121 error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
1122 /*
1123 * XXX: I don't actually know what the correct
1124 * thing to do in case of an error is, so I'll
1125 * just ignore it for the time being.
1126 */
1127 error = pops->puffs_node_fcntl2(pcc, preq->preq_cookie,
1128 (struct puffs_vnreq_fcntl *)auxbuf, &pop);
1129 break;
1130 #endif
1131
1132 default:
1133 printf("inval op %d\n", preq->preq_optype);
1134 error = EINVAL;
1135 break;
1136 }
1137 } else {
1138 /*
1139 * this one also
1140 */
1141 error = EINVAL;
1142 }
1143
1144 preq->preq_rv = error;
1145
1146 pcc->pcc_rv = rv;
1147 pcc->pcc_flags |= PCC_DONE;
1148 }
1149
1150
1151 #if 0
1152 case PUFFS_VN_POLL:
1153 {
1154 struct puffs_vnreq_poll *auxt = auxbuf;
1155 if (pops->puffs_node_poll == NULL) {
1156 error = 0;
1157 break;
1158 }
1159
1160 error = pops->puffs_node_poll(pcc,
1161 preq->preq_cookie, preq-);
1162 break;
1163 }
1164
1165 case PUFFS_VN_KQFILTER:
1166 {
1167 struct puffs_vnreq_kqfilter *auxt = auxbuf;
1168 if (pops->puffs_node_kqfilter == NULL) {
1169 error = 0;
1170 break;
1171 }
1172
1173 error = pops->puffs_node_kqfilter(pcc,
1174 preq->preq_cookie, );
1175 break;
1176 }
1177
1178 case PUFFS_VN_CLOSEEXTATTR:
1179 {
1180 struct puffs_vnreq_closeextattr *auxt = auxbuf;
1181 if (pops->puffs_closeextattr == NULL) {
1182 error = 0;
1183 break;
1184 }
1185
1186 error = pops->puffs_closeextattr(pcc,
1187 preq->preq_cookie, );
1188 break;
1189 }
1190
1191 case PUFFS_VN_GETEXTATTR:
1192 {
1193 struct puffs_vnreq_getextattr *auxt = auxbuf;
1194 if (pops->puffs_getextattr == NULL) {
1195 error = 0;
1196 break;
1197 }
1198
1199 error = pops->puffs_getextattr(pcc,
1200 preq->preq_cookie, );
1201 break;
1202 }
1203
1204 case PUFFS_VN_LISTEXTATTR:
1205 {
1206 struct puffs_vnreq_listextattr *auxt = auxbuf;
1207 if (pops->puffs_listextattr == NULL) {
1208 error = 0;
1209 break;
1210 }
1211
1212 error = pops->puffs_listextattr(pcc,
1213 preq->preq_cookie, );
1214 break;
1215 }
1216
1217 case PUFFS_VN_OPENEXTATTR:
1218 {
1219 struct puffs_vnreq_openextattr *auxt = auxbuf;
1220 if (pops->puffs_openextattr == NULL) {
1221 error = 0;
1222 break;
1223 }
1224
1225 error = pops->puffs_openextattr(pcc,
1226 preq->preq_cookie, );
1227 break;
1228 }
1229
1230 case PUFFS_VN_DELETEEXTATTR:
1231 {
1232 struct puffs_vnreq_deleteextattr *auxt = auxbuf;
1233 if (pops->puffs_deleteextattr == NULL) {
1234 error = 0;
1235 break;
1236 }
1237
1238 error = pops->puffs_deleteextattr(pcc,
1239 preq->preq_cookie, );
1240 break;
1241 }
1242
1243 case PUFFS_VN_SETEXTATTR:
1244 {
1245 struct puffs_vnreq_setextattr *auxt = auxbuf;
1246 if (pops->puffs_setextattr == NULL) {
1247 error = 0;
1248 break;
1249 }
1250
1251 error = pops->puffs_setextattr(pcc,
1252 preq->preq_cookie, );
1253 break;
1254 }
1255
1256 #endif
1257