xref: /openbsd/sys/miscfs/fuse/fusefs_node.h (revision 51d8761d)
1 /* $OpenBSD: fusefs_node.h,v 1.5 2024/10/31 13:55:21 claudio Exp $ */
2 /*
3  * Copyright (c) 2012-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 _FUSEFS_NODE_H_
19 #define _FUSEFS_NODE_H_
20 
21 #include <sys/queue.h>
22 
23 enum fufh_type {
24 	FUFH_INVALID = -1,
25 	FUFH_RDONLY  = 0,
26 	FUFH_WRONLY  = 1,
27 	FUFH_RDWR    = 2,
28 	FUFH_MAXTYPE = 3,
29 };
30 
31 struct fusefs_filehandle {
32 	uint64_t fh_id;
33 	enum fufh_type fh_type;
34 };
35 
36 struct fusefs_mnt;
37 struct fusefs_node {
38 	LIST_ENTRY(fusefs_node)	 i_hash; /* Hash chain */
39 	struct	vnode		*i_vnode;/* Vnode associated with this inode. */
40 	struct	fusefs_mnt	*i_ump;
41 	dev_t			 i_dev;	 /* Device associated with the inode. */
42 	ino_t			 i_number;	/* The identity of the inode. */
43 	struct	lockf_state	*i_lockf;	/* Byte-level lock state. */
44 	struct	rrwlock		 i_lock;	/* Inode lock */
45 
46 	/** I/O **/
47 	struct     fusefs_filehandle fufh[FUFH_MAXTYPE];
48 
49 	/** meta **/
50 	off_t			 filesize;
51 };
52 
53 #ifdef ITOV
54 # undef ITOV
55 #endif
56 #define ITOV(ip) ((ip)->i_vnode)
57 
58 #ifdef VTOI
59 # undef VTOI
60 #endif
61 #define VTOI(vp) ((struct fusefs_node *)(vp)->v_data)
62 
63 void		 fuse_ihashinit(void);
64 struct vnode	*fuse_ihashget(dev_t, ino_t);
65 int		 fuse_ihashins(struct fusefs_node *);
66 void		 fuse_ihashrem(struct fusefs_node *);
67 
68 uint64_t fusefs_fd_get(struct fusefs_node *, enum fufh_type);
69 
70 #endif /* _FUSEFS_NODE_H_ */
71