|
|
1.1 root 1: /*
2: * Copyright (c) 1989 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution is only permitted until one year after the first shipment
6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
7: * binary forms are permitted provided that: (1) source distributions retain
8: * this entire copyright notice and comment, and (2) distributions including
9: * binaries display the following acknowledgement: This product includes
10: * software developed by the University of California, Berkeley and its
11: * contributors'' in the documentation or other materials provided with the
12: * distribution and in all advertising materials mentioning features or use
13: * of this software. Neither the name of the University nor the names of
14: * its contributors may be used to endorse or promote products derived from
15: * this software without specific prior written permission.
16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19: *
20: * @(#)dead_vnops.c 7.10 (Berkeley) 6/28/90
21: */
22:
23: #include "param.h"
24: #include "time.h"
25: #include "vnode.h"
26: #include "errno.h"
27: #include "namei.h"
28: #include "buf.h"
29:
30: int dead_lookup(),
31: dead_open(),
32: dead_read(),
33: dead_write(),
34: dead_strategy(),
35: dead_ioctl(),
36: dead_select(),
37: dead_lock(),
38: dead_bmap(),
39: dead_print(),
40: dead_ebadf(),
41: dead_badop(),
42: dead_nullop();
43:
44: struct vnodeops dead_vnodeops = {
45: dead_lookup, /* lookup */
46: dead_badop, /* create */
47: dead_badop, /* mknod */
48: dead_open, /* open */
49: dead_nullop, /* close */
50: dead_ebadf, /* access */
51: dead_ebadf, /* getattr */
52: dead_ebadf, /* setattr */
53: dead_read, /* read */
54: dead_write, /* write */
55: dead_ioctl, /* ioctl */
56: dead_select, /* select */
57: dead_badop, /* mmap */
58: dead_nullop, /* fsync */
59: dead_nullop, /* seek */
60: dead_badop, /* remove */
61: dead_badop, /* link */
62: dead_badop, /* rename */
63: dead_badop, /* mkdir */
64: dead_badop, /* rmdir */
65: dead_badop, /* symlink */
66: dead_ebadf, /* readdir */
67: dead_ebadf, /* readlink */
68: dead_badop, /* abortop */
69: dead_nullop, /* inactive */
70: dead_nullop, /* reclaim */
71: dead_lock, /* lock */
72: dead_nullop, /* unlock */
73: dead_bmap, /* bmap */
74: dead_strategy, /* strategy */
75: dead_print, /* print */
76: dead_nullop, /* islocked */
77: };
78:
79: /*
80: * Trivial lookup routine that always fails.
81: */
82: dead_lookup(vp, ndp)
83: struct vnode *vp;
84: struct nameidata *ndp;
85: {
86:
87: ndp->ni_dvp = vp;
88: ndp->ni_vp = NULL;
89: return (ENOTDIR);
90: }
91:
92: /*
93: * Open always fails as if device did not exist.
94: */
95: /* ARGSUSED */
96: dead_open(vp, mode, cred)
97: struct vnode *vp;
98: int mode;
99: struct ucred *cred;
100: {
101:
102: return (ENXIO);
103: }
104:
105: /*
106: * Vnode op for read
107: */
108: /* ARGSUSED */
109: dead_read(vp, uio, ioflag, cred)
110: struct vnode *vp;
111: struct uio *uio;
112: int ioflag;
113: struct ucred *cred;
114: {
115:
116: if (chkvnlock(vp))
117: panic("dead_read: lock");
118: /*
119: * Return EOF for character devices, EIO for others
120: */
121: if (vp->v_type != VCHR)
122: return (EIO);
123: return (0);
124: }
125:
126: /*
127: * Vnode op for write
128: */
129: /* ARGSUSED */
130: dead_write(vp, uio, ioflag, cred)
131: register struct vnode *vp;
132: struct uio *uio;
133: int ioflag;
134: struct ucred *cred;
135: {
136:
137: if (chkvnlock(vp))
138: panic("dead_write: lock");
139: return (EIO);
140: }
141:
142: /*
143: * Device ioctl operation.
144: */
145: /* ARGSUSED */
146: dead_ioctl(vp, com, data, fflag, cred)
147: struct vnode *vp;
148: register int com;
149: caddr_t data;
150: int fflag;
151: struct ucred *cred;
152: {
153:
154: if (!chkvnlock(vp))
155: return (EBADF);
156: return (VOP_IOCTL(vp, com, data, fflag, cred));
157: }
158:
159: /* ARGSUSED */
160: dead_select(vp, which, fflags, cred)
161: struct vnode *vp;
162: int which, fflags;
163: struct ucred *cred;
164: {
165:
166: /*
167: * Let the user find out that the descriptor is gone.
168: */
169: return (1);
170: }
171:
172: /*
173: * Just call the device strategy routine
174: */
175: dead_strategy(bp)
176: register struct buf *bp;
177: {
178:
179: if (bp->b_vp == NULL || !chkvnlock(bp->b_vp)) {
180: bp->b_flags |= B_ERROR;
181: biodone(bp);
182: return (EIO);
183: }
184: return (VOP_STRATEGY(bp));
185: }
186:
187: /*
188: * Wait until the vnode has finished changing state.
189: */
190: dead_lock(vp)
191: struct vnode *vp;
192: {
193:
194: if (!chkvnlock(vp))
195: return (0);
196: return (VOP_LOCK(vp));
197: }
198:
199: /*
200: * Wait until the vnode has finished changing state.
201: */
202: dead_bmap(vp, bn, vpp, bnp)
203: struct vnode *vp;
204: daddr_t bn;
205: struct vnode **vpp;
206: daddr_t *bnp;
207: {
208:
209: if (!chkvnlock(vp))
210: return (EIO);
211: return (VOP_BMAP(vp, bn, vpp, bnp));
212: }
213:
214: /*
215: * Print out the contents of a dead vnode.
216: */
217: dead_print(vp)
218: struct vnode *vp;
219: {
220:
221: printf("tag VT_NON, dead vnode\n");
222: }
223:
224: /*
225: * Empty vnode failed operation
226: */
227: dead_ebadf()
228: {
229:
230: return (EBADF);
231: }
232:
233: /*
234: * Empty vnode bad operation
235: */
236: dead_badop()
237: {
238:
239: panic("dead_badop called");
240: /* NOTREACHED */
241: }
242:
243: /*
244: * Empty vnode null operation
245: */
246: dead_nullop()
247: {
248:
249: return (0);
250: }
251:
252: /*
253: * We have to wait during times when the vnode is
254: * in a state of change.
255: */
256: chkvnlock(vp)
257: register struct vnode *vp;
258: {
259: int locked = 0;
260:
261: while (vp->v_flag & VXLOCK) {
262: vp->v_flag |= VXWANT;
263: sleep((caddr_t)vp, PINOD);
264: locked = 1;
265: }
266: return (locked);
267: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.