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. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)dead_vnops.c 8.1 (Berkeley) 6/10/93 30 * $FreeBSD: src/sys/miscfs/deadfs/dead_vnops.c,v 1.26 1999/08/28 00:46:42 peter Exp $ 31 * $DragonFly: src/sys/vfs/deadfs/dead_vnops.c,v 1.20 2007/08/13 17:31:56 dillon Exp $ 32 */ 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/kernel.h> 37 #include <sys/lock.h> 38 #include <sys/vnode.h> 39 #include <sys/fcntl.h> 40 #include <sys/buf.h> 41 42 /* 43 * Prototypes for dead operations on vnodes. 44 */ 45 static int dead_badop (void); 46 static int dead_bmap (struct vop_bmap_args *); 47 static int dead_ioctl (struct vop_ioctl_args *); 48 static int dead_lookup (struct vop_old_lookup_args *); 49 static int dead_open (struct vop_open_args *); 50 static int dead_close (struct vop_close_args *); 51 static int dead_print (struct vop_print_args *); 52 static int dead_read (struct vop_read_args *); 53 static int dead_write (struct vop_write_args *); 54 55 struct vop_ops dead_vnode_vops = { 56 .vop_default = vop_defaultop, 57 .vop_access = (void *)vop_ebadf, 58 .vop_advlock = (void *)vop_ebadf, 59 .vop_bmap = dead_bmap, 60 .vop_old_create = (void *)dead_badop, 61 .vop_getattr = (void *)vop_ebadf, 62 .vop_inactive = (void *)vop_null, 63 .vop_ioctl = dead_ioctl, 64 .vop_old_link = (void *)dead_badop, 65 .vop_old_lookup = dead_lookup, 66 .vop_old_mkdir = (void *)dead_badop, 67 .vop_old_mknod = (void *)dead_badop, 68 .vop_mmap = (void *)dead_badop, 69 .vop_open = dead_open, 70 .vop_close = dead_close, 71 .vop_pathconf = (void *)vop_ebadf, /* per pathconf(2) */ 72 .vop_print = dead_print, 73 .vop_read = dead_read, 74 .vop_readdir = (void *)vop_ebadf, 75 .vop_readlink = (void *)vop_ebadf, 76 .vop_reclaim = (void *)vop_null, 77 .vop_old_remove = (void *)dead_badop, 78 .vop_old_rename = (void *)dead_badop, 79 .vop_old_rmdir = (void *)dead_badop, 80 .vop_setattr = (void *)vop_ebadf, 81 .vop_old_symlink = (void *)dead_badop, 82 .vop_write = dead_write 83 }; 84 85 struct vop_ops *dead_vnode_vops_p = &dead_vnode_vops; 86 87 VNODEOP_SET(dead_vnode_vops); 88 89 /* 90 * Trivial lookup routine that always fails. 91 * 92 * dead_lookup(struct vnode *a_dvp, struct vnode **a_vpp, 93 * struct componentname *a_cnp) 94 */ 95 /* ARGSUSED */ 96 static int 97 dead_lookup(struct vop_old_lookup_args *ap) 98 { 99 *ap->a_vpp = NULL; 100 return (ENOTDIR); 101 } 102 103 /* 104 * Open always fails as if device did not exist. 105 * 106 * dead_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred, 107 * struct proc *a_p) 108 */ 109 /* ARGSUSED */ 110 static int 111 dead_open(struct vop_open_args *ap) 112 { 113 return (ENXIO); 114 } 115 116 /* 117 * Close always succeeds, and does not warn or panic if v_opencount or 118 * v_writecount is incorrect, because a forced unmount or revocation 119 * might have closed the file out from under the descriptor. 120 */ 121 static int 122 dead_close(struct vop_close_args *ap) 123 { 124 struct vnode *vp = ap->a_vp; 125 126 vn_lock(vp, LK_UPGRADE | LK_RETRY); /* safety */ 127 if (vp->v_opencount > 0) { 128 if ((ap->a_fflag & FWRITE) && vp->v_writecount > 0) 129 atomic_add_int(&vp->v_writecount, -1); 130 atomic_add_int(&vp->v_opencount, -1); 131 } 132 return (0); 133 } 134 135 /* 136 * Vnode op for read 137 * 138 * dead_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag, 139 * struct ucred *a_cred) 140 */ 141 /* ARGSUSED */ 142 static int 143 dead_read(struct vop_read_args *ap) 144 { 145 /* 146 * Return EOF for tty devices, EIO for others 147 */ 148 if ((ap->a_vp->v_flag & VISTTY) == 0) 149 return (EIO); 150 return (0); 151 } 152 153 /* 154 * Vnode op for write 155 * 156 * dead_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag, 157 * struct ucred *a_cred) 158 */ 159 /* ARGSUSED */ 160 static int 161 dead_write(struct vop_write_args *ap) 162 { 163 return (EIO); 164 } 165 166 /* 167 * Device ioctl operation. 168 * 169 * dead_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data, int a_fflag, 170 * struct ucred *a_cred, struct proc *a_p) 171 */ 172 /* ARGSUSED */ 173 static int 174 dead_ioctl(struct vop_ioctl_args *ap) 175 { 176 return (ENOTTY); 177 } 178 179 /* 180 * Wait until the vnode has finished changing state. 181 * 182 * dead_bmap(struct vnode *a_vp, off_t a_loffset, 183 * off_t *a_doffsetp, int *a_runp, int *a_runb) 184 */ 185 static int 186 dead_bmap(struct vop_bmap_args *ap) 187 { 188 return (EIO); 189 } 190 191 /* 192 * Print out the contents of a dead vnode. 193 * 194 * dead_print(struct vnode *a_vp) 195 */ 196 /* ARGSUSED */ 197 static int 198 dead_print(struct vop_print_args *ap) 199 { 200 kprintf("tag VT_NON, dead vnode\n"); 201 return (0); 202 } 203 204 /* 205 * Empty vnode bad operation 206 */ 207 static int 208 dead_badop(void) 209 { 210 panic("dead_badop called"); 211 /* NOTREACHED */ 212 } 213