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