refuse.c revision 1.11 1 /* $NetBSD: refuse.c,v 1.11 2007/02/15 10:54:40 pooka Exp $ */
2
3 /*
4 * Copyright 2007 Alistair Crooks. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include <sys/cdefs.h>
32 #if !defined(lint)
33 __RCSID("$NetBSD: refuse.c,v 1.11 2007/02/15 10:54:40 pooka Exp $");
34 #endif /* !lint */
35
36 #include <err.h>
37 #include <errno.h>
38 #include <fuse.h>
39 #include <ucontext.h>
40 #include <unistd.h>
41
42 #include "defs.h"
43
44 typedef uint64_t fuse_ino_t;
45
46 struct fuse_config {
47 uid_t uid;
48 gid_t gid;
49 mode_t umask;
50 double entry_timeout;
51 double negative_timeout;
52 double attr_timeout;
53 double ac_attr_timeout;
54 int ac_attr_timeout_set;
55 int debug;
56 int hard_remove;
57 int use_ino;
58 int readdir_ino;
59 int set_mode;
60 int set_uid;
61 int set_gid;
62 int direct_io;
63 int kernel_cache;
64 int auto_cache;
65 int intr;
66 int intr_signal;
67 };
68
69 /* this is the private fuse structure */
70 struct fuse {
71 struct fuse_session *se; /* fuse session pointer */
72 struct fuse_operations op; /* switch table of operations */
73 int compat; /* compat level -
74 * not used in puffs_fuse */
75 struct node **name_table;
76 size_t name_table_size;
77 struct node **id_table;
78 size_t id_table_size;
79 fuse_ino_t ctr;
80 unsigned int generation;
81 unsigned int hidectr;
82 pthread_mutex_t lock;
83 pthread_rwlock_t tree_lock;
84 void *user_data;
85 struct fuse_config conf;
86 int intr_installed;
87 struct puffs_usermount *pu;
88 };
89
90 struct refusenode {
91 struct fuse_file_info file_info;
92 };
93
94 static struct puffs_node *
95 newrn(struct puffs_usermount *pu)
96 {
97 struct puffs_node *pn;
98 struct refusenode *rn;
99
100 rn = malloc(sizeof(struct refusenode));
101 if (!rn)
102 abort(); /*XXX*/
103
104 memset(rn, 0, sizeof(struct refusenode));
105 pn = puffs_pn_new(pu, rn);
106
107 return pn;
108 }
109
110 static void
111 nukern(struct puffs_node *pn)
112 {
113
114 free(pn->pn_data);
115 puffs_pn_put(pn);
116 }
117
118 static ino_t fakeino = 3;
119
120 /* XXX: rethinkme */
121 struct fuse_dirh {
122 struct dirent *dent;
123 size_t reslen;
124 off_t readoff;
125 };
126
127 /* ARGSUSED2 */
128 static int
129 puffs_fuse_fill_dir(void *buf, const char *name,
130 const struct stat *stbuf, off_t off)
131 {
132 struct fuse_dirh *deh = buf;
133 uint8_t dtype;
134
135 /* XXX: this is hacked *purely* for hellofs, so fiXXXme */
136 if (*name == '.')
137 dtype = DT_DIR;
138 else
139 dtype = DT_REG;
140
141 return !puffs_nextdent(&deh->dent, name, fakeino++, dtype,&deh->reslen);
142 }
143
144 static int
145 puffs_fuse_dirfil(fuse_dirh_t h, const char *name, int type, ino_t ino)
146 {
147 ino_t dino;
148 int dtype;
149
150 /* XXX: this is hacked *purely* for cddafs, so fiXXXme */
151 if (type == 0) {
152 if (*name == '.')
153 dtype = DT_DIR;
154 else
155 dtype = DT_REG;
156 } else
157 dtype = type;
158
159 if (ino)
160 dino = ino;
161 else
162 dino = fakeino++;
163
164 return !puffs_nextdent(&h->dent, name, dino, dtype, &h->reslen);
165 }
166
167 int
168 fuse_opt_add_arg(struct fuse_args *args, const char *arg)
169 {
170 char **oldargv;
171 int oldargc;
172
173 if (args->allocated) {
174 RENEW(char *, args->argv, args->argc + 1,
175 "fuse_opt_add_arg1", return 0);
176 } else {
177 oldargv = args->argv;
178 oldargc = args->argc;
179 NEWARRAY(char *, args->argv, oldargc + 1,
180 "fuse_opt_add_arg2", return 0);
181 (void) memcpy(args->argv, oldargv, oldargc * sizeof(char *));
182 args->allocated = 1;
183 }
184 args->argv[args->argc++] = strdup(arg);
185 return 1;
186 }
187
188 /* operation wrappers start here */
189
190 /* lookup the path */
191 /* ARGSUSED1 */
192 static int
193 puffs_fuse_node_lookup(struct puffs_cc *pcc, void *opc, void **newnode,
194 enum vtype *newtype, voff_t *newsize, dev_t *newrdev,
195 const struct puffs_cn *pcn)
196 {
197 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
198 struct stat st;
199 struct fuse *fuse;
200 const char *path = PCNPATH(pcn);
201 int ret;
202
203 /* XXX: THIS IS VERY WRONG */
204 fuse = (struct fuse *)pu->pu_privdata;
205 ret = fuse->op.getattr(path, &st);
206 ret = -ret; /* linux foo */
207 if (ret != 0) {
208 return ret;
209 }
210 *newnode = newrn(pu);
211 *newtype = (S_ISDIR(st.st_mode)) ? VDIR : VREG;
212 *newsize = st.st_size;
213 return ret;
214 }
215
216 /* get attributes for the path name */
217 /* ARGSUSED3 */
218 static int
219 puffs_fuse_node_getattr(struct puffs_cc *pcc, void *opc, struct vattr *va,
220 const struct puffs_cred *pcr, pid_t pid)
221 {
222 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
223 struct puffs_node *pn = opc;
224 struct stat st;
225 struct fuse *fuse;
226 const char *path = PNPATH(pn);
227 int ret;
228
229 fuse = (struct fuse *)pu->pu_privdata;
230 if (fuse->op.getattr == NULL) {
231 return ENOSYS;
232 }
233
234 /* wrap up return code */
235 ret = (*fuse->op.getattr)(path, &st);
236
237 if (ret == 0) {
238 /* fill in va from st */
239 va->va_mode = st.st_mode;
240 va->va_nlink = st.st_nlink;
241 va->va_uid = st.st_uid;
242 va->va_gid = st.st_gid;
243 va->va_fsid = st.st_rdev;
244 va->va_fileid = st.st_ino;
245 va->va_size = st.st_size;
246 va->va_blocksize = st.st_blksize;
247 va->va_atime = st.st_atimespec;
248 va->va_mtime = st.st_mtimespec;
249 va->va_ctime = st.st_ctimespec;
250 va->va_birthtime = st.st_birthtimespec;
251 va->va_gen = st.st_gen;
252 va->va_flags = st.st_flags;
253 va->va_rdev = st.st_rdev;
254 va->va_bytes = st.st_size;
255 va->va_filerev = st.st_gen;
256 va->va_vaflags = st.st_flags;
257
258 }
259
260 return ret;
261 }
262
263 /* read the contents of the symbolic link */
264 /* ARGSUSED2 */
265 static int
266 puffs_fuse_node_readlink(struct puffs_cc *pcc, void *opc,
267 const struct puffs_cred *cred, char *linkname, size_t *linklen)
268 {
269 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
270 struct puffs_node *pn = opc;
271 struct fuse *fuse;
272 const char *path = PNPATH(pn);
273 int ret;
274
275 fuse = (struct fuse *)pu->pu_privdata;
276 if (fuse->op.readlink == NULL) {
277 return ENOSYS;
278 }
279
280 /* wrap up return code */
281 ret = (*fuse->op.readlink)(path, linkname, *linklen);
282
283 if (ret == 0) {
284 }
285
286 return ret;
287 }
288
289 /* make the special node */
290 /* ARGSUSED1 */
291 static int
292 puffs_fuse_node_mknod(struct puffs_cc *pcc, void *opc, void **newnode,
293 const struct puffs_cn *pcn, const struct vattr *va)
294 {
295 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
296 struct puffs_node *pn;
297 struct fuse *fuse;
298 mode_t mode = va->va_mode;
299 const char *path = PCNPATH(pcn);
300 int ret;
301
302 fuse = (struct fuse *)pu->pu_privdata;
303 if (fuse->op.mknod == NULL) {
304 return ENOSYS;
305 }
306
307 /* wrap up return code */
308 ret = (*fuse->op.mknod)(path, mode, va->va_rdev);
309
310 if (ret == 0) {
311 /* fix up nodes */
312 pn = newrn(pu);
313 if (pn == NULL) {
314 unlink(PCNPATH(pcn));
315 return ENOMEM;
316 }
317 puffs_setvattr(&pn->pn_va, va);
318
319 *newnode = pn;
320 }
321
322 return ret;
323 }
324
325 /* make a directory */
326 /* ARGSUSED1 */
327 static int
328 puffs_fuse_node_mkdir(struct puffs_cc *pcc, void *opc, void **newnode,
329 const struct puffs_cn *pcn, const struct vattr *va)
330 {
331 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
332 struct puffs_node *pn;
333 struct fuse *fuse;
334 mode_t mode = va->va_mode;
335 const char *path = PCNPATH(pcn);
336 int ret;
337
338 fuse = (struct fuse *)pu->pu_privdata;
339 if (fuse->op.mkdir == NULL) {
340 return ENOSYS;
341 }
342
343 /* wrap up return code */
344 ret = (*fuse->op.mkdir)(path, mode);
345
346 if (ret == 0) {
347 /* fix up nodes */
348 pn = newrn(pu);
349 if (pn == NULL) {
350 rmdir(PCNPATH(pcn));
351 return ENOMEM;
352 }
353 puffs_setvattr(&pn->pn_va, va);
354
355 *newnode = pn;
356 }
357
358 return ret;
359 }
360
361 /* remove the directory entry */
362 /* ARGSUSED1 */
363 static int
364 puffs_fuse_node_remove(struct puffs_cc *pcc, void *opc, void *targ,
365 const struct puffs_cn *pcn)
366 {
367 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
368 struct fuse *fuse;
369 const char *path = PCNPATH(pcn);
370 int ret;
371
372 fuse = (struct fuse *)pu->pu_privdata;
373 if (fuse->op.unlink == NULL) {
374 return ENOSYS;
375 }
376
377 /* wrap up return code */
378 ret = (*fuse->op.unlink)(path);
379
380 return ret;
381 }
382
383 /* remove the directory */
384 /* ARGSUSED1 */
385 static int
386 puffs_fuse_node_rmdir(struct puffs_cc *pcc, void *opc, void *targ,
387 const struct puffs_cn *pcn)
388 {
389 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
390 struct fuse *fuse;
391 const char *path = PCNPATH(pcn);
392 int ret;
393
394 fuse = (struct fuse *)pu->pu_privdata;
395 if (fuse->op.rmdir == NULL) {
396 return ENOSYS;
397 }
398
399 /* wrap up return code */
400 ret = (*fuse->op.rmdir)(path);
401
402 return ret;
403 }
404
405 /* create a symbolic link */
406 /* ARGSUSED1 */
407 static int
408 puffs_fuse_node_symlink(struct puffs_cc *pcc, void *opc, void **newnode,
409 const struct puffs_cn *pcn_src, const struct vattr *va,
410 const char *link_target)
411 {
412 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
413 struct puffs_node *pn;
414 struct fuse *fuse;
415 const char *path = PCNPATH(pcn_src);
416 int ret;
417
418 fuse = (struct fuse *)pu->pu_privdata;
419 if (fuse->op.symlink == NULL) {
420 return ENOSYS;
421 }
422
423 /* wrap up return code */
424 ret = (*fuse->op.symlink)(path, link_target);
425 /* XXX - check I haven't transposed these args */
426
427 if (ret == 0) {
428 /* fix up nodes */
429 pn = newrn(pu);
430 if (pn == NULL) {
431 unlink(link_target);
432 return ENOMEM;
433 }
434 puffs_setvattr(&pn->pn_va, va);
435
436 *newnode = pn;
437 }
438
439 return ret;
440 }
441
442 /* rename a directory entry */
443 /* ARGSUSED1 */
444 static int
445 puffs_fuse_node_rename(struct puffs_cc *pcc, void *opc, void *src,
446 const struct puffs_cn *pcn_src, void *targ_dir, void *targ,
447 const struct puffs_cn *pcn_targ)
448 {
449 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
450 struct puffs_node *pn = opc;
451 struct vattr va;
452 struct fuse *fuse;
453 const char *path = PCNPATH(pcn_src);
454 int ret;
455
456 fuse = (struct fuse *)pu->pu_privdata;
457 if (fuse->op.rename == NULL) {
458 return ENOSYS;
459 }
460
461 /* wrap up return code */
462 ret = (*fuse->op.rename)(path, PCNPATH(pcn_targ));
463
464 /* XXX: what's this guy doing??? */
465 if (ret == 0) {
466 (void) memcpy(&va, &pn->pn_va, sizeof(va));
467
468 puffs_pn_put(pn);
469
470 pn = puffs_pn_new(pu, NULL);
471 if (pn == NULL) {
472 return ENOMEM;
473 }
474 puffs_setvattr(&pn->pn_va, &va);
475
476 }
477
478 return ret;
479 }
480
481 /* create a link in the file system */
482 /* ARGSUSED1 */
483 static int
484 puffs_fuse_node_link(struct puffs_cc *pcc, void *opc, void *targ,
485 const struct puffs_cn *pcn)
486 {
487 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
488 struct puffs_node *pn = targ;
489 struct fuse *fuse;
490 int ret;
491
492 fuse = (struct fuse *)pu->pu_privdata;
493 if (fuse->op.link == NULL) {
494 return ENOSYS;
495 }
496
497 /* wrap up return code */
498 ret = (*fuse->op.link)(PNPATH(pn), PCNPATH(pcn));
499
500 return ret;
501 }
502
503 /*
504 * We run into a slight problemette here - puffs provides
505 * setattr/getattr, whilst fuse provides all the usual chown/chmod/chgrp
506 * functionality. So that we don't miss out on anything when calling a
507 * fuse operation, we have to get the vattr from the existing file,
508 * find out what's changed, and then switch on that to call the fuse
509 * function accordingly.
510 */
511 /* ARGSUSED3 */
512 static int
513 puffs_fuse_node_setattr(struct puffs_cc *pcc, void *opc,
514 const struct vattr *va, const struct puffs_cred *pcr, pid_t pid)
515 {
516 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
517 struct puffs_node *pn = opc;
518 struct fuse *fuse;
519 const char *path = PNPATH(pn);
520 mode_t mode;
521 uid_t uid;
522 gid_t gid;
523 int ret;
524
525 fuse = (struct fuse *)pu->pu_privdata;
526
527 ret = -1;
528
529 mode = va->va_mode;
530 uid = va->va_uid;
531 gid = va->va_gid;
532
533 if (mode != (mode_t)PUFFS_VNOVAL) {
534 if (fuse->op.chmod == NULL) {
535 return ENOSYS;
536 }
537 ret = (*fuse->op.chmod)(path, mode);
538 }
539 if (uid != (uid_t)PUFFS_VNOVAL || gid != (gid_t)PUFFS_VNOVAL) {
540 if (fuse->op.chown == NULL) {
541 return ENOSYS;
542 }
543 ret = (*fuse->op.chown)(path, uid, gid);
544 }
545
546 if (ret == 0) {
547 }
548
549 return ret;
550 }
551
552 /* ARGSUSED2 */
553 static int
554 puffs_fuse_node_open(struct puffs_cc *pcc, void *opc, int flags,
555 const struct puffs_cred *cred, pid_t pid)
556 {
557 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
558 struct puffs_node *pn = opc;
559 struct refusenode *rn = pn->pn_data;
560 struct fuse *fuse;
561 struct stat st;
562 const char *path = PNPATH(pn);
563 int ret;
564
565 fuse = (struct fuse *)pu->pu_privdata;
566 if (fuse->op.open == NULL) {
567 return ENOSYS;
568 }
569
570 /* examine type - if directory, return 0 rather than open */
571 ret = (fuse->op.getattr == NULL) ?
572 stat(path, &st) :
573 (*fuse->op.getattr)(path, &st);
574 if (ret == 0 && (st.st_mode & S_IFMT) == S_IFDIR) {
575 return 0;
576 }
577
578 if (strcmp(path, "/") == 0) {
579 return 0;
580 }
581
582 ret = (*fuse->op.open)(path, &rn->file_info);
583
584 if (ret == 0) {
585 }
586
587 return ret;
588 }
589
590 /* read some more from the file */
591 /* ARGSUSED5 */
592 static int
593 puffs_fuse_node_read(struct puffs_cc *pcc, void *opc, uint8_t *buf,
594 off_t offset, size_t *resid, const struct puffs_cred *pcr,
595 int ioflag)
596 {
597 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
598 struct puffs_node *pn = opc;
599 struct refusenode *rn = pn->pn_data;
600 struct fuse *fuse;
601 const char *path = PNPATH(pn);
602 int ret;
603
604 fuse = (struct fuse *)pu->pu_privdata;
605 if (fuse->op.read == NULL) {
606 return ENOSYS;
607 }
608
609 ret = (*fuse->op.read)(path, (char *)buf, *resid, offset,
610 &rn->file_info);
611
612 if (ret > 0) {
613 *resid -= ret;
614 }
615
616 return 0;
617 }
618
619 /* write to the file */
620 /* ARGSUSED0 */
621 static int
622 puffs_fuse_node_write(struct puffs_cc *pcc, void *opc, uint8_t *buf,
623 off_t offset, size_t *resid, const struct puffs_cred *pcr,
624 int ioflag)
625 {
626 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
627 struct puffs_node *pn = opc;
628 struct refusenode *rn = pn->pn_data;
629 struct fuse *fuse;
630 const char *path = PNPATH(pn);
631 int ret;
632
633 fuse = (struct fuse *)pu->pu_privdata;
634 if (fuse->op.write == NULL) {
635 return ENOSYS;
636 }
637
638 ret = (*fuse->op.write)(path, (char *)buf, *resid, offset,
639 &rn->file_info);
640
641 if (ret > 0) {
642 *resid -= ret;
643 }
644
645 return ret;
646 }
647
648
649 /* ARGSUSED3 */
650 static int
651 puffs_fuse_node_readdir(struct puffs_cc *pcc, void *opc,
652 struct dirent *dent, const struct puffs_cred *pcr, off_t *readoff,
653 size_t *reslen)
654 {
655 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
656 struct puffs_node *pn = opc;
657 struct refusenode *rn = pn->pn_data;
658 struct fuse *fuse;
659 const char *path = PNPATH(pn);
660 struct fuse_dirh deh;
661 int ret;
662
663 fuse = (struct fuse *)pu->pu_privdata;
664 if (fuse->op.readdir == NULL && fuse->op.getdir == NULL) {
665 return ENOSYS;
666 }
667
668 /* XXX: how to handle this??? */
669 if (*readoff != 0) {
670 return 0;
671 }
672
673 deh.dent = dent;
674 deh.reslen = *reslen;
675 deh.readoff = *readoff;
676
677 if (fuse->op.readdir)
678 ret = fuse->op.readdir(path, &deh, puffs_fuse_fill_dir,
679 *readoff, &rn->file_info);
680 else
681 ret = fuse->op.getdir(path, &deh, puffs_fuse_dirfil);
682 *reslen = deh.reslen;
683 *readoff = 1;
684
685 if (ret == 0) {
686 }
687
688 return ret;
689 }
690
691 /* ARGSUSED */
692 static int
693 puffs_fuse_node_reclaim(struct puffs_cc *pcc, void *opc, pid_t pid)
694 {
695 struct puffs_node *pn = opc;
696
697 nukern(pn);
698
699 return 0;
700 }
701
702 /* ARGSUSED1 */
703 static int
704 puffs_fuse_fs_unmount(struct puffs_cc *pcc, int flags, pid_t pid)
705 {
706 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
707 struct fuse *fuse;
708
709 fuse = (struct fuse *)pu->pu_privdata;
710 if (fuse->op.destroy == NULL) {
711 return 0;
712 }
713 (*fuse->op.destroy)(fuse);
714 return 0;
715 }
716
717 /* ARGSUSED0 */
718 static int
719 puffs_fuse_fs_sync(struct puffs_cc *pcc, int flags,
720 const struct puffs_cred *cr, pid_t pid)
721 {
722 return 0;
723 }
724
725 /* ARGSUSED2 */
726 static int
727 puffs_fuse_fs_statvfs(struct puffs_cc *pcc, struct statvfs *svfsb, pid_t pid)
728 {
729 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
730 struct fuse *fuse;
731 int ret;
732
733 fuse = (struct fuse *)pu->pu_privdata;
734 if (fuse->op.statfs == NULL) {
735 if ((ret = statvfs(PNPATH(pu->pu_pn_root), svfsb)) == -1) {
736 return errno;
737 }
738 } else {
739 ret = (*fuse->op.statfs)(PNPATH(pu->pu_pn_root), svfsb);
740 }
741
742 return ret;
743 }
744
745
746
747
748 /* End of puffs_fuse operations */
749
750 /*
751 * XXX: do this otherwise if/when we grow thread support
752 *
753 * XXX2: does not supply uid, gid or pid currently
754 */
755 static struct fuse_context fcon;
756
757 /* ARGSUSED3 */
758 int
759 fuse_main_real(int argc, char **argv, const struct fuse_operations *ops,
760 size_t size, void *userdata)
761 {
762 struct puffs_usermount *pu;
763 struct puffs_pathobj *po_root;
764 struct puffs_ops *pops;
765 struct statvfs svfsb;
766 struct fuse *fuse;
767 char name[64];
768 char *slash;
769 int ret;
770
771 /* initialise the puffs operations structure */
772 PUFFSOP_INIT(pops);
773
774 PUFFSOP_SET(pops, puffs_fuse, fs, sync);
775 PUFFSOP_SET(pops, puffs_fuse, fs, statvfs);
776 PUFFSOP_SET(pops, puffs_fuse, fs, unmount);
777
778 /*
779 * XXX: all of these don't possibly need to be
780 * unconditionally set
781 */
782 PUFFSOP_SET(pops, puffs_fuse, node, lookup);
783 PUFFSOP_SET(pops, puffs_fuse, node, getattr);
784 PUFFSOP_SET(pops, puffs_fuse, node, readdir);
785 PUFFSOP_SET(pops, puffs_fuse, node, readlink);
786 PUFFSOP_SET(pops, puffs_fuse, node, mknod);
787 PUFFSOP_SET(pops, puffs_fuse, node, mkdir);
788 PUFFSOP_SET(pops, puffs_fuse, node, remove);
789 PUFFSOP_SET(pops, puffs_fuse, node, rmdir);
790 PUFFSOP_SET(pops, puffs_fuse, node, symlink);
791 PUFFSOP_SET(pops, puffs_fuse, node, rename);
792 PUFFSOP_SET(pops, puffs_fuse, node, link);
793 PUFFSOP_SET(pops, puffs_fuse, node, setattr);
794 PUFFSOP_SET(pops, puffs_fuse, node, open);
795 PUFFSOP_SET(pops, puffs_fuse, node, read);
796 PUFFSOP_SET(pops, puffs_fuse, node, write);
797 PUFFSOP_SET(pops, puffs_fuse, node, readdir);
798 PUFFSOP_SET(pops, puffs_fuse, node, read);
799 PUFFSOP_SET(pops, puffs_fuse, node, write);
800 PUFFSOP_SET(pops, puffs_fuse, node, reclaim);
801
802 NEW(struct fuse, fuse, "fuse_main_real", exit(EXIT_FAILURE));
803
804 /* copy fuse ops to their own stucture */
805 (void) memcpy(&fuse->op, ops, sizeof(fuse->op));
806
807 fcon.fuse = fuse;
808 fcon.private_data = userdata;
809
810 /* whilst this (assigning the pu_privdata in the puffs
811 * usermount struct to be the fuse struct) might seem like
812 * we are chasing our tail here, the logic is as follows:
813 + the operation wrapper gets called with the puffs
814 calling conventions
815 + we need to fix up args first
816 + then call the fuse user-supplied operation
817 + then we fix up any values on return that we need to
818 + and fix up any nodes, etc
819 * so we need to be able to get at the fuse ops from within the
820 * puffs_usermount struct
821 */
822 if ((slash = strrchr(*argv, '/')) == NULL) {
823 slash = *argv;
824 } else {
825 slash += 1;
826 }
827 (void) snprintf(name, sizeof(name), "refuse:%s", slash);
828 pu = puffs_mount(pops, argv[argc - 1], MNT_NODEV | MNT_NOSUID,
829 name, fuse,
830 PUFFS_FLAG_BUILDPATH | PUFFS_FLAG_OPDUMP, 0);
831 if (pu == NULL) {
832 err(EXIT_FAILURE, "puffs_mount");
833 }
834
835 fuse->pu = pu;
836 pu->pu_pn_root = puffs_pn_new(pu, NULL);
837 po_root = puffs_getrootpathobj(pu);
838 po_root->po_path = strdup("/");
839 po_root->po_len = 1;
840
841 if (fuse->op.init)
842 fcon.private_data = fuse->op.init(NULL); /* XXX */
843
844 statvfs(argv[argc - 1], &svfsb); /* XXX - not really the correct dir */
845 if (puffs_start(pu, pu->pu_pn_root, &svfsb) == -1) {
846 err(EXIT_FAILURE, "puffs_start");
847 }
848
849 ret = puffs_mainloop(fuse->pu, PUFFSLOOP_NODAEMON);
850
851 (void) free(po_root->po_path);
852 FREE(fuse);
853 return ret;
854 }
855
856 /* ARGSUSED0 */
857 int
858 fuse_opt_parse(struct fuse_args *args, void *data,
859 const struct fuse_opt *opts, fuse_opt_proc_t proc)
860 {
861 return 0;
862 }
863
864 /* XXX: threads */
865 struct fuse_context *
866 fuse_get_context()
867 {
868
869 return &fcon;
870 }
871