xref: /openbsd/lib/libfuse/fuse_private.h (revision 9b7c3dbb)
1 /* $OpenBSD: fuse_private.h,v 1.13 2016/08/30 16:45:54 natano 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_dirhandle;
33 struct fuse_args;
34 
35 struct fuse_vnode {
36 	ino_t ino;
37 	ino_t parent;
38 
39 	char path[NAME_MAX + 1];
40 	struct fuse_dirhandle *fd;
41 
42 	SIMPLEQ_ENTRY(fuse_vnode) node; /* for dict */
43 };
44 
45 SIMPLEQ_HEAD(fuse_vn_head, fuse_vnode);
46 SPLAY_HEAD(dict, dictentry);
47 SPLAY_HEAD(tree, treeentry);
48 
49 struct fuse_session {
50 	void *args;
51 };
52 
53 struct fuse_chan {
54 	char *dir;
55 	struct fuse_args *args;
56 
57 	int fd;
58 	int dead;
59 
60 	/* kqueue stuff */
61 	int kq;
62 	struct kevent event;
63 };
64 
65 struct fuse_config {
66 	uid_t			uid;
67 	gid_t			gid;
68 	pid_t			pid;
69 	mode_t			umask;
70 	int			set_mode;
71 	int			set_uid;
72 	int			set_gid;
73 };
74 
75 struct fuse_core_opt {
76 	char *mp;
77 };
78 
79 struct fuse {
80 	struct fuse_chan	*fc;
81 	struct fuse_operations	op;
82 
83 	int			compat;
84 
85 	struct tree		vnode_tree;
86 	struct dict		name_tree;
87 	uint64_t		max_ino;
88 	void			*private_data;
89 
90 	struct fuse_config	conf;
91 	struct fuse_session	se;
92 };
93 
94 #define	FUSE_MAX_OPS	39
95 #define FUSE_ROOT_INO ((ino_t)1)
96 
97 /* fuse_ops.c */
98 int	ifuse_exec_opcode(struct fuse *, struct fusebuf *);
99 
100 /* fuse_subr.c */
101 struct fuse_vnode	*alloc_vn(struct fuse *, const char *, ino_t, ino_t);
102 struct fuse_vnode	*get_vn_by_name_and_parent(struct fuse *, uint8_t *,
103     ino_t);
104 void			remove_vnode_from_name_tree(struct fuse *,
105     struct fuse_vnode *);
106 int			set_vn(struct fuse *, struct fuse_vnode *);
107 char			*build_realname(struct fuse *, ino_t);
108 
109 /* tree.c */
110 #define tree_init(t)	SPLAY_INIT((t))
111 #define tree_empty(t)	SPLAY_EMPTY((t))
112 int			tree_check(struct tree *, uint64_t);
113 void			*tree_set(struct tree *, uint64_t, void *);
114 void			*tree_get(struct tree *, uint64_t);;
115 void			*tree_pop(struct tree *, uint64_t);
116 
117 /* dict.c */
118 int			dict_check(struct dict *, const char *);
119 void			*dict_set(struct dict *, const char *, void *);
120 void			*dict_get(struct dict *, const char *);;
121 void			*dict_pop(struct dict *, const char *);
122 
123 #define FUSE_VERSION_PKG_INFO "2.8.0"
124 #define unused __attribute__ ((unused))
125 
126 #endif /* _FUSE_SUBR_ */
127