Home | History | Annotate | Line # | Download | only in libpuffs
dispatcher.c revision 1.13
      1  1.13  pooka /*	$NetBSD: dispatcher.c,v 1.13 2007/10/01 21:10:50 pooka Exp $	*/
      2   1.1  pooka 
      3   1.1  pooka /*
      4   1.2  pooka  * Copyright (c) 2006, 2007  Antti Kantee.  All Rights Reserved.
      5   1.1  pooka  *
      6   1.1  pooka  * Development of this software was supported by the
      7   1.2  pooka  * Ulla Tuominen Foundation.
      8   1.1  pooka  *
      9   1.1  pooka  * Redistribution and use in source and binary forms, with or without
     10   1.1  pooka  * modification, are permitted provided that the following conditions
     11   1.1  pooka  * are met:
     12   1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     13   1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     14   1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     16   1.1  pooka  *    documentation and/or other materials provided with the distribution.
     17   1.1  pooka  *
     18   1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19   1.1  pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20   1.1  pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21   1.1  pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     22   1.1  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23   1.1  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24   1.1  pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25   1.1  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26   1.1  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27   1.1  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28   1.1  pooka  * SUCH DAMAGE.
     29   1.1  pooka  */
     30   1.1  pooka 
     31   1.1  pooka #include <sys/cdefs.h>
     32   1.1  pooka #if !defined(lint)
     33  1.13  pooka __RCSID("$NetBSD: dispatcher.c,v 1.13 2007/10/01 21:10:50 pooka Exp $");
     34   1.1  pooka #endif /* !lint */
     35   1.1  pooka 
     36   1.1  pooka #include <sys/types.h>
     37   1.4  pooka #include <sys/poll.h>
     38   1.1  pooka 
     39   1.1  pooka #include <assert.h>
     40   1.1  pooka #include <errno.h>
     41   1.1  pooka #include <puffs.h>
     42   1.1  pooka #include <puffsdump.h>
     43   1.1  pooka #include <stdio.h>
     44   1.1  pooka #include <stdlib.h>
     45   1.1  pooka #include <unistd.h>
     46   1.1  pooka 
     47   1.1  pooka #include "puffs_priv.h"
     48   1.1  pooka 
     49   1.3  pooka static void processresult(struct puffs_cc *, struct puffs_putreq *, int);
     50   1.3  pooka 
     51   1.1  pooka /*
     52   1.1  pooka  * Set the following to 1 to not handle each request on a separate
     53   1.1  pooka  * stack.  This is highly volatile kludge, therefore no external
     54   1.1  pooka  * interface.
     55   1.1  pooka  */
     56   1.1  pooka int puffs_fakecc;
     57   1.1  pooka 
     58   1.3  pooka /* user-visible point to handle a request from */
     59   1.1  pooka int
     60   1.1  pooka puffs_dopreq(struct puffs_usermount *pu, struct puffs_req *preq,
     61   1.1  pooka 	struct puffs_putreq *ppr)
     62   1.1  pooka {
     63   1.1  pooka 	struct puffs_cc fakecc;
     64   1.1  pooka 	struct puffs_cc *pcc;
     65   1.1  pooka 
     66   1.1  pooka 	/*
     67   1.1  pooka 	 * XXX: the structure is currently a mess.  anyway, trap
     68   1.1  pooka 	 * the cacheops here already, since they don't need a cc.
     69   1.1  pooka 	 * I really should get around to revamping the operation
     70   1.1  pooka 	 * dispatching code one of these days.
     71  1.12  pooka 	 *
     72  1.12  pooka 	 * Do the same for error notifications.
     73   1.1  pooka 	 */
     74   1.1  pooka 	if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_CACHE) {
     75   1.1  pooka 		struct puffs_cacheinfo *pci = (void *)preq;
     76   1.1  pooka 
     77   1.1  pooka 		if (pu->pu_ops.puffs_cache_write == NULL)
     78   1.1  pooka 			return 0;
     79   1.1  pooka 
     80   1.1  pooka 		pu->pu_ops.puffs_cache_write(pu, preq->preq_cookie,
     81   1.1  pooka 		    pci->pcache_nruns, pci->pcache_runs);
     82  1.12  pooka 		return 0;
     83  1.12  pooka 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_ERROR) {
     84  1.12  pooka 		struct puffs_error *perr = (void *)preq;
     85  1.12  pooka 
     86  1.12  pooka 		pu->pu_errnotify(pu, preq->preq_optype,
     87  1.13  pooka 		    perr->perr_error, perr->perr_str, preq->preq_cookie);
     88  1.12  pooka 		return 0;
     89   1.1  pooka 	}
     90   1.1  pooka 
     91   1.1  pooka 	if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
     92   1.1  pooka 		puffsdump_req(preq);
     93   1.1  pooka 
     94   1.1  pooka 	if (puffs_fakecc) {
     95   1.1  pooka 		pcc = &fakecc;
     96   1.1  pooka 		pcc_init_local(pcc);
     97   1.1  pooka 
     98   1.1  pooka 		pcc->pcc_pu = pu;
     99   1.1  pooka 		pcc->pcc_preq = preq;
    100   1.1  pooka 		pcc->pcc_flags = PCC_FAKECC;
    101   1.1  pooka 	} else {
    102   1.1  pooka 		pcc = puffs_cc_create(pu);
    103   1.1  pooka 
    104   1.1  pooka 		/* XXX: temporary kludging */
    105   1.1  pooka 		pcc->pcc_preq = malloc(preq->preq_buflen);
    106   1.1  pooka 		if (pcc->pcc_preq == NULL)
    107   1.1  pooka 			return -1;
    108   1.1  pooka 		(void) memcpy(pcc->pcc_preq, preq, preq->preq_buflen);
    109   1.1  pooka 	}
    110   1.1  pooka 
    111   1.3  pooka 	puffs_docc(pcc, ppr);
    112   1.3  pooka 	return 0;
    113   1.1  pooka }
    114   1.1  pooka 
    115   1.1  pooka enum {PUFFCALL_ANSWER, PUFFCALL_IGNORE, PUFFCALL_AGAIN};
    116   1.1  pooka 
    117   1.3  pooka /* user-visible continuation point */
    118   1.3  pooka void
    119   1.1  pooka puffs_docc(struct puffs_cc *pcc, struct puffs_putreq *ppr)
    120   1.1  pooka {
    121   1.1  pooka 	struct puffs_usermount *pu = pcc->pcc_pu;
    122   1.3  pooka 	struct puffs_cc *pcc_iter;
    123   1.1  pooka 
    124   1.1  pooka 	assert((pcc->pcc_flags & PCC_DONE) == 0);
    125   1.3  pooka 	pcc->pcc_ppr = ppr;
    126   1.1  pooka 
    127   1.1  pooka 	if (pcc->pcc_flags & PCC_REALCC)
    128   1.1  pooka 		puffs_cc_continue(pcc);
    129   1.1  pooka 	else
    130   1.1  pooka 		puffs_calldispatcher(pcc);
    131   1.1  pooka 
    132   1.3  pooka 	/* can't do this above due to PCC_BORROWED */
    133   1.3  pooka 	while ((pcc_iter = LIST_FIRST(&pu->pu_ccnukelst)) != NULL) {
    134   1.3  pooka 		LIST_REMOVE(pcc_iter, nlst_entries);
    135   1.3  pooka 		puffs_cc_destroy(pcc_iter);
    136   1.1  pooka 	}
    137   1.1  pooka }
    138   1.1  pooka 
    139   1.1  pooka /* library private, but linked from callcontext.c */
    140   1.1  pooka 
    141   1.1  pooka void
    142   1.1  pooka puffs_calldispatcher(struct puffs_cc *pcc)
    143   1.1  pooka {
    144   1.1  pooka 	struct puffs_usermount *pu = pcc->pcc_pu;
    145   1.1  pooka 	struct puffs_ops *pops = &pu->pu_ops;
    146   1.1  pooka 	struct puffs_req *preq = pcc->pcc_preq;
    147   1.1  pooka 	void *auxbuf = preq; /* help with typecasting */
    148   1.1  pooka 	void *opcookie = preq->preq_cookie;
    149   1.1  pooka 	int error, rv, buildpath;
    150   1.1  pooka 
    151   1.1  pooka 	assert(pcc->pcc_flags & (PCC_FAKECC | PCC_REALCC));
    152   1.1  pooka 
    153   1.1  pooka 	if (PUFFSOP_WANTREPLY(preq->preq_opclass))
    154   1.1  pooka 		rv = PUFFCALL_ANSWER;
    155   1.1  pooka 	else
    156   1.1  pooka 		rv = PUFFCALL_IGNORE;
    157   1.1  pooka 
    158   1.1  pooka 	buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
    159   1.1  pooka 	preq->preq_setbacks = 0;
    160   1.1  pooka 
    161   1.1  pooka 	if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
    162   1.1  pooka 		switch (preq->preq_optype) {
    163   1.1  pooka 		case PUFFS_VFS_UNMOUNT:
    164   1.1  pooka 		{
    165   1.1  pooka 			struct puffs_vfsreq_unmount *auxt = auxbuf;
    166   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvfsr_cid);
    167   1.1  pooka 
    168   1.1  pooka 			PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTING);
    169   1.1  pooka 			error = pops->puffs_fs_unmount(pcc,
    170   1.8  pooka 			    auxt->pvfsr_flags, pcid);
    171   1.1  pooka 			if (!error)
    172   1.1  pooka 				PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTED);
    173   1.1  pooka 			else
    174   1.1  pooka 				PU_SETSTATE(pu, PUFFS_STATE_RUNNING);
    175   1.1  pooka 			break;
    176   1.1  pooka 		}
    177   1.1  pooka 
    178   1.1  pooka 		case PUFFS_VFS_STATVFS:
    179   1.1  pooka 		{
    180   1.1  pooka 			struct puffs_vfsreq_statvfs *auxt = auxbuf;
    181   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvfsr_cid);
    182   1.1  pooka 
    183   1.1  pooka 			error = pops->puffs_fs_statvfs(pcc,
    184   1.8  pooka 			    &auxt->pvfsr_sb, pcid);
    185   1.1  pooka 			break;
    186   1.1  pooka 		}
    187   1.1  pooka 
    188   1.1  pooka 		case PUFFS_VFS_SYNC:
    189   1.1  pooka 		{
    190   1.1  pooka 			struct puffs_vfsreq_sync *auxt = auxbuf;
    191   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvfsr_cred);
    192   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvfsr_cid);
    193   1.1  pooka 
    194   1.1  pooka 			error = pops->puffs_fs_sync(pcc,
    195   1.8  pooka 			    auxt->pvfsr_waitfor, pcr, pcid);
    196   1.1  pooka 			break;
    197   1.1  pooka 		}
    198   1.1  pooka 
    199   1.1  pooka 		case PUFFS_VFS_FHTOVP:
    200   1.1  pooka 		{
    201   1.1  pooka 			struct puffs_vfsreq_fhtonode *auxt = auxbuf;
    202   1.9  pooka 			struct puffs_newinfo pni;
    203   1.9  pooka 
    204   1.9  pooka 			pni.pni_cookie = &auxt->pvfsr_fhcookie;
    205   1.9  pooka 			pni.pni_vtype = &auxt->pvfsr_vtype;
    206   1.9  pooka 			pni.pni_size = &auxt->pvfsr_size;
    207   1.9  pooka 			pni.pni_rdev = &auxt->pvfsr_rdev;
    208   1.1  pooka 
    209   1.1  pooka 			error = pops->puffs_fs_fhtonode(pcc, auxt->pvfsr_data,
    210   1.9  pooka 			    auxt->pvfsr_dsize, &pni);
    211   1.1  pooka 
    212   1.1  pooka 			break;
    213   1.1  pooka 		}
    214   1.1  pooka 
    215   1.1  pooka 		case PUFFS_VFS_VPTOFH:
    216   1.1  pooka 		{
    217   1.1  pooka 			struct puffs_vfsreq_nodetofh *auxt = auxbuf;
    218   1.1  pooka 
    219   1.1  pooka 			error = pops->puffs_fs_nodetofh(pcc,
    220   1.1  pooka 			    auxt->pvfsr_fhcookie, auxt->pvfsr_data,
    221   1.1  pooka 			    &auxt->pvfsr_dsize);
    222   1.1  pooka 
    223   1.1  pooka 			break;
    224   1.1  pooka 		}
    225   1.1  pooka 
    226   1.1  pooka 		case PUFFS_VFS_SUSPEND:
    227   1.1  pooka 		{
    228   1.1  pooka 			struct puffs_vfsreq_suspend *auxt = auxbuf;
    229   1.1  pooka 
    230   1.1  pooka 			error = 0;
    231   1.1  pooka 			if (pops->puffs_fs_suspend == NULL)
    232   1.1  pooka 				break;
    233   1.1  pooka 
    234   1.1  pooka 			pops->puffs_fs_suspend(pcc, auxt->pvfsr_status);
    235   1.1  pooka 			break;
    236   1.1  pooka 		}
    237   1.1  pooka 
    238   1.1  pooka 		default:
    239   1.1  pooka 			/*
    240   1.1  pooka 			 * I guess the kernel sees this one coming
    241   1.1  pooka 			 */
    242   1.1  pooka 			error = EINVAL;
    243   1.1  pooka 			break;
    244   1.1  pooka 		}
    245   1.1  pooka 
    246   1.1  pooka 	/* XXX: audit return values */
    247   1.1  pooka 	/* XXX: sync with kernel */
    248   1.1  pooka 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
    249   1.1  pooka 		switch (preq->preq_optype) {
    250   1.1  pooka 		case PUFFS_VN_LOOKUP:
    251   1.1  pooka 		{
    252   1.1  pooka 			struct puffs_vnreq_lookup *auxt = auxbuf;
    253   1.9  pooka 			struct puffs_newinfo pni;
    254   1.1  pooka 			struct puffs_cn pcn;
    255   1.1  pooka 
    256   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    257   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    258   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    259   1.9  pooka 			pni.pni_cookie = &auxt->pvnr_newnode;
    260   1.9  pooka 			pni.pni_vtype = &auxt->pvnr_vtype;
    261   1.9  pooka 			pni.pni_size = &auxt->pvnr_size;
    262   1.9  pooka 			pni.pni_rdev = &auxt->pvnr_rdev;
    263   1.7  pooka 
    264   1.1  pooka 			if (buildpath) {
    265   1.1  pooka 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    266   1.1  pooka 				if (error)
    267   1.1  pooka 					break;
    268   1.1  pooka 			}
    269   1.1  pooka 
    270   1.1  pooka 			/* lookup *must* be present */
    271   1.1  pooka 			error = pops->puffs_node_lookup(pcc, opcookie,
    272   1.9  pooka 			    &pni, &pcn);
    273   1.1  pooka 
    274   1.1  pooka 			if (buildpath) {
    275   1.1  pooka 				if (error) {
    276   1.1  pooka 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    277   1.1  pooka 				} else {
    278   1.1  pooka 					struct puffs_node *pn;
    279   1.1  pooka 
    280   1.1  pooka 					/*
    281   1.1  pooka 					 * did we get a new node or a
    282   1.1  pooka 					 * recycled node?
    283   1.1  pooka 					 */
    284   1.1  pooka 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    285   1.1  pooka 					if (pn->pn_po.po_path == NULL)
    286   1.1  pooka 						pn->pn_po = pcn.pcn_po_full;
    287   1.1  pooka 					else
    288   1.1  pooka 						pu->pu_pathfree(pu,
    289   1.1  pooka 						    &pcn.pcn_po_full);
    290   1.1  pooka 				}
    291   1.1  pooka 			}
    292   1.1  pooka 
    293   1.1  pooka 			break;
    294   1.1  pooka 		}
    295   1.1  pooka 
    296   1.1  pooka 		case PUFFS_VN_CREATE:
    297   1.1  pooka 		{
    298   1.1  pooka 			struct puffs_vnreq_create *auxt = auxbuf;
    299   1.9  pooka 			struct puffs_newinfo pni;
    300   1.1  pooka 			struct puffs_cn pcn;
    301   1.9  pooka 
    302   1.1  pooka 			if (pops->puffs_node_create == NULL) {
    303   1.1  pooka 				error = 0;
    304   1.1  pooka 				break;
    305   1.1  pooka 			}
    306   1.1  pooka 
    307   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    308   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    309   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    310   1.7  pooka 
    311   1.9  pooka 			memset(&pni, 0, sizeof(pni));
    312   1.9  pooka 			pni.pni_cookie = &auxt->pvnr_newnode;
    313   1.9  pooka 
    314   1.1  pooka 			if (buildpath) {
    315   1.1  pooka 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    316   1.1  pooka 				if (error)
    317   1.1  pooka 					break;
    318   1.1  pooka 			}
    319   1.1  pooka 
    320   1.1  pooka 			error = pops->puffs_node_create(pcc,
    321   1.9  pooka 			    opcookie, &pni, &pcn, &auxt->pvnr_va);
    322   1.1  pooka 
    323   1.1  pooka 			if (buildpath) {
    324   1.1  pooka 				if (error) {
    325   1.1  pooka 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    326   1.1  pooka 				} else {
    327   1.1  pooka 					struct puffs_node *pn;
    328   1.1  pooka 
    329   1.1  pooka 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    330   1.1  pooka 					pn->pn_po = pcn.pcn_po_full;
    331   1.1  pooka 				}
    332   1.1  pooka 			}
    333   1.1  pooka 
    334   1.1  pooka 			break;
    335   1.1  pooka 		}
    336   1.1  pooka 
    337   1.1  pooka 		case PUFFS_VN_MKNOD:
    338   1.1  pooka 		{
    339   1.1  pooka 			struct puffs_vnreq_mknod *auxt = auxbuf;
    340   1.9  pooka 			struct puffs_newinfo pni;
    341   1.1  pooka 			struct puffs_cn pcn;
    342   1.9  pooka 
    343   1.1  pooka 			if (pops->puffs_node_mknod == NULL) {
    344   1.1  pooka 				error = 0;
    345   1.1  pooka 				break;
    346   1.1  pooka 			}
    347   1.1  pooka 
    348   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    349   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    350   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    351   1.7  pooka 
    352   1.9  pooka 			memset(&pni, 0, sizeof(pni));
    353   1.9  pooka 			pni.pni_cookie = &auxt->pvnr_newnode;
    354   1.9  pooka 
    355   1.1  pooka 			if (buildpath) {
    356   1.1  pooka 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    357   1.1  pooka 				if (error)
    358   1.1  pooka 					break;
    359   1.1  pooka 			}
    360   1.1  pooka 
    361   1.1  pooka 			error = pops->puffs_node_mknod(pcc,
    362   1.9  pooka 			    opcookie, &pni, &pcn, &auxt->pvnr_va);
    363   1.1  pooka 
    364   1.1  pooka 			if (buildpath) {
    365   1.1  pooka 				if (error) {
    366   1.1  pooka 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    367   1.1  pooka 				} else {
    368   1.1  pooka 					struct puffs_node *pn;
    369   1.1  pooka 
    370   1.1  pooka 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    371   1.1  pooka 					pn->pn_po = pcn.pcn_po_full;
    372   1.1  pooka 				}
    373   1.1  pooka 			}
    374   1.1  pooka 
    375   1.1  pooka 			break;
    376   1.1  pooka 		}
    377   1.1  pooka 
    378   1.1  pooka 		case PUFFS_VN_OPEN:
    379   1.1  pooka 		{
    380   1.1  pooka 			struct puffs_vnreq_open *auxt = auxbuf;
    381   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    382   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    383   1.7  pooka 
    384   1.1  pooka 			if (pops->puffs_node_open == NULL) {
    385   1.1  pooka 				error = 0;
    386   1.1  pooka 				break;
    387   1.1  pooka 			}
    388   1.1  pooka 
    389   1.1  pooka 			error = pops->puffs_node_open(pcc,
    390   1.8  pooka 			    opcookie, auxt->pvnr_mode, pcr, pcid);
    391   1.1  pooka 			break;
    392   1.1  pooka 		}
    393   1.1  pooka 
    394   1.1  pooka 		case PUFFS_VN_CLOSE:
    395   1.1  pooka 		{
    396   1.1  pooka 			struct puffs_vnreq_close *auxt = auxbuf;
    397   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    398   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    399   1.8  pooka 
    400   1.7  pooka 
    401   1.1  pooka 			if (pops->puffs_node_close == NULL) {
    402   1.1  pooka 				error = 0;
    403   1.1  pooka 				break;
    404   1.1  pooka 			}
    405   1.1  pooka 
    406   1.1  pooka 			error = pops->puffs_node_close(pcc,
    407   1.8  pooka 			    opcookie, auxt->pvnr_fflag, pcr, pcid);
    408   1.1  pooka 			break;
    409   1.1  pooka 		}
    410   1.1  pooka 
    411   1.1  pooka 		case PUFFS_VN_ACCESS:
    412   1.1  pooka 		{
    413   1.1  pooka 			struct puffs_vnreq_access *auxt = auxbuf;
    414   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    415   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    416   1.8  pooka 
    417   1.7  pooka 
    418   1.1  pooka 			if (pops->puffs_node_access == NULL) {
    419   1.1  pooka 				error = 0;
    420   1.1  pooka 				break;
    421   1.1  pooka 			}
    422   1.1  pooka 
    423   1.1  pooka 			error = pops->puffs_node_access(pcc,
    424   1.8  pooka 			    opcookie, auxt->pvnr_mode, pcr, pcid);
    425   1.1  pooka 			break;
    426   1.1  pooka 		}
    427   1.1  pooka 
    428   1.1  pooka 		case PUFFS_VN_GETATTR:
    429   1.1  pooka 		{
    430   1.1  pooka 			struct puffs_vnreq_getattr *auxt = auxbuf;
    431   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    432   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    433   1.8  pooka 
    434   1.7  pooka 
    435   1.1  pooka 			if (pops->puffs_node_getattr == NULL) {
    436   1.1  pooka 				error = EOPNOTSUPP;
    437   1.1  pooka 				break;
    438   1.1  pooka 			}
    439   1.1  pooka 
    440   1.1  pooka 			error = pops->puffs_node_getattr(pcc,
    441   1.8  pooka 			    opcookie, &auxt->pvnr_va, pcr, pcid);
    442   1.1  pooka 			break;
    443   1.1  pooka 		}
    444   1.1  pooka 
    445   1.1  pooka 		case PUFFS_VN_SETATTR:
    446   1.1  pooka 		{
    447   1.1  pooka 			struct puffs_vnreq_setattr *auxt = auxbuf;
    448   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    449   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    450   1.8  pooka 
    451   1.7  pooka 
    452   1.1  pooka 			if (pops->puffs_node_setattr == NULL) {
    453   1.1  pooka 				error = EOPNOTSUPP;
    454   1.1  pooka 				break;
    455   1.1  pooka 			}
    456   1.1  pooka 
    457   1.1  pooka 			error = pops->puffs_node_setattr(pcc,
    458   1.8  pooka 			    opcookie, &auxt->pvnr_va, pcr, pcid);
    459   1.1  pooka 			break;
    460   1.1  pooka 		}
    461   1.1  pooka 
    462   1.1  pooka 		case PUFFS_VN_MMAP:
    463   1.1  pooka 		{
    464   1.1  pooka 			struct puffs_vnreq_mmap *auxt = auxbuf;
    465   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    466   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    467   1.8  pooka 
    468   1.7  pooka 
    469   1.1  pooka 			if (pops->puffs_node_mmap == NULL) {
    470   1.1  pooka 				error = 0;
    471   1.1  pooka 				break;
    472   1.1  pooka 			}
    473   1.1  pooka 
    474   1.1  pooka 			error = pops->puffs_node_mmap(pcc,
    475  1.11  pooka 			    opcookie, auxt->pvnr_prot, pcr, pcid);
    476   1.1  pooka 			break;
    477   1.1  pooka 		}
    478   1.1  pooka 
    479   1.1  pooka 		case PUFFS_VN_FSYNC:
    480   1.1  pooka 		{
    481   1.1  pooka 			struct puffs_vnreq_fsync *auxt = auxbuf;
    482   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    483   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    484   1.8  pooka 
    485   1.7  pooka 
    486   1.1  pooka 			if (pops->puffs_node_fsync == NULL) {
    487   1.1  pooka 				error = 0;
    488   1.1  pooka 				break;
    489   1.1  pooka 			}
    490   1.1  pooka 
    491   1.7  pooka 			error = pops->puffs_node_fsync(pcc, opcookie, pcr,
    492   1.1  pooka 			    auxt->pvnr_flags, auxt->pvnr_offlo,
    493   1.8  pooka 			    auxt->pvnr_offhi, pcid);
    494   1.1  pooka 			break;
    495   1.1  pooka 		}
    496   1.1  pooka 
    497   1.1  pooka 		case PUFFS_VN_SEEK:
    498   1.1  pooka 		{
    499   1.1  pooka 			struct puffs_vnreq_seek *auxt = auxbuf;
    500   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    501   1.7  pooka 
    502   1.1  pooka 			if (pops->puffs_node_seek == NULL) {
    503   1.1  pooka 				error = 0;
    504   1.1  pooka 				break;
    505   1.1  pooka 			}
    506   1.1  pooka 
    507   1.1  pooka 			error = pops->puffs_node_seek(pcc,
    508   1.1  pooka 			    opcookie, auxt->pvnr_oldoff,
    509   1.7  pooka 			    auxt->pvnr_newoff, pcr);
    510   1.1  pooka 			break;
    511   1.1  pooka 		}
    512   1.1  pooka 
    513   1.1  pooka 		case PUFFS_VN_REMOVE:
    514   1.1  pooka 		{
    515   1.1  pooka 			struct puffs_vnreq_remove *auxt = auxbuf;
    516   1.1  pooka 			struct puffs_cn pcn;
    517   1.1  pooka 			if (pops->puffs_node_remove == NULL) {
    518   1.1  pooka 				error = 0;
    519   1.1  pooka 				break;
    520   1.1  pooka 			}
    521   1.1  pooka 
    522   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    523   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    524   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    525   1.1  pooka 
    526   1.1  pooka 			error = pops->puffs_node_remove(pcc,
    527   1.1  pooka 			    opcookie, auxt->pvnr_cookie_targ, &pcn);
    528   1.1  pooka 			break;
    529   1.1  pooka 		}
    530   1.1  pooka 
    531   1.1  pooka 		case PUFFS_VN_LINK:
    532   1.1  pooka 		{
    533   1.1  pooka 			struct puffs_vnreq_link *auxt = auxbuf;
    534   1.1  pooka 			struct puffs_cn pcn;
    535   1.1  pooka 			if (pops->puffs_node_link == NULL) {
    536   1.1  pooka 				error = 0;
    537   1.1  pooka 				break;
    538   1.1  pooka 			}
    539   1.1  pooka 
    540   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    541   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    542   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    543   1.7  pooka 
    544   1.1  pooka 			if (buildpath) {
    545   1.1  pooka 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    546   1.1  pooka 				if (error)
    547   1.1  pooka 					break;
    548   1.1  pooka 			}
    549   1.1  pooka 
    550   1.1  pooka 			error = pops->puffs_node_link(pcc,
    551   1.1  pooka 			    opcookie, auxt->pvnr_cookie_targ, &pcn);
    552   1.1  pooka 			if (buildpath)
    553   1.1  pooka 				pu->pu_pathfree(pu, &pcn.pcn_po_full);
    554   1.1  pooka 
    555   1.1  pooka 			break;
    556   1.1  pooka 		}
    557   1.1  pooka 
    558   1.1  pooka 		case PUFFS_VN_RENAME:
    559   1.1  pooka 		{
    560   1.1  pooka 			struct puffs_vnreq_rename *auxt = auxbuf;
    561   1.1  pooka 			struct puffs_cn pcn_src, pcn_targ;
    562   1.1  pooka 			struct puffs_node *pn_src;
    563   1.1  pooka 
    564   1.1  pooka 			if (pops->puffs_node_rename == NULL) {
    565   1.1  pooka 				error = 0;
    566   1.1  pooka 				break;
    567   1.1  pooka 			}
    568   1.1  pooka 
    569   1.1  pooka 			pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
    570   1.7  pooka 			PUFFS_KCREDTOCRED(pcn_src.pcn_cred,
    571   1.7  pooka 			    &auxt->pvnr_cn_src_cred);
    572   1.8  pooka 			PUFFS_KCIDTOCID(pcn_src.pcn_cid,
    573   1.8  pooka 			    &auxt->pvnr_cn_src_cid);
    574   1.8  pooka 
    575   1.1  pooka 			pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
    576   1.7  pooka 			PUFFS_KCREDTOCRED(pcn_targ.pcn_cred,
    577   1.7  pooka 			    &auxt->pvnr_cn_targ_cred);
    578   1.8  pooka 			PUFFS_KCIDTOCID(pcn_targ.pcn_cid,
    579   1.8  pooka 			    &auxt->pvnr_cn_targ_cid);
    580   1.7  pooka 
    581   1.1  pooka 			if (buildpath) {
    582   1.1  pooka 				pn_src = auxt->pvnr_cookie_src;
    583   1.1  pooka 				pcn_src.pcn_po_full = pn_src->pn_po;
    584   1.1  pooka 
    585   1.1  pooka 				error = puffs_path_pcnbuild(pu, &pcn_targ,
    586   1.1  pooka 				    auxt->pvnr_cookie_targdir);
    587   1.1  pooka 				if (error)
    588   1.1  pooka 					break;
    589   1.1  pooka 			}
    590   1.1  pooka 
    591   1.1  pooka 			error = pops->puffs_node_rename(pcc,
    592   1.1  pooka 			    opcookie, auxt->pvnr_cookie_src,
    593   1.1  pooka 			    &pcn_src, auxt->pvnr_cookie_targdir,
    594   1.1  pooka 			    auxt->pvnr_cookie_targ, &pcn_targ);
    595   1.1  pooka 
    596   1.1  pooka 			if (buildpath) {
    597   1.1  pooka 				if (error) {
    598   1.1  pooka 					pu->pu_pathfree(pu,
    599   1.1  pooka 					    &pcn_targ.pcn_po_full);
    600   1.1  pooka 				} else {
    601   1.1  pooka 					struct puffs_pathinfo pi;
    602   1.1  pooka 					struct puffs_pathobj po_old;
    603   1.1  pooka 
    604   1.1  pooka 					/* handle this node */
    605   1.1  pooka 					po_old = pn_src->pn_po;
    606   1.1  pooka 					pn_src->pn_po = pcn_targ.pcn_po_full;
    607   1.1  pooka 
    608   1.1  pooka 					if (pn_src->pn_va.va_type != VDIR) {
    609   1.1  pooka 						pu->pu_pathfree(pu, &po_old);
    610   1.1  pooka 						break;
    611   1.1  pooka 					}
    612   1.1  pooka 
    613   1.1  pooka 					/* handle all child nodes for DIRs */
    614   1.1  pooka 					pi.pi_old = &pcn_src.pcn_po_full;
    615   1.1  pooka 					pi.pi_new = &pcn_targ.pcn_po_full;
    616   1.1  pooka 
    617   1.1  pooka 					if (puffs_pn_nodewalk(pu,
    618   1.1  pooka 					    puffs_path_prefixadj, &pi) != NULL)
    619   1.1  pooka 						error = ENOMEM;
    620   1.1  pooka 					pu->pu_pathfree(pu, &po_old);
    621   1.1  pooka 				}
    622   1.1  pooka 			}
    623   1.1  pooka 			break;
    624   1.1  pooka 		}
    625   1.1  pooka 
    626   1.1  pooka 		case PUFFS_VN_MKDIR:
    627   1.1  pooka 		{
    628   1.1  pooka 			struct puffs_vnreq_mkdir *auxt = auxbuf;
    629   1.9  pooka 			struct puffs_newinfo pni;
    630   1.1  pooka 			struct puffs_cn pcn;
    631   1.9  pooka 
    632   1.1  pooka 			if (pops->puffs_node_mkdir == NULL) {
    633   1.1  pooka 				error = 0;
    634   1.1  pooka 				break;
    635   1.1  pooka 			}
    636   1.1  pooka 
    637   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    638   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    639   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    640   1.7  pooka 
    641   1.9  pooka 			memset(&pni, 0, sizeof(pni));
    642   1.9  pooka 			pni.pni_cookie = &auxt->pvnr_newnode;
    643   1.9  pooka 
    644   1.1  pooka 			if (buildpath) {
    645   1.1  pooka 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    646   1.1  pooka 				if (error)
    647   1.1  pooka 					break;
    648   1.1  pooka 			}
    649   1.1  pooka 
    650   1.1  pooka 			error = pops->puffs_node_mkdir(pcc,
    651   1.9  pooka 			    opcookie, &pni, &pcn, &auxt->pvnr_va);
    652   1.1  pooka 
    653   1.1  pooka 			if (buildpath) {
    654   1.1  pooka 				if (error) {
    655   1.1  pooka 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    656   1.1  pooka 				} else {
    657   1.1  pooka 					struct puffs_node *pn;
    658   1.1  pooka 
    659   1.1  pooka 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    660   1.1  pooka 					pn->pn_po = pcn.pcn_po_full;
    661   1.1  pooka 				}
    662   1.1  pooka 			}
    663   1.1  pooka 
    664   1.1  pooka 			break;
    665   1.1  pooka 		}
    666   1.1  pooka 
    667   1.1  pooka 		case PUFFS_VN_RMDIR:
    668   1.1  pooka 		{
    669   1.1  pooka 			struct puffs_vnreq_rmdir *auxt = auxbuf;
    670   1.1  pooka 			struct puffs_cn pcn;
    671   1.1  pooka 			if (pops->puffs_node_rmdir == NULL) {
    672   1.1  pooka 				error = 0;
    673   1.1  pooka 				break;
    674   1.1  pooka 			}
    675   1.1  pooka 
    676   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    677   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    678   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    679   1.1  pooka 
    680   1.1  pooka 			error = pops->puffs_node_rmdir(pcc,
    681   1.1  pooka 			    opcookie, auxt->pvnr_cookie_targ, &pcn);
    682   1.1  pooka 			break;
    683   1.1  pooka 		}
    684   1.1  pooka 
    685   1.1  pooka 		case PUFFS_VN_SYMLINK:
    686   1.1  pooka 		{
    687   1.1  pooka 			struct puffs_vnreq_symlink *auxt = auxbuf;
    688   1.9  pooka 			struct puffs_newinfo pni;
    689   1.1  pooka 			struct puffs_cn pcn;
    690   1.9  pooka 
    691   1.1  pooka 			if (pops->puffs_node_symlink == NULL) {
    692   1.1  pooka 				error = 0;
    693   1.1  pooka 				break;
    694   1.1  pooka 			}
    695   1.1  pooka 
    696   1.1  pooka 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    697   1.7  pooka 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    698   1.8  pooka 			PUFFS_KCIDTOCID(pcn.pcn_cid, &auxt->pvnr_cn_cid);
    699   1.7  pooka 
    700   1.9  pooka 			memset(&pni, 0, sizeof(pni));
    701   1.9  pooka 			pni.pni_cookie = &auxt->pvnr_newnode;
    702   1.9  pooka 
    703   1.1  pooka 			if (buildpath) {
    704   1.1  pooka 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    705   1.1  pooka 				if (error)
    706   1.1  pooka 					break;
    707   1.1  pooka 			}
    708   1.1  pooka 
    709   1.1  pooka 			error = pops->puffs_node_symlink(pcc,
    710   1.9  pooka 			    opcookie, &pni, &pcn,
    711   1.9  pooka 			    &auxt->pvnr_va, auxt->pvnr_link);
    712   1.1  pooka 
    713   1.1  pooka 			if (buildpath) {
    714   1.1  pooka 				if (error) {
    715   1.1  pooka 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    716   1.1  pooka 				} else {
    717   1.1  pooka 					struct puffs_node *pn;
    718   1.1  pooka 
    719   1.1  pooka 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    720   1.1  pooka 					pn->pn_po = pcn.pcn_po_full;
    721   1.1  pooka 				}
    722   1.1  pooka 			}
    723   1.1  pooka 
    724   1.1  pooka 			break;
    725   1.1  pooka 		}
    726   1.1  pooka 
    727   1.1  pooka 		case PUFFS_VN_READDIR:
    728   1.1  pooka 		{
    729   1.1  pooka 			struct puffs_vnreq_readdir *auxt = auxbuf;
    730   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    731   1.1  pooka 			struct dirent *dent;
    732   1.1  pooka 			off_t *cookies;
    733   1.1  pooka 			size_t res, origcookies;
    734   1.1  pooka 
    735   1.1  pooka 			if (pops->puffs_node_readdir == NULL) {
    736   1.1  pooka 				error = 0;
    737   1.1  pooka 				break;
    738   1.1  pooka 			}
    739   1.1  pooka 
    740   1.1  pooka 			if (auxt->pvnr_ncookies) {
    741   1.1  pooka 				/* LINTED: pvnr_data is __aligned() */
    742   1.1  pooka 				cookies = (off_t *)auxt->pvnr_data;
    743   1.1  pooka 				origcookies = auxt->pvnr_ncookies;
    744   1.1  pooka 			} else {
    745   1.1  pooka 				cookies = NULL;
    746   1.1  pooka 				origcookies = 0;
    747   1.1  pooka 			}
    748   1.1  pooka 			/* LINTED: dentoff is aligned in the kernel */
    749   1.1  pooka 			dent = (struct dirent *)
    750   1.1  pooka 			    (auxt->pvnr_data + auxt->pvnr_dentoff);
    751   1.1  pooka 
    752   1.1  pooka 			res = auxt->pvnr_resid;
    753   1.1  pooka 			error = pops->puffs_node_readdir(pcc,
    754   1.1  pooka 			    opcookie, dent, &auxt->pvnr_offset,
    755   1.7  pooka 			    &auxt->pvnr_resid, pcr, &auxt->pvnr_eofflag,
    756   1.7  pooka 			    cookies, &auxt->pvnr_ncookies);
    757   1.1  pooka 
    758   1.1  pooka 			/* much easier to track non-working NFS */
    759   1.1  pooka 			assert(auxt->pvnr_ncookies <= origcookies);
    760   1.1  pooka 
    761   1.1  pooka 			/* need to move a bit more */
    762   1.1  pooka 			preq->preq_buflen = sizeof(struct puffs_vnreq_readdir)
    763   1.1  pooka 			    + auxt->pvnr_dentoff + (res - auxt->pvnr_resid);
    764   1.1  pooka 			break;
    765   1.1  pooka 		}
    766   1.1  pooka 
    767   1.1  pooka 		case PUFFS_VN_READLINK:
    768   1.1  pooka 		{
    769   1.1  pooka 			struct puffs_vnreq_readlink *auxt = auxbuf;
    770   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    771   1.7  pooka 
    772   1.1  pooka 			if (pops->puffs_node_readlink == NULL) {
    773   1.1  pooka 				error = EOPNOTSUPP;
    774   1.1  pooka 				break;
    775   1.1  pooka 			}
    776   1.1  pooka 
    777   1.7  pooka 			/*LINTED*/
    778   1.7  pooka 			error = pops->puffs_node_readlink(pcc, opcookie, pcr,
    779   1.1  pooka 			    auxt->pvnr_link, &auxt->pvnr_linklen);
    780   1.1  pooka 			break;
    781   1.1  pooka 		}
    782   1.1  pooka 
    783   1.1  pooka 		case PUFFS_VN_RECLAIM:
    784   1.1  pooka 		{
    785   1.1  pooka 			struct puffs_vnreq_reclaim *auxt = auxbuf;
    786   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    787   1.8  pooka 
    788   1.1  pooka 			if (pops->puffs_node_reclaim == NULL) {
    789   1.1  pooka 				error = 0;
    790   1.1  pooka 				break;
    791   1.1  pooka 			}
    792   1.1  pooka 
    793   1.8  pooka 			error = pops->puffs_node_reclaim(pcc, opcookie, pcid);
    794   1.1  pooka 			break;
    795   1.1  pooka 		}
    796   1.1  pooka 
    797   1.1  pooka 		case PUFFS_VN_INACTIVE:
    798   1.1  pooka 		{
    799   1.1  pooka 			struct puffs_vnreq_inactive *auxt = auxbuf;
    800   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    801   1.8  pooka 
    802   1.1  pooka 			if (pops->puffs_node_inactive == NULL) {
    803   1.1  pooka 				error = EOPNOTSUPP;
    804   1.1  pooka 				break;
    805   1.1  pooka 			}
    806   1.1  pooka 
    807  1.10  pooka 			error = pops->puffs_node_inactive(pcc, opcookie, pcid);
    808   1.1  pooka 			break;
    809   1.1  pooka 		}
    810   1.1  pooka 
    811   1.1  pooka 		case PUFFS_VN_PATHCONF:
    812   1.1  pooka 		{
    813   1.1  pooka 			struct puffs_vnreq_pathconf *auxt = auxbuf;
    814   1.1  pooka 			if (pops->puffs_node_pathconf == NULL) {
    815   1.1  pooka 				error = 0;
    816   1.1  pooka 				break;
    817   1.1  pooka 			}
    818   1.1  pooka 
    819   1.1  pooka 			error = pops->puffs_node_pathconf(pcc,
    820   1.1  pooka 			    opcookie, auxt->pvnr_name,
    821   1.1  pooka 			    &auxt->pvnr_retval);
    822   1.1  pooka 			break;
    823   1.1  pooka 		}
    824   1.1  pooka 
    825   1.1  pooka 		case PUFFS_VN_ADVLOCK:
    826   1.1  pooka 		{
    827   1.1  pooka 			struct puffs_vnreq_advlock *auxt = auxbuf;
    828   1.1  pooka 			if (pops->puffs_node_advlock == NULL) {
    829   1.1  pooka 				error = 0;
    830   1.1  pooka 				break;
    831   1.1  pooka 			}
    832   1.1  pooka 
    833   1.1  pooka 			error = pops->puffs_node_advlock(pcc,
    834   1.1  pooka 			    opcookie, auxt->pvnr_id, auxt->pvnr_op,
    835   1.1  pooka 			    &auxt->pvnr_fl, auxt->pvnr_flags);
    836   1.1  pooka 			break;
    837   1.1  pooka 		}
    838   1.1  pooka 
    839   1.1  pooka 		case PUFFS_VN_PRINT:
    840   1.1  pooka 		{
    841   1.1  pooka 			if (pops->puffs_node_print == NULL) {
    842   1.1  pooka 				error = 0;
    843   1.1  pooka 				break;
    844   1.1  pooka 			}
    845   1.1  pooka 
    846   1.1  pooka 			error = pops->puffs_node_print(pcc,
    847   1.1  pooka 			    opcookie);
    848   1.1  pooka 			break;
    849   1.1  pooka 		}
    850   1.1  pooka 
    851   1.1  pooka 		case PUFFS_VN_READ:
    852   1.1  pooka 		{
    853   1.1  pooka 			struct puffs_vnreq_read *auxt = auxbuf;
    854   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    855   1.1  pooka 			size_t res;
    856   1.1  pooka 
    857   1.1  pooka 			if (pops->puffs_node_read == NULL) {
    858   1.1  pooka 				error = EIO;
    859   1.1  pooka 				break;
    860   1.1  pooka 			}
    861   1.1  pooka 
    862   1.1  pooka 			res = auxt->pvnr_resid;
    863   1.1  pooka 			error = pops->puffs_node_read(pcc,
    864   1.1  pooka 			    opcookie, auxt->pvnr_data,
    865   1.1  pooka 			    auxt->pvnr_offset, &auxt->pvnr_resid,
    866   1.7  pooka 			    pcr, auxt->pvnr_ioflag);
    867   1.1  pooka 
    868   1.1  pooka 			/* need to move a bit more */
    869   1.1  pooka 			preq->preq_buflen = sizeof(struct puffs_vnreq_read)
    870   1.1  pooka 			    + (res - auxt->pvnr_resid);
    871   1.1  pooka 			break;
    872   1.1  pooka 		}
    873   1.1  pooka 
    874   1.1  pooka 		case PUFFS_VN_WRITE:
    875   1.1  pooka 		{
    876   1.1  pooka 			struct puffs_vnreq_write *auxt = auxbuf;
    877   1.7  pooka 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    878   1.1  pooka 
    879   1.1  pooka 			if (pops->puffs_node_write == NULL) {
    880   1.1  pooka 				error = EIO;
    881   1.1  pooka 				break;
    882   1.1  pooka 			}
    883   1.1  pooka 
    884   1.1  pooka 			error = pops->puffs_node_write(pcc,
    885   1.1  pooka 			    opcookie, auxt->pvnr_data,
    886   1.1  pooka 			    auxt->pvnr_offset, &auxt->pvnr_resid,
    887   1.7  pooka 			    pcr, auxt->pvnr_ioflag);
    888   1.1  pooka 
    889   1.1  pooka 			/* don't need to move data back to the kernel */
    890   1.1  pooka 			preq->preq_buflen = sizeof(struct puffs_vnreq_write);
    891   1.1  pooka 			break;
    892   1.1  pooka 		}
    893   1.1  pooka 
    894   1.4  pooka 		case PUFFS_VN_POLL:
    895   1.4  pooka 		{
    896   1.4  pooka 			struct puffs_vnreq_poll *auxt = auxbuf;
    897   1.8  pooka 			PUFFS_MAKECID(pcid, &auxt->pvnr_cid);
    898   1.8  pooka 
    899   1.4  pooka 			if (pops->puffs_node_poll == NULL) {
    900   1.4  pooka 				error = 0;
    901   1.4  pooka 
    902   1.4  pooka 				/* emulate genfs_poll() */
    903   1.4  pooka 				auxt->pvnr_events &= (POLLIN | POLLOUT
    904   1.4  pooka 						    | POLLRDNORM | POLLWRNORM);
    905   1.4  pooka 
    906   1.4  pooka 				break;
    907   1.4  pooka 			}
    908   1.4  pooka 
    909   1.4  pooka 			error = pops->puffs_node_poll(pcc,
    910   1.8  pooka 			    opcookie, &auxt->pvnr_events, pcid);
    911   1.4  pooka 			break;
    912   1.4  pooka 		}
    913   1.4  pooka 
    914   1.1  pooka /* holy bitrot, ryydman! */
    915   1.1  pooka #if 0
    916   1.1  pooka 		case PUFFS_VN_IOCTL:
    917   1.1  pooka 			error = pops->puffs_node_ioctl1(pcc, opcookie,
    918   1.1  pooka 			     (struct puffs_vnreq_ioctl *)auxbuf, &pop);
    919   1.1  pooka 			if (error != 0)
    920   1.1  pooka 				break;
    921   1.1  pooka 			pop.pso_reqid = preq->preq_id;
    922   1.1  pooka 
    923   1.1  pooka 			/* let the kernel do it's intermediate duty */
    924   1.1  pooka 			error = ioctl(pu->pu_kargs.pa_fd, PUFFSSIZEOP, &pop);
    925   1.1  pooka 			/*
    926   1.1  pooka 			 * XXX: I don't actually know what the correct
    927   1.1  pooka 			 * thing to do in case of an error is, so I'll
    928   1.1  pooka 			 * just ignore it for the time being.
    929   1.1  pooka 			 */
    930   1.1  pooka 			error = pops->puffs_node_ioctl2(pcc, opcookie,
    931   1.1  pooka 			    (struct puffs_vnreq_ioctl *)auxbuf, &pop);
    932   1.1  pooka 			break;
    933   1.1  pooka 
    934   1.1  pooka 		case PUFFS_VN_FCNTL:
    935   1.1  pooka 			error = pops->puffs_node_fcntl1(pcc, opcookie,
    936   1.1  pooka 			     (struct puffs_vnreq_fcntl *)auxbuf, &pop);
    937   1.1  pooka 			if (error != 0)
    938   1.1  pooka 				break;
    939   1.1  pooka 			pop.pso_reqid = preq->preq_id;
    940   1.1  pooka 
    941   1.1  pooka 			/* let the kernel do it's intermediate duty */
    942   1.1  pooka 			error = ioctl(pu->pu_kargs.pa_fd, PUFFSSIZEOP, &pop);
    943   1.1  pooka 			/*
    944   1.1  pooka 			 * XXX: I don't actually know what the correct
    945   1.1  pooka 			 * thing to do in case of an error is, so I'll
    946   1.1  pooka 			 * just ignore it for the time being.
    947   1.1  pooka 			 */
    948   1.1  pooka 			error = pops->puffs_node_fcntl2(pcc, opcookie,
    949   1.1  pooka 			    (struct puffs_vnreq_fcntl *)auxbuf, &pop);
    950   1.1  pooka 			break;
    951   1.1  pooka #endif
    952   1.1  pooka 
    953   1.1  pooka 		default:
    954   1.1  pooka 			printf("inval op %d\n", preq->preq_optype);
    955   1.1  pooka 			error = EINVAL;
    956   1.1  pooka 			break;
    957   1.1  pooka 		}
    958   1.1  pooka 	} else {
    959   1.1  pooka 		/*
    960   1.1  pooka 		 * this one also
    961   1.1  pooka 		 */
    962   1.1  pooka 		error = EINVAL;
    963   1.1  pooka 	}
    964   1.1  pooka 
    965   1.1  pooka 	preq->preq_rv = error;
    966   1.3  pooka 	pcc->pcc_flags |= PCC_DONE;
    967   1.1  pooka 
    968   1.3  pooka 	/*
    969   1.3  pooka 	 * Note, we are calling this from here so that we can run it
    970   1.3  pooka 	 * off of the continuation stack.  Otherwise puffs_goto() would
    971   1.3  pooka 	 * not work.
    972   1.3  pooka 	 */
    973   1.3  pooka 	processresult(pcc, pcc->pcc_ppr, rv);
    974   1.3  pooka }
    975   1.3  pooka 
    976   1.3  pooka static void
    977   1.3  pooka processresult(struct puffs_cc *pcc, struct puffs_putreq *ppr, int how)
    978   1.3  pooka {
    979   1.3  pooka 	struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
    980   1.3  pooka 
    981   1.3  pooka 	/* check if we need to store this reply */
    982   1.3  pooka 	switch (how) {
    983   1.3  pooka 	case PUFFCALL_ANSWER:
    984   1.3  pooka 		if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
    985   1.3  pooka 			puffsdump_rv(pcc->pcc_preq);
    986   1.3  pooka 
    987   1.3  pooka 		if (pcc->pcc_flags & PCC_REALCC)
    988   1.3  pooka 			puffs_req_putcc(ppr, pcc);
    989   1.3  pooka 		else
    990   1.3  pooka 			puffs_req_put(ppr, pcc->pcc_preq);
    991   1.3  pooka 		break;
    992   1.3  pooka 	case PUFFCALL_IGNORE:
    993   1.3  pooka 		if (pcc->pcc_flags & PCC_REALCC)
    994   1.3  pooka 			LIST_INSERT_HEAD(&pu->pu_ccnukelst, pcc, nlst_entries);
    995   1.3  pooka 		break;
    996   1.3  pooka 	case PUFFCALL_AGAIN:
    997   1.3  pooka 		if (pcc->pcc_flags & PCC_FAKECC)
    998   1.3  pooka 			assert(pcc->pcc_flags & PCC_DONE);
    999   1.3  pooka 		break;
   1000   1.3  pooka 	default:
   1001   1.3  pooka 		assert(/*CONSTCOND*/0);
   1002   1.3  pooka 	}
   1003   1.3  pooka 
   1004   1.3  pooka 	/* who needs information when you're living on borrowed time? */
   1005   1.3  pooka 	if (pcc->pcc_flags & PCC_BORROWED)
   1006   1.3  pooka 		puffs_cc_yield(pcc); /* back to borrow source */
   1007   1.1  pooka }
   1008   1.1  pooka 
   1009   1.1  pooka 
   1010   1.1  pooka #if 0
   1011   1.1  pooka 		case PUFFS_VN_KQFILTER:
   1012   1.1  pooka 		{
   1013   1.1  pooka 			struct puffs_vnreq_kqfilter *auxt = auxbuf;
   1014   1.1  pooka 			if (pops->puffs_node_kqfilter == NULL) {
   1015   1.1  pooka 				error = 0;
   1016   1.1  pooka 				break;
   1017   1.1  pooka 			}
   1018   1.1  pooka 
   1019   1.1  pooka 			error = pops->puffs_node_kqfilter(pcc,
   1020   1.1  pooka 			    opcookie, );
   1021   1.1  pooka 			break;
   1022   1.1  pooka 		}
   1023   1.1  pooka 
   1024   1.1  pooka 		case PUFFS_VN_CLOSEEXTATTR:
   1025   1.1  pooka 		{
   1026   1.1  pooka 			struct puffs_vnreq_closeextattr *auxt = auxbuf;
   1027   1.1  pooka 			if (pops->puffs_closeextattr == NULL) {
   1028   1.1  pooka 				error = 0;
   1029   1.1  pooka 				break;
   1030   1.1  pooka 			}
   1031   1.1  pooka 
   1032   1.1  pooka 			error = pops->puffs_closeextattr(pcc,
   1033   1.1  pooka 			    opcookie, );
   1034   1.1  pooka 			break;
   1035   1.1  pooka 		}
   1036   1.1  pooka 
   1037   1.1  pooka 		case PUFFS_VN_GETEXTATTR:
   1038   1.1  pooka 		{
   1039   1.1  pooka 			struct puffs_vnreq_getextattr *auxt = auxbuf;
   1040   1.1  pooka 			if (pops->puffs_getextattr == NULL) {
   1041   1.1  pooka 				error = 0;
   1042   1.1  pooka 				break;
   1043   1.1  pooka 			}
   1044   1.1  pooka 
   1045   1.1  pooka 			error = pops->puffs_getextattr(pcc,
   1046   1.1  pooka 			    opcookie, );
   1047   1.1  pooka 			break;
   1048   1.1  pooka 		}
   1049   1.1  pooka 
   1050   1.1  pooka 		case PUFFS_VN_LISTEXTATTR:
   1051   1.1  pooka 		{
   1052   1.1  pooka 			struct puffs_vnreq_listextattr *auxt = auxbuf;
   1053   1.1  pooka 			if (pops->puffs_listextattr == NULL) {
   1054   1.1  pooka 				error = 0;
   1055   1.1  pooka 				break;
   1056   1.1  pooka 			}
   1057   1.1  pooka 
   1058   1.1  pooka 			error = pops->puffs_listextattr(pcc,
   1059   1.1  pooka 			    opcookie, );
   1060   1.1  pooka 			break;
   1061   1.1  pooka 		}
   1062   1.1  pooka 
   1063   1.1  pooka 		case PUFFS_VN_OPENEXTATTR:
   1064   1.1  pooka 		{
   1065   1.1  pooka 			struct puffs_vnreq_openextattr *auxt = auxbuf;
   1066   1.1  pooka 			if (pops->puffs_openextattr == NULL) {
   1067   1.1  pooka 				error = 0;
   1068   1.1  pooka 				break;
   1069   1.1  pooka 			}
   1070   1.1  pooka 
   1071   1.1  pooka 			error = pops->puffs_openextattr(pcc,
   1072   1.1  pooka 			    opcookie, );
   1073   1.1  pooka 			break;
   1074   1.1  pooka 		}
   1075   1.1  pooka 
   1076   1.1  pooka 		case PUFFS_VN_DELETEEXTATTR:
   1077   1.1  pooka 		{
   1078   1.1  pooka 			struct puffs_vnreq_deleteextattr *auxt = auxbuf;
   1079   1.1  pooka 			if (pops->puffs_deleteextattr == NULL) {
   1080   1.1  pooka 				error = 0;
   1081   1.1  pooka 				break;
   1082   1.1  pooka 			}
   1083   1.1  pooka 
   1084   1.1  pooka 			error = pops->puffs_deleteextattr(pcc,
   1085   1.1  pooka 			    opcookie, );
   1086   1.1  pooka 			break;
   1087   1.1  pooka 		}
   1088   1.1  pooka 
   1089   1.1  pooka 		case PUFFS_VN_SETEXTATTR:
   1090   1.1  pooka 		{
   1091   1.1  pooka 			struct puffs_vnreq_setextattr *auxt = auxbuf;
   1092   1.1  pooka 			if (pops->puffs_setextattr == NULL) {
   1093   1.1  pooka 				error = 0;
   1094   1.1  pooka 				break;
   1095   1.1  pooka 			}
   1096   1.1  pooka 
   1097   1.1  pooka 			error = pops->puffs_setextattr(pcc,
   1098   1.1  pooka 			    opcookie, );
   1099   1.1  pooka 			break;
   1100   1.1  pooka 		}
   1101   1.1  pooka 
   1102   1.1  pooka #endif
   1103