2 * Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef _PSEUDOFS_H_INCLUDED
32 #define _PSEUDOFS_H_INCLUDED
48 * Limits and constants
50 #define PFS_NAMELEN 24
51 #define PFS_FSNAMELEN 16 /* equal to MFSNAMELEN */
52 #define PFS_DELEN (8 + PFS_NAMELEN)
68 #define PFS_RD 0x0001 /* readable */
69 #define PFS_WR 0x0002 /* writeable */
70 #define PFS_RDWR (PFS_RD|PFS_WR)
71 #define PFS_RAWRD 0x0004 /* raw reader */
72 #define PFS_RAWWR 0x0008 /* raw writer */
73 #define PFS_RAW (PFS_RAWRD|PFS_RAWWR)
74 #define PFS_PROCDEP 0x0010 /* process-dependent */
75 #define PFS_DISABLED 0x8000 /* node is disabled */
85 * Init / uninit callback
87 #define PFS_INIT_ARGS \
88 struct pfs_info *pi, struct vfsconf *vfc
89 #define PFS_INIT_PROTO(name) \
90 int name(PFS_INIT_ARGS);
91 typedef int (*pfs_init_t)(PFS_INIT_ARGS);
96 #define PFS_FILL_ARGS \
97 struct thread *td, struct proc *p, struct pfs_node *pn, \
98 struct sbuf *sb, struct uio *uio
99 #define PFS_FILL_PROTO(name) \
100 int name(PFS_FILL_ARGS);
101 typedef int (*pfs_fill_t)(PFS_FILL_ARGS);
107 #define PFS_ATTR_ARGS \
108 struct thread *td, struct proc *p, struct pfs_node *pn, \
110 #define PFS_ATTR_PROTO(name) \
111 int name(PFS_ATTR_ARGS);
112 typedef int (*pfs_attr_t)(PFS_ATTR_ARGS);
114 struct pfs_bitmap; /* opaque */
117 * Visibility callback
119 #define PFS_VIS_ARGS \
120 struct thread *td, struct proc *p, struct pfs_node *pn
121 #define PFS_VIS_PROTO(name) \
122 int name(PFS_VIS_ARGS);
123 typedef int (*pfs_vis_t)(PFS_VIS_ARGS);
128 #define PFS_IOCTL_ARGS \
129 struct thread *td, struct proc *p, struct pfs_node *pn, \
130 unsigned long cmd, void *data
131 #define PFS_IOCTL_PROTO(name) \
132 int name(PFS_IOCTL_ARGS);
133 typedef int (*pfs_ioctl_t)(PFS_IOCTL_ARGS);
136 * Getextattr callback
138 #define PFS_GETEXTATTR_ARGS \
139 struct thread *td, struct proc *p, struct pfs_node *pn, \
140 int attrnamespace, const char *name, struct uio *uio, \
141 size_t *size, struct ucred *cred
142 #define PFS_GETEXTATTR_PROTO(name) \
143 int name(PFS_GETEXTATTR_ARGS);
145 typedef int (*pfs_getextattr_t)(PFS_GETEXTATTR_ARGS);
148 * Last-close callback
150 #define PFS_CLOSE_ARGS \
151 struct thread *td, struct proc *p, struct pfs_node *pn
152 #define PFS_CLOSE_PROTO(name) \
153 int name(PFS_CLOSE_ARGS);
154 typedef int (*pfs_close_t)(PFS_CLOSE_ARGS);
157 * pfs_info: describes a pseudofs instance
159 * The pi_mutex is only used to avoid using the global subr_unit lock for
160 * unrhdr. The rest of struct pfs_info is only modified while Giant is
161 * held (during vfs_init() and vfs_uninit()).
164 char pi_name[PFS_FSNAMELEN];
166 pfs_init_t pi_uninit;
168 /* members below this line are initialized at run time*/
169 struct pfs_node *pi_root;
171 struct unrhdr *pi_unrhdr;
175 * pfs_node: describes a node (file or directory) within a pseudofs
178 char pn_name[PFS_NAMELEN];
183 struct pfs_node *_pn_nodes;
185 #define pn_func u1._pn_func
186 #define pn_nodes u1._pn_nodes
187 pfs_ioctl_t pn_ioctl;
188 pfs_close_t pn_close;
191 pfs_getextattr_t pn_getextattr;
195 struct pfs_info *pn_info;
196 struct pfs_node *pn_parent;
197 struct pfs_node *pn_next;
204 int pfs_mount (struct pfs_info *pi, struct mount *mp,
206 int pfs_unmount (struct mount *mp, int mntflags,
208 int pfs_root (struct mount *mp, int flags,
209 struct vnode **vpp, struct thread *td);
210 int pfs_statfs (struct mount *mp, struct statfs *sbp,
212 int pfs_init (struct pfs_info *pi, struct vfsconf *vfc);
213 int pfs_uninit (struct pfs_info *pi, struct vfsconf *vfc);
216 * Directory structure construction and manipulation
218 struct pfs_node *pfs_create_dir (struct pfs_node *parent, const char *name,
219 pfs_attr_t attr, pfs_vis_t vis, int flags);
220 struct pfs_node *pfs_create_file(struct pfs_node *parent, const char *name,
221 pfs_fill_t fill, pfs_attr_t attr,
222 pfs_vis_t vis, int flags);
223 struct pfs_node *pfs_create_link(struct pfs_node *parent, const char *name,
224 pfs_fill_t fill, pfs_attr_t attr,
225 pfs_vis_t vis, int flags);
226 struct pfs_node *pfs_find_node (struct pfs_node *parent, const char *name);
227 void pfs_purge (struct pfs_node *pn);
228 int pfs_disable (struct pfs_node *pn);
229 int pfs_enable (struct pfs_node *pn);
230 int pfs_destroy (struct pfs_node *pn);
233 * Now for some initialization magic...
235 #define PSEUDOFS(name, version) \
237 static struct pfs_info name##_info = { \
244 _##name##_mount(struct mount *mp, struct thread *td) { \
245 return pfs_mount(&name##_info, mp, td); \
249 _##name##_init(struct vfsconf *vfc) { \
250 return pfs_init(&name##_info, vfc); \
254 _##name##_uninit(struct vfsconf *vfc) { \
255 return pfs_uninit(&name##_info, vfc); \
258 static struct vfsops name##_vfsops = { \
259 .vfs_init = _##name##_init, \
260 .vfs_mount = _##name##_mount, \
261 .vfs_root = pfs_root, \
262 .vfs_statfs = pfs_statfs, \
263 .vfs_uninit = _##name##_uninit, \
264 .vfs_unmount = pfs_unmount, \
266 VFS_SET(name##_vfsops, name, VFCF_SYNTHETIC); \
267 MODULE_VERSION(name, version); \
268 MODULE_DEPEND(name, pseudofs, 1, 1, 1);