No empty .Rs/.Re
[netbsd-mini2440.git] / sys / miscfs / deadfs / dead_vnops.c
blobf7d59adc565bba49b0663c1c1b2a057cd275422a
1 /* $NetBSD: dead_vnops.c,v 1.47 2008/01/25 14:32:15 ad Exp $ */
3 /*
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
31 * @(#)dead_vnops.c 8.2 (Berkeley) 11/21/94
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: dead_vnops.c,v 1.47 2008/01/25 14:32:15 ad Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/time.h>
40 #include <sys/vnode.h>
41 #include <sys/errno.h>
42 #include <sys/namei.h>
43 #include <sys/buf.h>
44 #include <sys/proc.h>
46 #include <miscfs/genfs/genfs.h>
49 * Prototypes for dead operations on vnodes.
51 int dead_open(void *);
52 #define dead_close genfs_nullop
53 int dead_read(void *);
54 int dead_write(void *);
55 #define dead_fcntl genfs_nullop
56 int dead_ioctl(void *);
57 int dead_poll(void *);
58 #define dead_fsync genfs_nullop
59 #define dead_seek genfs_nullop
60 #define dead_inactive genfs_nullop
61 #define dead_reclaim genfs_nullop
62 int dead_lock(void *);
63 #define dead_unlock genfs_nullop
64 int dead_bmap(void *);
65 int dead_strategy(void *);
66 int dead_print(void *);
67 #define dead_islocked genfs_nullop
68 #define dead_bwrite genfs_nullop
69 #define dead_revoke genfs_nullop
70 int dead_getpages(void *);
71 #define dead_putpages genfs_null_putpages
73 int chkvnlock(struct vnode *, bool);
74 int dead_default_error(void *);
76 int (**dead_vnodeop_p)(void *);
78 const struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
79 { &vop_default_desc, dead_default_error },
80 { &vop_open_desc, dead_open }, /* open */
81 { &vop_close_desc, dead_close }, /* close */
82 { &vop_read_desc, dead_read }, /* read */
83 { &vop_write_desc, dead_write }, /* write */
84 { &vop_fcntl_desc, dead_fcntl }, /* fcntl */
85 { &vop_ioctl_desc, dead_ioctl }, /* ioctl */
86 { &vop_poll_desc, dead_poll }, /* poll */
87 { &vop_revoke_desc, dead_revoke }, /* revoke */
88 { &vop_fsync_desc, dead_fsync }, /* fsync */
89 { &vop_seek_desc, dead_seek }, /* seek */
90 { &vop_inactive_desc, dead_inactive }, /* inactive */
91 { &vop_reclaim_desc, dead_reclaim }, /* reclaim */
92 { &vop_lock_desc, dead_lock }, /* lock */
93 { &vop_unlock_desc, dead_unlock }, /* unlock */
94 { &vop_bmap_desc, dead_bmap }, /* bmap */
95 { &vop_strategy_desc, dead_strategy }, /* strategy */
96 { &vop_print_desc, dead_print }, /* print */
97 { &vop_islocked_desc, dead_islocked }, /* islocked */
98 { &vop_bwrite_desc, dead_bwrite }, /* bwrite */
99 { &vop_getpages_desc, dead_getpages }, /* getpages */
100 { &vop_putpages_desc, dead_putpages }, /* putpages */
101 { NULL, NULL }
103 const struct vnodeopv_desc dead_vnodeop_opv_desc =
104 { &dead_vnodeop_p, dead_vnodeop_entries };
107 dead_default_error(void *v)
110 return EBADF;
114 * Open always fails as if device did not exist.
116 /* ARGSUSED */
118 dead_open(void *v)
121 return (ENXIO);
125 * Vnode op for read
127 /* ARGSUSED */
129 dead_read(void *v)
131 struct vop_read_args /* {
132 struct vnode *a_vp;
133 struct uio *a_uio;
134 int a_ioflag;
135 kauth_cred_t a_cred;
136 } */ *ap = v;
138 if (chkvnlock(ap->a_vp, false))
139 panic("dead_read: lock");
141 * Return EOF for tty devices, EIO for others
143 if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
144 return (EIO);
145 return (0);
149 * Vnode op for write
151 /* ARGSUSED */
153 dead_write(void *v)
155 struct vop_write_args /* {
156 struct vnode *a_vp;
157 struct uio *a_uio;
158 int a_ioflag;
159 kauth_cred_t a_cred;
160 } */ *ap = v;
162 if (chkvnlock(ap->a_vp, false))
163 panic("dead_write: lock");
164 return (EIO);
168 * Device ioctl operation.
170 /* ARGSUSED */
172 dead_ioctl(void *v)
174 struct vop_ioctl_args /* {
175 struct vnode *a_vp;
176 u_long a_command;
177 void *a_data;
178 int a_fflag;
179 kauth_cred_t a_cred;
180 struct lwp *a_l;
181 } */ *ap = v;
183 if (!chkvnlock(ap->a_vp, false))
184 return (EBADF);
185 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
188 /* ARGSUSED */
190 dead_poll(void *v)
192 struct vop_poll_args /* {
193 struct vnode *a_vp;
194 int a_events;
195 struct lwp *a_l;
196 } */ *ap = v;
199 * Let the user find out that the descriptor is gone.
201 return (ap->a_events);
205 * Just call the device strategy routine
208 dead_strategy(void *v)
211 struct vop_strategy_args /* {
212 struct vnode *a_vp;
213 struct buf *a_bp;
214 } */ *ap = v;
215 struct buf *bp;
216 if (ap->a_vp == NULL || !chkvnlock(ap->a_vp, false)) {
217 bp = ap->a_bp;
218 bp->b_error = EIO;
219 bp->b_resid = bp->b_bcount;
220 biodone(ap->a_bp);
221 return (EIO);
223 return (VOP_STRATEGY(ap->a_vp, ap->a_bp));
227 * Wait until the vnode has finished changing state.
230 dead_lock(void *v)
232 struct vop_lock_args /* {
233 struct vnode *a_vp;
234 int a_flags;
235 struct proc *a_p;
236 } */ *ap = v;
237 bool interlock;
239 if (ap->a_flags & LK_INTERLOCK) {
240 interlock = true;
241 ap->a_flags &= ~LK_INTERLOCK;
242 } else
243 interlock = false;
244 if (!chkvnlock(ap->a_vp, interlock))
245 return (0);
246 return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap));
250 * Wait until the vnode has finished changing state.
253 dead_bmap(void *v)
255 struct vop_bmap_args /* {
256 struct vnode *a_vp;
257 daddr_t a_bn;
258 struct vnode **a_vpp;
259 daddr_t *a_bnp;
260 int *a_runp;
261 } */ *ap = v;
263 if (!chkvnlock(ap->a_vp, false))
264 return (EIO);
265 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp));
269 * Print out the contents of a dead vnode.
271 /* ARGSUSED */
273 dead_print(void *v)
275 printf("tag VT_NON, dead vnode\n");
276 return 0;
280 dead_getpages(void *v)
282 struct vop_getpages_args /* {
283 struct vnode *a_vp;
284 voff_t a_offset;
285 struct vm_page **a_m;
286 int *a_count;
287 int a_centeridx;
288 vm_prot_t a_access_type;
289 int a_advice;
290 int a_flags;
291 } */ *ap = v;
293 if ((ap->a_flags & PGO_LOCKED) == 0)
294 mutex_exit(&ap->a_vp->v_interlock);
296 return (EFAULT);
300 * We have to wait during times when the vnode is
301 * in a state of change.
304 chkvnlock(struct vnode *vp, bool interlock)
306 int locked = 0;
308 if (!interlock)
309 mutex_enter(&vp->v_interlock);
310 while (vp->v_iflag & VI_XLOCK) {
311 vwait(vp, VI_XLOCK);
312 locked = 1;
314 mutex_exit(&vp->v_interlock);
316 return (locked);