dead_vnops.c revision 1.9 1 /* $NetBSD: dead_vnops.c,v 1.9 1994/06/29 06:34:12 cgd 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.1 (Berkeley) 6/10/93
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
46 /*
47 * Prototypes for dead operations on vnodes.
48 */
49 int dead_badop(),
50 dead_ebadf();
51 int dead_lookup __P((struct vop_lookup_args *));
52 #define dead_create ((int (*) __P((struct vop_create_args *)))dead_badop)
53 #define dead_mknod ((int (*) __P((struct vop_mknod_args *)))dead_badop)
54 int dead_open __P((struct vop_open_args *));
55 #define dead_close ((int (*) __P((struct vop_close_args *)))nullop)
56 #define dead_access ((int (*) __P((struct vop_access_args *)))dead_ebadf)
57 #define dead_getattr ((int (*) __P((struct vop_getattr_args *)))dead_ebadf)
58 #define dead_setattr ((int (*) __P((struct vop_setattr_args *)))dead_ebadf)
59 int dead_read __P((struct vop_read_args *));
60 int dead_write __P((struct vop_write_args *));
61 int dead_ioctl __P((struct vop_ioctl_args *));
62 int dead_select __P((struct vop_select_args *));
63 #define dead_mmap ((int (*) __P((struct vop_mmap_args *)))dead_badop)
64 #define dead_fsync ((int (*) __P((struct vop_fsync_args *)))nullop)
65 #define dead_seek ((int (*) __P((struct vop_seek_args *)))nullop)
66 #define dead_remove ((int (*) __P((struct vop_remove_args *)))dead_badop)
67 #define dead_link ((int (*) __P((struct vop_link_args *)))dead_badop)
68 #define dead_rename ((int (*) __P((struct vop_rename_args *)))dead_badop)
69 #define dead_mkdir ((int (*) __P((struct vop_mkdir_args *)))dead_badop)
70 #define dead_rmdir ((int (*) __P((struct vop_rmdir_args *)))dead_badop)
71 #define dead_symlink ((int (*) __P((struct vop_symlink_args *)))dead_badop)
72 #define dead_readdir ((int (*) __P((struct vop_readdir_args *)))dead_ebadf)
73 #define dead_readlink ((int (*) __P((struct vop_readlink_args *)))dead_ebadf)
74 #define dead_abortop ((int (*) __P((struct vop_abortop_args *)))dead_badop)
75 #define dead_inactive ((int (*) __P((struct vop_inactive_args *)))nullop)
76 #define dead_reclaim ((int (*) __P((struct vop_reclaim_args *)))nullop)
77 int dead_lock __P((struct vop_lock_args *));
78 #define dead_unlock ((int (*) __P((struct vop_unlock_args *)))nullop)
79 int dead_bmap __P((struct vop_bmap_args *));
80 int dead_strategy __P((struct vop_strategy_args *));
81 int dead_print __P((struct vop_print_args *));
82 #define dead_islocked ((int (*) __P((struct vop_islocked_args *)))nullop)
83 #define dead_pathconf ((int (*) __P((struct vop_pathconf_args *)))dead_ebadf)
84 #define dead_advlock ((int (*) __P((struct vop_advlock_args *)))dead_ebadf)
85 #define dead_blkatoff ((int (*) __P((struct vop_blkatoff_args *)))dead_badop)
86 #define dead_valloc ((int (*) __P((struct vop_valloc_args *)))dead_badop)
87 #define dead_vfree ((int (*) __P((struct vop_vfree_args *)))dead_badop)
88 #define dead_truncate ((int (*) __P((struct vop_truncate_args *)))nullop)
89 #define dead_update ((int (*) __P((struct vop_update_args *)))nullop)
90 #define dead_bwrite ((int (*) __P((struct vop_bwrite_args *)))nullop)
91
92 int (**dead_vnodeop_p)();
93 struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
94 { &vop_default_desc, vn_default_error },
95 { &vop_lookup_desc, dead_lookup }, /* lookup */
96 { &vop_create_desc, dead_create }, /* create */
97 { &vop_mknod_desc, dead_mknod }, /* mknod */
98 { &vop_open_desc, dead_open }, /* open */
99 { &vop_close_desc, dead_close }, /* close */
100 { &vop_access_desc, dead_access }, /* access */
101 { &vop_getattr_desc, dead_getattr }, /* getattr */
102 { &vop_setattr_desc, dead_setattr }, /* setattr */
103 { &vop_read_desc, dead_read }, /* read */
104 { &vop_write_desc, dead_write }, /* write */
105 { &vop_ioctl_desc, dead_ioctl }, /* ioctl */
106 { &vop_select_desc, dead_select }, /* select */
107 { &vop_mmap_desc, dead_mmap }, /* mmap */
108 { &vop_fsync_desc, dead_fsync }, /* fsync */
109 { &vop_seek_desc, dead_seek }, /* seek */
110 { &vop_remove_desc, dead_remove }, /* remove */
111 { &vop_link_desc, dead_link }, /* link */
112 { &vop_rename_desc, dead_rename }, /* rename */
113 { &vop_mkdir_desc, dead_mkdir }, /* mkdir */
114 { &vop_rmdir_desc, dead_rmdir }, /* rmdir */
115 { &vop_symlink_desc, dead_symlink }, /* symlink */
116 { &vop_readdir_desc, dead_readdir }, /* readdir */
117 { &vop_readlink_desc, dead_readlink }, /* readlink */
118 { &vop_abortop_desc, dead_abortop }, /* abortop */
119 { &vop_inactive_desc, dead_inactive }, /* inactive */
120 { &vop_reclaim_desc, dead_reclaim }, /* reclaim */
121 { &vop_lock_desc, dead_lock }, /* lock */
122 { &vop_unlock_desc, dead_unlock }, /* unlock */
123 { &vop_bmap_desc, dead_bmap }, /* bmap */
124 { &vop_strategy_desc, dead_strategy }, /* strategy */
125 { &vop_print_desc, dead_print }, /* print */
126 { &vop_islocked_desc, dead_islocked }, /* islocked */
127 { &vop_pathconf_desc, dead_pathconf }, /* pathconf */
128 { &vop_advlock_desc, dead_advlock }, /* advlock */
129 { &vop_blkatoff_desc, dead_blkatoff }, /* blkatoff */
130 { &vop_valloc_desc, dead_valloc }, /* valloc */
131 { &vop_vfree_desc, dead_vfree }, /* vfree */
132 { &vop_truncate_desc, dead_truncate }, /* truncate */
133 { &vop_update_desc, dead_update }, /* update */
134 { &vop_bwrite_desc, dead_bwrite }, /* bwrite */
135 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
136 };
137 struct vnodeopv_desc dead_vnodeop_opv_desc =
138 { &dead_vnodeop_p, dead_vnodeop_entries };
139
140 /*
141 * Trivial lookup routine that always fails.
142 */
143 /* ARGSUSED */
144 int
145 dead_lookup(ap)
146 struct vop_lookup_args /* {
147 struct vnode * a_dvp;
148 struct vnode ** a_vpp;
149 struct componentname * a_cnp;
150 } */ *ap;
151 {
152
153 *ap->a_vpp = NULL;
154 return (ENOTDIR);
155 }
156
157 /*
158 * Open always fails as if device did not exist.
159 */
160 /* ARGSUSED */
161 dead_open(ap)
162 struct vop_open_args /* {
163 struct vnode *a_vp;
164 int a_mode;
165 struct ucred *a_cred;
166 struct proc *a_p;
167 } */ *ap;
168 {
169
170 return (ENXIO);
171 }
172
173 /*
174 * Vnode op for read
175 */
176 /* ARGSUSED */
177 dead_read(ap)
178 struct vop_read_args /* {
179 struct vnode *a_vp;
180 struct uio *a_uio;
181 int a_ioflag;
182 struct ucred *a_cred;
183 } */ *ap;
184 {
185
186 if (chkvnlock(ap->a_vp))
187 panic("dead_read: lock");
188 /*
189 * Return EOF for character devices, EIO for others
190 */
191 if (ap->a_vp->v_type != VCHR)
192 return (EIO);
193 return (0);
194 }
195
196 /*
197 * Vnode op for write
198 */
199 /* ARGSUSED */
200 dead_write(ap)
201 struct vop_write_args /* {
202 struct vnode *a_vp;
203 struct uio *a_uio;
204 int a_ioflag;
205 struct ucred *a_cred;
206 } */ *ap;
207 {
208
209 if (chkvnlock(ap->a_vp))
210 panic("dead_write: lock");
211 return (EIO);
212 }
213
214 /*
215 * Device ioctl operation.
216 */
217 /* ARGSUSED */
218 dead_ioctl(ap)
219 struct vop_ioctl_args /* {
220 struct vnode *a_vp;
221 int a_command;
222 caddr_t a_data;
223 int a_fflag;
224 struct ucred *a_cred;
225 struct proc *a_p;
226 } */ *ap;
227 {
228
229 if (!chkvnlock(ap->a_vp))
230 return (EBADF);
231 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
232 }
233
234 /* ARGSUSED */
235 dead_select(ap)
236 struct vop_select_args /* {
237 struct vnode *a_vp;
238 int a_which;
239 int a_fflags;
240 struct ucred *a_cred;
241 struct proc *a_p;
242 } */ *ap;
243 {
244
245 /*
246 * Let the user find out that the descriptor is gone.
247 */
248 return (1);
249 }
250
251 /*
252 * Just call the device strategy routine
253 */
254 dead_strategy(ap)
255 struct vop_strategy_args /* {
256 struct buf *a_bp;
257 } */ *ap;
258 {
259
260 if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) {
261 ap->a_bp->b_flags |= B_ERROR;
262 biodone(ap->a_bp);
263 return (EIO);
264 }
265 return (VOP_STRATEGY(ap->a_bp));
266 }
267
268 /*
269 * Wait until the vnode has finished changing state.
270 */
271 dead_lock(ap)
272 struct vop_lock_args /* {
273 struct vnode *a_vp;
274 } */ *ap;
275 {
276
277 if (!chkvnlock(ap->a_vp))
278 return (0);
279 return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap));
280 }
281
282 /*
283 * Wait until the vnode has finished changing state.
284 */
285 dead_bmap(ap)
286 struct vop_bmap_args /* {
287 struct vnode *a_vp;
288 daddr_t a_bn;
289 struct vnode **a_vpp;
290 daddr_t *a_bnp;
291 int *a_runp;
292 } */ *ap;
293 {
294
295 if (!chkvnlock(ap->a_vp))
296 return (EIO);
297 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp));
298 }
299
300 /*
301 * Print out the contents of a dead vnode.
302 */
303 /* ARGSUSED */
304 dead_print(ap)
305 struct vop_print_args /* {
306 struct vnode *a_vp;
307 } */ *ap;
308 {
309
310 printf("tag VT_NON, dead vnode\n");
311 }
312
313 /*
314 * Empty vnode failed operation
315 */
316 dead_ebadf()
317 {
318
319 return (EBADF);
320 }
321
322 /*
323 * Empty vnode bad operation
324 */
325 dead_badop()
326 {
327
328 panic("dead_badop called");
329 /* NOTREACHED */
330 }
331
332 /*
333 * Empty vnode null operation
334 */
335 dead_nullop()
336 {
337
338 return (0);
339 }
340
341 /*
342 * We have to wait during times when the vnode is
343 * in a state of change.
344 */
345 chkvnlock(vp)
346 register struct vnode *vp;
347 {
348 int locked = 0;
349
350 while (vp->v_flag & VXLOCK) {
351 vp->v_flag |= VXWANT;
352 sleep((caddr_t)vp, PINOD);
353 locked = 1;
354 }
355 return (locked);
356 }
357