1/*- 2 * Copyright (c) 2001 Dag-Erling Co��dan Sm��rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 16 * 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. 27 *
| 1/*- 2 * Copyright (c) 2001 Dag-Erling Co��dan Sm��rgrav 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 16 * 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. 27 *
|
34/* 35 * Opaque structures 36 */ 37struct mntarg; 38struct mount; 39struct nameidata; 40struct proc; 41struct sbuf; 42struct statfs; 43struct thread; 44struct uio; 45struct vfsconf; 46struct vnode; 47 48/* 49 * Limits and constants 50 */ 51#define PFS_NAMELEN 24 52#define PFS_FSNAMELEN 16 /* equal to MFSNAMELEN */ 53#define PFS_DELEN (8 + PFS_NAMELEN) 54 55typedef enum { 56 pfstype_none = 0, 57 pfstype_root, 58 pfstype_dir, 59 pfstype_this, 60 pfstype_parent, 61 pfstype_file, 62 pfstype_symlink, 63 pfstype_procdir 64} pfs_type_t; 65 66/* 67 * Flags 68 */ 69#define PFS_RD 0x0001 /* readable */ 70#define PFS_WR 0x0002 /* writeable */ 71#define PFS_RDWR (PFS_RD|PFS_WR) 72#define PFS_RAWRD 0x0004 /* raw reader */ 73#define PFS_RAWWR 0x0008 /* raw writer */ 74#define PFS_RAW (PFS_RAWRD|PFS_RAWWR) 75#define PFS_PROCDEP 0x0010 /* process-dependent */ 76 77/* 78 * Data structures 79 */ 80struct pfs_info; 81struct pfs_node; 82struct pfs_bitmap; 83 84/* 85 * Init / uninit callback 86 */ 87#define PFS_INIT_ARGS \ 88 struct pfs_info *pi, struct vfsconf *vfc 89#define PFS_INIT_ARGNAMES \ 90 pi, vfc 91#define PFS_INIT_PROTO(name) \ 92 int name(PFS_INIT_ARGS); 93typedef int (*pfs_init_t)(PFS_INIT_ARGS); 94 95/* 96 * Filler callback 97 * Called with proc held but unlocked 98 */ 99#define PFS_FILL_ARGS \ 100 struct thread *td, struct proc *p, struct pfs_node *pn, \ 101 struct sbuf *sb, struct uio *uio 102#define PFS_FILL_ARGNAMES \ 103 td, p, pn, sb, uio 104#define PFS_FILL_PROTO(name) \ 105 int name(PFS_FILL_ARGS); 106typedef int (*pfs_fill_t)(PFS_FILL_ARGS); 107 108/* 109 * Attribute callback 110 * Called with proc locked 111 */ 112struct vattr; 113#define PFS_ATTR_ARGS \ 114 struct thread *td, struct proc *p, struct pfs_node *pn, \ 115 struct vattr *vap 116#define PFS_ATTR_ARGNAMES \ 117 td, p, pn, vap 118#define PFS_ATTR_PROTO(name) \ 119 int name(PFS_ATTR_ARGS); 120typedef int (*pfs_attr_t)(PFS_ATTR_ARGS); 121 122struct pfs_bitmap; /* opaque */ 123 124/* 125 * Visibility callback 126 * Called with proc locked 127 */ 128#define PFS_VIS_ARGS \ 129 struct thread *td, struct proc *p, struct pfs_node *pn 130#define PFS_VIS_ARGNAMES \ 131 td, p, pn 132#define PFS_VIS_PROTO(name) \ 133 int name(PFS_VIS_ARGS); 134typedef int (*pfs_vis_t)(PFS_VIS_ARGS); 135 136/* 137 * Ioctl callback 138 * Called with proc locked 139 */ 140#define PFS_IOCTL_ARGS \ 141 struct thread *td, struct proc *p, struct pfs_node *pn, \ 142 unsigned long cmd, void *data 143#define PFS_IOCTL_ARGNAMES \ 144 td, p, pn, cmd, data 145#define PFS_IOCTL_PROTO(name) \ 146 int name(PFS_IOCTL_ARGS); 147typedef int (*pfs_ioctl_t)(PFS_IOCTL_ARGS); 148 149/* 150 * Getextattr callback 151 * Called with proc locked 152 */ 153#define PFS_GETEXTATTR_ARGS \ 154 struct thread *td, struct proc *p, struct pfs_node *pn, \ 155 int attrnamespace, const char *name, struct uio *uio, \ 156 size_t *size, struct ucred *cred 157#define PFS_GETEXTATTR_ARGNAMES \ 158 td, p, pn, attrnamespace, name, uio, size, cred 159#define PFS_GETEXTATTR_PROTO(name) \ 160 int name(PFS_GETEXTATTR_ARGS); 161struct ucred; 162typedef int (*pfs_getextattr_t)(PFS_GETEXTATTR_ARGS); 163 164/* 165 * Last-close callback 166 * Called with proc locked 167 */ 168#define PFS_CLOSE_ARGS \ 169 struct thread *td, struct proc *p, struct pfs_node *pn 170#define PFS_CLOSE_ARGNAMES \ 171 td, p, pn 172#define PFS_CLOSE_PROTO(name) \ 173 int name(PFS_CLOSE_ARGS); 174typedef int (*pfs_close_t)(PFS_CLOSE_ARGS); 175 176/* 177 * Destroy callback 178 */ 179#define PFS_DESTROY_ARGS \ 180 struct pfs_node *pn 181#define PFS_DESTROY_ARGNAMES \ 182 pn 183#define PFS_DESTROY_PROTO(name) \ 184 int name(PFS_DESTROY_ARGS); 185typedef int (*pfs_destroy_t)(PFS_DESTROY_ARGS); 186 187/* 188 * pfs_info: describes a pseudofs instance 189 * 190 * The pi_mutex is only used to avoid using the global subr_unit lock for 191 * unrhdr. The rest of struct pfs_info is only modified while Giant is 192 * held (during vfs_init() and vfs_uninit()). 193 */ 194struct pfs_info { 195 char pi_name[PFS_FSNAMELEN]; 196 pfs_init_t pi_init; 197 pfs_init_t pi_uninit; 198 199 /* members below this line are initialized at run time*/ 200 struct pfs_node *pi_root; 201 struct mtx pi_mutex; 202 struct unrhdr *pi_unrhdr; 203}; 204 205/* 206 * pfs_node: describes a node (file or directory) within a pseudofs 207 * 208 * - Fields marked (o) are protected by the node's own mutex. 209 * - Fields marked (p) are protected by the node's parent's mutex. 210 * - Remaining fields are not protected by any lock and are assumed to be 211 * immutable once the node has been created. 212 * 213 * To prevent deadlocks, if a node's mutex is to be held at the same time 214 * as its parent's (e.g. when adding or removing nodes to a directory), 215 * the parent's mutex must always be acquired first. Unfortunately, this 216 * is not enforcable by WITNESS. 217 */ 218struct pfs_node { 219 char pn_name[PFS_NAMELEN]; 220 pfs_type_t pn_type; 221 int pn_flags; 222 struct mtx pn_mutex; 223 void *pn_data; /* (o) */ 224 225 pfs_fill_t pn_fill; 226 pfs_ioctl_t pn_ioctl; 227 pfs_close_t pn_close; 228 pfs_attr_t pn_attr; 229 pfs_vis_t pn_vis; 230 pfs_getextattr_t pn_getextattr; 231 pfs_destroy_t pn_destroy; 232 233 struct pfs_info *pn_info; 234 u_int32_t pn_fileno; /* (o) */ 235 236 struct pfs_node *pn_parent; /* (o) */ 237 struct pfs_node *pn_nodes; /* (o) */ 238 struct pfs_node *pn_next; /* (p) */ 239}; 240 241/* 242 * VFS interface 243 */ 244int pfs_mount (struct pfs_info *pi, struct mount *mp); 245int pfs_cmount (struct mntarg *ma, void *data, uint64_t flags); 246int pfs_unmount (struct mount *mp, int mntflags); 247int pfs_root (struct mount *mp, int flags, 248 struct vnode **vpp); 249int pfs_statfs (struct mount *mp, struct statfs *sbp); 250int pfs_init (struct pfs_info *pi, struct vfsconf *vfc); 251int pfs_uninit (struct pfs_info *pi, struct vfsconf *vfc); 252 253/* 254 * Directory structure construction and manipulation 255 */ 256struct pfs_node *pfs_create_dir (struct pfs_node *parent, const char *name, 257 pfs_attr_t attr, pfs_vis_t vis, 258 pfs_destroy_t destroy, int flags); 259struct pfs_node *pfs_create_file(struct pfs_node *parent, const char *name, 260 pfs_fill_t fill, pfs_attr_t attr, 261 pfs_vis_t vis, pfs_destroy_t destroy, 262 int flags); 263struct pfs_node *pfs_create_link(struct pfs_node *parent, const char *name, 264 pfs_fill_t fill, pfs_attr_t attr, 265 pfs_vis_t vis, pfs_destroy_t destroy, 266 int flags); 267struct pfs_node *pfs_find_node (struct pfs_node *parent, const char *name); 268void pfs_purge (struct pfs_node *pn); 269int pfs_destroy (struct pfs_node *pn); 270 271/* 272 * Now for some initialization magic... 273 */
| 36/* 37 * Opaque structures 38 */ 39struct mntarg; 40struct mount; 41struct nameidata; 42struct proc; 43struct sbuf; 44struct statfs; 45struct thread; 46struct uio; 47struct vfsconf; 48struct vnode; 49 50/* 51 * Limits and constants 52 */ 53#define PFS_NAMELEN 24 54#define PFS_FSNAMELEN 16 /* equal to MFSNAMELEN */ 55#define PFS_DELEN (8 + PFS_NAMELEN) 56 57typedef enum { 58 pfstype_none = 0, 59 pfstype_root, 60 pfstype_dir, 61 pfstype_this, 62 pfstype_parent, 63 pfstype_file, 64 pfstype_symlink, 65 pfstype_procdir 66} pfs_type_t; 67 68/* 69 * Flags 70 */ 71#define PFS_RD 0x0001 /* readable */ 72#define PFS_WR 0x0002 /* writeable */ 73#define PFS_RDWR (PFS_RD|PFS_WR) 74#define PFS_RAWRD 0x0004 /* raw reader */ 75#define PFS_RAWWR 0x0008 /* raw writer */ 76#define PFS_RAW (PFS_RAWRD|PFS_RAWWR) 77#define PFS_PROCDEP 0x0010 /* process-dependent */ 78 79/* 80 * Data structures 81 */ 82struct pfs_info; 83struct pfs_node; 84struct pfs_bitmap; 85 86/* 87 * Init / uninit callback 88 */ 89#define PFS_INIT_ARGS \ 90 struct pfs_info *pi, struct vfsconf *vfc 91#define PFS_INIT_ARGNAMES \ 92 pi, vfc 93#define PFS_INIT_PROTO(name) \ 94 int name(PFS_INIT_ARGS); 95typedef int (*pfs_init_t)(PFS_INIT_ARGS); 96 97/* 98 * Filler callback 99 * Called with proc held but unlocked 100 */ 101#define PFS_FILL_ARGS \ 102 struct thread *td, struct proc *p, struct pfs_node *pn, \ 103 struct sbuf *sb, struct uio *uio 104#define PFS_FILL_ARGNAMES \ 105 td, p, pn, sb, uio 106#define PFS_FILL_PROTO(name) \ 107 int name(PFS_FILL_ARGS); 108typedef int (*pfs_fill_t)(PFS_FILL_ARGS); 109 110/* 111 * Attribute callback 112 * Called with proc locked 113 */ 114struct vattr; 115#define PFS_ATTR_ARGS \ 116 struct thread *td, struct proc *p, struct pfs_node *pn, \ 117 struct vattr *vap 118#define PFS_ATTR_ARGNAMES \ 119 td, p, pn, vap 120#define PFS_ATTR_PROTO(name) \ 121 int name(PFS_ATTR_ARGS); 122typedef int (*pfs_attr_t)(PFS_ATTR_ARGS); 123 124struct pfs_bitmap; /* opaque */ 125 126/* 127 * Visibility callback 128 * Called with proc locked 129 */ 130#define PFS_VIS_ARGS \ 131 struct thread *td, struct proc *p, struct pfs_node *pn 132#define PFS_VIS_ARGNAMES \ 133 td, p, pn 134#define PFS_VIS_PROTO(name) \ 135 int name(PFS_VIS_ARGS); 136typedef int (*pfs_vis_t)(PFS_VIS_ARGS); 137 138/* 139 * Ioctl callback 140 * Called with proc locked 141 */ 142#define PFS_IOCTL_ARGS \ 143 struct thread *td, struct proc *p, struct pfs_node *pn, \ 144 unsigned long cmd, void *data 145#define PFS_IOCTL_ARGNAMES \ 146 td, p, pn, cmd, data 147#define PFS_IOCTL_PROTO(name) \ 148 int name(PFS_IOCTL_ARGS); 149typedef int (*pfs_ioctl_t)(PFS_IOCTL_ARGS); 150 151/* 152 * Getextattr callback 153 * Called with proc locked 154 */ 155#define PFS_GETEXTATTR_ARGS \ 156 struct thread *td, struct proc *p, struct pfs_node *pn, \ 157 int attrnamespace, const char *name, struct uio *uio, \ 158 size_t *size, struct ucred *cred 159#define PFS_GETEXTATTR_ARGNAMES \ 160 td, p, pn, attrnamespace, name, uio, size, cred 161#define PFS_GETEXTATTR_PROTO(name) \ 162 int name(PFS_GETEXTATTR_ARGS); 163struct ucred; 164typedef int (*pfs_getextattr_t)(PFS_GETEXTATTR_ARGS); 165 166/* 167 * Last-close callback 168 * Called with proc locked 169 */ 170#define PFS_CLOSE_ARGS \ 171 struct thread *td, struct proc *p, struct pfs_node *pn 172#define PFS_CLOSE_ARGNAMES \ 173 td, p, pn 174#define PFS_CLOSE_PROTO(name) \ 175 int name(PFS_CLOSE_ARGS); 176typedef int (*pfs_close_t)(PFS_CLOSE_ARGS); 177 178/* 179 * Destroy callback 180 */ 181#define PFS_DESTROY_ARGS \ 182 struct pfs_node *pn 183#define PFS_DESTROY_ARGNAMES \ 184 pn 185#define PFS_DESTROY_PROTO(name) \ 186 int name(PFS_DESTROY_ARGS); 187typedef int (*pfs_destroy_t)(PFS_DESTROY_ARGS); 188 189/* 190 * pfs_info: describes a pseudofs instance 191 * 192 * The pi_mutex is only used to avoid using the global subr_unit lock for 193 * unrhdr. The rest of struct pfs_info is only modified while Giant is 194 * held (during vfs_init() and vfs_uninit()). 195 */ 196struct pfs_info { 197 char pi_name[PFS_FSNAMELEN]; 198 pfs_init_t pi_init; 199 pfs_init_t pi_uninit; 200 201 /* members below this line are initialized at run time*/ 202 struct pfs_node *pi_root; 203 struct mtx pi_mutex; 204 struct unrhdr *pi_unrhdr; 205}; 206 207/* 208 * pfs_node: describes a node (file or directory) within a pseudofs 209 * 210 * - Fields marked (o) are protected by the node's own mutex. 211 * - Fields marked (p) are protected by the node's parent's mutex. 212 * - Remaining fields are not protected by any lock and are assumed to be 213 * immutable once the node has been created. 214 * 215 * To prevent deadlocks, if a node's mutex is to be held at the same time 216 * as its parent's (e.g. when adding or removing nodes to a directory), 217 * the parent's mutex must always be acquired first. Unfortunately, this 218 * is not enforcable by WITNESS. 219 */ 220struct pfs_node { 221 char pn_name[PFS_NAMELEN]; 222 pfs_type_t pn_type; 223 int pn_flags; 224 struct mtx pn_mutex; 225 void *pn_data; /* (o) */ 226 227 pfs_fill_t pn_fill; 228 pfs_ioctl_t pn_ioctl; 229 pfs_close_t pn_close; 230 pfs_attr_t pn_attr; 231 pfs_vis_t pn_vis; 232 pfs_getextattr_t pn_getextattr; 233 pfs_destroy_t pn_destroy; 234 235 struct pfs_info *pn_info; 236 u_int32_t pn_fileno; /* (o) */ 237 238 struct pfs_node *pn_parent; /* (o) */ 239 struct pfs_node *pn_nodes; /* (o) */ 240 struct pfs_node *pn_next; /* (p) */ 241}; 242 243/* 244 * VFS interface 245 */ 246int pfs_mount (struct pfs_info *pi, struct mount *mp); 247int pfs_cmount (struct mntarg *ma, void *data, uint64_t flags); 248int pfs_unmount (struct mount *mp, int mntflags); 249int pfs_root (struct mount *mp, int flags, 250 struct vnode **vpp); 251int pfs_statfs (struct mount *mp, struct statfs *sbp); 252int pfs_init (struct pfs_info *pi, struct vfsconf *vfc); 253int pfs_uninit (struct pfs_info *pi, struct vfsconf *vfc); 254 255/* 256 * Directory structure construction and manipulation 257 */ 258struct pfs_node *pfs_create_dir (struct pfs_node *parent, const char *name, 259 pfs_attr_t attr, pfs_vis_t vis, 260 pfs_destroy_t destroy, int flags); 261struct pfs_node *pfs_create_file(struct pfs_node *parent, const char *name, 262 pfs_fill_t fill, pfs_attr_t attr, 263 pfs_vis_t vis, pfs_destroy_t destroy, 264 int flags); 265struct pfs_node *pfs_create_link(struct pfs_node *parent, const char *name, 266 pfs_fill_t fill, pfs_attr_t attr, 267 pfs_vis_t vis, pfs_destroy_t destroy, 268 int flags); 269struct pfs_node *pfs_find_node (struct pfs_node *parent, const char *name); 270void pfs_purge (struct pfs_node *pn); 271int pfs_destroy (struct pfs_node *pn); 272 273/* 274 * Now for some initialization magic... 275 */
|