Home | History | Annotate | Line # | Download | only in libpuffs
puffs.c revision 1.26
      1 /*	$NetBSD: puffs.c,v 1.26 2007/01/20 13:52:14 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.26 2007/01/20 13:52:14 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_putreq *ppr,
    345 	struct puffs_req *preq)
    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(ppr, pcc);
    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_putreq *ppr, struct puffs_cc *pcc)
    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 		default:
    452 			/*
    453 			 * I guess the kernel sees this one coming
    454 			 */
    455 			error = EINVAL;
    456 			break;
    457 		}
    458 
    459 	/* XXX: audit return values */
    460 	/* XXX: sync with kernel */
    461 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
    462 		switch (preq->preq_optype) {
    463 		case PUFFS_VN_LOOKUP:
    464 		{
    465 			struct puffs_vnreq_lookup *auxt = auxbuf;
    466 			struct puffs_cn pcn;
    467 
    468 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    469 			if (buildpath) {
    470 				if (pcn.pcn_flags & PUFFS_ISDOTDOT) {
    471 					buildpath = 0;
    472 				} else {
    473 					error = puffs_path_pcnbuild(pu, &pcn,
    474 					    preq->preq_cookie);
    475 					if (error)
    476 						break;
    477 				}
    478 			}
    479 
    480 			/* lookup *must* be present */
    481 			error = pops->puffs_node_lookup(pcc, preq->preq_cookie,
    482 			    &auxt->pvnr_newnode, &auxt->pvnr_vtype,
    483 			    &auxt->pvnr_size, &auxt->pvnr_rdev, &pcn);
    484 
    485 			if (buildpath) {
    486 				if (error) {
    487 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    488 				} else {
    489 					struct puffs_node *pn;
    490 
    491 					/*
    492 					 * did we get a new node or a
    493 					 * recycled node?
    494 					 * XXX: mapping assumption
    495 					 */
    496 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    497 					if (pn->pn_po.po_path == NULL)
    498 						pn->pn_po = pcn.pcn_po_full;
    499 					else
    500 						pu->pu_pathfree(pu,
    501 						    &pcn.pcn_po_full);
    502 				}
    503 			}
    504 
    505 			break;
    506 		}
    507 
    508 		case PUFFS_VN_CREATE:
    509 		{
    510 			struct puffs_vnreq_create *auxt = auxbuf;
    511 			struct puffs_cn pcn;
    512 			if (pops->puffs_node_create == NULL) {
    513 				error = 0;
    514 				break;
    515 			}
    516 
    517 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    518 			if (buildpath) {
    519 				error = puffs_path_pcnbuild(pu, &pcn,
    520 				    preq->preq_cookie);
    521 				if (error)
    522 					break;
    523 			}
    524 
    525 			error = pops->puffs_node_create(pcc,
    526 			    preq->preq_cookie, &auxt->pvnr_newnode,
    527 			    &pcn, &auxt->pvnr_va);
    528 
    529 			if (buildpath) {
    530 				if (error) {
    531 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    532 				} else {
    533 					struct puffs_node *pn;
    534 
    535 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    536 					pn->pn_po = pcn.pcn_po_full;
    537 				}
    538 			}
    539 
    540 			break;
    541 		}
    542 
    543 		case PUFFS_VN_MKNOD:
    544 		{
    545 			struct puffs_vnreq_mknod *auxt = auxbuf;
    546 			struct puffs_cn pcn;
    547 			if (pops->puffs_node_mknod == NULL) {
    548 				error = 0;
    549 				break;
    550 			}
    551 
    552 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    553 			if (buildpath) {
    554 				error = puffs_path_pcnbuild(pu, &pcn,
    555 				    preq->preq_cookie);
    556 				if (error)
    557 					break;
    558 			}
    559 
    560 			error = pops->puffs_node_mknod(pcc,
    561 			    preq->preq_cookie, &auxt->pvnr_newnode,
    562 			    &pcn, &auxt->pvnr_va);
    563 
    564 			if (buildpath) {
    565 				if (error) {
    566 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    567 				} else {
    568 					struct puffs_node *pn;
    569 
    570 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    571 					pn->pn_po = pcn.pcn_po_full;
    572 				}
    573 			}
    574 
    575 			break;
    576 		}
    577 
    578 		case PUFFS_VN_OPEN:
    579 		{
    580 			struct puffs_vnreq_open *auxt = auxbuf;
    581 			if (pops->puffs_node_open == NULL) {
    582 				error = 0;
    583 				break;
    584 			}
    585 
    586 			error = pops->puffs_node_open(pcc,
    587 			    preq->preq_cookie, auxt->pvnr_mode,
    588 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    589 			break;
    590 		}
    591 
    592 		case PUFFS_VN_CLOSE:
    593 		{
    594 			struct puffs_vnreq_close *auxt = auxbuf;
    595 			if (pops->puffs_node_close == NULL) {
    596 				error = 0;
    597 				break;
    598 			}
    599 
    600 			error = pops->puffs_node_close(pcc,
    601 			    preq->preq_cookie, auxt->pvnr_fflag,
    602 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    603 			break;
    604 		}
    605 
    606 		case PUFFS_VN_ACCESS:
    607 		{
    608 			struct puffs_vnreq_access *auxt = auxbuf;
    609 			if (pops->puffs_node_access == NULL) {
    610 				error = 0;
    611 				break;
    612 			}
    613 
    614 			error = pops->puffs_node_access(pcc,
    615 			    preq->preq_cookie, auxt->pvnr_mode,
    616 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    617 			break;
    618 		}
    619 
    620 		case PUFFS_VN_GETATTR:
    621 		{
    622 			struct puffs_vnreq_getattr *auxt = auxbuf;
    623 			if (pops->puffs_node_getattr == NULL) {
    624 				error = EOPNOTSUPP;
    625 				break;
    626 			}
    627 
    628 			error = pops->puffs_node_getattr(pcc,
    629 			    preq->preq_cookie, &auxt->pvnr_va,
    630 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    631 			break;
    632 		}
    633 
    634 		case PUFFS_VN_SETATTR:
    635 		{
    636 			struct puffs_vnreq_setattr *auxt = auxbuf;
    637 			if (pops->puffs_node_setattr == NULL) {
    638 				error = EOPNOTSUPP;
    639 				break;
    640 			}
    641 
    642 			error = pops->puffs_node_setattr(pcc,
    643 			    preq->preq_cookie, &auxt->pvnr_va,
    644 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    645 			break;
    646 		}
    647 
    648 		case PUFFS_VN_MMAP:
    649 		{
    650 			struct puffs_vnreq_mmap *auxt = auxbuf;
    651 			if (pops->puffs_node_mmap == NULL) {
    652 				error = 0;
    653 				break;
    654 			}
    655 
    656 			error = pops->puffs_node_mmap(pcc,
    657 			    preq->preq_cookie, auxt->pvnr_fflags,
    658 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    659 			break;
    660 		}
    661 
    662 		case PUFFS_VN_FSYNC:
    663 		{
    664 			struct puffs_vnreq_fsync *auxt = auxbuf;
    665 			if (pops->puffs_node_fsync == NULL) {
    666 				error = 0;
    667 				break;
    668 			}
    669 
    670 			error = pops->puffs_node_fsync(pcc,
    671 			    preq->preq_cookie, &auxt->pvnr_cred,
    672 			    auxt->pvnr_flags, auxt->pvnr_offlo,
    673 			    auxt->pvnr_offhi, auxt->pvnr_pid);
    674 			break;
    675 		}
    676 
    677 		case PUFFS_VN_SEEK:
    678 		{
    679 			struct puffs_vnreq_seek *auxt = auxbuf;
    680 			if (pops->puffs_node_seek == NULL) {
    681 				error = 0;
    682 				break;
    683 			}
    684 
    685 			error = pops->puffs_node_seek(pcc,
    686 			    preq->preq_cookie, auxt->pvnr_oldoff,
    687 			    auxt->pvnr_newoff, &auxt->pvnr_cred);
    688 			break;
    689 		}
    690 
    691 		case PUFFS_VN_REMOVE:
    692 		{
    693 			struct puffs_vnreq_remove *auxt = auxbuf;
    694 			struct puffs_cn pcn;
    695 			if (pops->puffs_node_remove == NULL) {
    696 				error = 0;
    697 				break;
    698 			}
    699 
    700 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    701 
    702 			error = pops->puffs_node_remove(pcc,
    703 			    preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
    704 			break;
    705 		}
    706 
    707 		case PUFFS_VN_LINK:
    708 		{
    709 			struct puffs_vnreq_link *auxt = auxbuf;
    710 			struct puffs_cn pcn;
    711 			if (pops->puffs_node_link == NULL) {
    712 				error = 0;
    713 				break;
    714 			}
    715 
    716 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    717 			if (buildpath) {
    718 				error = puffs_path_pcnbuild(pu, &pcn,
    719 				    preq->preq_cookie);
    720 				if (error)
    721 					break;
    722 			}
    723 
    724 			error = pops->puffs_node_link(pcc,
    725 			    preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
    726 			if (buildpath)
    727 				pu->pu_pathfree(pu, &pcn.pcn_po_full);
    728 
    729 			break;
    730 		}
    731 
    732 		case PUFFS_VN_RENAME:
    733 		{
    734 			struct puffs_vnreq_rename *auxt = auxbuf;
    735 			struct puffs_cn pcn_src, pcn_targ;
    736 			struct puffs_node *pn_src;
    737 
    738 			if (pops->puffs_node_rename == NULL) {
    739 				error = 0;
    740 				break;
    741 			}
    742 
    743 			pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
    744 			pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
    745 			if (buildpath) {
    746 				pn_src = auxt->pvnr_cookie_src;
    747 				pcn_src.pcn_po_full = pn_src->pn_po;
    748 
    749 				error = puffs_path_pcnbuild(pu, &pcn_targ,
    750 				    auxt->pvnr_cookie_targdir);
    751 				if (error)
    752 					break;
    753 			}
    754 
    755 			error = pops->puffs_node_rename(pcc,
    756 			    preq->preq_cookie, auxt->pvnr_cookie_src,
    757 			    &pcn_src, auxt->pvnr_cookie_targdir,
    758 			    auxt->pvnr_cookie_targ, &pcn_targ);
    759 
    760 			if (buildpath) {
    761 				if (error) {
    762 					pu->pu_pathfree(pu,
    763 					    &pcn_targ.pcn_po_full);
    764 				} else {
    765 					struct puffs_pathinfo pi;
    766 					struct puffs_pathobj po_old;
    767 
    768 					/* handle this node */
    769 					po_old = pn_src->pn_po;
    770 					pn_src->pn_po = pcn_targ.pcn_po_full;
    771 
    772 					if (pn_src->pn_va.va_type != VDIR) {
    773 						pu->pu_pathfree(pu, &po_old);
    774 						break;
    775 					}
    776 
    777 					/* handle all child nodes for DIRs */
    778 					pi.pi_old = &pcn_src.pcn_po_full;
    779 					pi.pi_new = &pcn_targ.pcn_po_full;
    780 
    781 					if (puffs_pn_nodewalk(pu,
    782 					    puffs_path_prefixadj, &pi) != NULL)
    783 						error = ENOMEM;
    784 					pu->pu_pathfree(pu, &po_old);
    785 				}
    786 			}
    787 			break;
    788 		}
    789 
    790 		case PUFFS_VN_MKDIR:
    791 		{
    792 			struct puffs_vnreq_mkdir *auxt = auxbuf;
    793 			struct puffs_cn pcn;
    794 			if (pops->puffs_node_mkdir == NULL) {
    795 				error = 0;
    796 				break;
    797 			}
    798 
    799 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    800 			if (buildpath) {
    801 				error = puffs_path_pcnbuild(pu, &pcn,
    802 				    preq->preq_cookie);
    803 				if (error)
    804 					break;
    805 			}
    806 
    807 			error = pops->puffs_node_mkdir(pcc,
    808 			    preq->preq_cookie, &auxt->pvnr_newnode,
    809 			    &pcn, &auxt->pvnr_va);
    810 
    811 			if (buildpath) {
    812 				if (error) {
    813 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    814 				} else {
    815 					struct puffs_node *pn;
    816 
    817 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    818 					pn->pn_po = pcn.pcn_po_full;
    819 				}
    820 			}
    821 
    822 			break;
    823 		}
    824 
    825 		case PUFFS_VN_RMDIR:
    826 		{
    827 			struct puffs_vnreq_rmdir *auxt = auxbuf;
    828 			struct puffs_cn pcn;
    829 			if (pops->puffs_node_rmdir == NULL) {
    830 				error = 0;
    831 				break;
    832 			}
    833 
    834 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    835 
    836 			error = pops->puffs_node_rmdir(pcc,
    837 			    preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
    838 			break;
    839 		}
    840 
    841 		case PUFFS_VN_SYMLINK:
    842 		{
    843 			struct puffs_vnreq_symlink *auxt = auxbuf;
    844 			struct puffs_cn pcn;
    845 			if (pops->puffs_node_symlink == NULL) {
    846 				error = 0;
    847 				break;
    848 			}
    849 
    850 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    851 			if (buildpath) {
    852 				error = puffs_path_pcnbuild(pu, &pcn,
    853 				    preq->preq_cookie);
    854 				if (error)
    855 					break;
    856 			}
    857 
    858 			error = pops->puffs_node_symlink(pcc,
    859 			    preq->preq_cookie, &auxt->pvnr_newnode,
    860 			    &pcn, &auxt->pvnr_va, auxt->pvnr_link);
    861 
    862 			if (buildpath) {
    863 				if (error) {
    864 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    865 				} else {
    866 					struct puffs_node *pn;
    867 
    868 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    869 					pn->pn_po = pcn.pcn_po_full;
    870 				}
    871 			}
    872 
    873 			break;
    874 		}
    875 
    876 		case PUFFS_VN_READDIR:
    877 		{
    878 			struct puffs_vnreq_readdir *auxt = auxbuf;
    879 			size_t res;
    880 
    881 			if (pops->puffs_node_readdir == NULL) {
    882 				error = 0;
    883 				break;
    884 			}
    885 
    886 			res = auxt->pvnr_resid;
    887 			error = pops->puffs_node_readdir(pcc,
    888 			    preq->preq_cookie, auxt->pvnr_dent,
    889 			    &auxt->pvnr_cred, &auxt->pvnr_offset,
    890 			    &auxt->pvnr_resid);
    891 
    892 			/* need to move a bit more */
    893 			preq->preq_buflen = sizeof(struct puffs_vnreq_readdir)
    894 			    + (res - auxt->pvnr_resid);
    895 			break;
    896 		}
    897 
    898 		case PUFFS_VN_READLINK:
    899 		{
    900 			struct puffs_vnreq_readlink *auxt = auxbuf;
    901 			if (pops->puffs_node_readlink == NULL) {
    902 				error = EOPNOTSUPP;
    903 				break;
    904 			}
    905 
    906 			error = pops->puffs_node_readlink(pcc,
    907 			    preq->preq_cookie, &auxt->pvnr_cred,
    908 			    auxt->pvnr_link, &auxt->pvnr_linklen);
    909 			break;
    910 		}
    911 
    912 		case PUFFS_VN_RECLAIM:
    913 		{
    914 			struct puffs_vnreq_reclaim *auxt = auxbuf;
    915 			if (pops->puffs_node_reclaim == NULL) {
    916 				error = 0;
    917 				break;
    918 			}
    919 
    920 			error = pops->puffs_node_reclaim(pcc,
    921 			    preq->preq_cookie, auxt->pvnr_pid);
    922 			break;
    923 		}
    924 
    925 		case PUFFS_VN_INACTIVE:
    926 		{
    927 			struct puffs_vnreq_inactive *auxt = auxbuf;
    928 			if (pops->puffs_node_inactive == NULL) {
    929 				error = EOPNOTSUPP;
    930 				break;
    931 			}
    932 
    933 			error = pops->puffs_node_inactive(pcc,
    934 			    preq->preq_cookie, auxt->pvnr_pid,
    935 			    &auxt->pvnr_backendrefs);
    936 			break;
    937 		}
    938 
    939 		case PUFFS_VN_PATHCONF:
    940 		{
    941 			struct puffs_vnreq_pathconf *auxt = auxbuf;
    942 			if (pops->puffs_node_pathconf == NULL) {
    943 				error = 0;
    944 				break;
    945 			}
    946 
    947 			error = pops->puffs_node_pathconf(pcc,
    948 			    preq->preq_cookie, auxt->pvnr_name,
    949 			    &auxt->pvnr_retval);
    950 			break;
    951 		}
    952 
    953 		case PUFFS_VN_ADVLOCK:
    954 		{
    955 			struct puffs_vnreq_advlock *auxt = auxbuf;
    956 			if (pops->puffs_node_advlock == NULL) {
    957 				error = 0;
    958 				break;
    959 			}
    960 
    961 			error = pops->puffs_node_advlock(pcc,
    962 			    preq->preq_cookie, auxt->pvnr_id, auxt->pvnr_op,
    963 			    &auxt->pvnr_fl, auxt->pvnr_flags);
    964 			break;
    965 		}
    966 
    967 		case PUFFS_VN_PRINT:
    968 		{
    969 			if (pops->puffs_node_print == NULL) {
    970 				error = 0;
    971 				break;
    972 			}
    973 
    974 			error = pops->puffs_node_print(pcc,
    975 			    preq->preq_cookie);
    976 			break;
    977 		}
    978 
    979 		case PUFFS_VN_READ:
    980 		{
    981 			struct puffs_vnreq_read *auxt = auxbuf;
    982 			size_t res;
    983 
    984 			if (pops->puffs_node_read == NULL) {
    985 				error = EIO;
    986 				break;
    987 			}
    988 
    989 			res = auxt->pvnr_resid;
    990 			error = pops->puffs_node_read(pcc,
    991 			    preq->preq_cookie, auxt->pvnr_data,
    992 			    auxt->pvnr_offset, &auxt->pvnr_resid,
    993 			    &auxt->pvnr_cred, auxt->pvnr_ioflag);
    994 
    995 			/* need to move a bit more */
    996 			preq->preq_buflen = sizeof(struct puffs_vnreq_read)
    997 			    + (res - auxt->pvnr_resid);
    998 			break;
    999 		}
   1000 
   1001 		case PUFFS_VN_WRITE:
   1002 		{
   1003 			struct puffs_vnreq_write *auxt = auxbuf;
   1004 
   1005 			if (pops->puffs_node_write == NULL) {
   1006 				error = EIO;
   1007 				break;
   1008 			}
   1009 
   1010 			error = pops->puffs_node_write(pcc,
   1011 			    preq->preq_cookie, auxt->pvnr_data,
   1012 			    auxt->pvnr_offset, &auxt->pvnr_resid,
   1013 			    &auxt->pvnr_cred, auxt->pvnr_ioflag);
   1014 
   1015 			/* don't need to move data back to the kernel */
   1016 			preq->preq_buflen = sizeof(struct puffs_vnreq_write);
   1017 			break;
   1018 		}
   1019 
   1020 /* holy bitrot, ryydman! */
   1021 #if 0
   1022 		case PUFFS_VN_IOCTL:
   1023 			error = pops->puffs_node_ioctl1(pcc, preq->preq_cookie,
   1024 			     (struct puffs_vnreq_ioctl *)auxbuf, &pop);
   1025 			if (error != 0)
   1026 				break;
   1027 			pop.pso_reqid = preq->preq_id;
   1028 
   1029 			/* let the kernel do it's intermediate duty */
   1030 			error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
   1031 			/*
   1032 			 * XXX: I don't actually know what the correct
   1033 			 * thing to do in case of an error is, so I'll
   1034 			 * just ignore it for the time being.
   1035 			 */
   1036 			error = pops->puffs_node_ioctl2(pcc, preq->preq_cookie,
   1037 			    (struct puffs_vnreq_ioctl *)auxbuf, &pop);
   1038 			break;
   1039 
   1040 		case PUFFS_VN_FCNTL:
   1041 			error = pops->puffs_node_fcntl1(pcc, preq->preq_cookie,
   1042 			     (struct puffs_vnreq_fcntl *)auxbuf, &pop);
   1043 			if (error != 0)
   1044 				break;
   1045 			pop.pso_reqid = preq->preq_id;
   1046 
   1047 			/* let the kernel do it's intermediate duty */
   1048 			error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
   1049 			/*
   1050 			 * XXX: I don't actually know what the correct
   1051 			 * thing to do in case of an error is, so I'll
   1052 			 * just ignore it for the time being.
   1053 			 */
   1054 			error = pops->puffs_node_fcntl2(pcc, preq->preq_cookie,
   1055 			    (struct puffs_vnreq_fcntl *)auxbuf, &pop);
   1056 			break;
   1057 #endif
   1058 
   1059 		default:
   1060 			printf("inval op %d\n", preq->preq_optype);
   1061 			error = EINVAL;
   1062 			break;
   1063 		}
   1064 	} else {
   1065 		/*
   1066 		 * this one also
   1067 		 */
   1068 		error = EINVAL;
   1069 	}
   1070 
   1071 	preq->preq_rv = error;
   1072 
   1073 	pcc->pcc_rv = rv;
   1074 	pcc->pcc_flags |= PCC_DONE;
   1075 }
   1076 
   1077 
   1078 #if 0
   1079 		case PUFFS_VN_POLL:
   1080 		{
   1081 			struct puffs_vnreq_poll *auxt = auxbuf;
   1082 			if (pops->puffs_node_poll == NULL) {
   1083 				error = 0;
   1084 				break;
   1085 			}
   1086 
   1087 			error = pops->puffs_node_poll(pcc,
   1088 			    preq->preq_cookie, preq-);
   1089 			break;
   1090 		}
   1091 
   1092 		case PUFFS_VN_KQFILTER:
   1093 		{
   1094 			struct puffs_vnreq_kqfilter *auxt = auxbuf;
   1095 			if (pops->puffs_node_kqfilter == NULL) {
   1096 				error = 0;
   1097 				break;
   1098 			}
   1099 
   1100 			error = pops->puffs_node_kqfilter(pcc,
   1101 			    preq->preq_cookie, );
   1102 			break;
   1103 		}
   1104 
   1105 		case PUFFS_VN_CLOSEEXTATTR:
   1106 		{
   1107 			struct puffs_vnreq_closeextattr *auxt = auxbuf;
   1108 			if (pops->puffs_closeextattr == NULL) {
   1109 				error = 0;
   1110 				break;
   1111 			}
   1112 
   1113 			error = pops->puffs_closeextattr(pcc,
   1114 			    preq->preq_cookie, );
   1115 			break;
   1116 		}
   1117 
   1118 		case PUFFS_VN_GETEXTATTR:
   1119 		{
   1120 			struct puffs_vnreq_getextattr *auxt = auxbuf;
   1121 			if (pops->puffs_getextattr == NULL) {
   1122 				error = 0;
   1123 				break;
   1124 			}
   1125 
   1126 			error = pops->puffs_getextattr(pcc,
   1127 			    preq->preq_cookie, );
   1128 			break;
   1129 		}
   1130 
   1131 		case PUFFS_VN_LISTEXTATTR:
   1132 		{
   1133 			struct puffs_vnreq_listextattr *auxt = auxbuf;
   1134 			if (pops->puffs_listextattr == NULL) {
   1135 				error = 0;
   1136 				break;
   1137 			}
   1138 
   1139 			error = pops->puffs_listextattr(pcc,
   1140 			    preq->preq_cookie, );
   1141 			break;
   1142 		}
   1143 
   1144 		case PUFFS_VN_OPENEXTATTR:
   1145 		{
   1146 			struct puffs_vnreq_openextattr *auxt = auxbuf;
   1147 			if (pops->puffs_openextattr == NULL) {
   1148 				error = 0;
   1149 				break;
   1150 			}
   1151 
   1152 			error = pops->puffs_openextattr(pcc,
   1153 			    preq->preq_cookie, );
   1154 			break;
   1155 		}
   1156 
   1157 		case PUFFS_VN_DELETEEXTATTR:
   1158 		{
   1159 			struct puffs_vnreq_deleteextattr *auxt = auxbuf;
   1160 			if (pops->puffs_deleteextattr == NULL) {
   1161 				error = 0;
   1162 				break;
   1163 			}
   1164 
   1165 			error = pops->puffs_deleteextattr(pcc,
   1166 			    preq->preq_cookie, );
   1167 			break;
   1168 		}
   1169 
   1170 		case PUFFS_VN_SETEXTATTR:
   1171 		{
   1172 			struct puffs_vnreq_setextattr *auxt = auxbuf;
   1173 			if (pops->puffs_setextattr == NULL) {
   1174 				error = 0;
   1175 				break;
   1176 			}
   1177 
   1178 			error = pops->puffs_setextattr(pcc,
   1179 			    preq->preq_cookie, );
   1180 			break;
   1181 		}
   1182 
   1183 #endif
   1184