xref: /openbsd/lib/libfuse/fuse_private.h (revision 4b23cf72)
1*4b23cf72Stedu /* $OpenBSD: fuse_private.h,v 1.22 2018/11/16 02:16:17 tedu Exp $ */
275af46c2Stedu /*
375af46c2Stedu  * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
475af46c2Stedu  *
575af46c2Stedu  * Permission to use, copy, modify, and distribute this software for any
675af46c2Stedu  * purpose with or without fee is hereby granted, provided that the above
775af46c2Stedu  * copyright notice and this permission notice appear in all copies.
875af46c2Stedu  *
975af46c2Stedu  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1075af46c2Stedu  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1175af46c2Stedu  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1275af46c2Stedu  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1375af46c2Stedu  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1475af46c2Stedu  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1575af46c2Stedu  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1675af46c2Stedu  */
1775af46c2Stedu 
1875af46c2Stedu #ifndef _FUSE_SUBR_H_
1975af46c2Stedu #define _FUSE_SUBR_H_
2075af46c2Stedu 
2175af46c2Stedu #include <sys/dirent.h>
226f9b5942Snatano #include <sys/event.h>
2375af46c2Stedu #include <sys/mount.h>
246f9b5942Snatano #include <sys/stat.h>
2575af46c2Stedu #include <sys/statvfs.h>
266f9b5942Snatano #include <sys/tree.h>
2775af46c2Stedu #include <sys/fusebuf.h>
28aea60beeSderaadt #include <limits.h>
2975af46c2Stedu 
3075af46c2Stedu #include "fuse.h"
3175af46c2Stedu 
3288a7ba5eStedu struct fuse_args;
3375af46c2Stedu 
3475af46c2Stedu struct fuse_vnode {
3575af46c2Stedu 	ino_t ino;
365e69e0b6Snatano 	struct fuse_vnode *parent;
375e69e0b6Snatano 	unsigned int ref;
3875af46c2Stedu 
39ddbf7910Ssyl 	char path[NAME_MAX + 1];
4075af46c2Stedu 
4175af46c2Stedu 	SIMPLEQ_ENTRY(fuse_vnode) node; /* for dict */
4275af46c2Stedu };
4375af46c2Stedu 
446751eb60Shelg struct fuse_dirhandle {
45390f10b5Shelg 	struct fuse *fuse;
46390f10b5Shelg 	fuse_fill_dir_t filler;
47390f10b5Shelg 	void *buf;
48390f10b5Shelg 	int full;
49390f10b5Shelg 	uint32_t size;
50390f10b5Shelg 	uint32_t start;
51390f10b5Shelg 	uint32_t idx;
52390f10b5Shelg 	off_t off;
536751eb60Shelg };
54390f10b5Shelg 
5575af46c2Stedu SIMPLEQ_HEAD(fuse_vn_head, fuse_vnode);
5675af46c2Stedu SPLAY_HEAD(dict, dictentry);
5775af46c2Stedu SPLAY_HEAD(tree, treeentry);
5875af46c2Stedu 
5975af46c2Stedu struct fuse_session {
6075af46c2Stedu 	void *args;
6175af46c2Stedu };
6275af46c2Stedu 
6375af46c2Stedu struct fuse_chan {
6475af46c2Stedu 	char *dir;
6575af46c2Stedu 	struct fuse_args *args;
6675af46c2Stedu 
6775af46c2Stedu 	int fd;
6875af46c2Stedu 	int dead;
6975af46c2Stedu 
7075af46c2Stedu 	/* kqueue stuff */
7175af46c2Stedu 	int kq;
7275af46c2Stedu };
7375af46c2Stedu 
7475af46c2Stedu struct fuse_config {
7575af46c2Stedu 	uid_t			uid;
7675af46c2Stedu 	gid_t			gid;
775f1aa8d9Ssyl 	pid_t			pid;
7875af46c2Stedu 	mode_t			umask;
7975af46c2Stedu 	int			set_mode;
8075af46c2Stedu 	int			set_uid;
8175af46c2Stedu 	int			set_gid;
82dae5ffecShelg 	int			use_ino;
8375af46c2Stedu };
8475af46c2Stedu 
8558efe7d1Shelg struct fuse_core_opts {
86f8cc4b14Ssyl 	char			*mp;
87c286f01cShelg 	int			foreground;
88f8cc4b14Ssyl };
89f8cc4b14Ssyl 
9058efe7d1Shelg struct fuse_mount_opts {
9158efe7d1Shelg 	char			*fsname;
920f4d2db5Shelg 	int			allow_other;
9358efe7d1Shelg 	int			def_perms;
9458efe7d1Shelg 	int			max_read;
9558efe7d1Shelg 	int			noatime;
9658efe7d1Shelg 	int			nonempty;
9758efe7d1Shelg 	int			rdonly;
9858efe7d1Shelg };
9958efe7d1Shelg 
10075af46c2Stedu struct fuse {
10175af46c2Stedu 	struct fuse_chan	*fc;
10275af46c2Stedu 	struct fuse_operations	op;
10375af46c2Stedu 
10475af46c2Stedu 	int			compat;
10575af46c2Stedu 
10675af46c2Stedu 	struct tree		vnode_tree;
10775af46c2Stedu 	struct dict		name_tree;
10875af46c2Stedu 	uint64_t		max_ino;
109593b95d9Ssyl 	void			*private_data;
11075af46c2Stedu 
11175af46c2Stedu 	struct fuse_config	conf;
11275af46c2Stedu 	struct fuse_session	se;
11375af46c2Stedu };
11475af46c2Stedu 
11575af46c2Stedu #define	FUSE_MAX_OPS	39
11675af46c2Stedu #define FUSE_ROOT_INO ((ino_t)1)
11775af46c2Stedu 
11875af46c2Stedu /* fuse_ops.c */
11975af46c2Stedu int	ifuse_exec_opcode(struct fuse *, struct fusebuf *);
12075af46c2Stedu 
12175af46c2Stedu /* fuse_subr.c */
12275af46c2Stedu struct fuse_vnode	*alloc_vn(struct fuse *, const char *, ino_t, ino_t);
1235e69e0b6Snatano void			 ref_vn(struct fuse_vnode *);
1245e69e0b6Snatano void			 unref_vn(struct fuse *, struct fuse_vnode *);
125dedc9797Ssyl struct fuse_vnode	*get_vn_by_name_and_parent(struct fuse *, uint8_t *,
12675af46c2Stedu     ino_t);
1270e0c4c5cSsyl void			remove_vnode_from_name_tree(struct fuse *,
1280e0c4c5cSsyl     struct fuse_vnode *);
12975af46c2Stedu int			set_vn(struct fuse *, struct fuse_vnode *);
13075af46c2Stedu char			*build_realname(struct fuse *, ino_t);
13175af46c2Stedu 
13275af46c2Stedu /* tree.c */
13375af46c2Stedu #define tree_init(t)	SPLAY_INIT((t))
13475af46c2Stedu #define tree_empty(t)	SPLAY_EMPTY((t))
13575af46c2Stedu int			tree_check(struct tree *, uint64_t);
13675af46c2Stedu void			*tree_set(struct tree *, uint64_t, void *);
13775af46c2Stedu void			*tree_get(struct tree *, uint64_t);;
13875af46c2Stedu void			*tree_pop(struct tree *, uint64_t);
13975af46c2Stedu 
14075af46c2Stedu /* dict.c */
14175af46c2Stedu int			dict_check(struct dict *, const char *);
14275af46c2Stedu void			*dict_set(struct dict *, const char *, void *);
14375af46c2Stedu void			*dict_get(struct dict *, const char *);;
14475af46c2Stedu void			*dict_pop(struct dict *, const char *);
14575af46c2Stedu 
1469af1ea27Ssyl #define FUSE_VERSION_PKG_INFO "2.8.0"
14775af46c2Stedu #define unused __attribute__ ((unused))
14875af46c2Stedu 
1497c0bee30Sjca #define	PROTO(x)	__dso_hidden typeof(x) x asm("__"#x)
1507c0bee30Sjca #define	DEF(x)		__strong_alias(x, __##x)
1517c0bee30Sjca 
1527c0bee30Sjca PROTO(fuse_daemonize);
1537c0bee30Sjca PROTO(fuse_destroy);
1547c0bee30Sjca PROTO(fuse_get_context);
1557c0bee30Sjca PROTO(fuse_get_session);
1567c0bee30Sjca PROTO(fuse_loop);
1577c0bee30Sjca PROTO(fuse_mount);
1587c0bee30Sjca PROTO(fuse_new);
1597c0bee30Sjca PROTO(fuse_opt_add_arg);
1607c0bee30Sjca PROTO(fuse_opt_free_args);
1617c0bee30Sjca PROTO(fuse_opt_insert_arg);
1627c0bee30Sjca PROTO(fuse_opt_match);
1637c0bee30Sjca PROTO(fuse_opt_parse);
1647c0bee30Sjca PROTO(fuse_parse_cmdline);
1657c0bee30Sjca PROTO(fuse_remove_signal_handlers);
1667c0bee30Sjca PROTO(fuse_setup);
1677c0bee30Sjca PROTO(fuse_unmount);
1687c0bee30Sjca 
16975af46c2Stedu #endif /* _FUSE_SUBR_ */
170