1 /* $OpenBSD: fuse_private.h,v 1.22 2018/11/16 02:16:17 tedu Exp $ */ 2 /* 3 * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #ifndef _FUSE_SUBR_H_ 19 #define _FUSE_SUBR_H_ 20 21 #include <sys/dirent.h> 22 #include <sys/event.h> 23 #include <sys/mount.h> 24 #include <sys/stat.h> 25 #include <sys/statvfs.h> 26 #include <sys/tree.h> 27 #include <sys/fusebuf.h> 28 #include <limits.h> 29 30 #include "fuse.h" 31 32 struct fuse_args; 33 34 struct fuse_vnode { 35 ino_t ino; 36 struct fuse_vnode *parent; 37 unsigned int ref; 38 39 char path[NAME_MAX + 1]; 40 41 SIMPLEQ_ENTRY(fuse_vnode) node; /* for dict */ 42 }; 43 44 struct fuse_dirhandle { 45 struct fuse *fuse; 46 fuse_fill_dir_t filler; 47 void *buf; 48 int full; 49 uint32_t size; 50 uint32_t start; 51 uint32_t idx; 52 off_t off; 53 }; 54 55 SIMPLEQ_HEAD(fuse_vn_head, fuse_vnode); 56 SPLAY_HEAD(dict, dictentry); 57 SPLAY_HEAD(tree, treeentry); 58 59 struct fuse_session { 60 void *args; 61 }; 62 63 struct fuse_chan { 64 char *dir; 65 struct fuse_args *args; 66 67 int fd; 68 int dead; 69 70 /* kqueue stuff */ 71 int kq; 72 }; 73 74 struct fuse_config { 75 uid_t uid; 76 gid_t gid; 77 pid_t pid; 78 mode_t umask; 79 int set_mode; 80 int set_uid; 81 int set_gid; 82 int use_ino; 83 }; 84 85 struct fuse_core_opts { 86 char *mp; 87 int foreground; 88 }; 89 90 struct fuse_mount_opts { 91 char *fsname; 92 int allow_other; 93 int def_perms; 94 int max_read; 95 int noatime; 96 int nonempty; 97 int rdonly; 98 }; 99 100 struct fuse { 101 struct fuse_chan *fc; 102 struct fuse_operations op; 103 104 int compat; 105 106 struct tree vnode_tree; 107 struct dict name_tree; 108 uint64_t max_ino; 109 void *private_data; 110 111 struct fuse_config conf; 112 struct fuse_session se; 113 }; 114 115 #define FUSE_MAX_OPS 39 116 #define FUSE_ROOT_INO ((ino_t)1) 117 118 /* fuse_ops.c */ 119 int ifuse_exec_opcode(struct fuse *, struct fusebuf *); 120 121 /* fuse_subr.c */ 122 struct fuse_vnode *alloc_vn(struct fuse *, const char *, ino_t, ino_t); 123 void ref_vn(struct fuse_vnode *); 124 void unref_vn(struct fuse *, struct fuse_vnode *); 125 struct fuse_vnode *get_vn_by_name_and_parent(struct fuse *, uint8_t *, 126 ino_t); 127 void remove_vnode_from_name_tree(struct fuse *, 128 struct fuse_vnode *); 129 int set_vn(struct fuse *, struct fuse_vnode *); 130 char *build_realname(struct fuse *, ino_t); 131 132 /* tree.c */ 133 #define tree_init(t) SPLAY_INIT((t)) 134 #define tree_empty(t) SPLAY_EMPTY((t)) 135 int tree_check(struct tree *, uint64_t); 136 void *tree_set(struct tree *, uint64_t, void *); 137 void *tree_get(struct tree *, uint64_t);; 138 void *tree_pop(struct tree *, uint64_t); 139 140 /* dict.c */ 141 int dict_check(struct dict *, const char *); 142 void *dict_set(struct dict *, const char *, void *); 143 void *dict_get(struct dict *, const char *);; 144 void *dict_pop(struct dict *, const char *); 145 146 #define FUSE_VERSION_PKG_INFO "2.8.0" 147 #define unused __attribute__ ((unused)) 148 149 #define PROTO(x) __dso_hidden typeof(x) x asm("__"#x) 150 #define DEF(x) __strong_alias(x, __##x) 151 152 PROTO(fuse_daemonize); 153 PROTO(fuse_destroy); 154 PROTO(fuse_get_context); 155 PROTO(fuse_get_session); 156 PROTO(fuse_loop); 157 PROTO(fuse_mount); 158 PROTO(fuse_new); 159 PROTO(fuse_opt_add_arg); 160 PROTO(fuse_opt_free_args); 161 PROTO(fuse_opt_insert_arg); 162 PROTO(fuse_opt_match); 163 PROTO(fuse_opt_parse); 164 PROTO(fuse_parse_cmdline); 165 PROTO(fuse_remove_signal_handlers); 166 PROTO(fuse_setup); 167 PROTO(fuse_unmount); 168 169 #endif /* _FUSE_SUBR_ */ 170