Media table reorganization.
[unix-history] / sys / kern / dead_vnops.c
CommitLineData
15637ed4
RG
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * 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 *
600f7f07 33 * from: @(#)dead_vnops.c 7.13 (Berkeley) 4/15/91
4c45483e 34 * $Id: dead_vnops.c,v 1.3 1993/11/07 21:44:40 wollman Exp $
15637ed4
RG
35 */
36
37#include "param.h"
38#include "systm.h"
39#include "time.h"
40#include "vnode.h"
41#include "errno.h"
42#include "namei.h"
43#include "buf.h"
44
45/*
46 * Prototypes for dead operations on vnodes.
47 */
48int dead_badop(),
49 dead_ebadf();
50int dead_lookup __P((
51 struct vnode *vp,
52 struct nameidata *ndp,
53 struct proc *p));
54#define dead_create ((int (*) __P(( \
55 struct nameidata *ndp, \
56 struct vattr *vap, \
57 struct proc *p))) dead_badop)
58#define dead_mknod ((int (*) __P(( \
59 struct nameidata *ndp, \
60 struct vattr *vap, \
61 struct ucred *cred, \
62 struct proc *p))) dead_badop)
63int dead_open __P((
64 struct vnode *vp,
65 int mode,
66 struct ucred *cred,
67 struct proc *p));
68#define dead_close ((int (*) __P(( \
69 struct vnode *vp, \
70 int fflag, \
71 struct ucred *cred, \
72 struct proc *p))) nullop)
73#define dead_access ((int (*) __P(( \
74 struct vnode *vp, \
75 int mode, \
76 struct ucred *cred, \
77 struct proc *p))) dead_ebadf)
78#define dead_getattr ((int (*) __P(( \
79 struct vnode *vp, \
80 struct vattr *vap, \
81 struct ucred *cred, \
82 struct proc *p))) dead_ebadf)
83#define dead_setattr ((int (*) __P(( \
84 struct vnode *vp, \
85 struct vattr *vap, \
86 struct ucred *cred, \
87 struct proc *p))) dead_ebadf)
88int dead_read __P((
89 struct vnode *vp,
90 struct uio *uio,
91 int ioflag,
92 struct ucred *cred));
93int dead_write __P((
94 struct vnode *vp,
95 struct uio *uio,
96 int ioflag,
97 struct ucred *cred));
98int dead_ioctl __P((
99 struct vnode *vp,
100 int command,
101 caddr_t data,
102 int fflag,
103 struct ucred *cred,
104 struct proc *p));
105int dead_select __P((
106 struct vnode *vp,
107 int which,
108 int fflags,
109 struct ucred *cred,
110 struct proc *p));
111#define dead_mmap ((int (*) __P(( \
112 struct vnode *vp, \
113 int fflags, \
114 struct ucred *cred, \
115 struct proc *p))) dead_badop)
116#define dead_fsync ((int (*) __P(( \
117 struct vnode *vp, \
118 int fflags, \
119 struct ucred *cred, \
120 int waitfor, \
121 struct proc *p))) nullop)
122#define dead_seek ((int (*) __P(( \
123 struct vnode *vp, \
124 off_t oldoff, \
125 off_t newoff, \
126 struct ucred *cred))) nullop)
127#define dead_remove ((int (*) __P(( \
128 struct nameidata *ndp, \
129 struct proc *p))) dead_badop)
130#define dead_link ((int (*) __P(( \
131 struct vnode *vp, \
132 struct nameidata *ndp, \
133 struct proc *p))) dead_badop)
134#define dead_rename ((int (*) __P(( \
135 struct nameidata *fndp, \
136 struct nameidata *tdnp, \
137 struct proc *p))) dead_badop)
138#define dead_mkdir ((int (*) __P(( \
139 struct nameidata *ndp, \
140 struct vattr *vap, \
141 struct proc *p))) dead_badop)
142#define dead_rmdir ((int (*) __P(( \
143 struct nameidata *ndp, \
144 struct proc *p))) dead_badop)
145#define dead_symlink ((int (*) __P(( \
146 struct nameidata *ndp, \
147 struct vattr *vap, \
148 char *target, \
149 struct proc *p))) dead_badop)
150#define dead_readdir ((int (*) __P(( \
151 struct vnode *vp, \
152 struct uio *uio, \
153 struct ucred *cred, \
154 int *eofflagp))) dead_ebadf)
155#define dead_readlink ((int (*) __P(( \
156 struct vnode *vp, \
157 struct uio *uio, \
158 struct ucred *cred))) dead_ebadf)
159#define dead_abortop ((int (*) __P(( \
160 struct nameidata *ndp))) dead_badop)
161#define dead_inactive ((int (*) __P(( \
162 struct vnode *vp, \
163 struct proc *p))) nullop)
164#define dead_reclaim ((int (*) __P(( \
165 struct vnode *vp))) nullop)
166int dead_lock __P((
167 struct vnode *vp));
168#define dead_unlock ((int (*) __P(( \
169 struct vnode *vp))) nullop)
170int dead_bmap __P((
171 struct vnode *vp,
172 daddr_t bn,
173 struct vnode **vpp,
174 daddr_t *bnp));
175int dead_strategy __P((
176 struct buf *bp));
4c45483e 177void dead_print __P((
15637ed4
RG
178 struct vnode *vp));
179#define dead_islocked ((int (*) __P(( \
180 struct vnode *vp))) nullop)
181#define dead_advlock ((int (*) __P(( \
182 struct vnode *vp, \
183 caddr_t id, \
184 int op, \
185 struct flock *fl, \
186 int flags))) dead_ebadf)
187
188struct vnodeops dead_vnodeops = {
189 dead_lookup, /* lookup */
190 dead_create, /* create */
191 dead_mknod, /* mknod */
192 dead_open, /* open */
193 dead_close, /* close */
194 dead_access, /* access */
195 dead_getattr, /* getattr */
196 dead_setattr, /* setattr */
197 dead_read, /* read */
198 dead_write, /* write */
199 dead_ioctl, /* ioctl */
200 dead_select, /* select */
201 dead_mmap, /* mmap */
202 dead_fsync, /* fsync */
203 dead_seek, /* seek */
204 dead_remove, /* remove */
205 dead_link, /* link */
206 dead_rename, /* rename */
207 dead_mkdir, /* mkdir */
208 dead_rmdir, /* rmdir */
209 dead_symlink, /* symlink */
210 dead_readdir, /* readdir */
211 dead_readlink, /* readlink */
212 dead_abortop, /* abortop */
213 dead_inactive, /* inactive */
214 dead_reclaim, /* reclaim */
215 dead_lock, /* lock */
216 dead_unlock, /* unlock */
217 dead_bmap, /* bmap */
218 dead_strategy, /* strategy */
219 dead_print, /* print */
220 dead_islocked, /* islocked */
221 dead_advlock, /* advlock */
222};
223
224/*
225 * Trivial lookup routine that always fails.
226 */
227/* ARGSUSED */
4c45483e 228int
15637ed4
RG
229dead_lookup(vp, ndp, p)
230 struct vnode *vp;
231 struct nameidata *ndp;
232 struct proc *p;
233{
234
235 ndp->ni_dvp = vp;
236 ndp->ni_vp = NULL;
237 return (ENOTDIR);
238}
239
240/*
241 * Open always fails as if device did not exist.
242 */
243/* ARGSUSED */
4c45483e 244int
15637ed4
RG
245dead_open(vp, mode, cred, p)
246 struct vnode *vp;
247 int mode;
248 struct ucred *cred;
249 struct proc *p;
250{
251
252 return (ENXIO);
253}
254
255/*
256 * Vnode op for read
257 */
258/* ARGSUSED */
4c45483e 259int
15637ed4
RG
260dead_read(vp, uio, ioflag, cred)
261 struct vnode *vp;
262 struct uio *uio;
263 int ioflag;
264 struct ucred *cred;
265{
266
267 if (chkvnlock(vp))
268 panic("dead_read: lock");
269 /*
270 * Return EOF for character devices, EIO for others
271 */
272 if (vp->v_type != VCHR)
273 return (EIO);
274 return (0);
275}
276
277/*
278 * Vnode op for write
279 */
280/* ARGSUSED */
4c45483e 281int
15637ed4
RG
282dead_write(vp, uio, ioflag, cred)
283 register struct vnode *vp;
284 struct uio *uio;
285 int ioflag;
286 struct ucred *cred;
287{
288
289 if (chkvnlock(vp))
290 panic("dead_write: lock");
291 return (EIO);
292}
293
294/*
295 * Device ioctl operation.
296 */
297/* ARGSUSED */
4c45483e 298int
15637ed4
RG
299dead_ioctl(vp, com, data, fflag, cred, p)
300 struct vnode *vp;
301 register int com;
302 caddr_t data;
303 int fflag;
304 struct ucred *cred;
305 struct proc *p;
306{
307
308 if (!chkvnlock(vp))
309 return (EBADF);
310 return (VOP_IOCTL(vp, com, data, fflag, cred, p));
311}
312
313/* ARGSUSED */
4c45483e 314int
15637ed4
RG
315dead_select(vp, which, fflags, cred, p)
316 struct vnode *vp;
317 int which, fflags;
318 struct ucred *cred;
319 struct proc *p;
320{
321
322 /*
323 * Let the user find out that the descriptor is gone.
324 */
325 return (1);
326}
327
328/*
329 * Just call the device strategy routine
330 */
4c45483e 331int
15637ed4
RG
332dead_strategy(bp)
333 register struct buf *bp;
334{
335
336 if (bp->b_vp == NULL || !chkvnlock(bp->b_vp)) {
337 bp->b_flags |= B_ERROR;
338 biodone(bp);
339 return (EIO);
340 }
341 return (VOP_STRATEGY(bp));
342}
343
344/*
345 * Wait until the vnode has finished changing state.
346 */
4c45483e 347int
15637ed4
RG
348dead_lock(vp)
349 struct vnode *vp;
350{
351
352 if (!chkvnlock(vp))
353 return (0);
354 return (VOP_LOCK(vp));
355}
356
357/*
358 * Wait until the vnode has finished changing state.
359 */
4c45483e 360int
15637ed4
RG
361dead_bmap(vp, bn, vpp, bnp)
362 struct vnode *vp;
363 daddr_t bn;
364 struct vnode **vpp;
365 daddr_t *bnp;
366{
367
368 if (!chkvnlock(vp))
369 return (EIO);
370 return (VOP_BMAP(vp, bn, vpp, bnp));
371}
372
373/*
374 * Print out the contents of a dead vnode.
375 */
376/* ARGSUSED */
4c45483e 377void
15637ed4
RG
378dead_print(vp)
379 struct vnode *vp;
380{
381
382 printf("tag VT_NON, dead vnode\n");
383}
384
385/*
386 * Empty vnode failed operation
387 */
4c45483e 388int
15637ed4
RG
389dead_ebadf()
390{
391
392 return (EBADF);
393}
394
395/*
396 * Empty vnode bad operation
397 */
4c45483e 398int
15637ed4
RG
399dead_badop()
400{
401
402 panic("dead_badop called");
403 /* NOTREACHED */
404}
405
406/*
407 * Empty vnode null operation
408 */
4c45483e 409int
15637ed4
RG
410dead_nullop()
411{
412
413 return (0);
414}
415
416/*
417 * We have to wait during times when the vnode is
418 * in a state of change.
419 */
4c45483e 420int
15637ed4
RG
421chkvnlock(vp)
422 register struct vnode *vp;
423{
424 int locked = 0;
425
426 while (vp->v_flag & VXLOCK) {
427 vp->v_flag |= VXWANT;
73419b27 428 tsleep((caddr_t)vp, PINOD, "chkvnlk", 0);
15637ed4
RG
429 locked = 1;
430 }
431 return (locked);
432}