dead_vnops.c revision 1541
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. 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 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)dead_vnops.c 8.1 (Berkeley) 6/10/93 34 */ 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/time.h> 39#include <sys/vnode.h> 40#include <sys/errno.h> 41#include <sys/namei.h> 42#include <sys/buf.h> 43 44/* 45 * Prototypes for dead operations on vnodes. 46 */ 47int dead_badop(), 48 dead_ebadf(); 49int dead_lookup __P((struct vop_lookup_args *)); 50#define dead_create ((int (*) __P((struct vop_create_args *)))dead_badop) 51#define dead_mknod ((int (*) __P((struct vop_mknod_args *)))dead_badop) 52int dead_open __P((struct vop_open_args *)); 53#define dead_close ((int (*) __P((struct vop_close_args *)))nullop) 54#define dead_access ((int (*) __P((struct vop_access_args *)))dead_ebadf) 55#define dead_getattr ((int (*) __P((struct vop_getattr_args *)))dead_ebadf) 56#define dead_setattr ((int (*) __P((struct vop_setattr_args *)))dead_ebadf) 57int dead_read __P((struct vop_read_args *)); 58int dead_write __P((struct vop_write_args *)); 59int dead_ioctl __P((struct vop_ioctl_args *)); 60int dead_select __P((struct vop_select_args *)); 61#define dead_mmap ((int (*) __P((struct vop_mmap_args *)))dead_badop) 62#define dead_fsync ((int (*) __P((struct vop_fsync_args *)))nullop) 63#define dead_seek ((int (*) __P((struct vop_seek_args *)))nullop) 64#define dead_remove ((int (*) __P((struct vop_remove_args *)))dead_badop) 65#define dead_link ((int (*) __P((struct vop_link_args *)))dead_badop) 66#define dead_rename ((int (*) __P((struct vop_rename_args *)))dead_badop) 67#define dead_mkdir ((int (*) __P((struct vop_mkdir_args *)))dead_badop) 68#define dead_rmdir ((int (*) __P((struct vop_rmdir_args *)))dead_badop) 69#define dead_symlink ((int (*) __P((struct vop_symlink_args *)))dead_badop) 70#define dead_readdir ((int (*) __P((struct vop_readdir_args *)))dead_ebadf) 71#define dead_readlink ((int (*) __P((struct vop_readlink_args *)))dead_ebadf) 72#define dead_abortop ((int (*) __P((struct vop_abortop_args *)))dead_badop) 73#define dead_inactive ((int (*) __P((struct vop_inactive_args *)))nullop) 74#define dead_reclaim ((int (*) __P((struct vop_reclaim_args *)))nullop) 75int dead_lock __P((struct vop_lock_args *)); 76#define dead_unlock ((int (*) __P((struct vop_unlock_args *)))nullop) 77int dead_bmap __P((struct vop_bmap_args *)); 78int dead_strategy __P((struct vop_strategy_args *)); 79int dead_print __P((struct vop_print_args *)); 80#define dead_islocked ((int (*) __P((struct vop_islocked_args *)))nullop) 81#define dead_pathconf ((int (*) __P((struct vop_pathconf_args *)))dead_ebadf) 82#define dead_advlock ((int (*) __P((struct vop_advlock_args *)))dead_ebadf) 83#define dead_blkatoff ((int (*) __P((struct vop_blkatoff_args *)))dead_badop) 84#define dead_valloc ((int (*) __P((struct vop_valloc_args *)))dead_badop) 85#define dead_vfree ((int (*) __P((struct vop_vfree_args *)))dead_badop) 86#define dead_truncate ((int (*) __P((struct vop_truncate_args *)))nullop) 87#define dead_update ((int (*) __P((struct vop_update_args *)))nullop) 88#define dead_bwrite ((int (*) __P((struct vop_bwrite_args *)))nullop) 89 90int (**dead_vnodeop_p)(); 91struct vnodeopv_entry_desc dead_vnodeop_entries[] = { 92 { &vop_default_desc, vn_default_error }, 93 { &vop_lookup_desc, dead_lookup }, /* lookup */ 94 { &vop_create_desc, dead_create }, /* create */ 95 { &vop_mknod_desc, dead_mknod }, /* mknod */ 96 { &vop_open_desc, dead_open }, /* open */ 97 { &vop_close_desc, dead_close }, /* close */ 98 { &vop_access_desc, dead_access }, /* access */ 99 { &vop_getattr_desc, dead_getattr }, /* getattr */ 100 { &vop_setattr_desc, dead_setattr }, /* setattr */ 101 { &vop_read_desc, dead_read }, /* read */ 102 { &vop_write_desc, dead_write }, /* write */ 103 { &vop_ioctl_desc, dead_ioctl }, /* ioctl */ 104 { &vop_select_desc, dead_select }, /* select */ 105 { &vop_mmap_desc, dead_mmap }, /* mmap */ 106 { &vop_fsync_desc, dead_fsync }, /* fsync */ 107 { &vop_seek_desc, dead_seek }, /* seek */ 108 { &vop_remove_desc, dead_remove }, /* remove */ 109 { &vop_link_desc, dead_link }, /* link */ 110 { &vop_rename_desc, dead_rename }, /* rename */ 111 { &vop_mkdir_desc, dead_mkdir }, /* mkdir */ 112 { &vop_rmdir_desc, dead_rmdir }, /* rmdir */ 113 { &vop_symlink_desc, dead_symlink }, /* symlink */ 114 { &vop_readdir_desc, dead_readdir }, /* readdir */ 115 { &vop_readlink_desc, dead_readlink }, /* readlink */ 116 { &vop_abortop_desc, dead_abortop }, /* abortop */ 117 { &vop_inactive_desc, dead_inactive }, /* inactive */ 118 { &vop_reclaim_desc, dead_reclaim }, /* reclaim */ 119 { &vop_lock_desc, dead_lock }, /* lock */ 120 { &vop_unlock_desc, dead_unlock }, /* unlock */ 121 { &vop_bmap_desc, dead_bmap }, /* bmap */ 122 { &vop_strategy_desc, dead_strategy }, /* strategy */ 123 { &vop_print_desc, dead_print }, /* print */ 124 { &vop_islocked_desc, dead_islocked }, /* islocked */ 125 { &vop_pathconf_desc, dead_pathconf }, /* pathconf */ 126 { &vop_advlock_desc, dead_advlock }, /* advlock */ 127 { &vop_blkatoff_desc, dead_blkatoff }, /* blkatoff */ 128 { &vop_valloc_desc, dead_valloc }, /* valloc */ 129 { &vop_vfree_desc, dead_vfree }, /* vfree */ 130 { &vop_truncate_desc, dead_truncate }, /* truncate */ 131 { &vop_update_desc, dead_update }, /* update */ 132 { &vop_bwrite_desc, dead_bwrite }, /* bwrite */ 133 { (struct vnodeop_desc*)NULL, (int(*)())NULL } 134}; 135struct vnodeopv_desc dead_vnodeop_opv_desc = 136 { &dead_vnodeop_p, dead_vnodeop_entries }; 137 138/* 139 * Trivial lookup routine that always fails. 140 */ 141/* ARGSUSED */ 142int 143dead_lookup(ap) 144 struct vop_lookup_args /* { 145 struct vnode * a_dvp; 146 struct vnode ** a_vpp; 147 struct componentname * a_cnp; 148 } */ *ap; 149{ 150 151 *ap->a_vpp = NULL; 152 return (ENOTDIR); 153} 154 155/* 156 * Open always fails as if device did not exist. 157 */ 158/* ARGSUSED */ 159dead_open(ap) 160 struct vop_open_args /* { 161 struct vnode *a_vp; 162 int a_mode; 163 struct ucred *a_cred; 164 struct proc *a_p; 165 } */ *ap; 166{ 167 168 return (ENXIO); 169} 170 171/* 172 * Vnode op for read 173 */ 174/* ARGSUSED */ 175dead_read(ap) 176 struct vop_read_args /* { 177 struct vnode *a_vp; 178 struct uio *a_uio; 179 int a_ioflag; 180 struct ucred *a_cred; 181 } */ *ap; 182{ 183 184 if (chkvnlock(ap->a_vp)) 185 panic("dead_read: lock"); 186 /* 187 * Return EOF for character devices, EIO for others 188 */ 189 if (ap->a_vp->v_type != VCHR) 190 return (EIO); 191 return (0); 192} 193 194/* 195 * Vnode op for write 196 */ 197/* ARGSUSED */ 198dead_write(ap) 199 struct vop_write_args /* { 200 struct vnode *a_vp; 201 struct uio *a_uio; 202 int a_ioflag; 203 struct ucred *a_cred; 204 } */ *ap; 205{ 206 207 if (chkvnlock(ap->a_vp)) 208 panic("dead_write: lock"); 209 return (EIO); 210} 211 212/* 213 * Device ioctl operation. 214 */ 215/* ARGSUSED */ 216dead_ioctl(ap) 217 struct vop_ioctl_args /* { 218 struct vnode *a_vp; 219 int a_command; 220 caddr_t a_data; 221 int a_fflag; 222 struct ucred *a_cred; 223 struct proc *a_p; 224 } */ *ap; 225{ 226 227 if (!chkvnlock(ap->a_vp)) 228 return (EBADF); 229 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap)); 230} 231 232/* ARGSUSED */ 233dead_select(ap) 234 struct vop_select_args /* { 235 struct vnode *a_vp; 236 int a_which; 237 int a_fflags; 238 struct ucred *a_cred; 239 struct proc *a_p; 240 } */ *ap; 241{ 242 243 /* 244 * Let the user find out that the descriptor is gone. 245 */ 246 return (1); 247} 248 249/* 250 * Just call the device strategy routine 251 */ 252dead_strategy(ap) 253 struct vop_strategy_args /* { 254 struct buf *a_bp; 255 } */ *ap; 256{ 257 258 if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) { 259 ap->a_bp->b_flags |= B_ERROR; 260 biodone(ap->a_bp); 261 return (EIO); 262 } 263 return (VOP_STRATEGY(ap->a_bp)); 264} 265 266/* 267 * Wait until the vnode has finished changing state. 268 */ 269dead_lock(ap) 270 struct vop_lock_args /* { 271 struct vnode *a_vp; 272 } */ *ap; 273{ 274 275 if (!chkvnlock(ap->a_vp)) 276 return (0); 277 return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap)); 278} 279 280/* 281 * Wait until the vnode has finished changing state. 282 */ 283dead_bmap(ap) 284 struct vop_bmap_args /* { 285 struct vnode *a_vp; 286 daddr_t a_bn; 287 struct vnode **a_vpp; 288 daddr_t *a_bnp; 289 int *a_runp; 290 } */ *ap; 291{ 292 293 if (!chkvnlock(ap->a_vp)) 294 return (EIO); 295 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp)); 296} 297 298/* 299 * Print out the contents of a dead vnode. 300 */ 301/* ARGSUSED */ 302dead_print(ap) 303 struct vop_print_args /* { 304 struct vnode *a_vp; 305 } */ *ap; 306{ 307 308 printf("tag VT_NON, dead vnode\n"); 309} 310 311/* 312 * Empty vnode failed operation 313 */ 314dead_ebadf() 315{ 316 317 return (EBADF); 318} 319 320/* 321 * Empty vnode bad operation 322 */ 323dead_badop() 324{ 325 326 panic("dead_badop called"); 327 /* NOTREACHED */ 328} 329 330/* 331 * Empty vnode null operation 332 */ 333dead_nullop() 334{ 335 336 return (0); 337} 338 339/* 340 * We have to wait during times when the vnode is 341 * in a state of change. 342 */ 343chkvnlock(vp) 344 register struct vnode *vp; 345{ 346 int locked = 0; 347 348 while (vp->v_flag & VXLOCK) { 349 vp->v_flag |= VXWANT; 350 sleep((caddr_t)vp, PINOD); 351 locked = 1; 352 } 353 return (locked); 354} 355