xref: /dragonfly/sys/vfs/deadfs/dead_vnops.c (revision f746689a)
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: src/sys/miscfs/deadfs/dead_vnops.c,v 1.26 1999/08/28 00:46:42 peter Exp $
35  * $DragonFly: src/sys/vfs/deadfs/dead_vnops.c,v 1.20 2007/08/13 17:31:56 dillon Exp $
36  */
37 
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/lock.h>
42 #include <sys/vnode.h>
43 #include <sys/fcntl.h>
44 #include <sys/buf.h>
45 #include <sys/poll.h>
46 
47 /*
48  * Prototypes for dead operations on vnodes.
49  */
50 static int	dead_badop (void);
51 static int	dead_bmap (struct vop_bmap_args *);
52 static int	dead_ioctl (struct vop_ioctl_args *);
53 static int	dead_lookup (struct vop_old_lookup_args *);
54 static int	dead_open (struct vop_open_args *);
55 static int	dead_close (struct vop_close_args *);
56 static int	dead_poll (struct vop_poll_args *);
57 static int	dead_print (struct vop_print_args *);
58 static int	dead_read (struct vop_read_args *);
59 static int	dead_write (struct vop_write_args *);
60 
61 struct vop_ops dead_vnode_vops = {
62 	.vop_default =		vop_defaultop,
63 	.vop_access =		(void *)vop_ebadf,
64 	.vop_advlock =		(void *)vop_ebadf,
65 	.vop_bmap =		dead_bmap,
66 	.vop_old_create =	(void *)dead_badop,
67 	.vop_getattr =		(void *)vop_ebadf,
68 	.vop_inactive =		(void *)vop_null,
69 	.vop_ioctl =		dead_ioctl,
70 	.vop_old_link =		(void *)dead_badop,
71 	.vop_old_lookup =	dead_lookup,
72 	.vop_old_mkdir =	(void *)dead_badop,
73 	.vop_old_mknod =	(void *)dead_badop,
74 	.vop_mmap =		(void *)dead_badop,
75 	.vop_open =		dead_open,
76 	.vop_close =		dead_close,
77 	.vop_pathconf =		(void *)vop_ebadf,	/* per pathconf(2) */
78 	.vop_poll =		dead_poll,
79 	.vop_print =		dead_print,
80 	.vop_read =		dead_read,
81 	.vop_readdir =		(void *)vop_ebadf,
82 	.vop_readlink =		(void *)vop_ebadf,
83 	.vop_reclaim =		(void *)vop_null,
84 	.vop_old_remove =	(void *)dead_badop,
85 	.vop_old_rename =	(void *)dead_badop,
86 	.vop_old_rmdir =	(void *)dead_badop,
87 	.vop_setattr =		(void *)vop_ebadf,
88 	.vop_old_symlink =	(void *)dead_badop,
89 	.vop_write =		dead_write
90 };
91 
92 struct vop_ops *dead_vnode_vops_p = &dead_vnode_vops;
93 
94 VNODEOP_SET(dead_vnode_vops);
95 
96 /*
97  * Trivial lookup routine that always fails.
98  *
99  * dead_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
100  *	       struct componentname *a_cnp)
101  */
102 /* ARGSUSED */
103 static int
104 dead_lookup(struct vop_old_lookup_args *ap)
105 {
106 	*ap->a_vpp = NULL;
107 	return (ENOTDIR);
108 }
109 
110 /*
111  * Open always fails as if device did not exist.
112  *
113  * dead_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
114  *	     struct proc *a_p)
115  */
116 /* ARGSUSED */
117 static int
118 dead_open(struct vop_open_args *ap)
119 {
120 	return (ENXIO);
121 }
122 
123 /*
124  * Close always succeeds, and does not warn or panic if v_opencount or
125  * v_writecount is incorrect, because a forced unmount or revocation
126  * might have closed the file out from under the descriptor.
127  */
128 static int
129 dead_close(struct vop_close_args *ap)
130 {
131 	struct vnode *vp = ap->a_vp;
132 
133 	if (vp->v_opencount > 0) {
134 		if ((ap->a_fflag & FWRITE) && vp->v_writecount > 0)
135 			--vp->v_writecount;
136 		--vp->v_opencount;
137 	}
138 	return (0);
139 }
140 
141 /*
142  * Vnode op for read
143  *
144  * dead_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
145  *	     struct ucred *a_cred)
146  */
147 /* ARGSUSED */
148 static int
149 dead_read(struct vop_read_args *ap)
150 {
151 	/*
152 	 * Return EOF for tty devices, EIO for others
153 	 */
154 	if ((ap->a_vp->v_flag & VISTTY) == 0)
155 		return (EIO);
156 	return (0);
157 }
158 
159 /*
160  * Vnode op for write
161  *
162  * dead_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
163  *	      struct ucred *a_cred)
164  */
165 /* ARGSUSED */
166 static int
167 dead_write(struct vop_write_args *ap)
168 {
169 	return (EIO);
170 }
171 
172 /*
173  * Device ioctl operation.
174  *
175  * dead_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data, int a_fflag,
176  *	      struct ucred *a_cred, struct proc *a_p)
177  */
178 /* ARGSUSED */
179 static int
180 dead_ioctl(struct vop_ioctl_args *ap)
181 {
182 	return (ENOTTY);
183 }
184 
185 /*
186  * Wait until the vnode has finished changing state.
187  *
188  * dead_bmap(struct vnode *a_vp, off_t a_loffset,
189  *	     off_t *a_doffsetp, int *a_runp, int *a_runb)
190  */
191 static int
192 dead_bmap(struct vop_bmap_args *ap)
193 {
194 	return (EIO);
195 }
196 
197 /*
198  * Print out the contents of a dead vnode.
199  *
200  * dead_print(struct vnode *a_vp)
201  */
202 /* ARGSUSED */
203 static int
204 dead_print(struct vop_print_args *ap)
205 {
206 	kprintf("tag VT_NON, dead vnode\n");
207 	return (0);
208 }
209 
210 /*
211  * Empty vnode bad operation
212  */
213 static int
214 dead_badop(void)
215 {
216 	panic("dead_badop called");
217 	/* NOTREACHED */
218 }
219 
220 /*
221  * Trivial poll routine that always returns POLLHUP.
222  * This is necessary so that a process which is polling a file
223  * gets notified when that file is revoke()d.
224  */
225 static int
226 dead_poll(struct vop_poll_args *ap)
227 {
228 	return (POLLHUP);
229 }
230