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