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: releng/5.0/sys/fs/deadfs/dead_vnops.c 105212 2002-10-16 08:04:11Z phk $
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(struct vnode *);
46 /*
47 * Prototypes for dead operations on vnodes.
48 */
49 static int dead_bmap(struct vop_bmap_args *);
50 static int dead_ioctl(struct vop_ioctl_args *);
51 static int dead_lock(struct vop_lock_args *);
52 static int dead_lookup(struct vop_lookup_args *);
53 static int dead_open(struct vop_open_args *);
54 static int dead_poll(struct vop_poll_args *);
55 static int dead_read(struct vop_read_args *);
56 static int dead_write(struct vop_write_args *);
57
58 vop_t **dead_vnodeop_p;
59 static struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
60 { &vop_default_desc, (vop_t *) vop_defaultop },
61 { &vop_access_desc, (vop_t *) vop_ebadf },
62 { &vop_advlock_desc, (vop_t *) vop_ebadf },
63 { &vop_bmap_desc, (vop_t *) dead_bmap },
64 { &vop_create_desc, (vop_t *) vop_panic },
65 { &vop_getattr_desc, (vop_t *) vop_ebadf },
66 { &vop_inactive_desc, (vop_t *) vop_null },
67 { &vop_ioctl_desc, (vop_t *) dead_ioctl },
68 { &vop_link_desc, (vop_t *) vop_panic },
69 { &vop_lock_desc, (vop_t *) dead_lock },
70 { &vop_lookup_desc, (vop_t *) dead_lookup },
71 { &vop_mkdir_desc, (vop_t *) vop_panic },
72 { &vop_mknod_desc, (vop_t *) vop_panic },
73 { &vop_open_desc, (vop_t *) dead_open },
74 { &vop_pathconf_desc, (vop_t *) vop_ebadf }, /* per pathconf(2) */
75 { &vop_poll_desc, (vop_t *) dead_poll },
76 { &vop_print_desc, (vop_t *) vop_null },
77 { &vop_read_desc, (vop_t *) dead_read },
78 { &vop_readdir_desc, (vop_t *) vop_ebadf },
79 { &vop_readlink_desc, (vop_t *) vop_ebadf },
80 { &vop_reclaim_desc, (vop_t *) vop_null },
81 { &vop_remove_desc, (vop_t *) vop_panic },
82 { &vop_rename_desc, (vop_t *) vop_panic },
83 { &vop_rmdir_desc, (vop_t *) vop_panic },
84 { &vop_setattr_desc, (vop_t *) vop_ebadf },
85 { &vop_symlink_desc, (vop_t *) vop_panic },
86 { &vop_write_desc, (vop_t *) dead_write },
87 { NULL, NULL }
88 };
89 static struct vnodeopv_desc dead_vnodeop_opv_desc =
90 { &dead_vnodeop_p, dead_vnodeop_entries };
91
92 VNODEOP_SET(dead_vnodeop_opv_desc);
93
94 /*
95 * Trivial lookup routine that always fails.
96 */
97 /* ARGSUSED */
98 static int
99 dead_lookup(ap)
100 struct vop_lookup_args /* {
101 struct vnode * a_dvp;
102 struct vnode ** a_vpp;
103 struct componentname * a_cnp;
104 } */ *ap;
105 {
106
107 *ap->a_vpp = NULL;
108 return (ENOTDIR);
109 }
110
111 /*
112 * Open always fails as if device did not exist.
113 */
114 /* ARGSUSED */
115 static int
116 dead_open(ap)
117 struct vop_open_args /* {
118 struct vnode *a_vp;
119 int a_mode;
120 struct ucred *a_cred;
121 struct proc *a_p;
122 } */ *ap;
123 {
124
125 return (ENXIO);
126 }
127
128 /*
129 * Vnode op for read
130 */
131 /* ARGSUSED */
132 static int
133 dead_read(ap)
134 struct vop_read_args /* {
135 struct vnode *a_vp;
136 struct uio *a_uio;
137 int a_ioflag;
138 struct ucred *a_cred;
139 } */ *ap;
140 {
141
142 if (chkvnlock(ap->a_vp))
143 panic("dead_read: lock");
144 /*
145 * Return EOF for tty devices, EIO for others
146 */
147 if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
148 return (EIO);
149 return (0);
150 }
151
152 /*
153 * Vnode op for write
154 */
155 /* ARGSUSED */
156 static int
157 dead_write(ap)
158 struct vop_write_args /* {
159 struct vnode *a_vp;
160 struct uio *a_uio;
161 int a_ioflag;
162 struct ucred *a_cred;
163 } */ *ap;
164 {
165
166 if (chkvnlock(ap->a_vp))
167 panic("dead_write: lock");
168 return (EIO);
169 }
170
171 /*
172 * Device ioctl operation.
173 */
174 /* ARGSUSED */
175 static int
176 dead_ioctl(ap)
177 struct vop_ioctl_args /* {
178 struct vnode *a_vp;
179 u_long a_command;
180 caddr_t a_data;
181 int a_fflag;
182 struct ucred *a_cred;
183 struct proc *a_p;
184 } */ *ap;
185 {
186
187 if (!chkvnlock(ap->a_vp))
188 return (ENOTTY);
189 /* XXX: Doesn't this just recurse back here ? */
190 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
191 }
192
193
194 /*
195 * Wait until the vnode has finished changing state.
196 */
197 static int
198 dead_lock(ap)
199 struct vop_lock_args /* {
200 struct vnode *a_vp;
201 int a_flags;
202 struct proc *a_p;
203 } */ *ap;
204 {
205 struct vnode *vp = ap->a_vp;
206
207 /*
208 * Since we are not using the lock manager, we must clear
209 * the interlock here.
210 */
211 if (ap->a_flags & LK_INTERLOCK) {
212 mtx_unlock(&vp->v_interlock);
213 ap->a_flags &= ~LK_INTERLOCK;
214 }
215 if (!chkvnlock(vp))
216 return (0);
217 return (VCALL(vp, VOFFSET(vop_lock), ap));
218 }
219
220 /*
221 * Wait until the vnode has finished changing state.
222 */
223 static int
224 dead_bmap(ap)
225 struct vop_bmap_args /* {
226 struct vnode *a_vp;
227 daddr_t a_bn;
228 struct vnode **a_vpp;
229 daddr_t *a_bnp;
230 int *a_runp;
231 int *a_runb;
232 } */ *ap;
233 {
234
235 if (!chkvnlock(ap->a_vp))
236 return (EIO);
237 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp, ap->a_runb));
238 }
239
240 /*
241 * We have to wait during times when the vnode is
242 * in a state of change.
243 */
244 static int
245 chkvnlock(vp)
246 register struct vnode *vp;
247 {
248 int locked = 0;
249
250 VI_LOCK(vp);
251 while (vp->v_iflag & VI_XLOCK) {
252 vp->v_iflag |= VI_XWANT;
253 (void) msleep((caddr_t)vp, VI_MTX(vp), PINOD, "ckvnlk", 0);
254 locked = 1;
255 }
256 VI_UNLOCK(vp);
257 return (locked);
258 }
259
260 /*
261 * Trivial poll routine that always returns POLLHUP.
262 * This is necessary so that a process which is polling a file
263 * gets notified when that file is revoke()d.
264 */
265 static int
266 dead_poll(ap)
267 struct vop_poll_args *ap;
268 {
269 return (POLLHUP);
270 }
Cache object: 4b991f2d383d91ae8854cf1c5a4cb8a5
|