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