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