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