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