1 /* $NetBSD: puffs_priv.h,v 1.41 2008/08/11 16:23:37 pooka Exp $ */
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
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
28 #ifndef _PUFFS_PRIVATE_H_
29 #define _PUFFS_PRIVATE_H_
31 #include <sys/types.h>
34 /* FIXME: fs/puffs/puffs_msgif.h? */
35 #include "puffs_msgif.h"
41 #define SU_UID ((uid_t) 0) /* super_user's uid_t */
44 #define ATIME 002 /* set if atime field needs updating */
45 #define CTIME 004 /* set if ctime field needs updating */
46 #define MTIME 010 /* set if mtime field needs updating */
48 #define REQ_READ_SUPER 28
50 #ifdef PUFFS_WITH_THREADS
52 extern pthread_mutex_t pu_lock
;
53 #define PU_LOCK() pthread_mutex_lock(&pu_lock)
54 #define PU_UNLOCK() pthread_mutex_unlock(&pu_lock)
60 #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(pu,c) : (struct puffs_node*)c)
62 struct puffs_framectrl
{
63 puffs_framev_readframe_fn rfb
;
64 puffs_framev_writeframe_fn wfb
;
65 puffs_framev_cmpframe_fn cmpfb
;
66 puffs_framev_gotframe_fn gotfb
;
67 puffs_framev_fdnotify_fn fdnotfn
;
70 struct puffs_fctrl_io
{
71 struct puffs_framectrl
*fctrl
;
79 struct puffs_framebuf
*cur_in
;
81 TAILQ_HEAD(, puffs_framebuf
) snd_qing
; /* queueing to be sent */
82 TAILQ_HEAD(, puffs_framebuf
) res_qing
; /* q'ing for rescue */
83 LIST_HEAD(, puffs_fbevent
) ev_qing
; /* q'ing for events */
85 LIST_ENTRY(puffs_fctrl_io
) fio_entries
;
88 #define FIO_WRGONE 0x02
89 #define FIO_RDGONE 0x04
91 #define FIO_ENABLE_R 0x10
92 #define FIO_ENABLE_W 0x20
94 #define FIO_EN_WRITE(fio) \
95 (!(fio->stat & FIO_WR) \
96 && ((!TAILQ_EMPTY(&fio->snd_qing) \
97 && (fio->stat & FIO_ENABLE_W)) \
100 #define FIO_RM_WRITE(fio) \
101 ((fio->stat & FIO_WR) \
102 && (((TAILQ_EMPTY(&fio->snd_qing) \
103 || (fio->stat & FIO_ENABLE_W) == 0)) \
104 && (fio->wwait == 0)))
108 * usermount: describes one file system instance
110 struct puffs_usermount
{
111 struct puffs_ops pu_ops
;
117 int pu_cc_stackshift
;
119 ucontext_t pu_mainctx
;
120 #define PUFFS_CCMAXSTORE 32
125 #define PU_STATEMASK 0x00ff
126 #define PU_INLOOP 0x0100
127 #define PU_ASYNCFD 0x0200
128 #define PU_HASKQ 0x0400
129 #define PU_PUFFSDAEMON 0x0800
130 #define PU_MAINRESTORE 0x1000
131 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
132 #define PU_SETSFLAG(pu, s) (pu->pu_state |= (s))
133 #define PU_CLRSFLAG(pu, s) \
134 (pu->pu_state = ((pu->pu_state &= ~(s)) | (pu->pu_state & PU_STATEMASK)))
137 struct puffs_node
*pu_pn_root
;
139 LIST_HEAD(, puffs_node
) pu_pnodelst
;
140 LIST_HEAD(, puffs_node
) pu_pnode_removed_lst
;
142 LIST_HEAD(, puffs_cc
) pu_ccmagazin
;
143 TAILQ_HEAD(, puffs_cc
) pu_lazyctx
;
144 TAILQ_HEAD(, puffs_cc
) pu_sched
;
148 pu_pathbuild_fn pu_pathbuild
;
149 pu_pathtransform_fn pu_pathtransform
;
150 pu_pathcmp_fn pu_pathcmp
;
151 pu_pathfree_fn pu_pathfree
;
152 pu_namemod_fn pu_namemod
;
154 pu_errnotify_fn pu_errnotify
;
156 pu_prepost_fn pu_oppre
;
157 pu_prepost_fn pu_oppost
;
159 struct puffs_framectrl pu_framectrl
[2];
160 #define PU_FRAMECTRL_FS 0
161 #define PU_FRAMECTRL_USER 1
162 LIST_HEAD(, puffs_fctrl_io
) pu_ios
;
163 LIST_HEAD(, puffs_fctrl_io
) pu_ios_rmlist
;
164 struct kevent
*pu_evs
;
167 puffs_ml_loop_fn pu_ml_lfn
;
168 struct timespec pu_ml_timeout
;
169 struct timespec
*pu_ml_timep
;
171 struct puffs_kargs
*pu_kargp
;
180 typedef void (*puffs_ccfunc
)(struct puffs_cc
*);
183 struct puffs_usermount
*pcc_pu
;
184 struct puffs_framebuf
*pcc_pb
;
189 ucontext_t uc
; /* "continue" */
190 ucontext_t uc_ret
; /* "yield" */
203 TAILQ_ENTRY(puffs_cc
) pcc_schedent
;
204 LIST_ENTRY(puffs_cc
) pcc_rope
;
206 #define pcc_uc pcc_u.real.uc
207 #define pcc_uc_ret pcc_u.real.uc_ret
208 #define pcc_func pcc_u.fake.func
209 #define pcc_farg pcc_u.fake.farg
210 #define PCC_DONE 0x01
211 #define PCC_BORROWED 0x02
212 #define PCC_HASCALLER 0x04
213 #define PCC_MLCONT 0x08
215 struct puffs_newinfo
{
217 enum vtype
*pni_vtype
;
222 #define PUFFS_MAKEKCRED(to, from) \
223 /*LINTED: tnilxnaht, the cast is ok */ \
224 const struct puffs_kcred *to = (const void *)from
225 #define PUFFS_MAKECRED(to, from) \
226 /*LINTED: tnilxnaht, the cast is ok */ \
227 const struct puffs_cred *to = (const void *)from
228 #define PUFFS_KCREDTOCRED(to, from) \
229 /*LINTED: tnilxnaht, the cast is ok */ \
234 void puffs__framev_input(struct puffs_usermount
*, struct puffs_framectrl
*,
235 struct puffs_fctrl_io
*);
236 int puffs__framev_output(struct puffs_usermount
*, struct puffs_framectrl
*,
237 struct puffs_fctrl_io
*);
238 void puffs__framev_exit(struct puffs_usermount
*);
239 void puffs__framev_readclose(struct puffs_usermount
*,
240 struct puffs_fctrl_io
*, int);
241 void puffs__framev_writeclose(struct puffs_usermount
*,
242 struct puffs_fctrl_io
*, int);
243 void puffs__framev_notify(struct puffs_fctrl_io
*, int);
244 void *puffs__framebuf_getdataptr(struct puffs_framebuf
*);
245 int puffs__framev_addfd_ctrl(struct puffs_usermount
*, int, int,
246 struct puffs_framectrl
*);
247 void puffs__framebuf_moveinfo(struct puffs_framebuf
*,
248 struct puffs_framebuf
*);
250 void puffs__theloop(struct puffs_cc
*);
251 void puffs__ml_dispatch(struct puffs_usermount
*, struct puffs_framebuf
*);
253 int puffs__cc_create(struct puffs_usermount
*, puffs_ccfunc
,
255 void puffs__cc_cont(struct puffs_cc
*);
256 void puffs__cc_destroy(struct puffs_cc
*, int);
257 void puffs__cc_setcaller(struct puffs_cc
*, pid_t
, lwpid_t
);
258 void puffs__goto(struct puffs_cc
*);
259 int puffs__cc_savemain(struct puffs_usermount
*);
260 int puffs__cc_restoremain(struct puffs_usermount
*);
261 void puffs__cc_exit(struct puffs_usermount
*);
263 int puffs__fsframe_read(struct puffs_usermount
*, struct puffs_framebuf
*,
265 int puffs__fsframe_write(struct puffs_usermount
*, struct puffs_framebuf
*,
267 int puffs__fsframe_cmp(struct puffs_usermount
*, struct puffs_framebuf
*,
268 struct puffs_framebuf
*, int *);
269 void puffs__fsframe_gotframe(struct puffs_usermount
*,
270 struct puffs_framebuf
*);
274 #define NUL(str,l,m) mfs_nul_f(__FILE__,__LINE__,(str), (l), (m))
276 #endif /* _PUFFS_PRIVATE_H_ */