puffs_portal.c revision 1.8 1 /* $NetBSD: puffs_portal.c,v 1.8 2017/05/09 21:17:54 christos Exp $ */
2
3 /*
4 * Copyright (c) 2007 Antti Kantee. All Rights Reserved.
5 * Development was supported by the Finnish Cultural Foundation.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 #ifndef lint
31 __RCSID("$NetBSD: puffs_portal.c,v 1.8 2017/05/09 21:17:54 christos Exp $");
32 #endif /* !lint */
33
34 #include <sys/types.h>
35 #include <sys/wait.h>
36 #include <sys/socket.h>
37
38 #include <assert.h>
39 #include <err.h>
40 #include <errno.h>
41 #include <mntopts.h>
42 #include <paths.h>
43 #include <poll.h>
44 #include <puffs.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <unistd.h>
49 #include <util.h>
50
51 #include "portald.h"
52
53 struct portal_node {
54 char *path;
55 int fd;
56 };
57
58 __dead static void usage(void);
59
60 PUFFSOP_PROTOS(portal);
61
62 #define PORTAL_ROOT NULL
63 #define METADATASIZE (sizeof(int) + sizeof(size_t))
64
65 qelem q;
66 int readcfg, sigchild;
67 const char *cfg;
68
69 static void
70 usage(void)
71 {
72
73 errx(1, "usage: %s [-o options] /path/portal.conf mount_point",
74 getprogname());
75 }
76
77 static void
78 sighup(int sig)
79 {
80
81 readcfg = 1;
82 }
83
84 static void
85 sigcry(int sig)
86 {
87
88 sigchild = 1;
89 }
90
91 static void
92 portal_loopfn(struct puffs_usermount *pu)
93 {
94
95 if (readcfg)
96 conf_read(&q, cfg);
97 readcfg = 0;
98
99 if (sigchild) {
100 sigchild = 0;
101 while (waitpid(-1, NULL, WNOHANG) != -1)
102 continue;
103 }
104 }
105
106 #define PUFBUF_FD 1
107 #define PUFBUF_DATA 2
108
109 #define CMSIZE (sizeof(struct cmsghdr) + sizeof(int))
110
111 /* receive file descriptor produced by our child process */
112 static int
113 readfd(struct puffs_framebuf *pufbuf, int fd, int *done)
114 {
115 struct cmsghdr *cmp;
116 struct msghdr msg;
117 struct iovec iov;
118 ssize_t n;
119 int error, rv;
120
121 rv = 0;
122 cmp = emalloc(CMSG_SPACE(sizeof(int)));
123
124 iov.iov_base = &error;
125 iov.iov_len = sizeof(int);
126 msg.msg_iov = &iov;
127 msg.msg_iovlen = 1;
128 msg.msg_name = NULL;
129 msg.msg_namelen = 0;
130 msg.msg_control = cmp;
131 msg.msg_controllen = CMSG_SPACE(sizeof(int));
132
133 n = recvmsg(fd, &msg, 0);
134 if (n == -1) {
135 rv = errno;
136 goto out;
137 }
138 if (n == 0) {
139 rv = ECONNRESET;
140 goto out;
141 }
142
143 /* the data for the server */
144 puffs_framebuf_putdata_atoff(pufbuf, 0, &error, sizeof(int));
145 if (error) {
146 rv = error;
147 goto out;
148 }
149 puffs_framebuf_putdata_atoff(pufbuf, sizeof(int),
150 CMSG_DATA(cmp), sizeof(int));
151 *done = 1;
152
153 out:
154 free(cmp);
155 return rv;
156 }
157
158 /*
159 * receive data from provider
160 *
161 * XXX: should read directly into the buffer and adjust offsets
162 * instead of doing memcpy
163 */
164 static int
165 readdata(struct puffs_framebuf *pufbuf, int fd, int *done)
166 {
167 char buf[1024];
168 size_t max;
169 ssize_t n;
170 size_t moved;
171
172 /* don't override metadata */
173 if (puffs_framebuf_telloff(pufbuf) == 0)
174 puffs_framebuf_seekset(pufbuf, METADATASIZE);
175 puffs_framebuf_getdata_atoff(pufbuf, sizeof(int), &max, sizeof(size_t));
176 moved = puffs_framebuf_tellsize(pufbuf) - METADATASIZE;
177 assert(max >= moved);
178 max -= moved;
179
180 do {
181 n = read(fd, buf, MIN(sizeof(buf), max));
182 if (n == 0) {
183 /*
184 * Deal with EOF here by closing the file descriptor
185 * and thus causing an error on subsequent accesses.
186 * This is the last kevent notification we are going
187 * to be getting for regular files.
188 */
189 close(fd);
190 if (moved)
191 break;
192 else
193 return -1; /* caught by read */
194 }
195 if (n < 0) {
196 if (moved)
197 return 0;
198
199 if (errno != EAGAIN)
200 return errno;
201 else
202 return 0;
203 }
204
205 puffs_framebuf_putdata(pufbuf, buf, n);
206 moved += n;
207 max -= n;
208 } while (max > 0);
209
210 *done = 1;
211
212 return 0;
213 }
214
215 static int
216 portal_frame_rf(struct puffs_usermount *pu, struct puffs_framebuf *pufbuf,
217 int fd, int *done)
218 {
219 int type;
220
221 if (puffs_framebuf_getdata_atoff(pufbuf, 0, &type, sizeof(int)) == -1)
222 return EINVAL;
223
224 if (type == PUFBUF_FD)
225 return readfd(pufbuf, fd, done);
226 else if (type == PUFBUF_DATA)
227 return readdata(pufbuf, fd, done);
228 else
229 abort();
230 }
231
232 static int
233 portal_frame_wf(struct puffs_usermount *pu, struct puffs_framebuf *pufbuf,
234 int fd, int *done)
235 {
236 void *win;
237 size_t pbsize, pboff, winlen;
238 ssize_t n;
239 int error;
240
241 pboff = puffs_framebuf_telloff(pufbuf);
242 pbsize = puffs_framebuf_tellsize(pufbuf);
243 error = 0;
244
245 do {
246 assert(pbsize > pboff);
247 winlen = pbsize - pboff;
248 if (puffs_framebuf_getwindow(pufbuf, pboff, &win, &winlen)==-1)
249 return errno;
250 n = write(fd, win, winlen);
251 if (n == 0) {
252 if (pboff != 0)
253 break;
254 else
255 return -1; /* caught by node_write */
256 }
257 if (n < 0) {
258 if (pboff != 0)
259 break;
260
261 if (errno != EAGAIN)
262 return errno;
263 return 0;
264 }
265
266 pboff += n;
267 puffs_framebuf_seekset(pufbuf, pboff);
268 } while (pboff != pbsize);
269
270 *done = 1;
271 puffs_framebuf_putdata_atoff(pufbuf, 0, &pboff, sizeof(size_t));
272 return error;
273 }
274
275 /* transfer file descriptor to master file server */
276 static int
277 sendfd(int s, int fd, int error)
278 {
279 struct cmsghdr *cmp;
280 struct msghdr msg;
281 struct iovec iov;
282 ssize_t n;
283 int rv;
284
285 rv = 0;
286 cmp = emalloc(CMSG_LEN(sizeof(int)));
287
288 iov.iov_base = &error;
289 iov.iov_len = sizeof(int);
290
291 msg.msg_iov = &iov;
292 msg.msg_iovlen = 1;
293 msg.msg_name = NULL;
294 msg.msg_namelen = 0;
295 if (error == 0) {
296 cmp->cmsg_level = SOL_SOCKET;
297 cmp->cmsg_type = SCM_RIGHTS;
298 cmp->cmsg_len = CMSG_LEN(sizeof(int));
299
300 msg.msg_control = cmp;
301 msg.msg_controllen = CMSG_LEN(sizeof(int));
302 *(int *)CMSG_DATA(cmp) = fd;
303 } else {
304 msg.msg_control = NULL;
305 msg.msg_controllen = 0;
306 }
307
308 n = sendmsg(s, &msg, 0);
309 if (n == -1)
310 rv = errno;
311 else if (n < (ssize_t)sizeof(int))
312 rv = EPROTO;
313
314 free(cmp);
315 return rv;
316 }
317
318 /*
319 * Produce I/O file descriptor by forking (like original portald).
320 *
321 * child: run provider and transfer produced fd to parent
322 * parent: yield until child produces fd. receive it and store it.
323 */
324 static int
325 provide(struct puffs_usermount *pu, struct portal_node *portn,
326 struct portal_cred *portc, char **v)
327 {
328 struct puffs_cc *pcc = puffs_cc_getcc(pu);
329 struct puffs_framebuf *pufbuf;
330 int s[2];
331 int fd, error;
332 int data;
333
334 pufbuf = puffs_framebuf_make();
335 if (pufbuf == NULL)
336 return ENOMEM;
337
338 data = PUFBUF_FD;
339 if (puffs_framebuf_putdata(pufbuf, &data, sizeof(int)) == -1)
340 goto bad;
341
342 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, s) == -1)
343 goto bad;
344
345 switch (fork()) {
346 case -1:
347 goto bad;
348 case 0:
349 error = activate_argv(portc, portn->path, v, &fd);
350 sendfd(s[1], fd, error);
351 exit(0);
352 default:
353 puffs_framev_addfd(pu, s[0], PUFFS_FBIO_READ);
354 puffs_framev_enqueue_directreceive(pcc, s[0], pufbuf, 0);
355 puffs_framev_removefd(pu, s[0], 0);
356 close(s[0]);
357 close(s[1]);
358
359 if (puffs_framebuf_tellsize(pufbuf) < sizeof(int)) {
360 errno = EIO;
361 goto bad;
362 }
363 puffs_framebuf_getdata_atoff(pufbuf, 0, &error, sizeof(int));
364 if (error) {
365 errno = error;
366 goto bad;
367 }
368
369 if (puffs_framebuf_tellsize(pufbuf) != 2*sizeof(int)) {
370 errno = EIO;
371 goto bad;
372 }
373
374 puffs_framebuf_getdata_atoff(pufbuf, sizeof(int),
375 &fd, sizeof(int));
376 puffs_framebuf_destroy(pufbuf);
377
378 data = 1;
379 if (ioctl(fd, FIONBIO, &data) == -1)
380 return errno;
381
382 if (puffs_framev_addfd(pu, fd, PUFFS_FBIO_WRITE) == -1)
383 return errno;
384
385 portn->fd = fd;
386 return 0;
387 }
388
389 bad:
390 puffs_framebuf_destroy(pufbuf);
391 return errno;
392 }
393
394 int
395 main(int argc, char *argv[])
396 {
397 extern char *optarg;
398 extern int optind;
399 struct puffs_usermount *pu;
400 struct puffs_ops *pops;
401 mntoptparse_t mp;
402 int pflags, mntflags;
403 int detach;
404 int ch;
405
406 setprogname(argv[0]);
407
408 mntflags = pflags = 0;
409 detach = 1;
410 while ((ch = getopt(argc, argv, "o:s")) != -1) {
411 switch (ch) {
412 case 'o':
413 mp = getmntopts(optarg, puffsmopts, &mntflags, &pflags);
414 if (mp == NULL)
415 err(1, "getmntopts");
416 freemntopts(mp);
417 break;
418 case 's': /* stay on top */
419 detach = 0;
420 break;
421 default:
422 usage();
423 /*NOTREACHED*/
424 }
425 }
426 pflags |= PUFFS_KFLAG_NOCACHE | PUFFS_KFLAG_LOOKUP_FULLPNBUF;
427 if (pflags & PUFFS_FLAG_OPDUMP)
428 detach = 0;
429 argc -= optind;
430 argv += optind;
431
432 if (argc != 2)
433 usage();
434
435 PUFFSOP_INIT(pops);
436
437 PUFFSOP_SETFSNOP(pops, unmount);
438 PUFFSOP_SETFSNOP(pops, sync);
439 PUFFSOP_SETFSNOP(pops, statvfs);
440
441 PUFFSOP_SET(pops, portal, node, lookup);
442 PUFFSOP_SET(pops, portal, node, getattr);
443 PUFFSOP_SET(pops, portal, node, setattr);
444 PUFFSOP_SET(pops, portal, node, open);
445 PUFFSOP_SET(pops, portal, node, read);
446 PUFFSOP_SET(pops, portal, node, write);
447 PUFFSOP_SET(pops, portal, node, seek);
448 PUFFSOP_SET(pops, portal, node, poll);
449 PUFFSOP_SET(pops, portal, node, inactive);
450 PUFFSOP_SET(pops, portal, node, reclaim);
451
452 pu = puffs_init(pops, _PATH_PUFFS, "portal", NULL, pflags);
453 if (pu == NULL)
454 err(1, "init");
455
456 if (signal(SIGHUP, sighup) == SIG_ERR)
457 warn("cannot set sighup handler");
458 if (signal(SIGCHLD, sigcry) == SIG_ERR)
459 err(1, "cannot set sigchild handler");
460 if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
461 err(1, "cannot ignore sigpipe");
462
463 readcfg = 0;
464 cfg = argv[0];
465 if (*cfg != '/')
466 errx(1, "need absolute path for config");
467 q.q_forw = q.q_back = &q;
468 if (conf_read(&q, cfg) == -1)
469 err(1, "cannot read cfg \"%s\"", cfg);
470
471 puffs_ml_setloopfn(pu, portal_loopfn);
472 puffs_framev_init(pu, portal_frame_rf, portal_frame_wf, NULL,NULL,NULL);
473
474 if (detach)
475 if (puffs_daemon(pu, 1, 1) == -1)
476 err(1, "puffs_daemon");
477
478 if (puffs_mount(pu, argv[1], mntflags, PORTAL_ROOT) == -1)
479 err(1, "mount");
480 if (puffs_mainloop(pu) == -1)
481 err(1, "mainloop");
482
483 return 0;
484 }
485
486 static struct portal_node *
487 makenode(const char *path)
488 {
489 struct portal_node *portn;
490
491 portn = emalloc(sizeof(struct portal_node));
492 portn->path = estrdup(path);
493 portn->fd = -1;
494
495 return portn;
496 }
497
498 static void
499 credtr(struct portal_cred *portc, const struct puffs_cred *puffc, int mode)
500 {
501 memset(portc, 0, sizeof(struct portal_cred));
502
503 portc->pcr_flag = mode;
504 puffs_cred_getuid(puffc, &portc->pcr_uid);
505 puffs_cred_getgid(puffc, &portc->pcr_gid);
506 puffs_cred_getgroups(puffc, portc->pcr_groups,
507 (short *)&portc->pcr_ngroups);
508 }
509
510 /*
511 * XXX: we could also simply already resolve the name at this stage
512 * instead of deferring it to open. But doing it in open is how the
513 * original portald does it, and I don't want to introduce any funny
514 * incompatibilities.
515 */
516 int
517 portal_node_lookup(struct puffs_usermount *pu, puffs_cookie_t opc,
518 struct puffs_newinfo *pni, const struct puffs_cn *pcn)
519 {
520 struct portal_node *portn;
521
522 assert(opc == PORTAL_ROOT);
523
524 if (pcn->pcn_nameiop != NAMEI_LOOKUP
525 && pcn->pcn_nameiop != NAMEI_CREATE)
526 return EOPNOTSUPP;
527
528 portn = makenode(pcn->pcn_name);
529 puffs_newinfo_setcookie(pni, portn);
530 puffs_newinfo_setvtype(pni, VREG);
531
532 pcn->pcn_flags &= ~NAMEI_REQUIREDIR;
533 pcn->pcn_consume = strlen(pcn->pcn_name) - pcn->pcn_namelen;
534
535 return 0;
536 }
537
538 int fakeid = 3;
539
540 /* XXX: libpuffs'ize */
541 int
542 portal_node_getattr(struct puffs_usermount *pu, puffs_cookie_t opc,
543 struct vattr *va, const struct puffs_cred *pcr)
544 {
545 struct timeval tv;
546 struct timespec ts;
547
548 puffs_vattr_null(va);
549 if (opc == PORTAL_ROOT) {
550 va->va_type = VDIR;
551 va->va_mode = 0777;
552 va->va_nlink = 2;
553 } else {
554 va->va_type = VREG;
555 va->va_mode = 0666;
556 va->va_nlink = 1;
557 }
558 va->va_uid = va->va_gid = 0;
559 va->va_fileid = fakeid++;
560 va->va_size = va->va_bytes = 0;
561 va->va_gen = 0;
562 va->va_rdev = PUFFS_VNOVAL;
563 va->va_blocksize = DEV_BSIZE;
564
565 gettimeofday(&tv, NULL);
566 TIMEVAL_TO_TIMESPEC(&tv, &ts);
567 va->va_atime = va->va_ctime = va->va_mtime = va->va_birthtime = ts;
568
569 return 0;
570 }
571
572 /* for writing, just pretend we care */
573 int
574 portal_node_setattr(struct puffs_usermount *pu, puffs_cookie_t opc,
575 const struct vattr *va, const struct puffs_cred *pcr)
576 {
577
578 return 0;
579 }
580
581 int
582 portal_node_open(struct puffs_usermount *pu, puffs_cookie_t opc, int mode,
583 const struct puffs_cred *pcr)
584 {
585 struct portal_node *portn = opc;
586 struct portal_cred portc;
587 char **v;
588
589 if (opc == PORTAL_ROOT)
590 return 0;
591
592 if (mode & O_NONBLOCK)
593 return EOPNOTSUPP;
594
595 v = conf_match(&q, portn->path);
596 if (v == NULL)
597 return ENOENT;
598
599 credtr(&portc, pcr, mode);
600 return provide(pu, portn, &portc, v);
601 }
602
603 int
604 portal_node_read(struct puffs_usermount *pu, puffs_cookie_t opc,
605 uint8_t *buf, off_t offset, size_t *resid,
606 const struct puffs_cred *pcr, int ioflag)
607 {
608 struct puffs_cc *pcc = puffs_cc_getcc(pu);
609 struct portal_node *portn = opc;
610 struct puffs_framebuf *pufbuf;
611 size_t xfersize, winsize, boff;
612 void *win;
613 int rv, error;
614 int data, dummy;
615
616 assert(opc != PORTAL_ROOT);
617 error = 0;
618
619 /* if we can't (re-)enable it, treat it as EOF */
620 rv = puffs_framev_enablefd(pu, portn->fd, PUFFS_FBIO_READ);
621 if (rv == -1)
622 return 0;
623
624 pufbuf = puffs_framebuf_make();
625 data = PUFBUF_DATA;
626 puffs_framebuf_putdata(pufbuf, &data, sizeof(int));
627 puffs_framebuf_putdata(pufbuf, resid, sizeof(size_t));
628
629 /* if we are doing nodelay, do read directly */
630 if (ioflag & PUFFS_IO_NDELAY) {
631 rv = readdata(pufbuf, portn->fd, &dummy);
632 if (rv != 0) {
633 error = rv;
634 goto out;
635 }
636 } else {
637 rv = puffs_framev_enqueue_directreceive(pcc,
638 portn->fd, pufbuf, 0);
639
640 if (rv == -1) {
641 error = errno;
642 goto out;
643 }
644 }
645
646 xfersize = puffs_framebuf_tellsize(pufbuf) - METADATASIZE;
647 if (xfersize == 0) {
648 assert(ioflag & PUFFS_IO_NDELAY);
649 error = EAGAIN;
650 goto out;
651 }
652
653 *resid -= xfersize;
654 boff = 0;
655 while (xfersize > 0) {
656 winsize = xfersize;
657 rv = puffs_framebuf_getwindow(pufbuf, METADATASIZE,
658 &win, &winsize);
659 assert(rv == 0);
660 assert(winsize > 0);
661
662 memcpy(buf + boff, win, winsize);
663 xfersize -= winsize;
664 boff += winsize;
665 }
666
667 out:
668 puffs_framev_disablefd(pu, portn->fd, PUFFS_FBIO_READ);
669 puffs_framebuf_destroy(pufbuf);
670
671 /* a trickery, from readdata() */
672 if (error == -1)
673 return 0;
674 return error;
675 }
676
677 int
678 portal_node_write(struct puffs_usermount *pu, puffs_cookie_t opc,
679 uint8_t *buf, off_t offset, size_t *resid,
680 const struct puffs_cred *pcr, int ioflag)
681 {
682 struct puffs_cc *pcc = puffs_cc_getcc(pu);
683 struct portal_node *portn = opc;
684 struct puffs_framebuf *pufbuf;
685 size_t written;
686 int error, rv, dummy;
687
688 assert(opc != PORTAL_ROOT);
689
690 pufbuf = puffs_framebuf_make();
691 puffs_framebuf_putdata(pufbuf, buf, *resid);
692
693 error = 0;
694 if (ioflag & PUFFS_IO_NDELAY) {
695 rv = portal_frame_wf(pu, pufbuf, portn->fd, &dummy);
696 if (rv) {
697 error = rv;
698 goto out;
699 }
700 } else {
701 rv = puffs_framev_enqueue_directsend(pcc, portn->fd, pufbuf, 0);
702 if (rv == -1) {
703 error = errno;
704 goto out;
705 }
706 }
707
708 rv = puffs_framebuf_getdata_atoff(pufbuf, 0, &written, sizeof(size_t));
709 assert(rv == 0);
710 assert(written <= *resid);
711 *resid -= written;
712
713 out:
714 puffs_framebuf_destroy(pufbuf);
715 if (error == -1)
716 error = 0;
717 return 0;
718 }
719
720 int
721 portal_node_seek(struct puffs_usermount *pu, puffs_cookie_t opc,
722 off_t oldoff, off_t newoff, const struct puffs_cred *pcr)
723 {
724 struct portal_node *portn = opc;
725
726 if (opc == PORTAL_ROOT || portn->fd == -1)
727 return EOPNOTSUPP;
728
729 if (lseek(portn->fd, newoff, SEEK_SET) == -1)
730 return errno;
731 return 0;
732 }
733
734 int
735 portal_node_poll(struct puffs_usermount *pu, puffs_cookie_t opc, int *events)
736 {
737 struct puffs_cc *pcc = puffs_cc_getcc(pu);
738 struct portal_node *portn = opc;
739 int what;
740
741 what = 0;
742 if (*events & POLLIN)
743 what |= PUFFS_FBIO_READ;
744 if (*events & POLLOUT)
745 what |= PUFFS_FBIO_WRITE;
746 if (*events & POLLERR)
747 what |= PUFFS_FBIO_ERROR;
748
749 if (puffs_framev_enqueue_waitevent(pcc, portn->fd, &what) == -1) {
750 *events = POLLERR;
751 return errno;
752 }
753
754 *events = 0;
755 if (what & PUFFS_FBIO_READ)
756 *events |= POLLIN;
757 if (what & PUFFS_FBIO_WRITE)
758 *events |= POLLOUT;
759 if (what & PUFFS_FBIO_ERROR)
760 *events |= POLLERR;
761
762 return 0;
763 }
764
765 int
766 portal_node_inactive(struct puffs_usermount *pu, puffs_cookie_t opc)
767 {
768
769 if (opc == PORTAL_ROOT)
770 return 0;
771
772 puffs_setback(puffs_cc_getcc(pu), PUFFS_SETBACK_NOREF_N1);
773 return 0;
774 }
775
776 int
777 portal_node_reclaim(struct puffs_usermount *pu, puffs_cookie_t opc)
778 {
779 struct portal_node *portn = opc;
780
781 if (portn->fd != -1) {
782 puffs_framev_removefd(pu, portn->fd, 0);
783 close(portn->fd);
784 }
785 free(portn->path);
786 free(portn);
787
788 return 0;
789 }
790