xref: /netbsd-src/lib/libperfuse/perfuse_priv.h (revision 4fee23f98c45552038ad6b5bd05124a41302fb01)
1 /*  $NetBSD: perfuse_priv.h,v 1.18 2011/05/30 14:50:08 manu Exp $ */
2 
3 /*-
4  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. 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  *
15  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  *  POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _PERFUSE_PRIV_H_
29 #define _PERFUSE_PRIV_H_
30 
31 #include <syslog.h>
32 #include <paths.h>
33 #include <err.h>
34 #include <sysexits.h>
35 #include <puffs.h>
36 
37 #include "perfuse_if.h"
38 #include "fuse.h"
39 
40 struct perfuse_state {
41 	void *ps_private;	/* Private field for libperfuse user */
42 	struct puffs_usermount *ps_pu;
43 	struct puffs_node *ps_root;
44 	uid_t ps_owner_uid;
45 	int ps_flags;
46 #define PS_NO_ACCESS	0x0001	/* access is unimplemented; */
47 #define PS_NO_CREAT	0x0004	/* create is unimplemented */
48 #define PS_INLOOP	0x0008	/* puffs mainloop started */
49 	uint64_t ps_fsid;
50 	uint32_t ps_max_readahead;
51 	uint32_t ps_max_write;
52 	uint64_t ps_syncreads;
53 	uint64_t ps_syncwrites;
54 	uint64_t ps_asyncreads;
55 	uint64_t ps_asyncwrites;
56 	char *ps_source;
57 	char *ps_target;
58 	char *ps_filesystemtype;
59 	int ps_mountflags;
60 	uint64_t ps_unique;
61 	perfuse_new_msg_fn ps_new_msg;
62 	perfuse_xchg_msg_fn ps_xchg_msg;
63 	perfuse_destroy_msg_fn ps_destroy_msg;
64 	perfuse_get_inhdr_fn ps_get_inhdr;
65 	perfuse_get_inpayload_fn ps_get_inpayload;
66 	perfuse_get_outhdr_fn ps_get_outhdr;
67 	perfuse_get_outpayload_fn ps_get_outpayload;
68 	perfuse_umount_fn ps_umount;
69 };
70 
71 
72 enum perfuse_qtype {
73 	PCQ_READDIR,
74 	PCQ_READ,
75 	PCQ_WRITE,
76 	PCQ_AFTERWRITE,
77 	PCQ_OPEN,
78 	PCQ_AFTERXCHG
79 };
80 
81 #ifdef PERFUSE_DEBUG
82 extern const char *perfuse_qtypestr[];
83 #endif
84 
85 struct perfuse_cc_queue {
86 	enum perfuse_qtype pcq_type;
87 	struct puffs_cc *pcq_cc;
88 	TAILQ_ENTRY(perfuse_cc_queue) pcq_next;
89 };
90 
91 struct perfuse_node_data {
92 	uint64_t pnd_rfh;
93 	uint64_t pnd_wfh;
94 	uint64_t pnd_ino;			/* inode */
95 	uint64_t pnd_nlookup;			/* vnode refcount */
96 	uint64_t pnd_lock_owner;
97 	struct dirent *pnd_dirent;		/* native buffer for readdir */
98 	off_t pnd_dirent_len;
99 	struct fuse_dirent *pnd_all_fd;		/* FUSE buffer for readdir */
100 	size_t pnd_all_fd_len;
101 	TAILQ_HEAD(,perfuse_cc_queue) pnd_pcq;	/* queued requests */
102 	int pnd_flags;
103 #define PND_RECLAIMED		0x001	/* reclaim pending */
104 #define PND_INREADDIR		0x002	/* readdir in progress */
105 #define PND_DIRTY		0x004	/* There is some data to sync */
106 #define PND_RFH			0x008	/* Read FH allocated */
107 #define PND_WFH			0x010	/* Write FH allocated */
108 #define PND_REMOVED		0x020	/* Node was removed */
109 #define PND_INWRITE		0x040	/* write in progress */
110 #define PND_INOPEN		0x100	/* open in progress */
111 #define PND_INXCHG		0x400	/* FUSE exchange in progress */
112 
113 #define PND_OPEN		(PND_RFH|PND_WFH)	/* File is open */
114 #define PND_BUSY		(PND_INREADDIR|PND_INWRITE|PND_INOPEN)
115 	puffs_cookie_t pnd_parent;
116 	int pnd_childcount;
117 	TAILQ_ENTRY(perfuse_node_data) pnd_next;
118 	puffs_cookie_t pnd_pn;
119 	char pnd_name[MAXPATHLEN];	/* node name */
120 	TAILQ_HEAD(,perfuse_node_data) pnd_children;
121 };
122 
123 #define PERFUSE_NODE_DATA(opc)	\
124 	((struct perfuse_node_data *)puffs_pn_getpriv((struct puffs_node *)opc))
125 
126 
127 #define UNSPEC_REPLY_LEN PERFUSE_UNSPEC_REPLY_LEN /* shorter! */
128 #define NO_PAYLOAD_REPLY_LEN 0
129 
130 #define GET_INHDR(ps, pm) ps->ps_get_inhdr(pm)
131 #define GET_INPAYLOAD(ps, pm, type) \
132 	(struct type *)(void *)ps->ps_get_inpayload(pm)
133 #define _GET_INPAYLOAD(ps, pm, type) (type)ps->ps_get_inpayload(pm)
134 #define GET_OUTHDR(ps, pm) ps->ps_get_outhdr(pm)
135 #define GET_OUTPAYLOAD(ps, pm, type) \
136 	(struct type *)(void *)ps->ps_get_outpayload(pm)
137 #define _GET_OUTPAYLOAD(ps, pm, type) (type)ps->ps_get_outpayload(pm)
138 
139 __BEGIN_DECLS
140 
141 struct puffs_node *perfuse_new_pn(struct puffs_usermount *, const char *,
142     struct puffs_node *);
143 void perfuse_destroy_pn(struct puffs_node *);
144 void perfuse_new_fh(puffs_cookie_t, uint64_t, int);
145 void perfuse_destroy_fh(puffs_cookie_t, uint64_t);
146 uint64_t perfuse_get_fh(puffs_cookie_t, int);
147 uint64_t perfuse_next_unique(struct puffs_usermount *);
148 char *perfuse_node_path(puffs_cookie_t);
149 int perfuse_node_close_common(struct puffs_usermount *, puffs_cookie_t, int);
150 
151 char *perfuse_fs_mount(int, ssize_t);
152 
153 
154 /*
155  * opc.c - filesystem operations
156  */
157 int perfuse_fs_unmount(struct puffs_usermount *, int);
158 int perfuse_fs_statvfs(struct puffs_usermount *, struct statvfs *);
159 int perfuse_fs_sync(struct puffs_usermount *, int,
160     const struct puffs_cred *);
161 int perfuse_fs_fhtonode(struct puffs_usermount *, void *, size_t,
162     struct puffs_newinfo *);
163 int perfuse_fs_nodetofh(struct puffs_usermount *, puffs_cookie_t,
164     void *, size_t *);
165 void perfuse_fs_suspend(struct puffs_usermount *, int);
166 int perfuse_node_lookup(struct puffs_usermount *,
167     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *);
168 int perfuse_node_create(struct puffs_usermount *,
169     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
170     const struct vattr *);
171 int perfuse_node_mknod(struct puffs_usermount *,
172     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
173     const struct vattr *);
174 int perfuse_node_open(struct puffs_usermount *,
175     puffs_cookie_t, int, const struct puffs_cred *);
176 int perfuse_node_close(struct puffs_usermount *,
177     puffs_cookie_t, int, const struct puffs_cred *);
178 int perfuse_node_access(struct puffs_usermount *,
179     puffs_cookie_t, int, const struct puffs_cred *);
180 int perfuse_node_getattr(struct puffs_usermount *,
181     puffs_cookie_t, struct vattr *, const struct puffs_cred *);
182 int perfuse_node_setattr(struct puffs_usermount *,
183     puffs_cookie_t, const struct vattr *, const struct puffs_cred *);
184 int perfuse_node_poll(struct puffs_usermount *, puffs_cookie_t, int *);
185 int perfuse_node_mmap(struct puffs_usermount *,
186     puffs_cookie_t, vm_prot_t, const struct puffs_cred *);
187 int perfuse_node_fsync(struct puffs_usermount *,
188     puffs_cookie_t, const struct puffs_cred *, int, off_t, off_t);
189 int perfuse_node_seek(struct puffs_usermount *,
190     puffs_cookie_t, off_t, off_t, const struct puffs_cred *);
191 int perfuse_node_remove(struct puffs_usermount *,
192     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
193 int perfuse_node_link(struct puffs_usermount *,
194     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
195 int perfuse_node_rename(struct puffs_usermount *,
196     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *,
197     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
198 int perfuse_node_mkdir(struct puffs_usermount *,
199     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
200     const struct vattr *);
201 int perfuse_node_rmdir(struct puffs_usermount *,
202     puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
203 int perfuse_node_symlink(struct puffs_usermount *,
204     puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
205     const struct vattr *, const char *);
206 int perfuse_node_readdir(struct puffs_usermount *,
207     puffs_cookie_t, struct dirent *, off_t *, size_t *,
208     const struct puffs_cred *, int *, off_t *, size_t *);
209 int perfuse_node_readlink(struct puffs_usermount *,
210     puffs_cookie_t, const struct puffs_cred *, char *, size_t *);
211 int perfuse_node_reclaim(struct puffs_usermount *, puffs_cookie_t);
212 int perfuse_node_inactive(struct puffs_usermount *, puffs_cookie_t);
213 int perfuse_node_print(struct puffs_usermount *, puffs_cookie_t);
214 int perfuse_node_pathconf(struct puffs_usermount *,
215     puffs_cookie_t, int, int *);
216 int perfuse_node_advlock(struct puffs_usermount *,
217     puffs_cookie_t, void *, int, struct flock *, int);
218 int perfuse_node_read(struct puffs_usermount *, puffs_cookie_t,
219     uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
220 int perfuse_node_write(struct puffs_usermount *, puffs_cookie_t,
221     uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
222 void perfuse_cache_write(struct puffs_usermount *,
223     puffs_cookie_t, size_t, struct puffs_cacherun *);
224 
225 __END_DECLS
226 
227 #endif /* _PERFUSE_PRIV_H_ */
228