]> git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/deadfs/dead_vnops.c
84ab174d64e3a65605cf61f27571f8753b9104d4
[apple/xnu.git] / bsd / miscfs / deadfs / dead_vnops.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 /*
25 * Copyright (c) 1989, 1993
26 * The Regents of the University of California. All rights reserved.
27 *
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
30 * are met:
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
43 *
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * SUCH DAMAGE.
55 *
56 * @(#)dead_vnops.c 8.3 (Berkeley) 5/14/95
57 */
58
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/time.h>
62 #include <sys/vnode_internal.h>
63 #include <sys/errno.h>
64 #include <sys/namei.h>
65 #include <sys/buf.h>
66 #include <vfs/vfs_support.h>
67
68 /*
69 * Prototypes for dead operations on vnodes.
70 */
71 int dead_badop(void *);
72 int dead_ebadf(void *);
73 int dead_lookup(struct vnop_lookup_args *);
74 #define dead_create (int (*)(struct vnop_create_args *))dead_badop
75 #define dead_mknod (int (*)(struct vnop_mknod_args *))dead_badop
76 int dead_open(struct vnop_open_args *);
77 #define dead_close (int (*)(struct vnop_close_args *))nullop
78 #define dead_access (int (*)(struct vnop_access_args *))dead_ebadf
79 #define dead_getattr (int (*)(struct vnop_getattr_args *))dead_ebadf
80 #define dead_setattr (int (*)(struct vnop_setattr_args *))dead_ebadf
81 int dead_read(struct vnop_read_args *);
82 int dead_write(struct vnop_write_args *);
83 int dead_ioctl(struct vnop_ioctl_args *);
84 int dead_select(struct vnop_select_args *);
85 #define dead_mmap (int (*)(struct vnop_mmap_args *))dead_badop
86 #define dead_fsync (int (*)(struct vnop_fsync_args *))nullop
87 #define dead_remove (int (*)(struct vnop_remove_args ))dead_badop
88 #define dead_link (int (*)(struct vnop_link_args *))dead_badop
89 #define dead_rename (int (*)(struct vnop_rename_args *))dead_badop
90 #define dead_mkdir (int (*)(struct vnop_mkdir_args *))dead_badop
91 #define dead_rmdir (int (*)(struct vnop_rmdir_args *))dead_badop
92 #define dead_symlink (int (*)(struct vnop_symlink_args *))dead_badop
93 #define dead_readdir (int (*)(struct vnop_readdir_args *))dead_ebadf
94 #define dead_readlink (int (*)(struct vnop_readlink_args *))dead_ebadf
95 #define dead_inactive (int (*)(struct vnop_inactive_args *))nullop
96 #define dead_reclaim (int (*)(struct vnop_reclaim_args *))nullop
97 int dead_strategy(struct vnop_strategy_args *);
98 #define dead_pathconf (int (*)(struct vnop_pathconf_args *))dead_ebadf
99 #define dead_advlock (int (*)(struct vnop_advlock_args *))dead_ebadf
100 #define dead_bwrite (int (*)(struct vnop_bwrite_args *))nullop
101 int dead_pagein(struct vnop_pagein_args *);
102 int dead_pageout(struct vnop_pageout_args *);
103 int dead_blktooff(struct vnop_blktooff_args *);
104 int dead_offtoblk(struct vnop_offtoblk_args *);
105 int dead_blockmap(struct vnop_blockmap_args *);
106
107 #define VOPFUNC int (*)(void *)
108 int (**dead_vnodeop_p)(void *);
109 struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
110 { &vnop_default_desc, (VOPFUNC)vn_default_error },
111 { &vnop_lookup_desc, (VOPFUNC)dead_lookup }, /* lookup */
112 { &vnop_create_desc, (VOPFUNC)dead_create }, /* create */
113 { &vnop_open_desc, (VOPFUNC)dead_open }, /* open */
114 { &vnop_mknod_desc, (VOPFUNC)dead_mknod }, /* mknod */
115 { &vnop_close_desc, (VOPFUNC)dead_close }, /* close */
116 { &vnop_access_desc, (VOPFUNC)dead_access }, /* access */
117 { &vnop_getattr_desc, (VOPFUNC)dead_getattr }, /* getattr */
118 { &vnop_setattr_desc, (VOPFUNC)dead_setattr }, /* setattr */
119 { &vnop_read_desc, (VOPFUNC)dead_read }, /* read */
120 { &vnop_write_desc, (VOPFUNC)dead_write }, /* write */
121 { &vnop_ioctl_desc, (VOPFUNC)dead_ioctl }, /* ioctl */
122 { &vnop_select_desc, (VOPFUNC)dead_select }, /* select */
123 { &vnop_mmap_desc, (VOPFUNC)dead_mmap }, /* mmap */
124 { &vnop_fsync_desc, (VOPFUNC)dead_fsync }, /* fsync */
125 { &vnop_remove_desc, (VOPFUNC)dead_remove }, /* remove */
126 { &vnop_link_desc, (VOPFUNC)dead_link }, /* link */
127 { &vnop_rename_desc, (VOPFUNC)dead_rename }, /* rename */
128 { &vnop_mkdir_desc, (VOPFUNC)dead_mkdir }, /* mkdir */
129 { &vnop_rmdir_desc, (VOPFUNC)dead_rmdir }, /* rmdir */
130 { &vnop_symlink_desc, (VOPFUNC)dead_symlink }, /* symlink */
131 { &vnop_readdir_desc, (VOPFUNC)dead_readdir }, /* readdir */
132 { &vnop_readlink_desc, (VOPFUNC)dead_readlink }, /* readlink */
133 { &vnop_inactive_desc, (VOPFUNC)dead_inactive }, /* inactive */
134 { &vnop_reclaim_desc, (VOPFUNC)dead_reclaim }, /* reclaim */
135 { &vnop_strategy_desc, (VOPFUNC)dead_strategy }, /* strategy */
136 { &vnop_pathconf_desc, (VOPFUNC)dead_pathconf }, /* pathconf */
137 { &vnop_advlock_desc, (VOPFUNC)dead_advlock }, /* advlock */
138 { &vnop_bwrite_desc, (VOPFUNC)dead_bwrite }, /* bwrite */
139 { &vnop_pagein_desc, (VOPFUNC)err_pagein }, /* Pagein */
140 { &vnop_pageout_desc, (VOPFUNC)err_pageout }, /* Pageout */
141 { &vnop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copyfile */
142 { &vnop_blktooff_desc, (VOPFUNC)dead_blktooff }, /* blktooff */
143 { &vnop_offtoblk_desc, (VOPFUNC)dead_offtoblk }, /* offtoblk */
144 { &vnop_blockmap_desc, (VOPFUNC)dead_blockmap }, /* blockmap */
145 { (struct vnodeop_desc*)NULL, (VOPFUNC)NULL }
146 };
147 struct vnodeopv_desc dead_vnodeop_opv_desc =
148 { &dead_vnodeop_p, dead_vnodeop_entries };
149
150 /*
151 * Trivial lookup routine that always fails.
152 */
153 /* ARGSUSED */
154 int
155 dead_lookup(ap)
156 struct vnop_lookup_args /* {
157 struct vnode * a_dvp;
158 struct vnode ** a_vpp;
159 struct componentname * a_cnp;
160 vfs_context_t a_context;
161 } */ *ap;
162 {
163
164 *ap->a_vpp = NULL;
165 return (ENOTDIR);
166 }
167
168 /*
169 * Open always fails as if device did not exist.
170 */
171 /* ARGSUSED */
172 int
173 dead_open(ap)
174 struct vnop_open_args /* {
175 struct vnode *a_vp;
176 int a_mode;
177 vfs_context_t a_context;
178 } */ *ap;
179 {
180
181 return (ENXIO);
182 }
183
184 /*
185 * Vnode op for read
186 */
187 /* ARGSUSED */
188 int
189 dead_read(ap)
190 struct vnop_read_args /* {
191 struct vnode *a_vp;
192 struct uio *a_uio;
193 int a_ioflag;
194 vfs_context_t a_context;
195 } */ *ap;
196 {
197
198 if (chkvnlock(ap->a_vp))
199 panic("dead_read: lock");
200 /*
201 * Return EOF for character devices, EIO for others
202 */
203 if (ap->a_vp->v_type != VCHR)
204 return (EIO);
205 return (0);
206 }
207
208 /*
209 * Vnode op for write
210 */
211 /* ARGSUSED */
212 int
213 dead_write(ap)
214 struct vnop_write_args /* {
215 struct vnode *a_vp;
216 struct uio *a_uio;
217 int a_ioflag;
218 vfs_context_t a_context;
219 } */ *ap;
220 {
221
222 if (chkvnlock(ap->a_vp))
223 panic("dead_write: lock");
224 return (EIO);
225 }
226
227 /*
228 * Device ioctl operation.
229 */
230 /* ARGSUSED */
231 int
232 dead_ioctl(ap)
233 struct vnop_ioctl_args /* {
234 struct vnode *a_vp;
235 u_long a_command;
236 caddr_t a_data;
237 int a_fflag;
238 vfs_context_t a_context;
239 } */ *ap;
240 {
241
242 if (!chkvnlock(ap->a_vp))
243 return (EBADF);
244 return (VCALL(ap->a_vp, VOFFSET(vnop_ioctl), ap));
245 }
246
247 /* ARGSUSED */
248 int
249 dead_select(ap)
250 struct vnop_select_args /* {
251 struct vnode *a_vp;
252 int a_which;
253 int a_fflags;
254 kauth_cred_t a_cred;
255 void *a_wql;
256 struct proc *a_p;
257 } */ *ap;
258 {
259
260 /*
261 * Let the user find out that the descriptor is gone.
262 */
263 return (1);
264 }
265
266 /*
267 * Just call the device strategy routine
268 */
269 int
270 dead_strategy(ap)
271 struct vnop_strategy_args /* {
272 struct buf *a_bp;
273 } */ *ap;
274 {
275
276 if (buf_vnode(ap->a_bp) == NULL || !chkvnlock(buf_vnode(ap->a_bp))) {
277 buf_seterror(ap->a_bp, EIO);
278 buf_biodone(ap->a_bp);
279 return (EIO);
280 }
281 return (VNOP_STRATEGY(ap->a_bp));
282 }
283
284 /*
285 * Wait until the vnode has finished changing state.
286 */
287 int
288 dead_blockmap(ap)
289 struct vnop_blockmap_args /* {
290 struct vnode *a_vp;
291 off_t a_foffset;
292 size_t a_size;
293 daddr64_t *a_bpn;
294 size_t *a_run;
295 void *a_poff;
296 int flags;
297 vfs_context_t a_context;
298 } */ *ap;
299 {
300
301 if (!chkvnlock(ap->a_vp))
302 return (EIO);
303 return (VNOP_BLOCKMAP(ap->a_vp, ap->a_foffset, ap->a_size, ap->a_bpn,
304 ap->a_run, ap->a_poff, ap->a_flags, ap->a_context));
305 }
306
307 /*
308 * Empty vnode failed operation
309 */
310 /* ARGSUSED */
311 int
312 dead_ebadf(void *dummy)
313 {
314
315 return (EBADF);
316 }
317
318 /*
319 * Empty vnode bad operation
320 */
321 /* ARGSUSED */
322 int
323 dead_badop(void *dummy)
324 {
325
326 panic("dead_badop called");
327 /* NOTREACHED */
328 }
329
330 /*
331 * Empty vnode null operation
332 */
333 /* ARGSUSED */
334 int
335 dead_nullop(void *dummy)
336 {
337
338 return (0);
339 }
340
341 /*
342 * We have to wait during times when the vnode is
343 * in a state of change.
344 */
345 int
346 chkvnlock(__unused vnode_t vp)
347 {
348 return (0);
349 }
350
351
352 /* Blktooff */
353 int
354 dead_blktooff(ap)
355 struct vnop_blktooff_args /* {
356 struct vnode *a_vp;
357 daddr64_t a_lblkno;
358 off_t *a_offset;
359 } */ *ap;
360 {
361 if (!chkvnlock(ap->a_vp))
362 return (EIO);
363
364 *ap->a_offset = (off_t)-1; /* failure */
365 return (0);
366 }
367 /* Blktooff */
368 int
369 dead_offtoblk(ap)
370 struct vnop_offtoblk_args /* {
371 struct vnode *a_vp;
372 off_t a_offset;
373 daddr64_t *a_lblkno;
374 } */ *ap;
375 {
376 if (!chkvnlock(ap->a_vp))
377 return (EIO);
378
379 *ap->a_lblkno = (daddr64_t)-1; /* failure */
380 return (0);
381 }