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 * $FreeBSD$ 35 */ 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/lock.h> 41 #include <sys/vnode.h> 42 #include <sys/buf.h> 43 #include <sys/poll.h> 44 45 static int chkvnlock __P((struct vnode *)); 46 /* 47 * Prototypes for dead operations on vnodes. 48 */ 49 static int dead_badop __P((void)); 50 static int dead_bmap __P((struct vop_bmap_args *)); 51 static int dead_ioctl __P((struct vop_ioctl_args *)); 52 static int dead_lock __P((struct vop_lock_args *)); 53 static int dead_lookup __P((struct vop_lookup_args *)); 54 static int dead_open __P((struct vop_open_args *)); 55 static int dead_poll __P((struct vop_poll_args *)); 56 static int dead_print __P((struct vop_print_args *)); 57 static int dead_read __P((struct vop_read_args *)); 58 static int dead_write __P((struct vop_write_args *)); 59 60 vop_t **dead_vnodeop_p; 61 static struct vnodeopv_entry_desc dead_vnodeop_entries[] = { 62 { &vop_default_desc, (vop_t *) vop_defaultop }, 63 { &vop_access_desc, (vop_t *) vop_ebadf }, 64 { &vop_advlock_desc, (vop_t *) vop_ebadf }, 65 { &vop_bmap_desc, (vop_t *) dead_bmap }, 66 { &vop_create_desc, (vop_t *) dead_badop }, 67 { &vop_getattr_desc, (vop_t *) vop_ebadf }, 68 { &vop_inactive_desc, (vop_t *) vop_null }, 69 { &vop_ioctl_desc, (vop_t *) dead_ioctl }, 70 { &vop_link_desc, (vop_t *) dead_badop }, 71 { &vop_lock_desc, (vop_t *) dead_lock }, 72 { &vop_lookup_desc, (vop_t *) dead_lookup }, 73 { &vop_mkdir_desc, (vop_t *) dead_badop }, 74 { &vop_mknod_desc, (vop_t *) dead_badop }, 75 { &vop_mmap_desc, (vop_t *) dead_badop }, 76 { &vop_open_desc, (vop_t *) dead_open }, 77 { &vop_pathconf_desc, (vop_t *) vop_ebadf }, /* per pathconf(2) */ 78 { &vop_poll_desc, (vop_t *) dead_poll }, 79 { &vop_print_desc, (vop_t *) dead_print }, 80 { &vop_read_desc, (vop_t *) dead_read }, 81 { &vop_readdir_desc, (vop_t *) vop_ebadf }, 82 { &vop_readlink_desc, (vop_t *) vop_ebadf }, 83 { &vop_reclaim_desc, (vop_t *) vop_null }, 84 { &vop_remove_desc, (vop_t *) dead_badop }, 85 { &vop_rename_desc, (vop_t *) dead_badop }, 86 { &vop_rmdir_desc, (vop_t *) dead_badop }, 87 { &vop_setattr_desc, (vop_t *) vop_ebadf }, 88 { &vop_symlink_desc, (vop_t *) dead_badop }, 89 { &vop_write_desc, (vop_t *) dead_write }, 90 { NULL, NULL } 91 }; 92 static struct vnodeopv_desc dead_vnodeop_opv_desc = 93 { &dead_vnodeop_p, dead_vnodeop_entries }; 94 95 VNODEOP_SET(dead_vnodeop_opv_desc); 96 97 /* 98 * Trivial lookup routine that always fails. 99 */ 100 /* ARGSUSED */ 101 static int 102 dead_lookup(ap) 103 struct vop_lookup_args /* { 104 struct vnode * a_dvp; 105 struct vnode ** a_vpp; 106 struct componentname * a_cnp; 107 } */ *ap; 108 { 109 110 *ap->a_vpp = NULL; 111 return (ENOTDIR); 112 } 113 114 /* 115 * Open always fails as if device did not exist. 116 */ 117 /* ARGSUSED */ 118 static int 119 dead_open(ap) 120 struct vop_open_args /* { 121 struct vnode *a_vp; 122 int a_mode; 123 struct ucred *a_cred; 124 struct proc *a_p; 125 } */ *ap; 126 { 127 128 return (ENXIO); 129 } 130 131 /* 132 * Vnode op for read 133 */ 134 /* ARGSUSED */ 135 static int 136 dead_read(ap) 137 struct vop_read_args /* { 138 struct vnode *a_vp; 139 struct uio *a_uio; 140 int a_ioflag; 141 struct ucred *a_cred; 142 } */ *ap; 143 { 144 145 if (chkvnlock(ap->a_vp)) 146 panic("dead_read: lock"); 147 /* 148 * Return EOF for tty devices, EIO for others 149 */ 150 if ((ap->a_vp->v_flag & VISTTY) == 0) 151 return (EIO); 152 return (0); 153 } 154 155 /* 156 * Vnode op for write 157 */ 158 /* ARGSUSED */ 159 static int 160 dead_write(ap) 161 struct vop_write_args /* { 162 struct vnode *a_vp; 163 struct uio *a_uio; 164 int a_ioflag; 165 struct ucred *a_cred; 166 } */ *ap; 167 { 168 169 if (chkvnlock(ap->a_vp)) 170 panic("dead_write: lock"); 171 return (EIO); 172 } 173 174 /* 175 * Device ioctl operation. 176 */ 177 /* ARGSUSED */ 178 static int 179 dead_ioctl(ap) 180 struct vop_ioctl_args /* { 181 struct vnode *a_vp; 182 int a_command; 183 caddr_t a_data; 184 int a_fflag; 185 struct ucred *a_cred; 186 struct proc *a_p; 187 } */ *ap; 188 { 189 190 if (!chkvnlock(ap->a_vp)) 191 return (ENOTTY); 192 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap)); 193 } 194 195 196 /* 197 * Wait until the vnode has finished changing state. 198 */ 199 static int 200 dead_lock(ap) 201 struct vop_lock_args /* { 202 struct vnode *a_vp; 203 int a_flags; 204 struct proc *a_p; 205 } */ *ap; 206 { 207 struct vnode *vp = ap->a_vp; 208 209 /* 210 * Since we are not using the lock manager, we must clear 211 * the interlock here. 212 */ 213 if (ap->a_flags & LK_INTERLOCK) { 214 simple_unlock(&vp->v_interlock); 215 ap->a_flags &= ~LK_INTERLOCK; 216 } 217 if (!chkvnlock(vp)) 218 return (0); 219 return (VCALL(vp, VOFFSET(vop_lock), ap)); 220 } 221 222 /* 223 * Wait until the vnode has finished changing state. 224 */ 225 static int 226 dead_bmap(ap) 227 struct vop_bmap_args /* { 228 struct vnode *a_vp; 229 daddr_t a_bn; 230 struct vnode **a_vpp; 231 daddr_t *a_bnp; 232 int *a_runp; 233 int *a_runb; 234 } */ *ap; 235 { 236 237 if (!chkvnlock(ap->a_vp)) 238 return (EIO); 239 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp, ap->a_runb)); 240 } 241 242 /* 243 * Print out the contents of a dead vnode. 244 */ 245 /* ARGSUSED */ 246 static int 247 dead_print(ap) 248 struct vop_print_args /* { 249 struct vnode *a_vp; 250 } */ *ap; 251 { 252 253 printf("tag VT_NON, dead vnode\n"); 254 return (0); 255 } 256 257 /* 258 * Empty vnode bad operation 259 */ 260 static int 261 dead_badop() 262 { 263 264 panic("dead_badop called"); 265 /* NOTREACHED */ 266 } 267 268 /* 269 * We have to wait during times when the vnode is 270 * in a state of change. 271 */ 272 int 273 chkvnlock(vp) 274 register struct vnode *vp; 275 { 276 int locked = 0; 277 278 while (vp->v_flag & VXLOCK) { 279 vp->v_flag |= VXWANT; 280 (void) tsleep((caddr_t)vp, PINOD, "ckvnlk", 0); 281 locked = 1; 282 } 283 return (locked); 284 } 285 286 /* 287 * Trivial poll routine that always returns POLLHUP. 288 * This is necessary so that a process which is polling a file 289 * gets notified when that file is revoke()d. 290 */ 291 static int 292 dead_poll(ap) 293 struct vop_poll_args *ap; 294 { 295 return (POLLHUP); 296 } 297