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