]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/fs/deadfs/dead_vnops.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / fs / deadfs / dead_vnops.c
1 /*-
2  * Copyright (c) 1989, 1993
3  *      The Regents of the University of California.  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  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  *      @(#)dead_vnops.c        8.1 (Berkeley) 6/10/93
30  * $FreeBSD$
31  */
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/lock.h>
37 #include <sys/mutex.h>
38 #include <sys/poll.h>
39 #include <sys/vnode.h>
40
41 /*
42  * Prototypes for dead operations on vnodes.
43  */
44 static vop_bmap_t       dead_bmap;
45 static vop_ioctl_t      dead_ioctl;
46 static vop_lookup_t     dead_lookup;
47 static vop_open_t       dead_open;
48 static vop_poll_t       dead_poll;
49 static vop_read_t       dead_read;
50 static vop_write_t      dead_write;
51 static vop_getwritemount_t dead_getwritemount;
52 static vop_rename_t     dead_rename;
53
54 struct vop_vector dead_vnodeops = {
55         .vop_default =          &default_vnodeops,
56
57         .vop_access =           VOP_EBADF,
58         .vop_advlock =          VOP_EBADF,
59         .vop_bmap =             dead_bmap,
60         .vop_create =           VOP_PANIC,
61         .vop_getattr =          VOP_EBADF,
62         .vop_getwritemount =    dead_getwritemount,
63         .vop_inactive =         VOP_NULL,
64         .vop_ioctl =            dead_ioctl,
65         .vop_link =             VOP_PANIC,
66         .vop_lookup =           dead_lookup,
67         .vop_mkdir =            VOP_PANIC,
68         .vop_mknod =            VOP_PANIC,
69         .vop_open =             dead_open,
70         .vop_pathconf =         VOP_EBADF,      /* per pathconf(2) */
71         .vop_poll =             dead_poll,
72         .vop_read =             dead_read,
73         .vop_readdir =          VOP_EBADF,
74         .vop_readlink =         VOP_EBADF,
75         .vop_reclaim =          VOP_NULL,
76         .vop_remove =           VOP_PANIC,
77         .vop_rename =           dead_rename,
78         .vop_rmdir =            VOP_PANIC,
79         .vop_setattr =          VOP_EBADF,
80         .vop_symlink =          VOP_PANIC,
81         .vop_write =            dead_write,
82 };
83
84 /* ARGSUSED */
85 static int
86 dead_getwritemount(ap)
87         struct vop_getwritemount_args /* {
88                 struct vnode *a_vp;
89                 struct mount **a_mpp;
90         } */ *ap;
91 {
92         *(ap->a_mpp) = NULL;
93         return (0);
94 }
95
96 /*
97  * Trivial lookup routine that always fails.
98  */
99 /* ARGSUSED */
100 static int
101 dead_lookup(ap)
102         struct vop_lookup_args /* {
103                 struct vnode * a_dvp;
104                 struct vnode ** a_vpp;
105                 struct componentname * a_cnp;
106         } */ *ap;
107 {
108
109         *ap->a_vpp = NULL;
110         return (ENOTDIR);
111 }
112
113 /*
114  * Open always fails as if device did not exist.
115  */
116 /* ARGSUSED */
117 static int
118 dead_open(ap)
119         struct vop_open_args /* {
120                 struct vnode *a_vp;
121                 int  a_mode;
122                 struct ucred *a_cred;
123                 struct proc *a_p;
124         } */ *ap;
125 {
126
127         return (ENXIO);
128 }
129
130 /*
131  * Vnode op for read
132  */
133 /* ARGSUSED */
134 static int
135 dead_read(ap)
136         struct vop_read_args /* {
137                 struct vnode *a_vp;
138                 struct uio *a_uio;
139                 int  a_ioflag;
140                 struct ucred *a_cred;
141         } */ *ap;
142 {
143         /*
144          * Return EOF for tty devices, EIO for others
145          */
146         if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
147                 return (EIO);
148         return (0);
149 }
150
151 /*
152  * Vnode op for write
153  */
154 /* ARGSUSED */
155 static int
156 dead_write(ap)
157         struct vop_write_args /* {
158                 struct vnode *a_vp;
159                 struct uio *a_uio;
160                 int  a_ioflag;
161                 struct ucred *a_cred;
162         } */ *ap;
163 {
164         return (EIO);
165 }
166
167 /*
168  * Device ioctl operation.
169  */
170 /* ARGSUSED */
171 static int
172 dead_ioctl(ap)
173         struct vop_ioctl_args /* {
174                 struct vnode *a_vp;
175                 u_long  a_command;
176                 caddr_t  a_data;
177                 int  a_fflag;
178                 struct ucred *a_cred;
179                 struct proc *a_p;
180         } */ *ap;
181 {
182         /* XXX: Doesn't this just recurse back here ? */
183         return (VOP_IOCTL_AP(ap));
184 }
185
186 /*
187  * Wait until the vnode has finished changing state.
188  */
189 static int
190 dead_bmap(ap)
191         struct vop_bmap_args /* {
192                 struct vnode *a_vp;
193                 daddr_t  a_bn;
194                 struct bufobj **a_bop;
195                 daddr_t *a_bnp;
196                 int *a_runp;
197                 int *a_runb;
198         } */ *ap;
199 {
200
201         return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_bop, ap->a_bnp, ap->a_runp, ap->a_runb));
202 }
203
204 /*
205  * Trivial poll routine that always returns POLLHUP.
206  * This is necessary so that a process which is polling a file
207  * gets notified when that file is revoke()d.
208  */
209 static int
210 dead_poll(ap)
211         struct vop_poll_args *ap;
212 {
213         return (POLLHUP);
214 }
215
216 static int
217 dead_rename(ap)
218         struct vop_rename_args  /* {
219                 struct vnode *a_fdvp;
220                 struct vnode *a_fvp;
221                 struct componentname *a_fcnp;
222                 struct vnode *a_tdvp;
223                 struct vnode *a_tvp;
224                 struct componentname *a_tcnp;
225         } */ *ap;
226 {
227         if (ap->a_tvp)
228                 vput(ap->a_tvp);
229         if (ap->a_tdvp == ap->a_tvp)
230                 vrele(ap->a_tdvp);
231         else
232                 vput(ap->a_tdvp);
233         vrele(ap->a_fdvp);
234         vrele(ap->a_fvp);
235         return (EXDEV);
236 }