Expand PMF_FN_* macros.
[netbsd-mini2440.git] / lib / libpuffs / puffs_priv.h
blob6483225afeda307032c0d619989e504e56560829
1 /* $NetBSD: puffs_priv.h,v 1.40 2008/08/11 15:59:01 pooka Exp $ */
3 /*
4 * Copyright (c) 2006, 2007, 2008 Antti Kantee. All Rights Reserved.
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
28 #ifndef _PUFFS_PRIVATE_H_
29 #define _PUFFS_PRIVATE_H_
31 #include <sys/types.h>
32 #include <fs/puffs/puffs_msgif.h>
34 #include <puffs.h>
35 #include <ucontext.h>
37 #ifdef PUFFS_WITH_THREADS
38 #include <pthread.h>
40 extern pthread_mutex_t pu_lock;
41 #define PU_LOCK() pthread_mutex_lock(&pu_lock)
42 #define PU_UNLOCK() pthread_mutex_unlock(&pu_lock)
43 #else
44 #define PU_LOCK()
45 #define PU_UNLOCK()
46 #endif
48 #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(pu,c) : (struct puffs_node*)c)
50 struct puffs_framectrl {
51 puffs_framev_readframe_fn rfb;
52 puffs_framev_writeframe_fn wfb;
53 puffs_framev_cmpframe_fn cmpfb;
54 puffs_framev_gotframe_fn gotfb;
55 puffs_framev_fdnotify_fn fdnotfn;
58 struct puffs_fctrl_io {
59 struct puffs_framectrl *fctrl;
61 int io_fd;
62 int stat;
64 int rwait;
65 int wwait;
67 struct puffs_framebuf *cur_in;
69 TAILQ_HEAD(, puffs_framebuf) snd_qing; /* queueing to be sent */
70 TAILQ_HEAD(, puffs_framebuf) res_qing; /* q'ing for rescue */
71 LIST_HEAD(, puffs_fbevent) ev_qing; /* q'ing for events */
73 LIST_ENTRY(puffs_fctrl_io) fio_entries;
75 #define FIO_WR 0x01
76 #define FIO_WRGONE 0x02
77 #define FIO_RDGONE 0x04
78 #define FIO_DEAD 0x08
79 #define FIO_ENABLE_R 0x10
80 #define FIO_ENABLE_W 0x20
82 #define FIO_EN_WRITE(fio) \
83 (!(fio->stat & FIO_WR) \
84 && ((!TAILQ_EMPTY(&fio->snd_qing) \
85 && (fio->stat & FIO_ENABLE_W)) \
86 || fio->wwait))
88 #define FIO_RM_WRITE(fio) \
89 ((fio->stat & FIO_WR) \
90 && (((TAILQ_EMPTY(&fio->snd_qing) \
91 || (fio->stat & FIO_ENABLE_W) == 0)) \
92 && (fio->wwait == 0)))
96 * usermount: describes one file system instance
98 struct puffs_usermount {
99 struct puffs_ops pu_ops;
101 int pu_fd;
102 size_t pu_maxreqlen;
104 uint32_t pu_flags;
105 int pu_cc_stackshift;
107 ucontext_t pu_mainctx;
108 #define PUFFS_CCMAXSTORE 32
109 int pu_cc_nstored;
111 int pu_kq;
112 int pu_state;
113 #define PU_STATEMASK 0x00ff
114 #define PU_INLOOP 0x0100
115 #define PU_ASYNCFD 0x0200
116 #define PU_HASKQ 0x0400
117 #define PU_PUFFSDAEMON 0x0800
118 #define PU_MAINRESTORE 0x1000
119 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
120 #define PU_SETSFLAG(pu, s) (pu->pu_state |= (s))
121 #define PU_CLRSFLAG(pu, s) \
122 (pu->pu_state = ((pu->pu_state &= ~(s)) | (pu->pu_state & PU_STATEMASK)))
123 int pu_dpipe[2];
125 struct puffs_node *pu_pn_root;
127 LIST_HEAD(, puffs_node) pu_pnodelst;
129 LIST_HEAD(, puffs_cc) pu_ccmagazin;
130 TAILQ_HEAD(, puffs_cc) pu_lazyctx;
131 TAILQ_HEAD(, puffs_cc) pu_sched;
133 pu_cmap_fn pu_cmap;
135 pu_pathbuild_fn pu_pathbuild;
136 pu_pathtransform_fn pu_pathtransform;
137 pu_pathcmp_fn pu_pathcmp;
138 pu_pathfree_fn pu_pathfree;
139 pu_namemod_fn pu_namemod;
141 pu_errnotify_fn pu_errnotify;
143 pu_prepost_fn pu_oppre;
144 pu_prepost_fn pu_oppost;
146 struct puffs_framectrl pu_framectrl[2];
147 #define PU_FRAMECTRL_FS 0
148 #define PU_FRAMECTRL_USER 1
149 LIST_HEAD(, puffs_fctrl_io) pu_ios;
150 LIST_HEAD(, puffs_fctrl_io) pu_ios_rmlist;
151 struct kevent *pu_evs;
152 size_t pu_nfds;
154 puffs_ml_loop_fn pu_ml_lfn;
155 struct timespec pu_ml_timeout;
156 struct timespec *pu_ml_timep;
158 struct puffs_kargs *pu_kargp;
160 uint64_t pu_nextreq;
161 void *pu_privdata;
164 /* call context */
166 struct puffs_cc;
167 typedef void (*puffs_ccfunc)(struct puffs_cc *);
169 struct puffs_cc {
170 struct puffs_usermount *pcc_pu;
171 struct puffs_framebuf *pcc_pb;
173 /* real cc */
174 union {
175 struct {
176 ucontext_t uc; /* "continue" */
177 ucontext_t uc_ret; /* "yield" */
178 } real;
179 struct {
180 puffs_ccfunc func;
181 void *farg;
182 } fake;
183 } pcc_u;
185 pid_t pcc_pid;
186 lwpid_t pcc_lid;
188 int pcc_flags;
190 TAILQ_ENTRY(puffs_cc) pcc_schedent;
191 LIST_ENTRY(puffs_cc) pcc_rope;
193 #define pcc_uc pcc_u.real.uc
194 #define pcc_uc_ret pcc_u.real.uc_ret
195 #define pcc_func pcc_u.fake.func
196 #define pcc_farg pcc_u.fake.farg
197 #define PCC_DONE 0x01
198 #define PCC_BORROWED 0x02
199 #define PCC_HASCALLER 0x04
200 #define PCC_MLCONT 0x08
202 struct puffs_newinfo {
203 void **pni_cookie;
204 enum vtype *pni_vtype;
205 voff_t *pni_size;
206 dev_t *pni_rdev;
209 #define PUFFS_MAKEKCRED(to, from) \
210 /*LINTED: tnilxnaht, the cast is ok */ \
211 const struct puffs_kcred *to = (const void *)from
212 #define PUFFS_MAKECRED(to, from) \
213 /*LINTED: tnilxnaht, the cast is ok */ \
214 const struct puffs_cred *to = (const void *)from
215 #define PUFFS_KCREDTOCRED(to, from) \
216 /*LINTED: tnilxnaht, the cast is ok */ \
217 to = (void *)from
219 __BEGIN_DECLS
221 void puffs__framev_input(struct puffs_usermount *, struct puffs_framectrl *,
222 struct puffs_fctrl_io *);
223 int puffs__framev_output(struct puffs_usermount *, struct puffs_framectrl*,
224 struct puffs_fctrl_io *);
225 void puffs__framev_exit(struct puffs_usermount *);
226 void puffs__framev_readclose(struct puffs_usermount *,
227 struct puffs_fctrl_io *, int);
228 void puffs__framev_writeclose(struct puffs_usermount *,
229 struct puffs_fctrl_io *, int);
230 void puffs__framev_notify(struct puffs_fctrl_io *, int);
231 void *puffs__framebuf_getdataptr(struct puffs_framebuf *);
232 int puffs__framev_addfd_ctrl(struct puffs_usermount *, int, int,
233 struct puffs_framectrl *);
234 void puffs__framebuf_moveinfo(struct puffs_framebuf *,
235 struct puffs_framebuf *);
237 void puffs__theloop(struct puffs_cc *);
238 void puffs__ml_dispatch(struct puffs_usermount *, struct puffs_framebuf *);
240 int puffs__cc_create(struct puffs_usermount *, puffs_ccfunc,
241 struct puffs_cc **);
242 void puffs__cc_cont(struct puffs_cc *);
243 void puffs__cc_destroy(struct puffs_cc *, int);
244 void puffs__cc_setcaller(struct puffs_cc *, pid_t, lwpid_t);
245 void puffs__goto(struct puffs_cc *);
246 int puffs__cc_savemain(struct puffs_usermount *);
247 int puffs__cc_restoremain(struct puffs_usermount *);
248 void puffs__cc_exit(struct puffs_usermount *);
250 int puffs__fsframe_read(struct puffs_usermount *, struct puffs_framebuf *,
251 int, int *);
252 int puffs__fsframe_write(struct puffs_usermount *, struct puffs_framebuf *,
253 int, int *);
254 int puffs__fsframe_cmp(struct puffs_usermount *, struct puffs_framebuf *,
255 struct puffs_framebuf *, int *);
256 void puffs__fsframe_gotframe(struct puffs_usermount *,
257 struct puffs_framebuf *);
259 uint64_t puffs__nextreq(struct puffs_usermount *pu);
261 __END_DECLS
263 #endif /* _PUFFS_PRIVATE_H_ */