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