puffs.c revision 1.28 1 /* $NetBSD: puffs.c,v 1.28 2007/01/26 23:00:33 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.28 2007/01/26 23:00:33 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_path_buildpath;
236 pu->pu_pathfree = puffs_path_freepath;
237 pu->pu_pathcmp = puffs_path_cmppath;
238 pu->pu_pathtransform = NULL;
239 pu->pu_namemod = NULL;
240
241 pu->pu_state = PUFFS_STATE_MOUNTING;
242 if (mount(MOUNT_PUFFS, dir, mntflags, &pargs) == -1)
243 goto failfree;
244 pu->pu_maxreqlen = pargs.pa_maxreqlen;
245
246 return pu;
247
248 failfree:
249 /* can't unmount() from here for obvious reasons */
250 if (fd)
251 close(fd);
252 free(pu);
253 return NULL;
254 }
255
256 int
257 puffs_start(struct puffs_usermount *pu, void *rootcookie, struct statvfs *sbp)
258 {
259 struct puffs_startreq sreq;
260
261 memset(&sreq, 0, sizeof(struct puffs_startreq));
262 sreq.psr_cookie = rootcookie;
263 sreq.psr_sb = *sbp;
264
265 /* tell kernel we're flying */
266 if (ioctl(pu->pu_fd, PUFFSSTARTOP, &sreq) == -1)
267 return -1;
268
269 pu->pu_state = PUFFS_STATE_RUNNING;
270
271 return 0;
272 }
273
274 /*
275 * XXX: there's currently no clean way to request unmount from
276 * within the user server, so be very brutal about it.
277 */
278 /*ARGSUSED*/
279 int
280 puffs_exit(struct puffs_usermount *pu, int force)
281 {
282 struct puffs_node *pn, *pn_next;
283
284 force = 1; /* currently */
285
286 if (pu->pu_fd)
287 close(pu->pu_fd);
288
289 pn = LIST_FIRST(&pu->pu_pnodelst);
290 while (pn) {
291 pn_next = LIST_NEXT(pn, pn_entries);
292 puffs_pn_put(pn);
293 pn = pn_next;
294 }
295 free(pu);
296
297 return 0; /* always succesful for now, WILL CHANGE */
298 }
299
300 int
301 puffs_mainloop(struct puffs_usermount *pu, int flags)
302 {
303 struct puffs_getreq *pgr;
304 struct puffs_putreq *ppr;
305 int rv;
306
307 rv = -1;
308 pgr = puffs_req_makeget(pu, pu->pu_maxreqlen, 0);
309 if (pgr == NULL)
310 return -1;
311
312 ppr = puffs_req_makeput(pu);
313 if (ppr == NULL) {
314 puffs_req_destroyget(pgr);
315 return -1;
316 }
317
318 if ((flags & PUFFSLOOP_NODAEMON) == 0)
319 if (daemon(1, 0) == -1)
320 goto out;
321
322 /* XXX: should be a bit more robust with errors here */
323 while (puffs_getstate(pu) == PUFFS_STATE_RUNNING
324 || puffs_getstate(pu) == PUFFS_STATE_UNMOUNTING) {
325 puffs_req_resetput(ppr);
326
327 if (puffs_req_handle(pu, pgr, ppr, 0) == -1) {
328 rv = -1;
329 break;
330 }
331 if (puffs_req_putput(ppr) == -1) {
332 rv = -1;
333 break;
334 }
335 }
336
337 out:
338 puffs_req_destroyput(ppr);
339 puffs_req_destroyget(pgr);
340 return rv;
341 }
342
343 int
344 puffs_dopreq(struct puffs_usermount *pu, struct puffs_req *preq,
345 struct puffs_putreq *ppr)
346 {
347 struct puffs_cc *pcc;
348 int rv;
349
350 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
351 puffsdump_req(preq);
352
353 pcc = puffs_cc_create(pu);
354
355 /* XXX: temporary kludging */
356 pcc->pcc_preq = malloc(preq->preq_buflen);
357 if (pcc->pcc_preq == NULL)
358 return -1;
359 (void) memcpy(pcc->pcc_preq, preq, preq->preq_buflen);
360
361 rv = puffs_docc(pcc, ppr);
362
363 if ((pcc->pcc_flags & PCC_DONE) == 0)
364 return 0;
365
366 return rv;
367 }
368
369 int
370 puffs_docc(struct puffs_cc *pcc, struct puffs_putreq *ppr)
371 {
372 int rv;
373
374 assert((pcc->pcc_flags & PCC_DONE) == 0);
375
376 puffs_cc_continue(pcc);
377 rv = pcc->pcc_rv;
378
379 if ((pcc->pcc_flags & PCC_DONE) == 0)
380 rv = PUFFCALL_AGAIN;
381
382 /* check if we need to store this reply */
383 switch (rv) {
384 case PUFFCALL_ANSWER:
385 puffs_req_putcc(ppr, pcc);
386 break;
387 case PUFFCALL_IGNORE:
388 puffs_cc_destroy(pcc);
389 break;
390 case PUFFCALL_AGAIN:
391 break;
392 default:
393 assert(/*CONSTCOND*/0);
394 }
395
396 return 0;
397 }
398
399 /* library private, but linked from callcontext.c */
400
401 void
402 puffs_calldispatcher(struct puffs_cc *pcc)
403 {
404 struct puffs_usermount *pu = pcc->pcc_pu;
405 struct puffs_ops *pops = &pu->pu_ops;
406 struct puffs_req *preq = pcc->pcc_preq;
407 void *auxbuf = preq; /* help with typecasting */
408 int error, rv, buildpath;
409
410 assert(pcc->pcc_flags & (PCC_ONCE | PCC_REALCC));
411
412 if (PUFFSOP_WANTREPLY(preq->preq_opclass))
413 rv = PUFFCALL_ANSWER;
414 else
415 rv = PUFFCALL_IGNORE;
416
417 buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
418
419 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
420 switch (preq->preq_optype) {
421 case PUFFS_VFS_UNMOUNT:
422 {
423 struct puffs_vfsreq_unmount *auxt = auxbuf;
424
425 pu->pu_state = PUFFS_STATE_UNMOUNTING;
426 error = pops->puffs_fs_unmount(pcc,
427 auxt->pvfsr_flags, auxt->pvfsr_pid);
428 if (!error)
429 pu->pu_state = PUFFS_STATE_UNMOUNTED;
430 else
431 pu->pu_state = PUFFS_STATE_RUNNING;
432 break;
433 }
434 case PUFFS_VFS_STATVFS:
435 {
436 struct puffs_vfsreq_statvfs *auxt = auxbuf;
437
438 error = pops->puffs_fs_statvfs(pcc,
439 &auxt->pvfsr_sb, auxt->pvfsr_pid);
440 break;
441 }
442 case PUFFS_VFS_SYNC:
443 {
444 struct puffs_vfsreq_sync *auxt = auxbuf;
445
446 error = pops->puffs_fs_sync(pcc,
447 auxt->pvfsr_waitfor, &auxt->pvfsr_cred,
448 auxt->pvfsr_pid);
449 break;
450 }
451 case PUFFS_VFS_SUSPEND:
452 {
453 struct puffs_vfsreq_suspend *auxt = auxbuf;
454
455 error = 0;
456 if (pops->puffs_fs_suspend == NULL)
457 break;
458
459 pops->puffs_fs_suspend(pcc, auxt->pvfsr_status);
460 break;
461 }
462
463 default:
464 /*
465 * I guess the kernel sees this one coming
466 */
467 error = EINVAL;
468 break;
469 }
470
471 /* XXX: audit return values */
472 /* XXX: sync with kernel */
473 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
474 switch (preq->preq_optype) {
475 case PUFFS_VN_LOOKUP:
476 {
477 struct puffs_vnreq_lookup *auxt = auxbuf;
478 struct puffs_cn pcn;
479
480 pcn.pcn_pkcnp = &auxt->pvnr_cn;
481 if (buildpath) {
482 if (pcn.pcn_flags & PUFFS_ISDOTDOT) {
483 buildpath = 0;
484 } else {
485 error = puffs_path_pcnbuild(pu, &pcn,
486 preq->preq_cookie);
487 if (error)
488 break;
489 }
490 }
491
492 /* lookup *must* be present */
493 error = pops->puffs_node_lookup(pcc, preq->preq_cookie,
494 &auxt->pvnr_newnode, &auxt->pvnr_vtype,
495 &auxt->pvnr_size, &auxt->pvnr_rdev, &pcn);
496
497 if (buildpath) {
498 if (error) {
499 pu->pu_pathfree(pu, &pcn.pcn_po_full);
500 } else {
501 struct puffs_node *pn;
502
503 /*
504 * did we get a new node or a
505 * recycled node?
506 * XXX: mapping assumption
507 */
508 pn = PU_CMAP(pu, auxt->pvnr_newnode);
509 if (pn->pn_po.po_path == NULL)
510 pn->pn_po = pcn.pcn_po_full;
511 else
512 pu->pu_pathfree(pu,
513 &pcn.pcn_po_full);
514 }
515 }
516
517 break;
518 }
519
520 case PUFFS_VN_CREATE:
521 {
522 struct puffs_vnreq_create *auxt = auxbuf;
523 struct puffs_cn pcn;
524 if (pops->puffs_node_create == NULL) {
525 error = 0;
526 break;
527 }
528
529 pcn.pcn_pkcnp = &auxt->pvnr_cn;
530 if (buildpath) {
531 error = puffs_path_pcnbuild(pu, &pcn,
532 preq->preq_cookie);
533 if (error)
534 break;
535 }
536
537 error = pops->puffs_node_create(pcc,
538 preq->preq_cookie, &auxt->pvnr_newnode,
539 &pcn, &auxt->pvnr_va);
540
541 if (buildpath) {
542 if (error) {
543 pu->pu_pathfree(pu, &pcn.pcn_po_full);
544 } else {
545 struct puffs_node *pn;
546
547 pn = PU_CMAP(pu, auxt->pvnr_newnode);
548 pn->pn_po = pcn.pcn_po_full;
549 }
550 }
551
552 break;
553 }
554
555 case PUFFS_VN_MKNOD:
556 {
557 struct puffs_vnreq_mknod *auxt = auxbuf;
558 struct puffs_cn pcn;
559 if (pops->puffs_node_mknod == NULL) {
560 error = 0;
561 break;
562 }
563
564 pcn.pcn_pkcnp = &auxt->pvnr_cn;
565 if (buildpath) {
566 error = puffs_path_pcnbuild(pu, &pcn,
567 preq->preq_cookie);
568 if (error)
569 break;
570 }
571
572 error = pops->puffs_node_mknod(pcc,
573 preq->preq_cookie, &auxt->pvnr_newnode,
574 &pcn, &auxt->pvnr_va);
575
576 if (buildpath) {
577 if (error) {
578 pu->pu_pathfree(pu, &pcn.pcn_po_full);
579 } else {
580 struct puffs_node *pn;
581
582 pn = PU_CMAP(pu, auxt->pvnr_newnode);
583 pn->pn_po = pcn.pcn_po_full;
584 }
585 }
586
587 break;
588 }
589
590 case PUFFS_VN_OPEN:
591 {
592 struct puffs_vnreq_open *auxt = auxbuf;
593 if (pops->puffs_node_open == NULL) {
594 error = 0;
595 break;
596 }
597
598 error = pops->puffs_node_open(pcc,
599 preq->preq_cookie, auxt->pvnr_mode,
600 &auxt->pvnr_cred, auxt->pvnr_pid);
601 break;
602 }
603
604 case PUFFS_VN_CLOSE:
605 {
606 struct puffs_vnreq_close *auxt = auxbuf;
607 if (pops->puffs_node_close == NULL) {
608 error = 0;
609 break;
610 }
611
612 error = pops->puffs_node_close(pcc,
613 preq->preq_cookie, auxt->pvnr_fflag,
614 &auxt->pvnr_cred, auxt->pvnr_pid);
615 break;
616 }
617
618 case PUFFS_VN_ACCESS:
619 {
620 struct puffs_vnreq_access *auxt = auxbuf;
621 if (pops->puffs_node_access == NULL) {
622 error = 0;
623 break;
624 }
625
626 error = pops->puffs_node_access(pcc,
627 preq->preq_cookie, auxt->pvnr_mode,
628 &auxt->pvnr_cred, auxt->pvnr_pid);
629 break;
630 }
631
632 case PUFFS_VN_GETATTR:
633 {
634 struct puffs_vnreq_getattr *auxt = auxbuf;
635 if (pops->puffs_node_getattr == NULL) {
636 error = EOPNOTSUPP;
637 break;
638 }
639
640 error = pops->puffs_node_getattr(pcc,
641 preq->preq_cookie, &auxt->pvnr_va,
642 &auxt->pvnr_cred, auxt->pvnr_pid);
643 break;
644 }
645
646 case PUFFS_VN_SETATTR:
647 {
648 struct puffs_vnreq_setattr *auxt = auxbuf;
649 if (pops->puffs_node_setattr == NULL) {
650 error = EOPNOTSUPP;
651 break;
652 }
653
654 error = pops->puffs_node_setattr(pcc,
655 preq->preq_cookie, &auxt->pvnr_va,
656 &auxt->pvnr_cred, auxt->pvnr_pid);
657 break;
658 }
659
660 case PUFFS_VN_MMAP:
661 {
662 struct puffs_vnreq_mmap *auxt = auxbuf;
663 if (pops->puffs_node_mmap == NULL) {
664 error = 0;
665 break;
666 }
667
668 error = pops->puffs_node_mmap(pcc,
669 preq->preq_cookie, auxt->pvnr_fflags,
670 &auxt->pvnr_cred, auxt->pvnr_pid);
671 break;
672 }
673
674 case PUFFS_VN_FSYNC:
675 {
676 struct puffs_vnreq_fsync *auxt = auxbuf;
677 if (pops->puffs_node_fsync == NULL) {
678 error = 0;
679 break;
680 }
681
682 error = pops->puffs_node_fsync(pcc,
683 preq->preq_cookie, &auxt->pvnr_cred,
684 auxt->pvnr_flags, auxt->pvnr_offlo,
685 auxt->pvnr_offhi, auxt->pvnr_pid);
686 break;
687 }
688
689 case PUFFS_VN_SEEK:
690 {
691 struct puffs_vnreq_seek *auxt = auxbuf;
692 if (pops->puffs_node_seek == NULL) {
693 error = 0;
694 break;
695 }
696
697 error = pops->puffs_node_seek(pcc,
698 preq->preq_cookie, auxt->pvnr_oldoff,
699 auxt->pvnr_newoff, &auxt->pvnr_cred);
700 break;
701 }
702
703 case PUFFS_VN_REMOVE:
704 {
705 struct puffs_vnreq_remove *auxt = auxbuf;
706 struct puffs_cn pcn;
707 if (pops->puffs_node_remove == NULL) {
708 error = 0;
709 break;
710 }
711
712 pcn.pcn_pkcnp = &auxt->pvnr_cn;
713
714 error = pops->puffs_node_remove(pcc,
715 preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
716 break;
717 }
718
719 case PUFFS_VN_LINK:
720 {
721 struct puffs_vnreq_link *auxt = auxbuf;
722 struct puffs_cn pcn;
723 if (pops->puffs_node_link == NULL) {
724 error = 0;
725 break;
726 }
727
728 pcn.pcn_pkcnp = &auxt->pvnr_cn;
729 if (buildpath) {
730 error = puffs_path_pcnbuild(pu, &pcn,
731 preq->preq_cookie);
732 if (error)
733 break;
734 }
735
736 error = pops->puffs_node_link(pcc,
737 preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
738 if (buildpath)
739 pu->pu_pathfree(pu, &pcn.pcn_po_full);
740
741 break;
742 }
743
744 case PUFFS_VN_RENAME:
745 {
746 struct puffs_vnreq_rename *auxt = auxbuf;
747 struct puffs_cn pcn_src, pcn_targ;
748 struct puffs_node *pn_src;
749
750 if (pops->puffs_node_rename == NULL) {
751 error = 0;
752 break;
753 }
754
755 pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
756 pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
757 if (buildpath) {
758 pn_src = auxt->pvnr_cookie_src;
759 pcn_src.pcn_po_full = pn_src->pn_po;
760
761 error = puffs_path_pcnbuild(pu, &pcn_targ,
762 auxt->pvnr_cookie_targdir);
763 if (error)
764 break;
765 }
766
767 error = pops->puffs_node_rename(pcc,
768 preq->preq_cookie, auxt->pvnr_cookie_src,
769 &pcn_src, auxt->pvnr_cookie_targdir,
770 auxt->pvnr_cookie_targ, &pcn_targ);
771
772 if (buildpath) {
773 if (error) {
774 pu->pu_pathfree(pu,
775 &pcn_targ.pcn_po_full);
776 } else {
777 struct puffs_pathinfo pi;
778 struct puffs_pathobj po_old;
779
780 /* handle this node */
781 po_old = pn_src->pn_po;
782 pn_src->pn_po = pcn_targ.pcn_po_full;
783
784 if (pn_src->pn_va.va_type != VDIR) {
785 pu->pu_pathfree(pu, &po_old);
786 break;
787 }
788
789 /* handle all child nodes for DIRs */
790 pi.pi_old = &pcn_src.pcn_po_full;
791 pi.pi_new = &pcn_targ.pcn_po_full;
792
793 if (puffs_pn_nodewalk(pu,
794 puffs_path_prefixadj, &pi) != NULL)
795 error = ENOMEM;
796 pu->pu_pathfree(pu, &po_old);
797 }
798 }
799 break;
800 }
801
802 case PUFFS_VN_MKDIR:
803 {
804 struct puffs_vnreq_mkdir *auxt = auxbuf;
805 struct puffs_cn pcn;
806 if (pops->puffs_node_mkdir == NULL) {
807 error = 0;
808 break;
809 }
810
811 pcn.pcn_pkcnp = &auxt->pvnr_cn;
812 if (buildpath) {
813 error = puffs_path_pcnbuild(pu, &pcn,
814 preq->preq_cookie);
815 if (error)
816 break;
817 }
818
819 error = pops->puffs_node_mkdir(pcc,
820 preq->preq_cookie, &auxt->pvnr_newnode,
821 &pcn, &auxt->pvnr_va);
822
823 if (buildpath) {
824 if (error) {
825 pu->pu_pathfree(pu, &pcn.pcn_po_full);
826 } else {
827 struct puffs_node *pn;
828
829 pn = PU_CMAP(pu, auxt->pvnr_newnode);
830 pn->pn_po = pcn.pcn_po_full;
831 }
832 }
833
834 break;
835 }
836
837 case PUFFS_VN_RMDIR:
838 {
839 struct puffs_vnreq_rmdir *auxt = auxbuf;
840 struct puffs_cn pcn;
841 if (pops->puffs_node_rmdir == NULL) {
842 error = 0;
843 break;
844 }
845
846 pcn.pcn_pkcnp = &auxt->pvnr_cn;
847
848 error = pops->puffs_node_rmdir(pcc,
849 preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
850 break;
851 }
852
853 case PUFFS_VN_SYMLINK:
854 {
855 struct puffs_vnreq_symlink *auxt = auxbuf;
856 struct puffs_cn pcn;
857 if (pops->puffs_node_symlink == NULL) {
858 error = 0;
859 break;
860 }
861
862 pcn.pcn_pkcnp = &auxt->pvnr_cn;
863 if (buildpath) {
864 error = puffs_path_pcnbuild(pu, &pcn,
865 preq->preq_cookie);
866 if (error)
867 break;
868 }
869
870 error = pops->puffs_node_symlink(pcc,
871 preq->preq_cookie, &auxt->pvnr_newnode,
872 &pcn, &auxt->pvnr_va, auxt->pvnr_link);
873
874 if (buildpath) {
875 if (error) {
876 pu->pu_pathfree(pu, &pcn.pcn_po_full);
877 } else {
878 struct puffs_node *pn;
879
880 pn = PU_CMAP(pu, auxt->pvnr_newnode);
881 pn->pn_po = pcn.pcn_po_full;
882 }
883 }
884
885 break;
886 }
887
888 case PUFFS_VN_READDIR:
889 {
890 struct puffs_vnreq_readdir *auxt = auxbuf;
891 size_t res;
892
893 if (pops->puffs_node_readdir == NULL) {
894 error = 0;
895 break;
896 }
897
898 res = auxt->pvnr_resid;
899 error = pops->puffs_node_readdir(pcc,
900 preq->preq_cookie, auxt->pvnr_dent,
901 &auxt->pvnr_cred, &auxt->pvnr_offset,
902 &auxt->pvnr_resid);
903
904 /* need to move a bit more */
905 preq->preq_buflen = sizeof(struct puffs_vnreq_readdir)
906 + (res - auxt->pvnr_resid);
907 break;
908 }
909
910 case PUFFS_VN_READLINK:
911 {
912 struct puffs_vnreq_readlink *auxt = auxbuf;
913 if (pops->puffs_node_readlink == NULL) {
914 error = EOPNOTSUPP;
915 break;
916 }
917
918 error = pops->puffs_node_readlink(pcc,
919 preq->preq_cookie, &auxt->pvnr_cred,
920 auxt->pvnr_link, &auxt->pvnr_linklen);
921 break;
922 }
923
924 case PUFFS_VN_RECLAIM:
925 {
926 struct puffs_vnreq_reclaim *auxt = auxbuf;
927 if (pops->puffs_node_reclaim == NULL) {
928 error = 0;
929 break;
930 }
931
932 error = pops->puffs_node_reclaim(pcc,
933 preq->preq_cookie, auxt->pvnr_pid);
934 break;
935 }
936
937 case PUFFS_VN_INACTIVE:
938 {
939 struct puffs_vnreq_inactive *auxt = auxbuf;
940 if (pops->puffs_node_inactive == NULL) {
941 error = EOPNOTSUPP;
942 break;
943 }
944
945 error = pops->puffs_node_inactive(pcc,
946 preq->preq_cookie, auxt->pvnr_pid,
947 &auxt->pvnr_backendrefs);
948 break;
949 }
950
951 case PUFFS_VN_PATHCONF:
952 {
953 struct puffs_vnreq_pathconf *auxt = auxbuf;
954 if (pops->puffs_node_pathconf == NULL) {
955 error = 0;
956 break;
957 }
958
959 error = pops->puffs_node_pathconf(pcc,
960 preq->preq_cookie, auxt->pvnr_name,
961 &auxt->pvnr_retval);
962 break;
963 }
964
965 case PUFFS_VN_ADVLOCK:
966 {
967 struct puffs_vnreq_advlock *auxt = auxbuf;
968 if (pops->puffs_node_advlock == NULL) {
969 error = 0;
970 break;
971 }
972
973 error = pops->puffs_node_advlock(pcc,
974 preq->preq_cookie, auxt->pvnr_id, auxt->pvnr_op,
975 &auxt->pvnr_fl, auxt->pvnr_flags);
976 break;
977 }
978
979 case PUFFS_VN_PRINT:
980 {
981 if (pops->puffs_node_print == NULL) {
982 error = 0;
983 break;
984 }
985
986 error = pops->puffs_node_print(pcc,
987 preq->preq_cookie);
988 break;
989 }
990
991 case PUFFS_VN_READ:
992 {
993 struct puffs_vnreq_read *auxt = auxbuf;
994 size_t res;
995
996 if (pops->puffs_node_read == NULL) {
997 error = EIO;
998 break;
999 }
1000
1001 res = auxt->pvnr_resid;
1002 error = pops->puffs_node_read(pcc,
1003 preq->preq_cookie, auxt->pvnr_data,
1004 auxt->pvnr_offset, &auxt->pvnr_resid,
1005 &auxt->pvnr_cred, auxt->pvnr_ioflag);
1006
1007 /* need to move a bit more */
1008 preq->preq_buflen = sizeof(struct puffs_vnreq_read)
1009 + (res - auxt->pvnr_resid);
1010 break;
1011 }
1012
1013 case PUFFS_VN_WRITE:
1014 {
1015 struct puffs_vnreq_write *auxt = auxbuf;
1016
1017 if (pops->puffs_node_write == NULL) {
1018 error = EIO;
1019 break;
1020 }
1021
1022 error = pops->puffs_node_write(pcc,
1023 preq->preq_cookie, auxt->pvnr_data,
1024 auxt->pvnr_offset, &auxt->pvnr_resid,
1025 &auxt->pvnr_cred, auxt->pvnr_ioflag);
1026
1027 /* don't need to move data back to the kernel */
1028 preq->preq_buflen = sizeof(struct puffs_vnreq_write);
1029 break;
1030 }
1031
1032 /* holy bitrot, ryydman! */
1033 #if 0
1034 case PUFFS_VN_IOCTL:
1035 error = pops->puffs_node_ioctl1(pcc, preq->preq_cookie,
1036 (struct puffs_vnreq_ioctl *)auxbuf, &pop);
1037 if (error != 0)
1038 break;
1039 pop.pso_reqid = preq->preq_id;
1040
1041 /* let the kernel do it's intermediate duty */
1042 error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
1043 /*
1044 * XXX: I don't actually know what the correct
1045 * thing to do in case of an error is, so I'll
1046 * just ignore it for the time being.
1047 */
1048 error = pops->puffs_node_ioctl2(pcc, preq->preq_cookie,
1049 (struct puffs_vnreq_ioctl *)auxbuf, &pop);
1050 break;
1051
1052 case PUFFS_VN_FCNTL:
1053 error = pops->puffs_node_fcntl1(pcc, preq->preq_cookie,
1054 (struct puffs_vnreq_fcntl *)auxbuf, &pop);
1055 if (error != 0)
1056 break;
1057 pop.pso_reqid = preq->preq_id;
1058
1059 /* let the kernel do it's intermediate duty */
1060 error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
1061 /*
1062 * XXX: I don't actually know what the correct
1063 * thing to do in case of an error is, so I'll
1064 * just ignore it for the time being.
1065 */
1066 error = pops->puffs_node_fcntl2(pcc, preq->preq_cookie,
1067 (struct puffs_vnreq_fcntl *)auxbuf, &pop);
1068 break;
1069 #endif
1070
1071 default:
1072 printf("inval op %d\n", preq->preq_optype);
1073 error = EINVAL;
1074 break;
1075 }
1076 } else {
1077 /*
1078 * this one also
1079 */
1080 error = EINVAL;
1081 }
1082
1083 preq->preq_rv = error;
1084
1085 pcc->pcc_rv = rv;
1086 pcc->pcc_flags |= PCC_DONE;
1087 }
1088
1089
1090 #if 0
1091 case PUFFS_VN_POLL:
1092 {
1093 struct puffs_vnreq_poll *auxt = auxbuf;
1094 if (pops->puffs_node_poll == NULL) {
1095 error = 0;
1096 break;
1097 }
1098
1099 error = pops->puffs_node_poll(pcc,
1100 preq->preq_cookie, preq-);
1101 break;
1102 }
1103
1104 case PUFFS_VN_KQFILTER:
1105 {
1106 struct puffs_vnreq_kqfilter *auxt = auxbuf;
1107 if (pops->puffs_node_kqfilter == NULL) {
1108 error = 0;
1109 break;
1110 }
1111
1112 error = pops->puffs_node_kqfilter(pcc,
1113 preq->preq_cookie, );
1114 break;
1115 }
1116
1117 case PUFFS_VN_CLOSEEXTATTR:
1118 {
1119 struct puffs_vnreq_closeextattr *auxt = auxbuf;
1120 if (pops->puffs_closeextattr == NULL) {
1121 error = 0;
1122 break;
1123 }
1124
1125 error = pops->puffs_closeextattr(pcc,
1126 preq->preq_cookie, );
1127 break;
1128 }
1129
1130 case PUFFS_VN_GETEXTATTR:
1131 {
1132 struct puffs_vnreq_getextattr *auxt = auxbuf;
1133 if (pops->puffs_getextattr == NULL) {
1134 error = 0;
1135 break;
1136 }
1137
1138 error = pops->puffs_getextattr(pcc,
1139 preq->preq_cookie, );
1140 break;
1141 }
1142
1143 case PUFFS_VN_LISTEXTATTR:
1144 {
1145 struct puffs_vnreq_listextattr *auxt = auxbuf;
1146 if (pops->puffs_listextattr == NULL) {
1147 error = 0;
1148 break;
1149 }
1150
1151 error = pops->puffs_listextattr(pcc,
1152 preq->preq_cookie, );
1153 break;
1154 }
1155
1156 case PUFFS_VN_OPENEXTATTR:
1157 {
1158 struct puffs_vnreq_openextattr *auxt = auxbuf;
1159 if (pops->puffs_openextattr == NULL) {
1160 error = 0;
1161 break;
1162 }
1163
1164 error = pops->puffs_openextattr(pcc,
1165 preq->preq_cookie, );
1166 break;
1167 }
1168
1169 case PUFFS_VN_DELETEEXTATTR:
1170 {
1171 struct puffs_vnreq_deleteextattr *auxt = auxbuf;
1172 if (pops->puffs_deleteextattr == NULL) {
1173 error = 0;
1174 break;
1175 }
1176
1177 error = pops->puffs_deleteextattr(pcc,
1178 preq->preq_cookie, );
1179 break;
1180 }
1181
1182 case PUFFS_VN_SETEXTATTR:
1183 {
1184 struct puffs_vnreq_setextattr *auxt = auxbuf;
1185 if (pops->puffs_setextattr == NULL) {
1186 error = 0;
1187 break;
1188 }
1189
1190 error = pops->puffs_setextattr(pcc,
1191 preq->preq_cookie, );
1192 break;
1193 }
1194
1195 #endif
1196