refuse.c revision 1.7 1 /* $NetBSD: refuse.c,v 1.7 2007/02/11 16:02:24 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.7 2007/02/11 16:02:24 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 if (ret == 0) {
501 /* fix up nodes */
502 pn = newrn(pu);
503 if (pn == NULL) {
504 unlink(PCNPATH(pcn));
505 return ENOMEM;
506 }
507 }
508
509 return ret;
510 }
511
512 /*
513 * We run into a slight problemette here - puffs provides
514 * setattr/getattr, whilst fuse provides all the usual chown/chmod/chgrp
515 * functionality. So that we don't miss out on anything when calling a
516 * fuse operation, we have to get the vattr from the existing file,
517 * find out what's changed, and then switch on that to call the fuse
518 * function accordingly.
519 */
520 /* ARGSUSED3 */
521 static int
522 puffs_fuse_node_setattr(struct puffs_cc *pcc, void *opc,
523 const struct vattr *va, const struct puffs_cred *pcr, pid_t pid)
524 {
525 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
526 struct puffs_node *pn = opc;
527 struct fuse *fuse;
528 const char *path = PNPATH(pn);
529 mode_t mode;
530 uid_t uid;
531 gid_t gid;
532 int ret;
533
534 fuse = (struct fuse *)pu->pu_privdata;
535
536 ret = -1;
537
538 mode = va->va_mode;
539 uid = va->va_uid;
540 gid = va->va_gid;
541
542 if (mode != 0) {
543 if (fuse->op.chmod == NULL) {
544 return ENOSYS;
545 }
546 ret = (*fuse->op.chmod)(path, mode);
547 }
548 if (uid != 0 || gid != 0) {
549 if (fuse->op.chown == NULL) {
550 return ENOSYS;
551 }
552 ret = (*fuse->op.chown)(path, uid, gid);
553 }
554
555 if (ret == 0) {
556 }
557
558 return ret;
559 }
560
561 /* ARGSUSED2 */
562 static int
563 puffs_fuse_node_open(struct puffs_cc *pcc, void *opc, int flags,
564 const struct puffs_cred *cred, pid_t pid)
565 {
566 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
567 struct puffs_node *pn = opc;
568 struct refusenode *rn = pn->pn_data;
569 struct fuse *fuse;
570 struct stat st;
571 const char *path = PNPATH(pn);
572 int ret;
573
574 fuse = (struct fuse *)pu->pu_privdata;
575 if (fuse->op.open == NULL) {
576 return ENOSYS;
577 }
578
579 /* examine type - if directory, return 0 rather than open */
580 ret = (fuse->op.getattr == NULL) ?
581 stat(path, &st) :
582 (*fuse->op.getattr)(path, &st);
583 if (ret == 0 && (st.st_mode & S_IFMT) == S_IFDIR) {
584 return 0;
585 }
586
587 if (strcmp(path, "/") == 0) {
588 return 0;
589 }
590
591 ret = (*fuse->op.open)(path, &rn->file_info);
592
593 if (ret == 0) {
594 }
595
596 return ret;
597 }
598
599 /* read some more from the file */
600 /* ARGSUSED5 */
601 static int
602 puffs_fuse_node_read(struct puffs_cc *pcc, void *opc, uint8_t *buf,
603 off_t offset, size_t *resid, const struct puffs_cred *pcr,
604 int ioflag)
605 {
606 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
607 struct puffs_node *pn = opc;
608 struct refusenode *rn = pn->pn_data;
609 struct fuse *fuse;
610 const char *path = PNPATH(pn);
611 int ret;
612
613 fuse = (struct fuse *)pu->pu_privdata;
614 if (fuse->op.read == NULL) {
615 return ENOSYS;
616 }
617
618 ret = (*fuse->op.read)(path, (char *)buf, *resid, offset,
619 &rn->file_info);
620
621 if (ret > 0) {
622 *resid -= ret;
623 }
624
625 return 0;
626 }
627
628 /* write to the file */
629 /* ARGSUSED0 */
630 static int
631 puffs_fuse_node_write(struct puffs_cc *pcc, void *opc, uint8_t *buf,
632 off_t offset, size_t *resid, const struct puffs_cred *pcr,
633 int ioflag)
634 {
635 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
636 struct fuse_file_info file_info;
637 struct puffs_node *pn = opc;
638 struct fuse *fuse;
639 const char *path = PNPATH(pn);
640 int ret;
641
642 fuse = (struct fuse *)pu->pu_privdata;
643 if (fuse->op.write == NULL) {
644 return ENOSYS;
645 }
646
647 (void) memset(&file_info, 0x0, sizeof(file_info));
648
649 /* XXX fill in file_info here */
650
651 ret = (*fuse->op.write)(path, (char *)buf, *resid, offset, &file_info);
652
653 if (ret > 0) {
654 *resid -= ret;
655 }
656
657 return ret;
658 }
659
660
661 /* ARGSUSED3 */
662 static int
663 puffs_fuse_node_readdir(struct puffs_cc *pcc, void *opc,
664 struct dirent *dent, const struct puffs_cred *pcr, off_t *readoff,
665 size_t *reslen)
666 {
667 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
668 struct fuse_file_info file_info;
669 struct puffs_node *pn = opc;
670 struct fuse *fuse;
671 const char *path = PNPATH(pn);
672 struct fuse_dirh deh;
673 int ret;
674
675 fuse = (struct fuse *)pu->pu_privdata;
676 if (fuse->op.readdir == NULL && fuse->op.getdir == NULL) {
677 return ENOSYS;
678 }
679
680 /* XXX: how to handle this??? */
681 if (*readoff != 0) {
682 return 0;
683 }
684
685 (void) memset(&file_info, 0x0, sizeof(file_info));
686 /* XXX - fill in file_info here */
687
688 deh.dent = dent;
689 deh.reslen = *reslen;
690 deh.readoff = *readoff;
691
692 if (fuse->op.readdir)
693 ret = fuse->op.readdir(path, &deh, puffs_fuse_fill_dir,
694 *readoff, &file_info);
695 else
696 ret = fuse->op.getdir(path, &deh, puffs_fuse_dirfil);
697 *reslen = deh.reslen;
698 *readoff = 1;
699
700 if (ret == 0) {
701 }
702
703 return ret;
704 }
705
706 /* ARGSUSED */
707 static int
708 puffs_fuse_node_reclaim(struct puffs_cc *pcc, void *opc, pid_t pid)
709 {
710 struct puffs_node *pn = opc;
711
712 nukern(pn);
713
714 return 0;
715 }
716
717 /* ARGSUSED1 */
718 static int
719 puffs_fuse_fs_unmount(struct puffs_cc *pcc, int flags, pid_t pid)
720 {
721 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
722 struct fuse *fuse;
723
724 fuse = (struct fuse *)pu->pu_privdata;
725 if (fuse->op.destroy == NULL) {
726 return 0;
727 }
728 (*fuse->op.destroy)(fuse);
729 return 0;
730 }
731
732 /* ARGSUSED0 */
733 static int
734 puffs_fuse_fs_sync(struct puffs_cc *pcc, int flags,
735 const struct puffs_cred *cr, pid_t pid)
736 {
737 return 0;
738 }
739
740 /* ARGSUSED2 */
741 static int
742 puffs_fuse_fs_statvfs(struct puffs_cc *pcc, struct statvfs *svfsb, pid_t pid)
743 {
744 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
745 struct fuse *fuse;
746 int ret;
747
748 fuse = (struct fuse *)pu->pu_privdata;
749 if (fuse->op.statfs == NULL) {
750 if ((ret = statvfs(PNPATH(pu->pu_pn_root), svfsb)) == -1) {
751 return errno;
752 }
753 } else {
754 ret = (*fuse->op.statfs)(PNPATH(pu->pu_pn_root), svfsb);
755 }
756
757 return ret;
758 }
759
760
761
762
763 /* End of puffs_fuse operations */
764
765 /* ARGSUSED3 */
766 int
767 fuse_main_real(int argc, char **argv, const struct fuse_operations *ops,
768 size_t size, void *userdata)
769 {
770 struct puffs_usermount *pu;
771 struct puffs_pathobj *po_root;
772 struct puffs_ops *pops;
773 struct statvfs svfsb;
774 struct fuse *fuse;
775 char name[64];
776 char *slash;
777 int ret;
778
779 /* initialise the puffs operations structure */
780 PUFFSOP_INIT(pops);
781
782 PUFFSOP_SET(pops, puffs_fuse, fs, sync);
783 PUFFSOP_SET(pops, puffs_fuse, fs, statvfs);
784 PUFFSOP_SET(pops, puffs_fuse, fs, unmount);
785
786 /*
787 * XXX: all of these don't possibly need to be
788 * unconditionally set
789 */
790 PUFFSOP_SET(pops, puffs_fuse, node, lookup);
791 PUFFSOP_SET(pops, puffs_fuse, node, getattr);
792 PUFFSOP_SET(pops, puffs_fuse, node, readdir);
793 PUFFSOP_SET(pops, puffs_fuse, node, readlink);
794 PUFFSOP_SET(pops, puffs_fuse, node, mknod);
795 PUFFSOP_SET(pops, puffs_fuse, node, mkdir);
796 PUFFSOP_SET(pops, puffs_fuse, node, remove);
797 PUFFSOP_SET(pops, puffs_fuse, node, rmdir);
798 PUFFSOP_SET(pops, puffs_fuse, node, symlink);
799 PUFFSOP_SET(pops, puffs_fuse, node, rename);
800 PUFFSOP_SET(pops, puffs_fuse, node, link);
801 PUFFSOP_SET(pops, puffs_fuse, node, setattr);
802 PUFFSOP_SET(pops, puffs_fuse, node, open);
803 PUFFSOP_SET(pops, puffs_fuse, node, read);
804 PUFFSOP_SET(pops, puffs_fuse, node, write);
805 PUFFSOP_SET(pops, puffs_fuse, node, readdir);
806 PUFFSOP_SET(pops, puffs_fuse, node, read);
807 PUFFSOP_SET(pops, puffs_fuse, node, write);
808 PUFFSOP_SET(pops, puffs_fuse, node, reclaim);
809
810 NEW(struct fuse, fuse, "fuse_main_real", exit(EXIT_FAILURE));
811
812 /* copy fuse ops to their own stucture */
813 (void) memcpy(&fuse->op, ops, sizeof(fuse->op));
814
815 /* whilst this (assigning the pu_privdata in the puffs
816 * usermount struct to be the fuse struct) might seem like
817 * we are chasing our tail here, the logic is as follows:
818 + the operation wrapper gets called with the puffs
819 calling conventions
820 + we need to fix up args first
821 + then call the fuse user-supplied operation
822 + then we fix up any values on return that we need to
823 + and fix up any nodes, etc
824 * so we need to be able to get at the fuse ops from within the
825 * puffs_usermount struct
826 */
827 if ((slash = strrchr(*argv, '/')) == NULL) {
828 slash = *argv;
829 } else {
830 slash += 1;
831 }
832 (void) snprintf(name, sizeof(name), "refuse:%s", slash);
833 pu = puffs_mount(pops, argv[argc - 1], MNT_NODEV | MNT_NOSUID,
834 name, fuse,
835 PUFFS_FLAG_BUILDPATH | PUFFS_FLAG_OPDUMP, 0);
836 if (pu == NULL) {
837 err(EXIT_FAILURE, "puffs_mount");
838 }
839
840 fuse->pu = pu;
841 pu->pu_pn_root = puffs_pn_new(pu, NULL);
842 po_root = puffs_getrootpathobj(pu);
843 po_root->po_path = strdup("/");
844 po_root->po_len = 1;
845
846 statvfs(argv[argc - 1], &svfsb); /* XXX - not really the correct dir */
847 if (puffs_start(pu, pu->pu_pn_root, &svfsb) == -1) {
848 err(EXIT_FAILURE, "puffs_start");
849 }
850
851 ret = puffs_mainloop(fuse->pu, PUFFSLOOP_NODAEMON);
852
853 (void) free(po_root->po_path);
854 FREE(fuse);
855 return ret;
856 }
857
858 /* ARGSUSED0 */
859 int
860 fuse_opt_parse(struct fuse_args *args, void *data,
861 const struct fuse_opt *opts, fuse_opt_proc_t proc)
862 {
863 return 0;
864 }
865