dead_vnops.c revision 1.14 1 /* $NetBSD: dead_vnops.c,v 1.14 1996/02/09 22:39:56 christos Exp $ */
2
3 /*
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)dead_vnops.c 8.2 (Berkeley) 11/21/94
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/time.h>
41 #include <sys/vnode.h>
42 #include <sys/errno.h>
43 #include <sys/namei.h>
44 #include <sys/buf.h>
45 #include <sys/proc.h>
46
47 /*
48 * Prototypes for dead operations on vnodes.
49 */
50 int dead_badop __P((void *));
51 int dead_ebadf __P((void *));
52 int dead_nullop __P((void *));
53 int dead_lookup __P((void *));
54 #define dead_create dead_badop
55 #define dead_mknod dead_badop
56 int dead_open __P((void *));
57 #define dead_close nullop
58 #define dead_access dead_ebadf
59 #define dead_getattr dead_ebadf
60 #define dead_setattr dead_ebadf
61 int dead_read __P((void *));
62 int dead_write __P((void *));
63 int dead_ioctl __P((void *));
64 int dead_select __P((void *));
65 #define dead_mmap dead_badop
66 #define dead_fsync nullop
67 #define dead_seek nullop
68 #define dead_remove dead_badop
69 #define dead_link dead_badop
70 #define dead_rename dead_badop
71 #define dead_mkdir dead_badop
72 #define dead_rmdir dead_badop
73 #define dead_symlink dead_badop
74 #define dead_readdir dead_ebadf
75 #define dead_readlink dead_ebadf
76 #define dead_abortop dead_badop
77 #define dead_inactive nullop
78 #define dead_reclaim nullop
79 int dead_lock __P((void *));
80 #define dead_unlock nullop
81 int dead_bmap __P((void *));
82 int dead_strategy __P((void *));
83 int dead_print __P((void *));
84 #define dead_islocked nullop
85 #define dead_pathconf dead_ebadf
86 #define dead_advlock dead_ebadf
87 #define dead_blkatoff dead_badop
88 #define dead_valloc dead_badop
89 #define dead_vfree dead_badop
90 #define dead_truncate nullop
91 #define dead_update nullop
92 #define dead_bwrite nullop
93
94 int chkvnlock __P((struct vnode *));
95
96 int (**dead_vnodeop_p) __P((void *));
97
98 struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
99 { &vop_default_desc, vn_default_error },
100 { &vop_lookup_desc, dead_lookup }, /* lookup */
101 { &vop_create_desc, dead_create }, /* create */
102 { &vop_mknod_desc, dead_mknod }, /* mknod */
103 { &vop_open_desc, dead_open }, /* open */
104 { &vop_close_desc, dead_close }, /* close */
105 { &vop_access_desc, dead_access }, /* access */
106 { &vop_getattr_desc, dead_getattr }, /* getattr */
107 { &vop_setattr_desc, dead_setattr }, /* setattr */
108 { &vop_read_desc, dead_read }, /* read */
109 { &vop_write_desc, dead_write }, /* write */
110 { &vop_ioctl_desc, dead_ioctl }, /* ioctl */
111 { &vop_select_desc, dead_select }, /* select */
112 { &vop_mmap_desc, dead_mmap }, /* mmap */
113 { &vop_fsync_desc, dead_fsync }, /* fsync */
114 { &vop_seek_desc, dead_seek }, /* seek */
115 { &vop_remove_desc, dead_remove }, /* remove */
116 { &vop_link_desc, dead_link }, /* link */
117 { &vop_rename_desc, dead_rename }, /* rename */
118 { &vop_mkdir_desc, dead_mkdir }, /* mkdir */
119 { &vop_rmdir_desc, dead_rmdir }, /* rmdir */
120 { &vop_symlink_desc, dead_symlink }, /* symlink */
121 { &vop_readdir_desc, dead_readdir }, /* readdir */
122 { &vop_readlink_desc, dead_readlink }, /* readlink */
123 { &vop_abortop_desc, dead_abortop }, /* abortop */
124 { &vop_inactive_desc, dead_inactive }, /* inactive */
125 { &vop_reclaim_desc, dead_reclaim }, /* reclaim */
126 { &vop_lock_desc, dead_lock }, /* lock */
127 { &vop_unlock_desc, dead_unlock }, /* unlock */
128 { &vop_bmap_desc, dead_bmap }, /* bmap */
129 { &vop_strategy_desc, dead_strategy }, /* strategy */
130 { &vop_print_desc, dead_print }, /* print */
131 { &vop_islocked_desc, dead_islocked }, /* islocked */
132 { &vop_pathconf_desc, dead_pathconf }, /* pathconf */
133 { &vop_advlock_desc, dead_advlock }, /* advlock */
134 { &vop_blkatoff_desc, dead_blkatoff }, /* blkatoff */
135 { &vop_valloc_desc, dead_valloc }, /* valloc */
136 { &vop_vfree_desc, dead_vfree }, /* vfree */
137 { &vop_truncate_desc, dead_truncate }, /* truncate */
138 { &vop_update_desc, dead_update }, /* update */
139 { &vop_bwrite_desc, dead_bwrite }, /* bwrite */
140 { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
141 };
142 struct vnodeopv_desc dead_vnodeop_opv_desc =
143 { &dead_vnodeop_p, dead_vnodeop_entries };
144
145 /*
146 * Trivial lookup routine that always fails.
147 */
148 /* ARGSUSED */
149 int
150 dead_lookup(v)
151 void *v;
152 {
153 struct vop_lookup_args /* {
154 struct vnode * a_dvp;
155 struct vnode ** a_vpp;
156 struct componentname * a_cnp;
157 } */ *ap = v;
158
159 *ap->a_vpp = NULL;
160 return (ENOTDIR);
161 }
162
163 /*
164 * Open always fails as if device did not exist.
165 */
166 /* ARGSUSED */
167 int
168 dead_open(v)
169 void *v;
170 {
171
172 return (ENXIO);
173 }
174
175 /*
176 * Vnode op for read
177 */
178 /* ARGSUSED */
179 int
180 dead_read(v)
181 void *v;
182 {
183 struct vop_read_args /* {
184 struct vnode *a_vp;
185 struct uio *a_uio;
186 int a_ioflag;
187 struct ucred *a_cred;
188 } */ *ap = v;
189
190 if (chkvnlock(ap->a_vp))
191 panic("dead_read: lock");
192 /*
193 * Return EOF for tty devices, EIO for others
194 */
195 if ((ap->a_vp->v_flag & VISTTY) == 0)
196 return (EIO);
197 return (0);
198 }
199
200 /*
201 * Vnode op for write
202 */
203 /* ARGSUSED */
204 int
205 dead_write(v)
206 void *v;
207 {
208 struct vop_write_args /* {
209 struct vnode *a_vp;
210 struct uio *a_uio;
211 int a_ioflag;
212 struct ucred *a_cred;
213 } */ *ap = v;
214
215 if (chkvnlock(ap->a_vp))
216 panic("dead_write: lock");
217 return (EIO);
218 }
219
220 /*
221 * Device ioctl operation.
222 */
223 /* ARGSUSED */
224 int
225 dead_ioctl(v)
226 void *v;
227 {
228 struct vop_ioctl_args /* {
229 struct vnode *a_vp;
230 u_long a_command;
231 caddr_t a_data;
232 int a_fflag;
233 struct ucred *a_cred;
234 struct proc *a_p;
235 } */ *ap = v;
236
237 if (!chkvnlock(ap->a_vp))
238 return (EBADF);
239 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
240 }
241
242 /* ARGSUSED */
243 int
244 dead_select(v)
245 void *v;
246 {
247 /*
248 * Let the user find out that the descriptor is gone.
249 */
250 return (1);
251 }
252
253 /*
254 * Just call the device strategy routine
255 */
256 int
257 dead_strategy(v)
258 void *v;
259 {
260
261 struct vop_strategy_args /* {
262 struct buf *a_bp;
263 } */ *ap = v;
264 if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) {
265 ap->a_bp->b_flags |= B_ERROR;
266 biodone(ap->a_bp);
267 return (EIO);
268 }
269 return (VOP_STRATEGY(ap->a_bp));
270 }
271
272 /*
273 * Wait until the vnode has finished changing state.
274 */
275 int
276 dead_lock(v)
277 void *v;
278 {
279 struct vop_lock_args /* {
280 struct vnode *a_vp;
281 } */ *ap = v;
282
283 if (!chkvnlock(ap->a_vp))
284 return (0);
285 return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap));
286 }
287
288 /*
289 * Wait until the vnode has finished changing state.
290 */
291 int
292 dead_bmap(v)
293 void *v;
294 {
295 struct vop_bmap_args /* {
296 struct vnode *a_vp;
297 daddr_t a_bn;
298 struct vnode **a_vpp;
299 daddr_t *a_bnp;
300 int *a_runp;
301 } */ *ap = v;
302
303 if (!chkvnlock(ap->a_vp))
304 return (EIO);
305 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp));
306 }
307
308 /*
309 * Print out the contents of a dead vnode.
310 */
311 /* ARGSUSED */
312 int
313 dead_print(v)
314 void *v;
315 {
316 printf("tag VT_NON, dead vnode\n");
317 return 0;
318 }
319
320 /*
321 * Empty vnode failed operation
322 */
323 /*ARGSUSED*/
324 int
325 dead_ebadf(v)
326 void *v;
327 {
328
329 return (EBADF);
330 }
331
332 /*
333 * Empty vnode bad operation
334 */
335 /*ARGSUSED*/
336 int
337 dead_badop(v)
338 void *v;
339 {
340
341 panic("dead_badop called");
342 /* NOTREACHED */
343 }
344
345 /*
346 * Empty vnode null operation
347 */
348 /*ARGSUSED*/
349 int
350 dead_nullop(v)
351 void *v;
352 {
353
354 return (0);
355 }
356
357 /*
358 * We have to wait during times when the vnode is
359 * in a state of change.
360 */
361 int
362 chkvnlock(vp)
363 register struct vnode *vp;
364 {
365 int locked = 0;
366
367 while (vp->v_flag & VXLOCK) {
368 vp->v_flag |= VXWANT;
369 sleep((caddr_t)vp, PINOD);
370 locked = 1;
371 }
372 return (locked);
373 }
374