1 1.54 hannken /* $NetBSD: specdev.h,v 1.54 2023/04/22 14:30:16 hannken Exp $ */ 2 1.34 ad 3 1.34 ad /*- 4 1.34 ad * Copyright (c) 2008 The NetBSD Foundation, Inc. 5 1.34 ad * All rights reserved. 6 1.34 ad * 7 1.34 ad * Redistribution and use in source and binary forms, with or without 8 1.34 ad * modification, are permitted provided that the following conditions 9 1.34 ad * are met: 10 1.34 ad * 1. Redistributions of source code must retain the above copyright 11 1.34 ad * notice, this list of conditions and the following disclaimer. 12 1.34 ad * 2. Redistributions in binary form must reproduce the above copyright 13 1.34 ad * notice, this list of conditions and the following disclaimer in the 14 1.34 ad * documentation and/or other materials provided with the distribution. 15 1.34 ad * 16 1.34 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 1.34 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 1.34 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 1.34 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 1.34 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.34 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.34 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.34 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.34 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.34 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.34 ad * POSSIBILITY OF SUCH DAMAGE. 27 1.34 ad */ 28 1.8 cgd 29 1.1 cgd /* 30 1.7 mycroft * Copyright (c) 1990, 1993 31 1.7 mycroft * The Regents of the University of California. All rights reserved. 32 1.1 cgd * 33 1.1 cgd * Redistribution and use in source and binary forms, with or without 34 1.1 cgd * modification, are permitted provided that the following conditions 35 1.1 cgd * are met: 36 1.1 cgd * 1. Redistributions of source code must retain the above copyright 37 1.1 cgd * notice, this list of conditions and the following disclaimer. 38 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright 39 1.1 cgd * notice, this list of conditions and the following disclaimer in the 40 1.1 cgd * documentation and/or other materials provided with the distribution. 41 1.24 agc * 3. Neither the name of the University nor the names of its contributors 42 1.1 cgd * may be used to endorse or promote products derived from this software 43 1.1 cgd * without specific prior written permission. 44 1.1 cgd * 45 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 46 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 49 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 50 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 51 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 52 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 53 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55 1.1 cgd * SUCH DAMAGE. 56 1.1 cgd * 57 1.17 fvdl * @(#)specdev.h 8.6 (Berkeley) 5/21/95 58 1.1 cgd */ 59 1.34 ad 60 1.23 matt #ifndef _MISCFS_SPECFS_SPECDEV_H_ 61 1.23 matt #define _MISCFS_SPECFS_SPECDEV_H_ 62 1.1 cgd 63 1.34 ad #include <sys/mutex.h> 64 1.34 ad #include <sys/vnode.h> 65 1.34 ad 66 1.34 ad typedef struct specnode { 67 1.34 ad vnode_t *sn_next; 68 1.34 ad struct specdev *sn_dev; 69 1.52 riastrad dev_t sn_rdev; 70 1.47 riastrad u_int sn_opencnt; /* # of opens, share of sd_opencnt */ 71 1.34 ad bool sn_gone; 72 1.34 ad } specnode_t; 73 1.34 ad 74 1.34 ad typedef struct specdev { 75 1.34 ad struct mount *sd_mountpoint; 76 1.34 ad struct lockf *sd_lockf; 77 1.34 ad vnode_t *sd_bdevvp; 78 1.47 riastrad u_int sd_opencnt; /* # of opens; close when ->0 */ 79 1.47 riastrad u_int sd_refcnt; /* # of specnodes referencing this */ 80 1.49 riastrad volatile u_int sd_iocnt; /* # bdev/cdev_* operations active */ 81 1.48 riastrad bool sd_opened; /* true if successfully opened */ 82 1.50 riastrad bool sd_closing; /* true when bdev/cdev_close ongoing */ 83 1.34 ad } specdev_t; 84 1.34 ad 85 1.1 cgd /* 86 1.1 cgd * Exported shorthand 87 1.1 cgd */ 88 1.34 ad #define v_specnext v_specnode->sn_next 89 1.34 ad #define v_rdev v_specnode->sn_rdev 90 1.34 ad #define v_speclockf v_specnode->sn_dev->sd_lockf 91 1.1 cgd 92 1.1 cgd /* 93 1.1 cgd * Special device management 94 1.1 cgd */ 95 1.34 ad void spec_node_init(vnode_t *, dev_t); 96 1.34 ad void spec_node_destroy(vnode_t *); 97 1.51 riastrad int spec_node_lookup_by_dev(enum vtype, dev_t, int, vnode_t **); 98 1.40 hannken int spec_node_lookup_by_mount(struct mount *, vnode_t **); 99 1.42 hannken struct mount *spec_node_getmountedfs(vnode_t *); 100 1.42 hannken void spec_node_setmountedfs(vnode_t *, struct mount *); 101 1.34 ad void spec_node_revoke(vnode_t *); 102 1.1 cgd 103 1.1 cgd /* 104 1.1 cgd * Prototypes for special file operations on vnodes. 105 1.1 cgd */ 106 1.53 riastrad extern const struct vnodeopv_desc spec_vnodeop_opv_desc; 107 1.27 xtraeme extern int (**spec_vnodeop_p)(void *); 108 1.1 cgd struct nameidata; 109 1.7 mycroft struct componentname; 110 1.1 cgd struct flock; 111 1.1 cgd struct buf; 112 1.1 cgd struct uio; 113 1.1 cgd 114 1.27 xtraeme int spec_lookup(void *); 115 1.27 xtraeme int spec_open(void *); 116 1.27 xtraeme int spec_close(void *); 117 1.27 xtraeme int spec_read(void *); 118 1.27 xtraeme int spec_write(void *); 119 1.43 dholland int spec_fdiscard(void *); 120 1.27 xtraeme int spec_ioctl(void *); 121 1.27 xtraeme int spec_poll(void *); 122 1.27 xtraeme int spec_kqfilter(void *); 123 1.31 pooka int spec_mmap(void *); 124 1.27 xtraeme int spec_fsync(void *); 125 1.16 kleink #define spec_seek genfs_nullop /* XXX should query device */ 126 1.27 xtraeme int spec_inactive(void *); 127 1.44 hannken int spec_reclaim(void *); 128 1.27 xtraeme int spec_bmap(void *); 129 1.27 xtraeme int spec_strategy(void *); 130 1.27 xtraeme int spec_print(void *); 131 1.27 xtraeme int spec_pathconf(void *); 132 1.27 xtraeme int spec_advlock(void *); 133 1.23 matt 134 1.45 dholland /* 135 1.45 dholland * This macro provides an initializer list for the fs-independent part 136 1.45 dholland * of a filesystem's special file vnode ops descriptor table. We still 137 1.45 dholland * need such a table in every filesystem, but we can at least avoid 138 1.45 dholland * the cutpaste. 139 1.45 dholland * 140 1.45 dholland * This contains these ops: 141 1.45 dholland * parsepath lookup 142 1.45 dholland * create whiteout mknod open fallocate fdiscard ioctl poll kqfilter 143 1.45 dholland * revoke mmap seek remove link rename mkdir rmdir symlink readdir 144 1.45 dholland * readlink abortop bmap strategy pathconf advlock getpages putpages 145 1.45 dholland * 146 1.45 dholland * The filesystem should provide these ops that need to be its own: 147 1.45 dholland * access and accessx 148 1.45 dholland * getattr 149 1.45 dholland * setattr 150 1.45 dholland * fcntl 151 1.45 dholland * inactive 152 1.45 dholland * reclaim 153 1.45 dholland * lock 154 1.45 dholland * unlock 155 1.45 dholland * print (should probably also call spec_print) 156 1.45 dholland * islocked 157 1.45 dholland * bwrite (normally vn_bwrite) 158 1.45 dholland * openextattr 159 1.45 dholland * closeextattr 160 1.45 dholland * getextattr 161 1.45 dholland * setextattr 162 1.45 dholland * listextattr 163 1.45 dholland * deleteextattr 164 1.45 dholland * getacl 165 1.45 dholland * setacl 166 1.45 dholland * aclcheck 167 1.45 dholland * 168 1.45 dholland * The filesystem should also provide these ops that some filesystems 169 1.45 dholland * do their own things with: 170 1.45 dholland * close 171 1.45 dholland * read 172 1.45 dholland * write 173 1.45 dholland * fsync 174 1.45 dholland * In most cases "their own things" means adjust timestamps and call 175 1.45 dholland * spec_foo. For fsync it varies, but should always also call spec_fsync. 176 1.45 dholland * 177 1.45 dholland * Note that because the op descriptor tables are unordered it does not 178 1.53 riastrad * matter where in the table this macro goes (except I think default 179 1.45 dholland * still needs to be first...) 180 1.45 dholland */ 181 1.45 dholland #define GENFS_SPECOP_ENTRIES \ 182 1.45 dholland { &vop_parsepath_desc, genfs_badop }, /* parsepath */ \ 183 1.45 dholland { &vop_lookup_desc, spec_lookup }, /* lookup */ \ 184 1.45 dholland { &vop_create_desc, genfs_badop }, /* create */ \ 185 1.45 dholland { &vop_whiteout_desc, genfs_badop }, /* whiteout */ \ 186 1.45 dholland { &vop_mknod_desc, genfs_badop }, /* mknod */ \ 187 1.45 dholland { &vop_open_desc, spec_open }, /* open */ \ 188 1.45 dholland { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ \ 189 1.45 dholland { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */ \ 190 1.45 dholland { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ \ 191 1.45 dholland { &vop_poll_desc, spec_poll }, /* poll */ \ 192 1.45 dholland { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ \ 193 1.45 dholland { &vop_revoke_desc, genfs_revoke }, /* revoke */ \ 194 1.45 dholland { &vop_mmap_desc, spec_mmap }, /* mmap */ \ 195 1.45 dholland { &vop_seek_desc, spec_seek }, /* seek */ \ 196 1.45 dholland { &vop_remove_desc, genfs_badop }, /* remove */ \ 197 1.45 dholland { &vop_link_desc, genfs_badop }, /* link */ \ 198 1.45 dholland { &vop_rename_desc, genfs_badop }, /* rename */ \ 199 1.45 dholland { &vop_mkdir_desc, genfs_badop }, /* mkdir */ \ 200 1.45 dholland { &vop_rmdir_desc, genfs_badop }, /* rmdir */ \ 201 1.45 dholland { &vop_symlink_desc, genfs_badop }, /* symlink */ \ 202 1.45 dholland { &vop_readdir_desc, genfs_badop }, /* readdir */ \ 203 1.45 dholland { &vop_readlink_desc, genfs_badop }, /* readlink */ \ 204 1.45 dholland { &vop_abortop_desc, genfs_badop }, /* abortop */ \ 205 1.45 dholland { &vop_bmap_desc, spec_bmap }, /* bmap */ \ 206 1.45 dholland { &vop_strategy_desc, spec_strategy }, /* strategy */ \ 207 1.45 dholland { &vop_pathconf_desc, spec_pathconf }, /* pathconf */ \ 208 1.45 dholland { &vop_advlock_desc, spec_advlock }, /* advlock */ \ 209 1.45 dholland { &vop_getpages_desc, genfs_getpages }, /* getpages */ \ 210 1.45 dholland { &vop_putpages_desc, genfs_putpages } /* putpages */ 211 1.45 dholland 212 1.45 dholland 213 1.38 elad bool iskmemvp(struct vnode *); 214 1.39 elad void spec_init(void); 215 1.38 elad 216 1.23 matt #endif /* _MISCFS_SPECFS_SPECDEV_H_ */ 217