Home | History | Annotate | Line # | Download | only in libpuffs
puffs.c revision 1.20
      1  1.20  pooka /*	$NetBSD: puffs.c,v 1.20 2007/01/02 15:53:05 pooka Exp $	*/
      2   1.1  pooka 
      3   1.1  pooka /*
      4   1.1  pooka  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
      5   1.1  pooka  *
      6   1.1  pooka  * Development of this software was supported by the
      7   1.1  pooka  * Google Summer of Code program and the Ulla Tuominen Foundation.
      8   1.1  pooka  * The Google SoC project was mentored by Bill Studenmund.
      9   1.1  pooka  *
     10   1.1  pooka  * Redistribution and use in source and binary forms, with or without
     11   1.1  pooka  * modification, are permitted provided that the following conditions
     12   1.1  pooka  * are met:
     13   1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     14   1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     15   1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  pooka  *    documentation and/or other materials provided with the distribution.
     18   1.1  pooka  * 3. The name of the company nor the name of the author may be used to
     19   1.1  pooka  *    endorse or promote products derived from this software without specific
     20   1.1  pooka  *    prior written permission.
     21   1.1  pooka  *
     22   1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     23   1.1  pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24   1.1  pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25   1.1  pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26   1.1  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28   1.1  pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1  pooka  * SUCH DAMAGE.
     33   1.1  pooka  */
     34   1.1  pooka 
     35   1.1  pooka #include <sys/cdefs.h>
     36   1.1  pooka #if !defined(lint)
     37  1.20  pooka __RCSID("$NetBSD: puffs.c,v 1.20 2007/01/02 15:53:05 pooka Exp $");
     38   1.1  pooka #endif /* !lint */
     39   1.1  pooka 
     40   1.1  pooka #include <sys/param.h>
     41   1.1  pooka #include <sys/mount.h>
     42   1.1  pooka 
     43   1.9  pooka #include <assert.h>
     44  1.12  pooka #include <err.h>
     45   1.1  pooka #include <errno.h>
     46   1.1  pooka #include <fcntl.h>
     47   1.1  pooka #include <puffs.h>
     48   1.1  pooka #include <puffsdump.h>
     49  1.19  pooka #include <stdarg.h>
     50   1.1  pooka #include <stdio.h>
     51   1.1  pooka #include <stdlib.h>
     52   1.1  pooka #include <string.h>
     53   1.1  pooka #include <syslog.h>
     54   1.1  pooka #include <unistd.h>
     55   1.1  pooka 
     56  1.19  pooka #include "puffs_priv.h"
     57  1.19  pooka 
     58  1.19  pooka static int do_buildpath(struct puffs_cn *, void *);
     59   1.1  pooka 
     60  1.10  pooka #define FILLOP(lower, upper)						\
     61  1.10  pooka do {									\
     62  1.13  pooka 	if (pops->puffs_node_##lower)					\
     63  1.10  pooka 		opmask[PUFFS_VN_##upper] = 1;				\
     64  1.10  pooka } while (/*CONSTCOND*/0)
     65  1.10  pooka static void
     66  1.13  pooka fillvnopmask(struct puffs_ops *pops, uint8_t *opmask)
     67  1.10  pooka {
     68  1.10  pooka 
     69  1.10  pooka 	memset(opmask, 0, PUFFS_VN_MAX);
     70  1.10  pooka 
     71  1.10  pooka 	FILLOP(create,   CREATE);
     72  1.10  pooka 	FILLOP(mknod,    MKNOD);
     73  1.10  pooka 	FILLOP(open,     OPEN);
     74  1.10  pooka 	FILLOP(close,    CLOSE);
     75  1.10  pooka 	FILLOP(access,   ACCESS);
     76  1.10  pooka 	FILLOP(getattr,  GETATTR);
     77  1.10  pooka 	FILLOP(setattr,  SETATTR);
     78  1.10  pooka 	FILLOP(poll,     POLL); /* XXX: not ready in kernel */
     79  1.10  pooka 	FILLOP(revoke,   REVOKE);
     80  1.16  pooka 	FILLOP(mmap,     MMAP);
     81  1.10  pooka 	FILLOP(fsync,    FSYNC);
     82  1.10  pooka 	FILLOP(seek,     SEEK);
     83  1.10  pooka 	FILLOP(remove,   REMOVE);
     84  1.10  pooka 	FILLOP(link,     LINK);
     85  1.10  pooka 	FILLOP(rename,   RENAME);
     86  1.10  pooka 	FILLOP(mkdir,    MKDIR);
     87  1.10  pooka 	FILLOP(rmdir,    RMDIR);
     88  1.10  pooka 	FILLOP(symlink,  SYMLINK);
     89  1.10  pooka 	FILLOP(readdir,  READDIR);
     90  1.10  pooka 	FILLOP(readlink, READLINK);
     91  1.10  pooka 	FILLOP(reclaim,  RECLAIM);
     92  1.10  pooka 	FILLOP(inactive, INACTIVE);
     93  1.10  pooka 	FILLOP(print,    PRINT);
     94  1.10  pooka 	FILLOP(read,     READ);
     95  1.10  pooka 	FILLOP(write,    WRITE);
     96  1.10  pooka 
     97  1.10  pooka 	/* XXX: not implemented in the kernel */
     98  1.10  pooka 	FILLOP(getextattr, GETEXTATTR);
     99  1.10  pooka 	FILLOP(setextattr, SETEXTATTR);
    100  1.10  pooka 	FILLOP(listextattr, LISTEXTATTR);
    101  1.19  pooka }
    102  1.19  pooka #undef FILLOP
    103  1.19  pooka 
    104  1.19  pooka int
    105  1.19  pooka puffs_getselectable(struct puffs_usermount *pu)
    106  1.19  pooka {
    107  1.10  pooka 
    108  1.19  pooka 	return pu->pu_fd;
    109  1.10  pooka }
    110  1.19  pooka 
    111  1.19  pooka int
    112  1.19  pooka puffs_setblockingmode(struct puffs_usermount *pu, int mode)
    113  1.19  pooka {
    114  1.19  pooka 	int x;
    115  1.19  pooka 
    116  1.19  pooka 	x = mode;
    117  1.19  pooka 	return ioctl(pu->pu_fd, FIONBIO, &x);
    118  1.19  pooka }
    119  1.19  pooka 
    120  1.19  pooka int
    121  1.19  pooka puffs_getstate(struct puffs_usermount *pu)
    122  1.19  pooka {
    123  1.19  pooka 
    124  1.19  pooka 	return pu->pu_state;
    125  1.19  pooka }
    126  1.19  pooka 
    127  1.19  pooka void
    128  1.19  pooka puffs_setstacksize(struct puffs_usermount *pu, size_t ss)
    129  1.19  pooka {
    130  1.19  pooka 
    131  1.19  pooka 	pu->pu_cc_stacksize = ss;
    132  1.19  pooka }
    133  1.19  pooka 
    134  1.19  pooka /*
    135  1.19  pooka  * in case the server wants to use some other scheme for paths, it
    136  1.19  pooka  * can (*must*) call this in mount.
    137  1.19  pooka  */
    138  1.19  pooka int
    139  1.19  pooka puffs_setrootpath(struct puffs_usermount *pu, const char *rootpath)
    140  1.19  pooka {
    141  1.19  pooka 	struct puffs_node *pnr;
    142  1.19  pooka 
    143  1.19  pooka 	pnr = pu->pu_pn_root;
    144  1.19  pooka 	if (pnr == NULL) {
    145  1.19  pooka 		errno = ENOENT;
    146  1.19  pooka 		return -1;
    147  1.19  pooka 	}
    148  1.19  pooka 
    149  1.19  pooka 	free(pnr->pn_path);
    150  1.19  pooka 	pnr->pn_path = strdup(rootpath);
    151  1.19  pooka 	if (pnr->pn_path == NULL)
    152  1.19  pooka 		return -1;
    153  1.19  pooka 	pnr->pn_plen = strlen(pnr->pn_path) + 1; /* yes, count nul */
    154  1.19  pooka 
    155  1.19  pooka 	return 0;
    156  1.19  pooka }
    157  1.19  pooka 
    158  1.19  pooka 
    159  1.19  pooka enum {PUFFCALL_ANSWER, PUFFCALL_IGNORE, PUFFCALL_AGAIN};
    160  1.10  pooka 
    161   1.1  pooka struct puffs_usermount *
    162  1.20  pooka _puffs_mount(int develv, struct puffs_ops *pops, const char *dir, int mntflags,
    163  1.19  pooka 	const char *puffsname, void *priv, uint32_t pflags, size_t maxreqlen)
    164   1.1  pooka {
    165   1.6  pooka 	struct puffs_startreq sreq;
    166   1.1  pooka 	struct puffs_args pargs;
    167   1.1  pooka 	struct puffs_usermount *pu;
    168   1.6  pooka 	int fd = 0, rv;
    169   1.1  pooka 
    170  1.20  pooka 	if (develv != PUFFS_DEVEL_LIBVERSION) {
    171  1.20  pooka 		warnx("puffs_mount: mounting with lib version %d, need %d",
    172  1.20  pooka 		    develv, PUFFS_DEVEL_LIBVERSION);
    173  1.20  pooka 		errno = EINVAL;
    174  1.20  pooka 		return NULL;
    175  1.20  pooka 	}
    176  1.20  pooka 
    177  1.13  pooka 	if (pops->puffs_fs_mount == NULL) {
    178   1.6  pooka 		errno = EINVAL;
    179   1.6  pooka 		return NULL;
    180   1.6  pooka 	}
    181   1.1  pooka 
    182   1.1  pooka 	fd = open("/dev/puffs", O_RDONLY);
    183   1.1  pooka 	if (fd == -1)
    184   1.1  pooka 		return NULL;
    185  1.12  pooka 	if (fd <= 2)
    186  1.12  pooka 		warnx("puffs_mount: device fd %d (<= 2), sure this is "
    187  1.12  pooka 		    "what you want?", fd);
    188   1.1  pooka 
    189  1.20  pooka 	pargs.pa_vers = PUFFSDEVELVERS | PUFFSVERSION;
    190  1.11  pooka 	pargs.pa_flags = PUFFS_FLAG_KERN(pflags);
    191   1.1  pooka 	pargs.pa_fd = fd;
    192   1.1  pooka 	pargs.pa_maxreqlen = maxreqlen;
    193  1.13  pooka 	fillvnopmask(pops, pargs.pa_vnopmask);
    194   1.1  pooka 	(void)strlcpy(pargs.pa_name, puffsname, sizeof(pargs.pa_name));
    195   1.1  pooka 
    196   1.1  pooka 	pu = malloc(sizeof(struct puffs_usermount));
    197   1.1  pooka 	if (!pu)
    198   1.6  pooka 		return NULL;
    199   1.1  pooka 
    200   1.1  pooka 	pu->pu_flags = pflags;
    201  1.13  pooka 	pu->pu_ops = *pops;
    202  1.19  pooka 	free(pops);
    203   1.1  pooka 	pu->pu_fd = fd;
    204  1.19  pooka 	pu->pu_privdata = priv;
    205  1.19  pooka 	pu->pu_cc_stacksize = PUFFS_CC_STACKSIZE_DEFAULT;
    206   1.1  pooka 	LIST_INIT(&pu->pu_pnodelst);
    207   1.1  pooka 
    208  1.19  pooka 	pu->pu_state = PUFFS_STATE_MOUNTING;
    209   1.1  pooka 	if (mount(MOUNT_PUFFS, dir, mntflags, &pargs) == -1)
    210   1.6  pooka 		goto failfree;
    211   1.1  pooka 	pu->pu_maxreqlen = pargs.pa_maxreqlen;
    212   1.1  pooka 
    213  1.19  pooka 	if ((rv = pops->puffs_fs_mount(pu, &sreq.psr_cookie,
    214  1.19  pooka 	    &sreq.psr_sb)) != 0) {
    215   1.8  pooka 		errno = rv;
    216   1.8  pooka 		goto failfree;
    217   1.8  pooka 	}
    218   1.8  pooka 
    219   1.1  pooka 	/* tell kernel we're flying */
    220   1.6  pooka 	if (ioctl(pu->pu_fd, PUFFSSTARTOP, &sreq) == -1)
    221   1.6  pooka 		goto failfree;
    222   1.6  pooka 
    223  1.19  pooka 	pu->pu_state = PUFFS_STATE_RUNNING;
    224   1.1  pooka 	return pu;
    225   1.6  pooka 
    226   1.1  pooka  failfree:
    227   1.6  pooka 	/* can't unmount() from here for obvious reasons */
    228   1.6  pooka 	if (fd)
    229   1.6  pooka 		close(fd);
    230   1.1  pooka 	free(pu);
    231   1.1  pooka 	return NULL;
    232   1.1  pooka }
    233   1.1  pooka 
    234   1.1  pooka int
    235   1.9  pooka puffs_mainloop(struct puffs_usermount *pu, int flags)
    236   1.1  pooka {
    237  1.19  pooka 	struct puffs_getreq *pgr;
    238  1.19  pooka 	struct puffs_putreq *ppr;
    239   1.1  pooka 	int rv;
    240   1.1  pooka 
    241  1.19  pooka 	rv = -1;
    242  1.19  pooka 	pgr = puffs_makegetreq(pu, pu->pu_maxreqlen, 0);
    243  1.19  pooka 	if (pgr == NULL)
    244  1.19  pooka 		return -1;
    245  1.18    alc 
    246  1.19  pooka 	ppr = puffs_makeputreq(pu);
    247  1.19  pooka 	if (ppr == NULL) {
    248  1.19  pooka 		puffs_destroygetreq(pgr);
    249   1.1  pooka 		return -1;
    250  1.19  pooka 	}
    251  1.19  pooka 
    252  1.19  pooka 	if ((flags & PUFFSLOOP_NODAEMON) == 0)
    253  1.19  pooka 		if (daemon(0, 0) == -1)
    254  1.19  pooka 			goto out;
    255   1.1  pooka 
    256  1.19  pooka 	/* XXX: should be a bit more robust with errors here */
    257  1.19  pooka 	while (puffs_getstate(pu) == PUFFS_STATE_RUNNING
    258  1.19  pooka 	    || puffs_getstate(pu) == PUFFS_STATE_UNMOUNTING) {
    259  1.19  pooka 		puffs_resetputreq(ppr);
    260  1.19  pooka 
    261  1.19  pooka 		if (puffs_handlereqs(pu, pgr, ppr, 0) == -1) {
    262  1.19  pooka 			rv = -1;
    263  1.19  pooka 			break;
    264  1.19  pooka 		}
    265  1.19  pooka 		if (puffs_putputreq(ppr) == -1) {
    266  1.19  pooka 			rv = -1;
    267  1.19  pooka 			break;
    268  1.19  pooka 		}
    269  1.18    alc 	}
    270  1.18    alc 
    271  1.19  pooka  out:
    272  1.19  pooka 	puffs_destroyputreq(ppr);
    273  1.19  pooka 	puffs_destroygetreq(pgr);
    274  1.18    alc 	return rv;
    275   1.1  pooka }
    276   1.1  pooka 
    277   1.1  pooka int
    278  1.19  pooka puffs_handlereqs(struct puffs_usermount *pu, struct puffs_getreq *pgr,
    279  1.19  pooka 	struct puffs_putreq *ppr, int maxops)
    280   1.1  pooka {
    281  1.12  pooka 	struct puffs_req *preq;
    282  1.19  pooka 	int pval;
    283  1.17  pooka 
    284  1.19  pooka 	puffs_setmaxgetreq(pgr, maxops);
    285  1.19  pooka 	if (puffs_loadgetreq(pgr) == -1)
    286  1.19  pooka 		return -1;
    287  1.12  pooka 
    288  1.19  pooka 	/* interlink pgr and ppr for diagnostic asserts */
    289  1.19  pooka 	pgr->pgr_nppr++;
    290  1.19  pooka 	ppr->ppr_pgr = pgr;
    291  1.19  pooka 
    292  1.19  pooka 	pval = 0;
    293  1.19  pooka 	while ((preq = puffs_getreq(pgr)) != NULL
    294  1.19  pooka 	    && pu->pu_state != PUFFS_STATE_UNMOUNTED)
    295  1.19  pooka 		pval = puffs_dopreq(pu, ppr, preq);
    296  1.12  pooka 
    297  1.19  pooka 	return pval;
    298  1.19  pooka }
    299   1.1  pooka 
    300  1.19  pooka int
    301  1.19  pooka puffs_dopreq(struct puffs_usermount *pu, struct puffs_putreq *ppr,
    302  1.19  pooka 	struct puffs_req *preq)
    303  1.19  pooka {
    304  1.19  pooka 	struct puffs_cc *pcc;
    305  1.19  pooka 	int rv;
    306  1.12  pooka 
    307  1.19  pooka 	if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
    308  1.19  pooka 		puffsdump_req(preq);
    309   1.1  pooka 
    310  1.19  pooka 	pcc = puffs_cc_create(pu, preq);
    311  1.19  pooka 	rv = puffs_docc(ppr, pcc);
    312   1.1  pooka 
    313  1.19  pooka 	if ((pcc->pcc_flags & PCC_DONE) == 0)
    314  1.19  pooka 		return 0;
    315  1.12  pooka 
    316  1.17  pooka 	return rv;
    317   1.1  pooka }
    318   1.1  pooka 
    319   1.1  pooka int
    320  1.19  pooka puffs_docc(struct puffs_putreq *ppr, struct puffs_cc *pcc)
    321   1.1  pooka {
    322  1.19  pooka 	int rv;
    323  1.19  pooka 
    324  1.19  pooka 	assert((pcc->pcc_flags & PCC_DONE) == 0);
    325   1.1  pooka 
    326  1.19  pooka 	puffs_cc_continue(pcc);
    327  1.19  pooka 	rv = pcc->pcc_rv;
    328  1.19  pooka 
    329  1.19  pooka 	if ((pcc->pcc_flags & PCC_DONE) == 0)
    330  1.19  pooka 		rv = PUFFCALL_AGAIN;
    331   1.1  pooka 
    332  1.19  pooka 	/* check if we need to store this reply */
    333  1.19  pooka 	switch (rv) {
    334  1.19  pooka 	case PUFFCALL_ANSWER:
    335  1.19  pooka 		puffs_putreq_cc(ppr, pcc);
    336  1.19  pooka 		break;
    337  1.19  pooka 	case PUFFCALL_AGAIN:
    338  1.19  pooka 	case PUFFCALL_IGNORE:
    339  1.19  pooka 		break;
    340  1.19  pooka 	default:
    341  1.19  pooka 		assert(/*CONSTCOND*/0);
    342  1.19  pooka 	}
    343   1.1  pooka 
    344  1.19  pooka 	return 0;
    345   1.1  pooka }
    346   1.1  pooka 
    347  1.19  pooka /* library private, but linked from callcontext.c */
    348  1.19  pooka 
    349  1.19  pooka void
    350  1.19  pooka puffs_calldispatcher(struct puffs_cc *pcc)
    351   1.1  pooka {
    352  1.19  pooka 	struct puffs_usermount *pu = pcc->pcc_pu;
    353  1.13  pooka 	struct puffs_ops *pops = &pu->pu_ops;
    354  1.19  pooka 	struct puffs_req *preq = pcc->pcc_preq;
    355  1.19  pooka 	void *auxbuf = preq; /* help with typecasting */
    356  1.19  pooka 	int error, rv, buildpath;
    357  1.19  pooka 
    358  1.19  pooka 	assert(pcc->pcc_flags & (PCC_ONCE | PCC_REALCC));
    359   1.1  pooka 
    360  1.12  pooka 	if (PUFFSOP_WANTREPLY(preq->preq_opclass))
    361  1.12  pooka 		rv = PUFFCALL_ANSWER;
    362  1.12  pooka 	else
    363  1.12  pooka 		rv = PUFFCALL_IGNORE;
    364   1.1  pooka 
    365  1.19  pooka 	buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
    366  1.12  pooka 
    367   1.5  pooka 	if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
    368   1.1  pooka 		switch (preq->preq_optype) {
    369   1.1  pooka 		case PUFFS_VFS_UNMOUNT:
    370   1.1  pooka 		{
    371  1.12  pooka 			struct puffs_vfsreq_unmount *auxt = auxbuf;
    372   1.1  pooka 
    373  1.19  pooka 			pu->pu_state = PUFFS_STATE_UNMOUNTING;
    374  1.19  pooka 			error = pops->puffs_fs_unmount(pcc,
    375   1.1  pooka 			    auxt->pvfsr_flags, auxt->pvfsr_pid);
    376  1.19  pooka 			if (!error)
    377  1.19  pooka 				pu->pu_state = PUFFS_STATE_UNMOUNTED;
    378  1.19  pooka 			else
    379  1.19  pooka 				pu->pu_state = PUFFS_STATE_RUNNING;
    380   1.1  pooka 			break;
    381   1.1  pooka 		}
    382   1.1  pooka 		case PUFFS_VFS_STATVFS:
    383   1.1  pooka 		{
    384  1.12  pooka 			struct puffs_vfsreq_statvfs *auxt = auxbuf;
    385   1.1  pooka 
    386  1.19  pooka 			error = pops->puffs_fs_statvfs(pcc,
    387   1.1  pooka 			    &auxt->pvfsr_sb, auxt->pvfsr_pid);
    388   1.1  pooka 			break;
    389   1.1  pooka 		}
    390   1.1  pooka 		case PUFFS_VFS_SYNC:
    391   1.1  pooka 		{
    392  1.12  pooka 			struct puffs_vfsreq_sync *auxt = auxbuf;
    393   1.1  pooka 
    394  1.19  pooka 			error = pops->puffs_fs_sync(pcc,
    395   1.1  pooka 			    auxt->pvfsr_waitfor, &auxt->pvfsr_cred,
    396   1.1  pooka 			    auxt->pvfsr_pid);
    397   1.1  pooka 			break;
    398   1.1  pooka 		}
    399   1.1  pooka 		default:
    400   1.1  pooka 			/*
    401   1.1  pooka 			 * I guess the kernel sees this one coming
    402   1.1  pooka 			 */
    403   1.1  pooka 			error = EINVAL;
    404   1.1  pooka 			break;
    405   1.1  pooka 		}
    406   1.1  pooka 
    407   1.1  pooka 	/* XXX: audit return values */
    408  1.10  pooka 	/* XXX: sync with kernel */
    409   1.5  pooka 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
    410   1.1  pooka 		switch (preq->preq_optype) {
    411   1.1  pooka 		case PUFFS_VN_LOOKUP:
    412   1.1  pooka 		{
    413  1.12  pooka 			struct puffs_vnreq_lookup *auxt = auxbuf;
    414  1.19  pooka 			struct puffs_cn pcn;
    415  1.19  pooka 
    416  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    417  1.19  pooka 			if (buildpath) {
    418  1.19  pooka 				if (pcn.pcn_flags & PUFFS_ISDOTDOT) {
    419  1.19  pooka 					buildpath = 0;
    420  1.19  pooka 				} else {
    421  1.19  pooka 					error = do_buildpath(&pcn,
    422  1.19  pooka 					    preq->preq_cookie);
    423  1.19  pooka 					if (error)
    424  1.19  pooka 						break;
    425  1.19  pooka 				}
    426  1.19  pooka 			}
    427   1.1  pooka 
    428   1.1  pooka 			/* lookup *must* be present */
    429  1.19  pooka 			error = pops->puffs_node_lookup(pcc, preq->preq_cookie,
    430   1.1  pooka 			    &auxt->pvnr_newnode, &auxt->pvnr_vtype,
    431  1.19  pooka 			    &auxt->pvnr_size, &auxt->pvnr_rdev, &pcn);
    432  1.19  pooka 
    433  1.19  pooka 			if (buildpath) {
    434  1.19  pooka 				if (error) {
    435  1.19  pooka 					free(pcn.pcn_fullpath);
    436  1.19  pooka 				} else {
    437  1.19  pooka 					struct puffs_node *pn;
    438  1.19  pooka 
    439  1.19  pooka 					/*
    440  1.19  pooka 					 * did we get a new node or a
    441  1.19  pooka 					 * recycled node?
    442  1.19  pooka 					 * XXX: mapping assumption
    443  1.19  pooka 					 */
    444  1.19  pooka 					pn = auxt->pvnr_newnode;
    445  1.19  pooka 					if (pn->pn_path == NULL) {
    446  1.19  pooka 						pn->pn_path = pcn.pcn_fullpath;
    447  1.19  pooka 						pn->pn_plen
    448  1.19  pooka 						    = pcn.pcn_fullplen;
    449  1.19  pooka 					}
    450  1.19  pooka 				}
    451  1.19  pooka 			}
    452  1.19  pooka 
    453   1.1  pooka 			break;
    454   1.1  pooka 		}
    455   1.1  pooka 
    456   1.1  pooka 		case PUFFS_VN_CREATE:
    457   1.1  pooka 		{
    458  1.12  pooka 			struct puffs_vnreq_create *auxt = auxbuf;
    459  1.19  pooka 			struct puffs_cn pcn;
    460  1.13  pooka 			if (pops->puffs_node_create == NULL) {
    461   1.1  pooka 				error = 0;
    462   1.1  pooka 				break;
    463   1.1  pooka 			}
    464   1.1  pooka 
    465  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    466  1.19  pooka 			if (buildpath) {
    467  1.19  pooka 				error = do_buildpath(&pcn, preq->preq_cookie);
    468  1.19  pooka 				if (error)
    469  1.19  pooka 					break;
    470  1.19  pooka 			}
    471  1.19  pooka 
    472  1.19  pooka 			error = pops->puffs_node_create(pcc,
    473   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_newnode,
    474  1.19  pooka 			    &pcn, &auxt->pvnr_va);
    475  1.19  pooka 
    476  1.19  pooka 			if (buildpath) {
    477  1.19  pooka 				if (error) {
    478  1.19  pooka 					free(pcn.pcn_fullpath);
    479  1.19  pooka 				} else {
    480  1.19  pooka 					struct puffs_node *pn;
    481  1.19  pooka 
    482  1.19  pooka 					pn = auxt->pvnr_newnode;
    483  1.19  pooka 					pn->pn_path = pcn.pcn_fullpath;
    484  1.19  pooka 					pn->pn_plen = pcn.pcn_fullplen;
    485  1.19  pooka 				}
    486  1.19  pooka 			}
    487  1.19  pooka 
    488   1.1  pooka 			break;
    489   1.1  pooka 		}
    490   1.1  pooka 
    491   1.1  pooka 		case PUFFS_VN_MKNOD:
    492   1.1  pooka 		{
    493  1.12  pooka 			struct puffs_vnreq_mknod *auxt = auxbuf;
    494  1.19  pooka 			struct puffs_cn pcn;
    495  1.13  pooka 			if (pops->puffs_node_mknod == NULL) {
    496   1.1  pooka 				error = 0;
    497   1.1  pooka 				break;
    498   1.1  pooka 			}
    499   1.1  pooka 
    500  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    501  1.19  pooka 			if (buildpath) {
    502  1.19  pooka 				error = do_buildpath(&pcn, preq->preq_cookie);
    503  1.19  pooka 				if (error)
    504  1.19  pooka 					break;
    505  1.19  pooka 			}
    506  1.19  pooka 
    507  1.19  pooka 			error = pops->puffs_node_mknod(pcc,
    508   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_newnode,
    509  1.19  pooka 			    &pcn, &auxt->pvnr_va);
    510  1.19  pooka 
    511  1.19  pooka 			if (buildpath) {
    512  1.19  pooka 				if (error) {
    513  1.19  pooka 					free(pcn.pcn_fullpath);
    514  1.19  pooka 				} else {
    515  1.19  pooka 					struct puffs_node *pn;
    516  1.19  pooka 
    517  1.19  pooka 					pn = auxt->pvnr_newnode;
    518  1.19  pooka 					pn->pn_path = pcn.pcn_fullpath;
    519  1.19  pooka 					pn->pn_plen = pcn.pcn_fullplen;
    520  1.19  pooka 				}
    521  1.19  pooka 			}
    522  1.19  pooka 
    523   1.1  pooka 			break;
    524   1.1  pooka 		}
    525   1.1  pooka 
    526   1.1  pooka 		case PUFFS_VN_OPEN:
    527   1.1  pooka 		{
    528  1.12  pooka 			struct puffs_vnreq_open *auxt = auxbuf;
    529  1.13  pooka 			if (pops->puffs_node_open == NULL) {
    530   1.1  pooka 				error = 0;
    531   1.1  pooka 				break;
    532   1.1  pooka 			}
    533   1.1  pooka 
    534  1.19  pooka 			error = pops->puffs_node_open(pcc,
    535   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_mode,
    536   1.1  pooka 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    537   1.1  pooka 			break;
    538   1.1  pooka 		}
    539   1.1  pooka 
    540   1.1  pooka 		case PUFFS_VN_CLOSE:
    541   1.1  pooka 		{
    542  1.12  pooka 			struct puffs_vnreq_close *auxt = auxbuf;
    543  1.13  pooka 			if (pops->puffs_node_close == NULL) {
    544   1.1  pooka 				error = 0;
    545   1.1  pooka 				break;
    546   1.1  pooka 			}
    547   1.1  pooka 
    548  1.19  pooka 			error = pops->puffs_node_close(pcc,
    549   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_fflag,
    550   1.1  pooka 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    551   1.1  pooka 			break;
    552   1.1  pooka 		}
    553   1.1  pooka 
    554   1.1  pooka 		case PUFFS_VN_ACCESS:
    555   1.1  pooka 		{
    556  1.12  pooka 			struct puffs_vnreq_access *auxt = auxbuf;
    557  1.13  pooka 			if (pops->puffs_node_access == NULL) {
    558   1.1  pooka 				error = 0;
    559   1.1  pooka 				break;
    560   1.1  pooka 			}
    561   1.1  pooka 
    562  1.19  pooka 			error = pops->puffs_node_access(pcc,
    563   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_mode,
    564   1.1  pooka 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    565   1.1  pooka 			break;
    566   1.1  pooka 		}
    567   1.1  pooka 
    568   1.1  pooka 		case PUFFS_VN_GETATTR:
    569   1.1  pooka 		{
    570  1.12  pooka 			struct puffs_vnreq_getattr *auxt = auxbuf;
    571  1.13  pooka 			if (pops->puffs_node_getattr == NULL) {
    572  1.12  pooka 				error = EOPNOTSUPP;
    573   1.1  pooka 				break;
    574   1.1  pooka 			}
    575   1.1  pooka 
    576  1.19  pooka 			error = pops->puffs_node_getattr(pcc,
    577   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_va,
    578   1.1  pooka 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    579   1.1  pooka 			break;
    580   1.1  pooka 		}
    581   1.1  pooka 
    582   1.1  pooka 		case PUFFS_VN_SETATTR:
    583   1.1  pooka 		{
    584  1.12  pooka 			struct puffs_vnreq_setattr *auxt = auxbuf;
    585  1.13  pooka 			if (pops->puffs_node_setattr == NULL) {
    586  1.12  pooka 				error = EOPNOTSUPP;
    587   1.1  pooka 				break;
    588   1.1  pooka 			}
    589   1.1  pooka 
    590  1.19  pooka 			error = pops->puffs_node_setattr(pcc,
    591   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_va,
    592   1.1  pooka 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    593   1.1  pooka 			break;
    594   1.1  pooka 		}
    595   1.1  pooka 
    596   1.1  pooka 		case PUFFS_VN_MMAP:
    597   1.1  pooka 		{
    598  1.12  pooka 			struct puffs_vnreq_mmap *auxt = auxbuf;
    599  1.13  pooka 			if (pops->puffs_node_mmap == NULL) {
    600   1.1  pooka 				error = 0;
    601   1.1  pooka 				break;
    602   1.1  pooka 			}
    603   1.1  pooka 
    604  1.19  pooka 			error = pops->puffs_node_mmap(pcc,
    605  1.15  pooka 			    preq->preq_cookie, auxt->pvnr_fflags,
    606  1.15  pooka 			    &auxt->pvnr_cred, auxt->pvnr_pid);
    607   1.1  pooka 			break;
    608   1.1  pooka 		}
    609   1.1  pooka 
    610   1.1  pooka 		case PUFFS_VN_REVOKE:
    611   1.1  pooka 		{
    612  1.12  pooka 			struct puffs_vnreq_revoke *auxt = auxbuf;
    613  1.13  pooka 			if (pops->puffs_node_revoke == NULL) {
    614   1.1  pooka 				error = 0;
    615   1.1  pooka 				break;
    616   1.1  pooka 			}
    617   1.1  pooka 
    618  1.19  pooka 			error = pops->puffs_node_revoke(pcc,
    619   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_flags);
    620   1.1  pooka 			break;
    621   1.1  pooka 		}
    622   1.1  pooka 
    623   1.1  pooka 		case PUFFS_VN_FSYNC:
    624   1.1  pooka 		{
    625  1.12  pooka 			struct puffs_vnreq_fsync *auxt = auxbuf;
    626  1.13  pooka 			if (pops->puffs_node_fsync == NULL) {
    627   1.1  pooka 				error = 0;
    628   1.1  pooka 				break;
    629   1.1  pooka 			}
    630   1.1  pooka 
    631  1.19  pooka 			error = pops->puffs_node_fsync(pcc,
    632   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_cred,
    633   1.1  pooka 			    auxt->pvnr_flags, auxt->pvnr_offlo,
    634   1.1  pooka 			    auxt->pvnr_offhi, auxt->pvnr_pid);
    635   1.1  pooka 			break;
    636   1.1  pooka 		}
    637   1.1  pooka 
    638   1.1  pooka 		case PUFFS_VN_SEEK:
    639   1.1  pooka 		{
    640  1.12  pooka 			struct puffs_vnreq_seek *auxt = auxbuf;
    641  1.13  pooka 			if (pops->puffs_node_seek == NULL) {
    642   1.1  pooka 				error = 0;
    643   1.1  pooka 				break;
    644   1.1  pooka 			}
    645   1.1  pooka 
    646  1.19  pooka 			error = pops->puffs_node_seek(pcc,
    647   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_oldoff,
    648   1.1  pooka 			    auxt->pvnr_newoff, &auxt->pvnr_cred);
    649   1.1  pooka 			break;
    650   1.1  pooka 		}
    651   1.1  pooka 
    652   1.1  pooka 		case PUFFS_VN_REMOVE:
    653   1.1  pooka 		{
    654  1.12  pooka 			struct puffs_vnreq_remove *auxt = auxbuf;
    655  1.19  pooka 			struct puffs_cn pcn;
    656  1.13  pooka 			if (pops->puffs_node_remove == NULL) {
    657   1.1  pooka 				error = 0;
    658   1.1  pooka 				break;
    659   1.1  pooka 			}
    660   1.1  pooka 
    661  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    662  1.19  pooka 
    663  1.19  pooka 			error = pops->puffs_node_remove(pcc,
    664  1.19  pooka 			    preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
    665   1.1  pooka 			break;
    666   1.1  pooka 		}
    667   1.1  pooka 
    668   1.1  pooka 		case PUFFS_VN_LINK:
    669   1.1  pooka 		{
    670  1.12  pooka 			struct puffs_vnreq_link *auxt = auxbuf;
    671  1.19  pooka 			struct puffs_cn pcn;
    672  1.13  pooka 			if (pops->puffs_node_link == NULL) {
    673   1.1  pooka 				error = 0;
    674   1.1  pooka 				break;
    675   1.1  pooka 			}
    676   1.1  pooka 
    677  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    678  1.19  pooka 
    679  1.19  pooka 			error = pops->puffs_node_link(pcc,
    680  1.19  pooka 			    preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
    681   1.1  pooka 			break;
    682   1.1  pooka 		}
    683   1.1  pooka 
    684   1.1  pooka 		case PUFFS_VN_RENAME:
    685   1.1  pooka 		{
    686  1.12  pooka 			struct puffs_vnreq_rename *auxt = auxbuf;
    687  1.19  pooka 			struct puffs_cn pcn_src, pcn_targ;
    688  1.19  pooka 			struct puffs_node *pn_src;
    689  1.19  pooka 
    690  1.13  pooka 			if (pops->puffs_node_rename == NULL) {
    691   1.1  pooka 				error = 0;
    692   1.1  pooka 				break;
    693   1.1  pooka 			}
    694   1.1  pooka 
    695  1.19  pooka 			pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
    696  1.19  pooka 			pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
    697  1.19  pooka 			if (buildpath) {
    698  1.19  pooka 				pn_src = auxt->pvnr_cookie_src;
    699  1.19  pooka 				pcn_src.pcn_fullpath = pn_src->pn_path;
    700  1.19  pooka 				pcn_src.pcn_fullplen = pn_src->pn_plen;
    701  1.19  pooka 
    702  1.19  pooka 				error = do_buildpath(&pcn_targ,
    703  1.19  pooka 				    auxt->pvnr_cookie_targdir);
    704  1.19  pooka 				if (error)
    705  1.19  pooka 					break;
    706  1.19  pooka 			}
    707  1.19  pooka 
    708  1.19  pooka 			error = pops->puffs_node_rename(pcc,
    709   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_cookie_src,
    710  1.19  pooka 			    &pcn_src, auxt->pvnr_cookie_targdir,
    711  1.19  pooka 			    auxt->pvnr_cookie_targ, &pcn_targ);
    712  1.19  pooka 
    713  1.19  pooka 			if (buildpath) {
    714  1.19  pooka 				if (error) {
    715  1.19  pooka 					free(pcn_targ.pcn_fullpath);
    716  1.19  pooka 				} else {
    717  1.19  pooka 					free(pn_src->pn_path);
    718  1.19  pooka 					pn_src->pn_path = pcn_targ.pcn_fullpath;
    719  1.19  pooka 					pn_src->pn_plen = pcn_targ.pcn_fullplen;
    720  1.19  pooka 				}
    721  1.19  pooka 			}
    722   1.1  pooka 			break;
    723   1.1  pooka 		}
    724   1.1  pooka 
    725   1.1  pooka 		case PUFFS_VN_MKDIR:
    726   1.1  pooka 		{
    727  1.12  pooka 			struct puffs_vnreq_mkdir *auxt = auxbuf;
    728  1.19  pooka 			struct puffs_cn pcn;
    729  1.13  pooka 			if (pops->puffs_node_mkdir == NULL) {
    730   1.1  pooka 				error = 0;
    731   1.1  pooka 				break;
    732   1.1  pooka 			}
    733   1.1  pooka 
    734  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    735  1.19  pooka 			if (buildpath) {
    736  1.19  pooka 				error = do_buildpath(&pcn, preq->preq_cookie);
    737  1.19  pooka 				if (error)
    738  1.19  pooka 					break;
    739  1.19  pooka 			}
    740  1.19  pooka 
    741  1.19  pooka 			error = pops->puffs_node_mkdir(pcc,
    742   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_newnode,
    743  1.19  pooka 			    &pcn, &auxt->pvnr_va);
    744  1.19  pooka 
    745  1.19  pooka 			if (buildpath) {
    746  1.19  pooka 				if (error) {
    747  1.19  pooka 					free(pcn.pcn_fullpath);
    748  1.19  pooka 				} else {
    749  1.19  pooka 					struct puffs_node *pn;
    750  1.19  pooka 
    751  1.19  pooka 					pn = auxt->pvnr_newnode;
    752  1.19  pooka 					pn->pn_path = pcn.pcn_fullpath;
    753  1.19  pooka 					pn->pn_plen = pcn.pcn_fullplen;
    754  1.19  pooka 				}
    755  1.19  pooka 			}
    756  1.19  pooka 
    757   1.1  pooka 			break;
    758   1.1  pooka 		}
    759   1.1  pooka 
    760   1.1  pooka 		case PUFFS_VN_RMDIR:
    761   1.1  pooka 		{
    762  1.12  pooka 			struct puffs_vnreq_rmdir *auxt = auxbuf;
    763  1.19  pooka 			struct puffs_cn pcn;
    764  1.13  pooka 			if (pops->puffs_node_rmdir == NULL) {
    765   1.1  pooka 				error = 0;
    766   1.1  pooka 				break;
    767   1.1  pooka 			}
    768   1.1  pooka 
    769  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    770  1.19  pooka 
    771  1.19  pooka 			error = pops->puffs_node_rmdir(pcc,
    772  1.19  pooka 			    preq->preq_cookie, auxt->pvnr_cookie_targ, &pcn);
    773   1.1  pooka 			break;
    774   1.1  pooka 		}
    775   1.1  pooka 
    776   1.1  pooka 		case PUFFS_VN_SYMLINK:
    777   1.1  pooka 		{
    778  1.12  pooka 			struct puffs_vnreq_symlink *auxt = auxbuf;
    779  1.19  pooka 			struct puffs_cn pcn;
    780  1.13  pooka 			if (pops->puffs_node_symlink == NULL) {
    781   1.1  pooka 				error = 0;
    782   1.1  pooka 				break;
    783   1.1  pooka 			}
    784   1.1  pooka 
    785  1.19  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    786  1.19  pooka 			if (buildpath) {
    787  1.19  pooka 				error = do_buildpath(&pcn, preq->preq_cookie);
    788  1.19  pooka 				if (error)
    789  1.19  pooka 					break;
    790  1.19  pooka 			}
    791  1.19  pooka 
    792  1.19  pooka 			error = pops->puffs_node_symlink(pcc,
    793   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_newnode,
    794  1.19  pooka 			    &pcn, &auxt->pvnr_va, auxt->pvnr_link);
    795  1.19  pooka 
    796  1.19  pooka 			if (buildpath) {
    797  1.19  pooka 				if (error) {
    798  1.19  pooka 					free(pcn.pcn_fullpath);
    799  1.19  pooka 				} else {
    800  1.19  pooka 					struct puffs_node *pn;
    801  1.19  pooka 
    802  1.19  pooka 					pn = auxt->pvnr_newnode;
    803  1.19  pooka 					pn->pn_path = pcn.pcn_fullpath;
    804  1.19  pooka 					pn->pn_plen = pcn.pcn_fullplen;
    805  1.19  pooka 				}
    806  1.19  pooka 			}
    807  1.19  pooka 
    808   1.1  pooka 			break;
    809   1.1  pooka 		}
    810   1.1  pooka 
    811   1.1  pooka 		case PUFFS_VN_READDIR:
    812   1.1  pooka 		{
    813  1.12  pooka 			struct puffs_vnreq_readdir *auxt = auxbuf;
    814   1.1  pooka 			size_t res;
    815   1.1  pooka 
    816  1.13  pooka 			if (pops->puffs_node_readdir == NULL) {
    817   1.1  pooka 				error = 0;
    818   1.1  pooka 				break;
    819   1.1  pooka 			}
    820   1.1  pooka 
    821   1.1  pooka 			res = auxt->pvnr_resid;
    822  1.19  pooka 			error = pops->puffs_node_readdir(pcc,
    823   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_dent,
    824   1.1  pooka 			    &auxt->pvnr_cred, &auxt->pvnr_offset,
    825   1.1  pooka 			    &auxt->pvnr_resid);
    826   1.1  pooka 
    827   1.1  pooka 			/* need to move a bit more */
    828  1.19  pooka 			preq->preq_buflen = sizeof(struct puffs_vnreq_readdir)
    829  1.12  pooka 			    + (res - auxt->pvnr_resid);
    830   1.1  pooka 			break;
    831   1.1  pooka 		}
    832   1.1  pooka 
    833   1.1  pooka 		case PUFFS_VN_READLINK:
    834   1.1  pooka 		{
    835  1.12  pooka 			struct puffs_vnreq_readlink *auxt = auxbuf;
    836  1.13  pooka 			if (pops->puffs_node_readlink == NULL) {
    837   1.1  pooka 				error = EOPNOTSUPP;
    838   1.1  pooka 				break;
    839   1.1  pooka 			}
    840   1.1  pooka 
    841  1.19  pooka 			error = pops->puffs_node_readlink(pcc,
    842   1.1  pooka 			    preq->preq_cookie, &auxt->pvnr_cred,
    843   1.1  pooka 			    auxt->pvnr_link, &auxt->pvnr_linklen);
    844   1.1  pooka 			break;
    845   1.1  pooka 		}
    846   1.1  pooka 
    847   1.1  pooka 		case PUFFS_VN_RECLAIM:
    848   1.1  pooka 		{
    849  1.12  pooka 			struct puffs_vnreq_reclaim *auxt = auxbuf;
    850  1.13  pooka 			if (pops->puffs_node_reclaim == NULL) {
    851   1.1  pooka 				error = 0;
    852   1.1  pooka 				break;
    853   1.1  pooka 			}
    854   1.1  pooka 
    855  1.19  pooka 			error = pops->puffs_node_reclaim(pcc,
    856   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_pid);
    857   1.1  pooka 			break;
    858   1.1  pooka 		}
    859   1.1  pooka 
    860   1.3  pooka 		case PUFFS_VN_INACTIVE:
    861   1.3  pooka 		{
    862  1.12  pooka 			struct puffs_vnreq_inactive *auxt = auxbuf;
    863  1.13  pooka 			if (pops->puffs_node_inactive == NULL) {
    864   1.3  pooka 				error = EOPNOTSUPP;
    865   1.3  pooka 				break;
    866   1.3  pooka 			}
    867   1.3  pooka 
    868  1.19  pooka 			error = pops->puffs_node_inactive(pcc,
    869   1.3  pooka 			    preq->preq_cookie, auxt->pvnr_pid,
    870   1.3  pooka 			    &auxt->pvnr_backendrefs);
    871   1.3  pooka 			break;
    872   1.3  pooka 		}
    873   1.3  pooka 
    874   1.1  pooka 		case PUFFS_VN_PATHCONF:
    875   1.1  pooka 		{
    876  1.12  pooka 			struct puffs_vnreq_pathconf *auxt = auxbuf;
    877  1.13  pooka 			if (pops->puffs_node_pathconf == NULL) {
    878   1.1  pooka 				error = 0;
    879   1.1  pooka 				break;
    880   1.1  pooka 			}
    881   1.1  pooka 
    882  1.19  pooka 			error = pops->puffs_node_pathconf(pcc,
    883   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_name,
    884   1.1  pooka 			    &auxt->pvnr_retval);
    885   1.1  pooka 			break;
    886   1.1  pooka 		}
    887   1.1  pooka 
    888   1.1  pooka 		case PUFFS_VN_ADVLOCK:
    889   1.1  pooka 		{
    890  1.12  pooka 			struct puffs_vnreq_advlock *auxt = auxbuf;
    891  1.13  pooka 			if (pops->puffs_node_advlock == NULL) {
    892   1.1  pooka 				error = 0;
    893   1.1  pooka 				break;
    894   1.1  pooka 			}
    895   1.1  pooka 
    896  1.19  pooka 			error = pops->puffs_node_advlock(pcc,
    897   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_id, auxt->pvnr_op,
    898   1.1  pooka 			    &auxt->pvnr_fl, auxt->pvnr_flags);
    899   1.1  pooka 			break;
    900   1.1  pooka 		}
    901   1.1  pooka 
    902   1.1  pooka 		case PUFFS_VN_PRINT:
    903   1.1  pooka 		{
    904  1.13  pooka 			if (pops->puffs_node_print == NULL) {
    905   1.1  pooka 				error = 0;
    906   1.1  pooka 				break;
    907   1.1  pooka 			}
    908   1.1  pooka 
    909  1.19  pooka 			error = pops->puffs_node_print(pcc,
    910   1.1  pooka 			    preq->preq_cookie);
    911   1.1  pooka 			break;
    912   1.1  pooka 		}
    913   1.1  pooka 
    914   1.1  pooka 		case PUFFS_VN_READ:
    915   1.1  pooka 		{
    916  1.12  pooka 			struct puffs_vnreq_read *auxt = auxbuf;
    917   1.1  pooka 			size_t res;
    918   1.1  pooka 
    919  1.13  pooka 			if (pops->puffs_node_read == NULL) {
    920   1.1  pooka 				error = EIO;
    921   1.1  pooka 				break;
    922   1.1  pooka 			}
    923   1.1  pooka 
    924   1.1  pooka 			res = auxt->pvnr_resid;
    925  1.19  pooka 			error = pops->puffs_node_read(pcc,
    926   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_data,
    927   1.1  pooka 			    auxt->pvnr_offset, &auxt->pvnr_resid,
    928   1.1  pooka 			    &auxt->pvnr_cred, auxt->pvnr_ioflag);
    929   1.1  pooka 
    930   1.1  pooka 			/* need to move a bit more */
    931  1.19  pooka 			preq->preq_buflen = sizeof(struct puffs_vnreq_read)
    932  1.12  pooka 			    + (res - auxt->pvnr_resid);
    933   1.1  pooka 			break;
    934   1.1  pooka 		}
    935   1.1  pooka 
    936   1.1  pooka 		case PUFFS_VN_WRITE:
    937   1.1  pooka 		{
    938  1.12  pooka 			struct puffs_vnreq_write *auxt = auxbuf;
    939   1.1  pooka 
    940  1.13  pooka 			if (pops->puffs_node_write == NULL) {
    941   1.1  pooka 				error = EIO;
    942   1.1  pooka 				break;
    943   1.1  pooka 			}
    944   1.1  pooka 
    945  1.19  pooka 			error = pops->puffs_node_write(pcc,
    946   1.1  pooka 			    preq->preq_cookie, auxt->pvnr_data,
    947   1.1  pooka 			    auxt->pvnr_offset, &auxt->pvnr_resid,
    948   1.1  pooka 			    &auxt->pvnr_cred, auxt->pvnr_ioflag);
    949   1.1  pooka 
    950   1.1  pooka 			/* don't need to move data back to the kernel */
    951  1.19  pooka 			preq->preq_buflen = sizeof(struct puffs_vnreq_write);
    952   1.1  pooka 			break;
    953   1.1  pooka 		}
    954   1.1  pooka 
    955  1.19  pooka /* holy bitrot, ryydman! */
    956  1.19  pooka #if 0
    957   1.1  pooka 		case PUFFS_VN_IOCTL:
    958  1.19  pooka 			error = pops->puffs_node_ioctl1(pcc, preq->preq_cookie,
    959  1.12  pooka 			     (struct puffs_vnreq_ioctl *)auxbuf, &pop);
    960   1.1  pooka 			if (error != 0)
    961   1.1  pooka 				break;
    962   1.1  pooka 			pop.pso_reqid = preq->preq_id;
    963   1.1  pooka 
    964   1.1  pooka 			/* let the kernel do it's intermediate duty */
    965   1.1  pooka 			error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
    966   1.1  pooka 			/*
    967   1.1  pooka 			 * XXX: I don't actually know what the correct
    968   1.1  pooka 			 * thing to do in case of an error is, so I'll
    969   1.1  pooka 			 * just ignore it for the time being.
    970   1.1  pooka 			 */
    971  1.19  pooka 			error = pops->puffs_node_ioctl2(pcc, preq->preq_cookie,
    972  1.12  pooka 			    (struct puffs_vnreq_ioctl *)auxbuf, &pop);
    973   1.1  pooka 			break;
    974   1.1  pooka 
    975   1.1  pooka 		case PUFFS_VN_FCNTL:
    976  1.19  pooka 			error = pops->puffs_node_fcntl1(pcc, preq->preq_cookie,
    977  1.12  pooka 			     (struct puffs_vnreq_fcntl *)auxbuf, &pop);
    978   1.1  pooka 			if (error != 0)
    979   1.1  pooka 				break;
    980   1.1  pooka 			pop.pso_reqid = preq->preq_id;
    981   1.1  pooka 
    982   1.1  pooka 			/* let the kernel do it's intermediate duty */
    983   1.1  pooka 			error = ioctl(pu->pu_fd, PUFFSSIZEOP, &pop);
    984   1.1  pooka 			/*
    985   1.1  pooka 			 * XXX: I don't actually know what the correct
    986   1.1  pooka 			 * thing to do in case of an error is, so I'll
    987   1.1  pooka 			 * just ignore it for the time being.
    988   1.1  pooka 			 */
    989  1.19  pooka 			error = pops->puffs_node_fcntl2(pcc, preq->preq_cookie,
    990  1.12  pooka 			    (struct puffs_vnreq_fcntl *)auxbuf, &pop);
    991   1.1  pooka 			break;
    992  1.19  pooka #endif
    993   1.1  pooka 
    994   1.1  pooka 		default:
    995   1.1  pooka 			printf("inval op %d\n", preq->preq_optype);
    996   1.1  pooka 			error = EINVAL;
    997   1.1  pooka 			break;
    998   1.1  pooka 		}
    999   1.1  pooka 	} else {
   1000   1.1  pooka 		/*
   1001   1.1  pooka 		 * this one also
   1002   1.1  pooka 		 */
   1003   1.1  pooka 		error = EINVAL;
   1004   1.1  pooka 	}
   1005   1.1  pooka 
   1006   1.1  pooka 	preq->preq_rv = error;
   1007  1.19  pooka 
   1008  1.19  pooka 	pcc->pcc_rv = rv;
   1009  1.19  pooka 	pcc->pcc_flags |= PCC_DONE;
   1010  1.19  pooka }
   1011  1.19  pooka 
   1012  1.19  pooka static int
   1013  1.19  pooka do_buildpath(struct puffs_cn *pcn, void *parent)
   1014  1.19  pooka {
   1015  1.19  pooka 	struct puffs_node *pn_parent;
   1016  1.19  pooka 	size_t plen;
   1017  1.19  pooka 
   1018  1.19  pooka 	pn_parent = parent; /* XXX */
   1019  1.19  pooka 	assert(pn_parent->pn_path != NULL);
   1020  1.19  pooka 
   1021  1.19  pooka 	/* +1 not for nul but for / */
   1022  1.19  pooka 	plen = pn_parent->pn_plen + pcn->pcn_namelen + 1;
   1023  1.19  pooka 	pcn->pcn_fullpath = malloc(plen);
   1024  1.19  pooka 	if (!pcn->pcn_fullpath)
   1025  1.19  pooka 		return errno;
   1026  1.19  pooka 
   1027  1.19  pooka 	strcpy(pcn->pcn_fullpath, pn_parent->pn_path);
   1028  1.19  pooka 	strcat(pcn->pcn_fullpath, "/");
   1029  1.19  pooka 	strcat(pcn->pcn_fullpath, pcn->pcn_name);
   1030  1.19  pooka 	pcn->pcn_fullpath[plen-1] = '\0'; /* paranoia */
   1031  1.19  pooka 	pcn->pcn_fullplen = plen;
   1032  1.19  pooka 
   1033  1.19  pooka 	return 0;
   1034   1.1  pooka }
   1035   1.1  pooka 
   1036   1.1  pooka 
   1037   1.1  pooka #if 0
   1038  1.14  pooka 		case PUFFS_VN_POLL:
   1039   1.1  pooka 		{
   1040  1.14  pooka 			struct puffs_vnreq_poll *auxt = auxbuf;
   1041  1.14  pooka 			if (pops->puffs_node_poll == NULL) {
   1042   1.1  pooka 				error = 0;
   1043   1.1  pooka 				break;
   1044   1.1  pooka 			}
   1045   1.1  pooka 
   1046  1.19  pooka 			error = pops->puffs_node_poll(pcc,
   1047  1.14  pooka 			    preq->preq_cookie, preq-);
   1048   1.1  pooka 			break;
   1049   1.1  pooka 		}
   1050   1.1  pooka 
   1051  1.14  pooka 		case PUFFS_VN_KQFILTER:
   1052   1.1  pooka 		{
   1053  1.14  pooka 			struct puffs_vnreq_kqfilter *auxt = auxbuf;
   1054  1.14  pooka 			if (pops->puffs_node_kqfilter == NULL) {
   1055   1.1  pooka 				error = 0;
   1056   1.1  pooka 				break;
   1057   1.1  pooka 			}
   1058   1.1  pooka 
   1059  1.19  pooka 			error = pops->puffs_node_kqfilter(pcc,
   1060   1.1  pooka 			    preq->preq_cookie, );
   1061   1.1  pooka 			break;
   1062   1.1  pooka 		}
   1063   1.1  pooka 
   1064   1.1  pooka 		case PUFFS_VN_CLOSEEXTATTR:
   1065   1.1  pooka 		{
   1066  1.12  pooka 			struct puffs_vnreq_closeextattr *auxt = auxbuf;
   1067  1.13  pooka 			if (pops->puffs_closeextattr == NULL) {
   1068   1.1  pooka 				error = 0;
   1069   1.1  pooka 				break;
   1070   1.1  pooka 			}
   1071   1.1  pooka 
   1072  1.19  pooka 			error = pops->puffs_closeextattr(pcc,
   1073   1.1  pooka 			    preq->preq_cookie, );
   1074   1.1  pooka 			break;
   1075   1.1  pooka 		}
   1076   1.1  pooka 
   1077   1.1  pooka 		case PUFFS_VN_GETEXTATTR:
   1078   1.1  pooka 		{
   1079  1.12  pooka 			struct puffs_vnreq_getextattr *auxt = auxbuf;
   1080  1.13  pooka 			if (pops->puffs_getextattr == NULL) {
   1081   1.1  pooka 				error = 0;
   1082   1.1  pooka 				break;
   1083   1.1  pooka 			}
   1084   1.1  pooka 
   1085  1.19  pooka 			error = pops->puffs_getextattr(pcc,
   1086   1.1  pooka 			    preq->preq_cookie, );
   1087   1.1  pooka 			break;
   1088   1.1  pooka 		}
   1089   1.1  pooka 
   1090   1.1  pooka 		case PUFFS_VN_LISTEXTATTR:
   1091   1.1  pooka 		{
   1092  1.12  pooka 			struct puffs_vnreq_listextattr *auxt = auxbuf;
   1093  1.13  pooka 			if (pops->puffs_listextattr == NULL) {
   1094   1.1  pooka 				error = 0;
   1095   1.1  pooka 				break;
   1096   1.1  pooka 			}
   1097   1.1  pooka 
   1098  1.19  pooka 			error = pops->puffs_listextattr(pcc,
   1099   1.1  pooka 			    preq->preq_cookie, );
   1100   1.1  pooka 			break;
   1101   1.1  pooka 		}
   1102   1.1  pooka 
   1103   1.1  pooka 		case PUFFS_VN_OPENEXTATTR:
   1104   1.1  pooka 		{
   1105  1.12  pooka 			struct puffs_vnreq_openextattr *auxt = auxbuf;
   1106  1.13  pooka 			if (pops->puffs_openextattr == NULL) {
   1107   1.1  pooka 				error = 0;
   1108   1.1  pooka 				break;
   1109   1.1  pooka 			}
   1110   1.1  pooka 
   1111  1.19  pooka 			error = pops->puffs_openextattr(pcc,
   1112   1.1  pooka 			    preq->preq_cookie, );
   1113   1.1  pooka 			break;
   1114   1.1  pooka 		}
   1115   1.1  pooka 
   1116   1.1  pooka 		case PUFFS_VN_DELETEEXTATTR:
   1117   1.1  pooka 		{
   1118  1.12  pooka 			struct puffs_vnreq_deleteextattr *auxt = auxbuf;
   1119  1.13  pooka 			if (pops->puffs_deleteextattr == NULL) {
   1120   1.1  pooka 				error = 0;
   1121   1.1  pooka 				break;
   1122   1.1  pooka 			}
   1123   1.1  pooka 
   1124  1.19  pooka 			error = pops->puffs_deleteextattr(pcc,
   1125   1.1  pooka 			    preq->preq_cookie, );
   1126   1.1  pooka 			break;
   1127   1.1  pooka 		}
   1128   1.1  pooka 
   1129   1.1  pooka 		case PUFFS_VN_SETEXTATTR:
   1130   1.1  pooka 		{
   1131  1.12  pooka 			struct puffs_vnreq_setextattr *auxt = auxbuf;
   1132  1.13  pooka 			if (pops->puffs_setextattr == NULL) {
   1133   1.1  pooka 				error = 0;
   1134   1.1  pooka 				break;
   1135   1.1  pooka 			}
   1136   1.1  pooka 
   1137  1.19  pooka 			error = pops->puffs_setextattr(pcc,
   1138   1.1  pooka 			    preq->preq_cookie, );
   1139   1.1  pooka 			break;
   1140   1.1  pooka 		}
   1141   1.1  pooka 
   1142   1.1  pooka #endif
   1143