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