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 * $Id: dead_vnops.c,v 1.5 1994/10/06 21:06:40 davidg Exp $ 35 */ 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/proc.h> 40 #include <sys/time.h> 41 #include <sys/kernel.h> 42 #include <sys/vnode.h> 43 #include <sys/errno.h> 44 #include <sys/namei.h> 45 #include <sys/buf.h> 46 47 static int chkvnlock __P((struct vnode *)); 48 /* 49 * Prototypes for dead operations on vnodes. 50 */ 51 int dead_badop(), 52 dead_ebadf(); 53 int dead_lookup __P((struct vop_lookup_args *)); 54 #define dead_create ((int (*) __P((struct vop_create_args *)))dead_badop) 55 #define dead_mknod ((int (*) __P((struct vop_mknod_args *)))dead_badop) 56 int dead_open __P((struct vop_open_args *)); 57 #define dead_close ((int (*) __P((struct vop_close_args *)))nullop) 58 #define dead_access ((int (*) __P((struct vop_access_args *)))dead_ebadf) 59 #define dead_getattr ((int (*) __P((struct vop_getattr_args *)))dead_ebadf) 60 #define dead_setattr ((int (*) __P((struct vop_setattr_args *)))dead_ebadf) 61 int dead_read __P((struct vop_read_args *)); 62 int dead_write __P((struct vop_write_args *)); 63 int dead_ioctl __P((struct vop_ioctl_args *)); 64 int dead_select __P((struct vop_select_args *)); 65 #define dead_mmap ((int (*) __P((struct vop_mmap_args *)))dead_badop) 66 #define dead_fsync ((int (*) __P((struct vop_fsync_args *)))nullop) 67 #define dead_seek ((int (*) __P((struct vop_seek_args *)))nullop) 68 #define dead_remove ((int (*) __P((struct vop_remove_args *)))dead_badop) 69 #define dead_link ((int (*) __P((struct vop_link_args *)))dead_badop) 70 #define dead_rename ((int (*) __P((struct vop_rename_args *)))dead_badop) 71 #define dead_mkdir ((int (*) __P((struct vop_mkdir_args *)))dead_badop) 72 #define dead_rmdir ((int (*) __P((struct vop_rmdir_args *)))dead_badop) 73 #define dead_symlink ((int (*) __P((struct vop_symlink_args *)))dead_badop) 74 #define dead_readdir ((int (*) __P((struct vop_readdir_args *)))dead_ebadf) 75 #define dead_readlink ((int (*) __P((struct vop_readlink_args *)))dead_ebadf) 76 #define dead_abortop ((int (*) __P((struct vop_abortop_args *)))dead_badop) 77 #define dead_inactive ((int (*) __P((struct vop_inactive_args *)))nullop) 78 #define dead_reclaim ((int (*) __P((struct vop_reclaim_args *)))nullop) 79 int dead_lock __P((struct vop_lock_args *)); 80 #define dead_unlock ((int (*) __P((struct vop_unlock_args *)))nullop) 81 int dead_bmap __P((struct vop_bmap_args *)); 82 int dead_strategy __P((struct vop_strategy_args *)); 83 int dead_print __P((struct vop_print_args *)); 84 #define dead_islocked ((int (*) __P((struct vop_islocked_args *)))nullop) 85 #define dead_pathconf ((int (*) __P((struct vop_pathconf_args *)))dead_ebadf) 86 #define dead_advlock ((int (*) __P((struct vop_advlock_args *)))dead_ebadf) 87 #define dead_blkatoff ((int (*) __P((struct vop_blkatoff_args *)))dead_badop) 88 #define dead_valloc ((int (*) __P((struct vop_valloc_args *)))dead_badop) 89 #define dead_vfree ((int (*) __P((struct vop_vfree_args *)))dead_badop) 90 #define dead_truncate ((int (*) __P((struct vop_truncate_args *)))nullop) 91 #define dead_update ((int (*) __P((struct vop_update_args *)))nullop) 92 #define dead_bwrite ((int (*) __P((struct vop_bwrite_args *)))nullop) 93 94 int (**dead_vnodeop_p)(); 95 struct vnodeopv_entry_desc dead_vnodeop_entries[] = { 96 { &vop_default_desc, vn_default_error }, 97 { &vop_lookup_desc, dead_lookup }, /* lookup */ 98 { &vop_create_desc, dead_create }, /* create */ 99 { &vop_mknod_desc, dead_mknod }, /* mknod */ 100 { &vop_open_desc, dead_open }, /* open */ 101 { &vop_close_desc, dead_close }, /* close */ 102 { &vop_access_desc, dead_access }, /* access */ 103 { &vop_getattr_desc, dead_getattr }, /* getattr */ 104 { &vop_setattr_desc, dead_setattr }, /* setattr */ 105 { &vop_read_desc, dead_read }, /* read */ 106 { &vop_write_desc, dead_write }, /* write */ 107 { &vop_ioctl_desc, dead_ioctl }, /* ioctl */ 108 { &vop_select_desc, dead_select }, /* select */ 109 { &vop_mmap_desc, dead_mmap }, /* mmap */ 110 { &vop_fsync_desc, dead_fsync }, /* fsync */ 111 { &vop_seek_desc, dead_seek }, /* seek */ 112 { &vop_remove_desc, dead_remove }, /* remove */ 113 { &vop_link_desc, dead_link }, /* link */ 114 { &vop_rename_desc, dead_rename }, /* rename */ 115 { &vop_mkdir_desc, dead_mkdir }, /* mkdir */ 116 { &vop_rmdir_desc, dead_rmdir }, /* rmdir */ 117 { &vop_symlink_desc, dead_symlink }, /* symlink */ 118 { &vop_readdir_desc, dead_readdir }, /* readdir */ 119 { &vop_readlink_desc, dead_readlink }, /* readlink */ 120 { &vop_abortop_desc, dead_abortop }, /* abortop */ 121 { &vop_inactive_desc, dead_inactive }, /* inactive */ 122 { &vop_reclaim_desc, dead_reclaim }, /* reclaim */ 123 { &vop_lock_desc, dead_lock }, /* lock */ 124 { &vop_unlock_desc, dead_unlock }, /* unlock */ 125 { &vop_bmap_desc, dead_bmap }, /* bmap */ 126 { &vop_strategy_desc, dead_strategy }, /* strategy */ 127 { &vop_print_desc, dead_print }, /* print */ 128 { &vop_islocked_desc, dead_islocked }, /* islocked */ 129 { &vop_pathconf_desc, dead_pathconf }, /* pathconf */ 130 { &vop_advlock_desc, dead_advlock }, /* advlock */ 131 { &vop_blkatoff_desc, dead_blkatoff }, /* blkatoff */ 132 { &vop_valloc_desc, dead_valloc }, /* valloc */ 133 { &vop_vfree_desc, dead_vfree }, /* vfree */ 134 { &vop_truncate_desc, dead_truncate }, /* truncate */ 135 { &vop_update_desc, dead_update }, /* update */ 136 { &vop_bwrite_desc, dead_bwrite }, /* bwrite */ 137 { (struct vnodeop_desc*)NULL, (int(*)())NULL } 138 }; 139 struct vnodeopv_desc dead_vnodeop_opv_desc = 140 { &dead_vnodeop_p, dead_vnodeop_entries }; 141 142 VNODEOP_SET(dead_vnodeop_opv_desc); 143 144 /* 145 * Trivial lookup routine that always fails. 146 */ 147 /* ARGSUSED */ 148 int 149 dead_lookup(ap) 150 struct vop_lookup_args /* { 151 struct vnode * a_dvp; 152 struct vnode ** a_vpp; 153 struct componentname * a_cnp; 154 } */ *ap; 155 { 156 157 *ap->a_vpp = NULL; 158 return (ENOTDIR); 159 } 160 161 /* 162 * Open always fails as if device did not exist. 163 */ 164 /* ARGSUSED */ 165 int 166 dead_open(ap) 167 struct vop_open_args /* { 168 struct vnode *a_vp; 169 int a_mode; 170 struct ucred *a_cred; 171 struct proc *a_p; 172 } */ *ap; 173 { 174 175 return (ENXIO); 176 } 177 178 /* 179 * Vnode op for read 180 */ 181 /* ARGSUSED */ 182 int 183 dead_read(ap) 184 struct vop_read_args /* { 185 struct vnode *a_vp; 186 struct uio *a_uio; 187 int a_ioflag; 188 struct ucred *a_cred; 189 } */ *ap; 190 { 191 192 if (chkvnlock(ap->a_vp)) 193 panic("dead_read: lock"); 194 /* 195 * Return EOF for character devices, EIO for others 196 */ 197 if (ap->a_vp->v_type != VCHR) 198 return (EIO); 199 return (0); 200 } 201 202 /* 203 * Vnode op for write 204 */ 205 /* ARGSUSED */ 206 int 207 dead_write(ap) 208 struct vop_write_args /* { 209 struct vnode *a_vp; 210 struct uio *a_uio; 211 int a_ioflag; 212 struct ucred *a_cred; 213 } */ *ap; 214 { 215 216 if (chkvnlock(ap->a_vp)) 217 panic("dead_write: lock"); 218 return (EIO); 219 } 220 221 /* 222 * Device ioctl operation. 223 */ 224 /* ARGSUSED */ 225 int 226 dead_ioctl(ap) 227 struct vop_ioctl_args /* { 228 struct vnode *a_vp; 229 int a_command; 230 caddr_t a_data; 231 int a_fflag; 232 struct ucred *a_cred; 233 struct proc *a_p; 234 } */ *ap; 235 { 236 237 if (!chkvnlock(ap->a_vp)) 238 return (EBADF); 239 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap)); 240 } 241 242 /* ARGSUSED */ 243 int 244 dead_select(ap) 245 struct vop_select_args /* { 246 struct vnode *a_vp; 247 int a_which; 248 int a_fflags; 249 struct ucred *a_cred; 250 struct proc *a_p; 251 } */ *ap; 252 { 253 254 /* 255 * Let the user find out that the descriptor is gone. 256 */ 257 return (1); 258 } 259 260 /* 261 * Just call the device strategy routine 262 */ 263 int 264 dead_strategy(ap) 265 struct vop_strategy_args /* { 266 struct buf *a_bp; 267 } */ *ap; 268 { 269 270 if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) { 271 ap->a_bp->b_flags |= B_ERROR; 272 biodone(ap->a_bp); 273 return (EIO); 274 } 275 return (VOP_STRATEGY(ap->a_bp)); 276 } 277 278 /* 279 * Wait until the vnode has finished changing state. 280 */ 281 int 282 dead_lock(ap) 283 struct vop_lock_args /* { 284 struct vnode *a_vp; 285 } */ *ap; 286 { 287 288 if (!chkvnlock(ap->a_vp)) 289 return (0); 290 return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap)); 291 } 292 293 /* 294 * Wait until the vnode has finished changing state. 295 */ 296 int 297 dead_bmap(ap) 298 struct vop_bmap_args /* { 299 struct vnode *a_vp; 300 daddr_t a_bn; 301 struct vnode **a_vpp; 302 daddr_t *a_bnp; 303 int *a_runp; 304 } */ *ap; 305 { 306 307 if (!chkvnlock(ap->a_vp)) 308 return (EIO); 309 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp)); 310 } 311 312 /* 313 * Print out the contents of a dead vnode. 314 */ 315 /* ARGSUSED */ 316 int 317 dead_print(ap) 318 struct vop_print_args /* { 319 struct vnode *a_vp; 320 } */ *ap; 321 { 322 323 printf("tag VT_NON, dead vnode\n"); 324 return (0); 325 } 326 327 /* 328 * Empty vnode failed operation 329 */ 330 int 331 dead_ebadf() 332 { 333 334 return (EBADF); 335 } 336 337 /* 338 * Empty vnode bad operation 339 */ 340 int 341 dead_badop() 342 { 343 344 panic("dead_badop called"); 345 /* NOTREACHED */ 346 } 347 348 /* 349 * Empty vnode null operation 350 */ 351 int 352 dead_nullop() 353 { 354 355 return (0); 356 } 357 358 /* 359 * We have to wait during times when the vnode is 360 * in a state of change. 361 */ 362 int 363 chkvnlock(vp) 364 register struct vnode *vp; 365 { 366 int locked = 0; 367 368 while (vp->v_flag & VXLOCK) { 369 vp->v_flag |= VXWANT; 370 (void) tsleep((caddr_t)vp, PINOD, "ckvnlk", 0); 371 locked = 1; 372 } 373 return (locked); 374 } 375