1 /* $NetBSD: puffs_priv.h,v 1.45 2012/04/18 00:57:22 manu 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>
32 #include <fs/puffs/puffs_msgif.h>
36 #endif /* !defined(__minix) */
45 #define SU_UID ((uid_t) 0) /* super_user's uid_t */
48 #define ATIME 002 /* set if atime field needs updating */
49 #define CTIME 004 /* set if ctime field needs updating */
50 #define MTIME 010 /* set if mtime field needs updating */
52 #define REQ_READ_SUPER 28
54 #define NUL(str,l,m) mfs_nul_f(__FILE__,__LINE__,(str), (l), (m))
57 extern pthread_mutex_t pu_lock
;
58 #define PU_LOCK() pthread_mutex_lock(&pu_lock)
59 #define PU_UNLOCK() pthread_mutex_unlock(&pu_lock)
60 #endif /* defined(__minix) */
62 #define PU_LOCK() /* nothing */
63 #define PU_UNLOCK() /* nothing */
64 #endif /* defined(__minix) */
66 #define PU_CMAP(pu, c) (pu->pu_cmap ? pu->pu_cmap(pu,c) : (struct puffs_node*)c)
68 struct puffs_framectrl
{
69 puffs_framev_readframe_fn rfb
;
70 puffs_framev_writeframe_fn wfb
;
71 puffs_framev_cmpframe_fn cmpfb
;
72 puffs_framev_gotframe_fn gotfb
;
73 puffs_framev_fdnotify_fn fdnotfn
;
76 struct puffs_fctrl_io
{
77 struct puffs_framectrl
*fctrl
;
85 struct puffs_framebuf
*cur_in
;
87 TAILQ_HEAD(, puffs_framebuf
) snd_qing
; /* queueing to be sent */
88 TAILQ_HEAD(, puffs_framebuf
) res_qing
; /* q'ing for rescue */
89 LIST_HEAD(, puffs_fbevent
) ev_qing
; /* q'ing for events */
91 LIST_ENTRY(puffs_fctrl_io
) fio_entries
;
94 #define FIO_WRGONE 0x02
95 #define FIO_RDGONE 0x04
97 #define FIO_ENABLE_R 0x10
98 #define FIO_ENABLE_W 0x20
100 #define FIO_EN_WRITE(fio) \
101 (!(fio->stat & FIO_WR) \
102 && ((!TAILQ_EMPTY(&fio->snd_qing) \
103 && (fio->stat & FIO_ENABLE_W)) \
106 #define FIO_RM_WRITE(fio) \
107 ((fio->stat & FIO_WR) \
108 && (((TAILQ_EMPTY(&fio->snd_qing) \
109 || (fio->stat & FIO_ENABLE_W) == 0)) \
110 && (fio->wwait == 0)))
114 * usermount: describes one file system instance
116 struct puffs_usermount
{
117 struct puffs_ops pu_ops
;
123 int pu_cc_stackshift
;
125 ucontext_t pu_mainctx
;
126 #define PUFFS_CCMAXSTORE 32
131 #define PU_STATEMASK 0x00ff
132 #define PU_INLOOP 0x0100
133 #define PU_ASYNCFD 0x0200
134 #define PU_HASKQ 0x0400
135 #define PU_PUFFSDAEMON 0x0800
136 #define PU_MAINRESTORE 0x1000
137 #define PU_DONEXIT 0x2000
138 #define PU_SETSTATE(pu, s) (pu->pu_state = (s) | (pu->pu_state & ~PU_STATEMASK))
139 #define PU_SETSFLAG(pu, s) (pu->pu_state |= (s))
140 #define PU_CLRSFLAG(pu, s) \
141 (pu->pu_state = ((pu->pu_state & ~(s)) | (pu->pu_state & PU_STATEMASK)))
144 struct puffs_node
*pu_pn_root
;
146 LIST_HEAD(, puffs_node
) pu_pnodelst
;
147 #if defined(__minix) // LSC TO KEEP??
148 LIST_HEAD(, puffs_node
) pu_pnode_removed_lst
;
149 #endif /* defined(__minix) */
151 LIST_HEAD(, puffs_cc
) pu_ccmagazin
;
152 TAILQ_HEAD(, puffs_cc
) pu_lazyctx
;
153 TAILQ_HEAD(, puffs_cc
) pu_sched
;
157 pu_pathbuild_fn pu_pathbuild
;
158 pu_pathtransform_fn pu_pathtransform
;
159 pu_pathcmp_fn pu_pathcmp
;
160 pu_pathfree_fn pu_pathfree
;
161 pu_namemod_fn pu_namemod
;
163 pu_errnotify_fn pu_errnotify
;
165 pu_prepost_fn pu_oppre
;
166 pu_prepost_fn pu_oppost
;
168 struct puffs_framectrl pu_framectrl
[2];
169 #define PU_FRAMECTRL_FS 0
170 #define PU_FRAMECTRL_USER 1
171 LIST_HEAD(, puffs_fctrl_io
) pu_ios
;
172 LIST_HEAD(, puffs_fctrl_io
) pu_ios_rmlist
;
173 struct kevent
*pu_evs
;
176 puffs_ml_loop_fn pu_ml_lfn
;
177 struct timespec pu_ml_timeout
;
178 struct timespec
*pu_ml_timep
;
180 struct puffs_kargs
*pu_kargp
;
189 typedef void (*puffs_ccfunc
)(struct puffs_cc
*);
192 struct puffs_usermount
*pcc_pu
;
193 struct puffs_framebuf
*pcc_pb
;
198 ucontext_t uc
; /* "continue" */
199 ucontext_t uc_ret
; /* "yield" */
212 TAILQ_ENTRY(puffs_cc
) pcc_schedent
;
213 LIST_ENTRY(puffs_cc
) pcc_rope
;
215 #define pcc_uc pcc_u.real.uc
216 #define pcc_uc_ret pcc_u.real.uc_ret
217 #define pcc_func pcc_u.fake.func
218 #define pcc_farg pcc_u.fake.farg
219 #define PCC_DONE 0x01
220 #define PCC_BORROWED 0x02
221 #define PCC_HASCALLER 0x04
222 #define PCC_MLCONT 0x08
224 struct puffs_newinfo
{
226 enum vtype
*pni_vtype
;
229 struct vattr
*pni_va
;
230 struct timespec
*pni_va_ttl
;
231 struct timespec
*pni_cn_ttl
;
234 #define PUFFS_MAKEKCRED(to, from) \
235 /*LINTED: tnilxnaht, the cast is ok */ \
236 const struct puffs_kcred *to = (const void *)from
237 #define PUFFS_MAKECRED(to, from) \
238 /*LINTED: tnilxnaht, the cast is ok */ \
239 const struct puffs_cred *to = (const void *)from
240 #define PUFFS_KCREDTOCRED(to, from) \
241 /*LINTED: tnilxnaht, the cast is ok */ \
246 void puffs__framev_input(struct puffs_usermount
*, struct puffs_framectrl
*,
247 struct puffs_fctrl_io
*);
248 int puffs__framev_output(struct puffs_usermount
*, struct puffs_framectrl
*,
249 struct puffs_fctrl_io
*);
250 void puffs__framev_exit(struct puffs_usermount
*);
251 void puffs__framev_readclose(struct puffs_usermount
*,
252 struct puffs_fctrl_io
*, int);
253 void puffs__framev_writeclose(struct puffs_usermount
*,
254 struct puffs_fctrl_io
*, int);
255 void puffs__framev_notify(struct puffs_fctrl_io
*, int);
256 void *puffs__framebuf_getdataptr(struct puffs_framebuf
*);
257 int puffs__framev_addfd_ctrl(struct puffs_usermount
*, int, int,
258 struct puffs_framectrl
*);
259 void puffs__framebuf_moveinfo(struct puffs_framebuf
*,
260 struct puffs_framebuf
*);
262 void puffs__theloop(struct puffs_cc
*);
263 void puffs__ml_dispatch(struct puffs_usermount
*, struct puffs_framebuf
*);
265 int puffs__cc_create(struct puffs_usermount
*, puffs_ccfunc
,
267 void puffs__cc_cont(struct puffs_cc
*);
268 void puffs__cc_destroy(struct puffs_cc
*, int);
269 void puffs__cc_setcaller(struct puffs_cc
*, pid_t
, lwpid_t
);
270 void puffs__goto(struct puffs_cc
*);
271 int puffs__cc_savemain(struct puffs_usermount
*);
272 int puffs__cc_restoremain(struct puffs_usermount
*);
273 void puffs__cc_exit(struct puffs_usermount
*);
275 int puffs__fsframe_read(struct puffs_usermount
*, struct puffs_framebuf
*,
277 int puffs__fsframe_write(struct puffs_usermount
*, struct puffs_framebuf
*,
279 int puffs__fsframe_cmp(struct puffs_usermount
*, struct puffs_framebuf
*,
280 struct puffs_framebuf
*, int *);
281 void puffs__fsframe_gotframe(struct puffs_usermount
*,
282 struct puffs_framebuf
*);
286 #endif /* _PUFFS_PRIVATE_H_ */