1*149aa6beShannken /* $NetBSD: specdev.h,v 1.54 2023/04/22 14:30:16 hannken Exp $ */ 2703069c0Sad 3703069c0Sad /*- 4703069c0Sad * Copyright (c) 2008 The NetBSD Foundation, Inc. 5703069c0Sad * All rights reserved. 6703069c0Sad * 7703069c0Sad * Redistribution and use in source and binary forms, with or without 8703069c0Sad * modification, are permitted provided that the following conditions 9703069c0Sad * are met: 10703069c0Sad * 1. Redistributions of source code must retain the above copyright 11703069c0Sad * notice, this list of conditions and the following disclaimer. 12703069c0Sad * 2. Redistributions in binary form must reproduce the above copyright 13703069c0Sad * notice, this list of conditions and the following disclaimer in the 14703069c0Sad * documentation and/or other materials provided with the distribution. 15703069c0Sad * 16703069c0Sad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17703069c0Sad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18703069c0Sad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19703069c0Sad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20703069c0Sad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21703069c0Sad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22703069c0Sad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23703069c0Sad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24703069c0Sad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25703069c0Sad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26703069c0Sad * POSSIBILITY OF SUCH DAMAGE. 27703069c0Sad */ 28cf92afd6Scgd 2961f28255Scgd /* 30cde1d475Smycroft * Copyright (c) 1990, 1993 31cde1d475Smycroft * The Regents of the University of California. All rights reserved. 3261f28255Scgd * 3361f28255Scgd * Redistribution and use in source and binary forms, with or without 3461f28255Scgd * modification, are permitted provided that the following conditions 3561f28255Scgd * are met: 3661f28255Scgd * 1. Redistributions of source code must retain the above copyright 3761f28255Scgd * notice, this list of conditions and the following disclaimer. 3861f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright 3961f28255Scgd * notice, this list of conditions and the following disclaimer in the 4061f28255Scgd * documentation and/or other materials provided with the distribution. 41aad01611Sagc * 3. Neither the name of the University nor the names of its contributors 4261f28255Scgd * may be used to endorse or promote products derived from this software 4361f28255Scgd * without specific prior written permission. 4461f28255Scgd * 4561f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 4661f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4761f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4861f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 4961f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 5061f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 5161f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 5261f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5361f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5461f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5561f28255Scgd * SUCH DAMAGE. 5661f28255Scgd * 57e5bc90f4Sfvdl * @(#)specdev.h 8.6 (Berkeley) 5/21/95 5861f28255Scgd */ 59703069c0Sad 605d09a845Smatt #ifndef _MISCFS_SPECFS_SPECDEV_H_ 615d09a845Smatt #define _MISCFS_SPECFS_SPECDEV_H_ 6261f28255Scgd 63703069c0Sad #include <sys/mutex.h> 64703069c0Sad #include <sys/vnode.h> 65142e9d5dShannken 66703069c0Sad typedef struct specnode { 67703069c0Sad vnode_t *sn_next; 68703069c0Sad struct specdev *sn_dev; 69703069c0Sad dev_t sn_rdev; 7024d512b1Sriastradh u_int sn_opencnt; /* # of opens, share of sd_opencnt */ 71703069c0Sad bool sn_gone; 72703069c0Sad } specnode_t; 73703069c0Sad 74703069c0Sad typedef struct specdev { 75703069c0Sad struct mount *sd_mountpoint; 76703069c0Sad struct lockf *sd_lockf; 77703069c0Sad vnode_t *sd_bdevvp; 78eb8abdf3Sriastradh u_int sd_opencnt; /* # of opens; close when ->0 */ 79eb8abdf3Sriastradh u_int sd_refcnt; /* # of specnodes referencing this */ 8066ae10f9Sriastradh volatile u_int sd_iocnt; /* # bdev/cdev_* operations active */ 8171a1e06aSriastradh bool sd_opened; /* true if successfully opened */ 82daba8dd8Sriastradh bool sd_closing; /* true when bdev/cdev_close ongoing */ 83703069c0Sad } specdev_t; 84703069c0Sad 8561f28255Scgd /* 8661f28255Scgd * Exported shorthand 8761f28255Scgd */ 88703069c0Sad #define v_specnext v_specnode->sn_next 89703069c0Sad #define v_rdev v_specnode->sn_rdev 90703069c0Sad #define v_speclockf v_specnode->sn_dev->sd_lockf 9161f28255Scgd 9261f28255Scgd /* 9361f28255Scgd * Special device management 9461f28255Scgd */ 95703069c0Sad void spec_node_init(vnode_t *, dev_t); 96703069c0Sad void spec_node_destroy(vnode_t *); 97a2155d69Sriastradh int spec_node_lookup_by_dev(enum vtype, dev_t, int, vnode_t **); 989f9ac3cbShannken int spec_node_lookup_by_mount(struct mount *, vnode_t **); 993881f4f3Shannken struct mount *spec_node_getmountedfs(vnode_t *); 1003881f4f3Shannken void spec_node_setmountedfs(vnode_t *, struct mount *); 101703069c0Sad void spec_node_revoke(vnode_t *); 10261f28255Scgd 10361f28255Scgd /* 10461f28255Scgd * Prototypes for special file operations on vnodes. 10561f28255Scgd */ 106fa76fa97Sriastradh extern const struct vnodeopv_desc spec_vnodeop_opv_desc; 107af97f2e8Sxtraeme extern int (**spec_vnodeop_p)(void *); 10861f28255Scgd struct nameidata; 109cde1d475Smycroft struct componentname; 11061f28255Scgd struct flock; 11161f28255Scgd struct buf; 11261f28255Scgd struct uio; 11361f28255Scgd 114af97f2e8Sxtraeme int spec_lookup(void *); 115af97f2e8Sxtraeme int spec_open(void *); 116af97f2e8Sxtraeme int spec_close(void *); 117af97f2e8Sxtraeme int spec_read(void *); 118af97f2e8Sxtraeme int spec_write(void *); 1192b17a74dSdholland int spec_fdiscard(void *); 120af97f2e8Sxtraeme int spec_ioctl(void *); 121af97f2e8Sxtraeme int spec_poll(void *); 122af97f2e8Sxtraeme int spec_kqfilter(void *); 12305ce20f4Spooka int spec_mmap(void *); 124af97f2e8Sxtraeme int spec_fsync(void *); 1259c16cd8aSkleink #define spec_seek genfs_nullop /* XXX should query device */ 126af97f2e8Sxtraeme int spec_inactive(void *); 1274e19d4c7Shannken int spec_reclaim(void *); 128af97f2e8Sxtraeme int spec_bmap(void *); 129af97f2e8Sxtraeme int spec_strategy(void *); 130af97f2e8Sxtraeme int spec_print(void *); 131af97f2e8Sxtraeme int spec_pathconf(void *); 132af97f2e8Sxtraeme int spec_advlock(void *); 1335d09a845Smatt 134d819c361Sdholland /* 135d819c361Sdholland * This macro provides an initializer list for the fs-independent part 136d819c361Sdholland * of a filesystem's special file vnode ops descriptor table. We still 137d819c361Sdholland * need such a table in every filesystem, but we can at least avoid 138d819c361Sdholland * the cutpaste. 139d819c361Sdholland * 140d819c361Sdholland * This contains these ops: 141d819c361Sdholland * parsepath lookup 142d819c361Sdholland * create whiteout mknod open fallocate fdiscard ioctl poll kqfilter 143d819c361Sdholland * revoke mmap seek remove link rename mkdir rmdir symlink readdir 144d819c361Sdholland * readlink abortop bmap strategy pathconf advlock getpages putpages 145d819c361Sdholland * 146d819c361Sdholland * The filesystem should provide these ops that need to be its own: 147d819c361Sdholland * access and accessx 148d819c361Sdholland * getattr 149d819c361Sdholland * setattr 150d819c361Sdholland * fcntl 151d819c361Sdholland * inactive 152d819c361Sdholland * reclaim 153d819c361Sdholland * lock 154d819c361Sdholland * unlock 155d819c361Sdholland * print (should probably also call spec_print) 156d819c361Sdholland * islocked 157d819c361Sdholland * bwrite (normally vn_bwrite) 158d819c361Sdholland * openextattr 159d819c361Sdholland * closeextattr 160d819c361Sdholland * getextattr 161d819c361Sdholland * setextattr 162d819c361Sdholland * listextattr 163d819c361Sdholland * deleteextattr 164d819c361Sdholland * getacl 165d819c361Sdholland * setacl 166d819c361Sdholland * aclcheck 167d819c361Sdholland * 168d819c361Sdholland * The filesystem should also provide these ops that some filesystems 169d819c361Sdholland * do their own things with: 170d819c361Sdholland * close 171d819c361Sdholland * read 172d819c361Sdholland * write 173d819c361Sdholland * fsync 174d819c361Sdholland * In most cases "their own things" means adjust timestamps and call 175d819c361Sdholland * spec_foo. For fsync it varies, but should always also call spec_fsync. 176d819c361Sdholland * 177d819c361Sdholland * Note that because the op descriptor tables are unordered it does not 178d819c361Sdholland * matter where in the table this macro goes (except I think default 179d819c361Sdholland * still needs to be first...) 180d819c361Sdholland */ 181d819c361Sdholland #define GENFS_SPECOP_ENTRIES \ 182d819c361Sdholland { &vop_parsepath_desc, genfs_badop }, /* parsepath */ \ 183d819c361Sdholland { &vop_lookup_desc, spec_lookup }, /* lookup */ \ 184d819c361Sdholland { &vop_create_desc, genfs_badop }, /* create */ \ 185d819c361Sdholland { &vop_whiteout_desc, genfs_badop }, /* whiteout */ \ 186d819c361Sdholland { &vop_mknod_desc, genfs_badop }, /* mknod */ \ 187d819c361Sdholland { &vop_open_desc, spec_open }, /* open */ \ 188d819c361Sdholland { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */ \ 189d819c361Sdholland { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */ \ 190d819c361Sdholland { &vop_ioctl_desc, spec_ioctl }, /* ioctl */ \ 191d819c361Sdholland { &vop_poll_desc, spec_poll }, /* poll */ \ 192d819c361Sdholland { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */ \ 193d819c361Sdholland { &vop_revoke_desc, genfs_revoke }, /* revoke */ \ 194d819c361Sdholland { &vop_mmap_desc, spec_mmap }, /* mmap */ \ 195d819c361Sdholland { &vop_seek_desc, spec_seek }, /* seek */ \ 196d819c361Sdholland { &vop_remove_desc, genfs_badop }, /* remove */ \ 197d819c361Sdholland { &vop_link_desc, genfs_badop }, /* link */ \ 198d819c361Sdholland { &vop_rename_desc, genfs_badop }, /* rename */ \ 199d819c361Sdholland { &vop_mkdir_desc, genfs_badop }, /* mkdir */ \ 200d819c361Sdholland { &vop_rmdir_desc, genfs_badop }, /* rmdir */ \ 201d819c361Sdholland { &vop_symlink_desc, genfs_badop }, /* symlink */ \ 202d819c361Sdholland { &vop_readdir_desc, genfs_badop }, /* readdir */ \ 203d819c361Sdholland { &vop_readlink_desc, genfs_badop }, /* readlink */ \ 204d819c361Sdholland { &vop_abortop_desc, genfs_badop }, /* abortop */ \ 205d819c361Sdholland { &vop_bmap_desc, spec_bmap }, /* bmap */ \ 206d819c361Sdholland { &vop_strategy_desc, spec_strategy }, /* strategy */ \ 207d819c361Sdholland { &vop_pathconf_desc, spec_pathconf }, /* pathconf */ \ 208d819c361Sdholland { &vop_advlock_desc, spec_advlock }, /* advlock */ \ 209d819c361Sdholland { &vop_getpages_desc, genfs_getpages }, /* getpages */ \ 210d819c361Sdholland { &vop_putpages_desc, genfs_putpages } /* putpages */ 211d819c361Sdholland 212d819c361Sdholland 213756638cfSelad bool iskmemvp(struct vnode *); 2141570e68cSelad void spec_init(void); 215756638cfSelad 2165d09a845Smatt #endif /* _MISCFS_SPECFS_SPECDEV_H_ */ 217