1 /* 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)dead_vnops.c 7.14 (Berkeley) 11/05/91 8 */ 9 10 #include "param.h" 11 #include "systm.h" 12 #include "time.h" 13 #include "vnode.h" 14 #include "errno.h" 15 #include "namei.h" 16 #include "buf.h" 17 18 /* 19 * Prototypes for dead operations on vnodes. 20 */ 21 int dead_badop(), 22 dead_ebadf(); 23 int dead_lookup __P(( 24 struct vnode *vp, 25 struct nameidata *ndp, 26 struct proc *p)); 27 #define dead_create ((int (*) __P(( \ 28 struct nameidata *ndp, \ 29 struct vattr *vap, \ 30 struct proc *p))) dead_badop) 31 #define dead_mknod ((int (*) __P(( \ 32 struct nameidata *ndp, \ 33 struct vattr *vap, \ 34 struct ucred *cred, \ 35 struct proc *p))) dead_badop) 36 int dead_open __P(( 37 struct vnode *vp, 38 int mode, 39 struct ucred *cred, 40 struct proc *p)); 41 #define dead_close ((int (*) __P(( \ 42 struct vnode *vp, \ 43 int fflag, \ 44 struct ucred *cred, \ 45 struct proc *p))) nullop) 46 #define dead_access ((int (*) __P(( \ 47 struct vnode *vp, \ 48 int mode, \ 49 struct ucred *cred, \ 50 struct proc *p))) dead_ebadf) 51 #define dead_getattr ((int (*) __P(( \ 52 struct vnode *vp, \ 53 struct vattr *vap, \ 54 struct ucred *cred, \ 55 struct proc *p))) dead_ebadf) 56 #define dead_setattr ((int (*) __P(( \ 57 struct vnode *vp, \ 58 struct vattr *vap, \ 59 struct ucred *cred, \ 60 struct proc *p))) dead_ebadf) 61 int dead_read __P(( 62 struct vnode *vp, 63 struct uio *uio, 64 int ioflag, 65 struct ucred *cred)); 66 int dead_write __P(( 67 struct vnode *vp, 68 struct uio *uio, 69 int ioflag, 70 struct ucred *cred)); 71 int dead_ioctl __P(( 72 struct vnode *vp, 73 int command, 74 caddr_t data, 75 int fflag, 76 struct ucred *cred, 77 struct proc *p)); 78 int dead_select __P(( 79 struct vnode *vp, 80 int which, 81 int fflags, 82 struct ucred *cred, 83 struct proc *p)); 84 #define dead_mmap ((int (*) __P(( \ 85 struct vnode *vp, \ 86 int fflags, \ 87 struct ucred *cred, \ 88 struct proc *p))) dead_badop) 89 #define dead_fsync ((int (*) __P(( \ 90 struct vnode *vp, \ 91 int fflags, \ 92 struct ucred *cred, \ 93 int waitfor, \ 94 struct proc *p))) nullop) 95 #define dead_seek ((int (*) __P(( \ 96 struct vnode *vp, \ 97 off_t oldoff, \ 98 off_t newoff, \ 99 struct ucred *cred))) nullop) 100 #define dead_remove ((int (*) __P(( \ 101 struct nameidata *ndp, \ 102 struct proc *p))) dead_badop) 103 #define dead_link ((int (*) __P(( \ 104 struct vnode *vp, \ 105 struct nameidata *ndp, \ 106 struct proc *p))) dead_badop) 107 #define dead_rename ((int (*) __P(( \ 108 struct nameidata *fndp, \ 109 struct nameidata *tdnp, \ 110 struct proc *p))) dead_badop) 111 #define dead_mkdir ((int (*) __P(( \ 112 struct nameidata *ndp, \ 113 struct vattr *vap, \ 114 struct proc *p))) dead_badop) 115 #define dead_rmdir ((int (*) __P(( \ 116 struct nameidata *ndp, \ 117 struct proc *p))) dead_badop) 118 #define dead_symlink ((int (*) __P(( \ 119 struct nameidata *ndp, \ 120 struct vattr *vap, \ 121 char *target, \ 122 struct proc *p))) dead_badop) 123 #define dead_readdir ((int (*) __P(( \ 124 struct vnode *vp, \ 125 struct uio *uio, \ 126 struct ucred *cred, \ 127 int *eofflagp))) dead_ebadf) 128 #define dead_readlink ((int (*) __P(( \ 129 struct vnode *vp, \ 130 struct uio *uio, \ 131 struct ucred *cred))) dead_ebadf) 132 #define dead_abortop ((int (*) __P(( \ 133 struct nameidata *ndp))) dead_badop) 134 #define dead_inactive ((int (*) __P(( \ 135 struct vnode *vp, \ 136 struct proc *p))) nullop) 137 #define dead_reclaim ((int (*) __P(( \ 138 struct vnode *vp))) nullop) 139 int dead_lock __P(( 140 struct vnode *vp)); 141 #define dead_unlock ((int (*) __P(( \ 142 struct vnode *vp))) nullop) 143 int dead_bmap __P(( 144 struct vnode *vp, 145 daddr_t bn, 146 struct vnode **vpp, 147 daddr_t *bnp)); 148 int dead_strategy __P(( 149 struct buf *bp)); 150 int dead_print __P(( 151 struct vnode *vp)); 152 #define dead_islocked ((int (*) __P(( \ 153 struct vnode *vp))) nullop) 154 #define dead_advlock ((int (*) __P(( \ 155 struct vnode *vp, \ 156 caddr_t id, \ 157 int op, \ 158 struct flock *fl, \ 159 int flags))) dead_ebadf) 160 #define dead_blkatoff ((int (*) __P(( \ 161 struct vnode *vp, \ 162 off_t offset, \ 163 char **res, \ 164 struct buf **bpp))) dead_badop) 165 #define dead_vget ((int (*) __P(( \ 166 struct mount *mp, \ 167 ino_t ino, \ 168 struct vnode **vpp))) dead_badop) 169 #define dead_valloc ((int (*) __P(( \ 170 struct vnode *pvp, \ 171 int mode, \ 172 struct ucred *cred, \ 173 struct vnode **vpp))) dead_badop) 174 #define dead_vfree ((void (*) __P(( \ 175 struct vnode *pvp, \ 176 ino_t ino, \ 177 int mode))) dead_badop) 178 #define dead_truncate ((int (*) __P(( \ 179 struct vnode *vp, \ 180 u_long length, \ 181 int flags))) nullop) 182 #define dead_update ((int (*) __P(( \ 183 struct vnode *vp, \ 184 struct timeval *ta, \ 185 struct timeval *tm, \ 186 int waitfor))) nullop) 187 #define dead_bwrite ((int (*) __P(( \ 188 struct buf *bp))) nullop) 189 190 struct vnodeops dead_vnodeops = { 191 dead_lookup, /* lookup */ 192 dead_create, /* create */ 193 dead_mknod, /* mknod */ 194 dead_open, /* open */ 195 dead_close, /* close */ 196 dead_access, /* access */ 197 dead_getattr, /* getattr */ 198 dead_setattr, /* setattr */ 199 dead_read, /* read */ 200 dead_write, /* write */ 201 dead_ioctl, /* ioctl */ 202 dead_select, /* select */ 203 dead_mmap, /* mmap */ 204 dead_fsync, /* fsync */ 205 dead_seek, /* seek */ 206 dead_remove, /* remove */ 207 dead_link, /* link */ 208 dead_rename, /* rename */ 209 dead_mkdir, /* mkdir */ 210 dead_rmdir, /* rmdir */ 211 dead_symlink, /* symlink */ 212 dead_readdir, /* readdir */ 213 dead_readlink, /* readlink */ 214 dead_abortop, /* abortop */ 215 dead_inactive, /* inactive */ 216 dead_reclaim, /* reclaim */ 217 dead_lock, /* lock */ 218 dead_unlock, /* unlock */ 219 dead_bmap, /* bmap */ 220 dead_strategy, /* strategy */ 221 dead_print, /* print */ 222 dead_islocked, /* islocked */ 223 dead_advlock, /* advlock */ 224 dead_blkatoff, /* blkatoff */ 225 dead_vget, /* vget */ 226 dead_valloc, /* valloc */ 227 dead_vfree, /* vfree */ 228 dead_truncate, /* truncate */ 229 dead_update, /* update */ 230 dead_bwrite, /* bwrite */ 231 }; 232 233 /* 234 * Trivial lookup routine that always fails. 235 */ 236 /* ARGSUSED */ 237 dead_lookup(vp, ndp, p) 238 struct vnode *vp; 239 struct nameidata *ndp; 240 struct proc *p; 241 { 242 243 ndp->ni_dvp = vp; 244 ndp->ni_vp = NULL; 245 return (ENOTDIR); 246 } 247 248 /* 249 * Open always fails as if device did not exist. 250 */ 251 /* ARGSUSED */ 252 dead_open(vp, mode, cred, p) 253 struct vnode *vp; 254 int mode; 255 struct ucred *cred; 256 struct proc *p; 257 { 258 259 return (ENXIO); 260 } 261 262 /* 263 * Vnode op for read 264 */ 265 /* ARGSUSED */ 266 dead_read(vp, uio, ioflag, cred) 267 struct vnode *vp; 268 struct uio *uio; 269 int ioflag; 270 struct ucred *cred; 271 { 272 273 if (chkvnlock(vp)) 274 panic("dead_read: lock"); 275 /* 276 * Return EOF for character devices, EIO for others 277 */ 278 if (vp->v_type != VCHR) 279 return (EIO); 280 return (0); 281 } 282 283 /* 284 * Vnode op for write 285 */ 286 /* ARGSUSED */ 287 dead_write(vp, uio, ioflag, cred) 288 register struct vnode *vp; 289 struct uio *uio; 290 int ioflag; 291 struct ucred *cred; 292 { 293 294 if (chkvnlock(vp)) 295 panic("dead_write: lock"); 296 return (EIO); 297 } 298 299 /* 300 * Device ioctl operation. 301 */ 302 /* ARGSUSED */ 303 dead_ioctl(vp, com, data, fflag, cred, p) 304 struct vnode *vp; 305 register int com; 306 caddr_t data; 307 int fflag; 308 struct ucred *cred; 309 struct proc *p; 310 { 311 312 if (!chkvnlock(vp)) 313 return (EBADF); 314 return (VOP_IOCTL(vp, com, data, fflag, cred, p)); 315 } 316 317 /* ARGSUSED */ 318 dead_select(vp, which, fflags, cred, p) 319 struct vnode *vp; 320 int which, fflags; 321 struct ucred *cred; 322 struct proc *p; 323 { 324 325 /* 326 * Let the user find out that the descriptor is gone. 327 */ 328 return (1); 329 } 330 331 /* 332 * Just call the device strategy routine 333 */ 334 dead_strategy(bp) 335 register struct buf *bp; 336 { 337 338 if (bp->b_vp == NULL || !chkvnlock(bp->b_vp)) { 339 bp->b_flags |= B_ERROR; 340 biodone(bp); 341 return (EIO); 342 } 343 return (VOP_STRATEGY(bp)); 344 } 345 346 /* 347 * Wait until the vnode has finished changing state. 348 */ 349 dead_lock(vp) 350 struct vnode *vp; 351 { 352 353 if (!chkvnlock(vp)) 354 return (0); 355 return (VOP_LOCK(vp)); 356 } 357 358 /* 359 * Wait until the vnode has finished changing state. 360 */ 361 dead_bmap(vp, bn, vpp, bnp) 362 struct vnode *vp; 363 daddr_t bn; 364 struct vnode **vpp; 365 daddr_t *bnp; 366 { 367 368 if (!chkvnlock(vp)) 369 return (EIO); 370 return (VOP_BMAP(vp, bn, vpp, bnp)); 371 } 372 373 /* 374 * Print out the contents of a dead vnode. 375 */ 376 /* ARGSUSED */ 377 dead_print(vp) 378 struct vnode *vp; 379 { 380 381 printf("tag VT_NON, dead vnode\n"); 382 } 383 384 /* 385 * Empty vnode failed operation 386 */ 387 dead_ebadf() 388 { 389 390 return (EBADF); 391 } 392 393 /* 394 * Empty vnode bad operation 395 */ 396 dead_badop() 397 { 398 399 panic("dead_badop called"); 400 /* NOTREACHED */ 401 } 402 403 /* 404 * Empty vnode null operation 405 */ 406 dead_nullop() 407 { 408 409 return (0); 410 } 411 412 /* 413 * We have to wait during times when the vnode is 414 * in a state of change. 415 */ 416 chkvnlock(vp) 417 register struct vnode *vp; 418 { 419 int locked = 0; 420 421 while (vp->v_flag & VXLOCK) { 422 vp->v_flag |= VXWANT; 423 sleep((caddr_t)vp, PINOD); 424 locked = 1; 425 } 426 return (locked); 427 } 428