]> git.saurik.com Git - apple/xnu.git/blame - bsd/miscfs/deadfs/dead_vnops.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / miscfs / deadfs / dead_vnops.c
CommitLineData
1c79356b 1/*
cb323159 2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 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
0a7de745 73int chkvnlock(vnode_t vp);
2d21ac55 74
1c79356b
A
75/*
76 * Prototypes for dead operations on vnodes.
77 */
0a7de745
A
78int dead_badop(void *);
79int dead_ebadf(void *);
80int dead_lookup(struct vnop_lookup_args *);
91447636
A
81#define dead_create (int (*)(struct vnop_create_args *))dead_badop
82#define dead_mknod (int (*)(struct vnop_mknod_args *))dead_badop
0a7de745 83int dead_open(struct vnop_open_args *);
91447636
A
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
0a7de745
A
88int dead_read(struct vnop_read_args *);
89int dead_write(struct vnop_write_args *);
90int dead_ioctl(struct vnop_ioctl_args *);
91int dead_select(struct vnop_select_args *);
91447636
A
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
0a7de745 104int dead_strategy(struct vnop_strategy_args *);
91447636
A
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
0a7de745
A
108int dead_pagein(struct vnop_pagein_args *);
109int dead_pageout(struct vnop_pageout_args *);
91447636
A
110int dead_blktooff(struct vnop_blktooff_args *);
111int dead_offtoblk(struct vnop_offtoblk_args *);
112int dead_blockmap(struct vnop_blockmap_args *);
1c79356b
A
113
114#define VOPFUNC int (*)(void *)
0a7de745 115int(**dead_vnodeop_p)(void *);
cb323159
A
116const struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
117 { .opve_op = &vnop_default_desc, .opve_impl = (VOPFUNC)vn_default_error },
118 { .opve_op = &vnop_lookup_desc, .opve_impl = (VOPFUNC)dead_lookup }, /* lookup */
119 { .opve_op = &vnop_create_desc, .opve_impl = (VOPFUNC)dead_create }, /* create */
120 { .opve_op = &vnop_open_desc, .opve_impl = (VOPFUNC)dead_open }, /* open */
121 { .opve_op = &vnop_mknod_desc, .opve_impl = (VOPFUNC)dead_mknod }, /* mknod */
122 { .opve_op = &vnop_close_desc, .opve_impl = (VOPFUNC)dead_close }, /* close */
123 { .opve_op = &vnop_access_desc, .opve_impl = (VOPFUNC)dead_access }, /* access */
124 { .opve_op = &vnop_getattr_desc, .opve_impl = (VOPFUNC)dead_getattr }, /* getattr */
125 { .opve_op = &vnop_setattr_desc, .opve_impl = (VOPFUNC)dead_setattr }, /* setattr */
126 { .opve_op = &vnop_read_desc, .opve_impl = (VOPFUNC)dead_read }, /* read */
127 { .opve_op = &vnop_write_desc, .opve_impl = (VOPFUNC)dead_write }, /* write */
128 { .opve_op = &vnop_ioctl_desc, .opve_impl = (VOPFUNC)dead_ioctl }, /* ioctl */
129 { .opve_op = &vnop_select_desc, .opve_impl = (VOPFUNC)dead_select }, /* select */
130 { .opve_op = &vnop_mmap_desc, .opve_impl = (VOPFUNC)dead_mmap }, /* mmap */
131 { .opve_op = &vnop_fsync_desc, .opve_impl = (VOPFUNC)dead_fsync }, /* fsync */
132 { .opve_op = &vnop_remove_desc, .opve_impl = (VOPFUNC)dead_remove }, /* remove */
133 { .opve_op = &vnop_link_desc, .opve_impl = (VOPFUNC)dead_link }, /* link */
134 { .opve_op = &vnop_rename_desc, .opve_impl = (VOPFUNC)dead_rename }, /* rename */
135 { .opve_op = &vnop_mkdir_desc, .opve_impl = (VOPFUNC)dead_mkdir }, /* mkdir */
136 { .opve_op = &vnop_rmdir_desc, .opve_impl = (VOPFUNC)dead_rmdir }, /* rmdir */
137 { .opve_op = &vnop_symlink_desc, .opve_impl = (VOPFUNC)dead_symlink }, /* symlink */
138 { .opve_op = &vnop_readdir_desc, .opve_impl = (VOPFUNC)dead_readdir }, /* readdir */
139 { .opve_op = &vnop_readlink_desc, .opve_impl = (VOPFUNC)dead_readlink }, /* readlink */
140 { .opve_op = &vnop_inactive_desc, .opve_impl = (VOPFUNC)dead_inactive }, /* inactive */
141 { .opve_op = &vnop_reclaim_desc, .opve_impl = (VOPFUNC)dead_reclaim }, /* reclaim */
142 { .opve_op = &vnop_strategy_desc, .opve_impl = (VOPFUNC)dead_strategy }, /* strategy */
143 { .opve_op = &vnop_pathconf_desc, .opve_impl = (VOPFUNC)dead_pathconf }, /* pathconf */
144 { .opve_op = &vnop_advlock_desc, .opve_impl = (VOPFUNC)dead_advlock }, /* advlock */
145 { .opve_op = &vnop_bwrite_desc, .opve_impl = (VOPFUNC)dead_bwrite }, /* bwrite */
146 { .opve_op = &vnop_pagein_desc, .opve_impl = (VOPFUNC)err_pagein }, /* Pagein */
147 { .opve_op = &vnop_pageout_desc, .opve_impl = (VOPFUNC)err_pageout }, /* Pageout */
148 { .opve_op = &vnop_copyfile_desc, .opve_impl = (VOPFUNC)err_copyfile }, /* Copyfile */
149 { .opve_op = &vnop_blktooff_desc, .opve_impl = (VOPFUNC)dead_blktooff }, /* blktooff */
150 { .opve_op = &vnop_offtoblk_desc, .opve_impl = (VOPFUNC)dead_offtoblk }, /* offtoblk */
151 { .opve_op = &vnop_blockmap_desc, .opve_impl = (VOPFUNC)dead_blockmap }, /* blockmap */
152 { .opve_op = (struct vnodeop_desc*)NULL, .opve_impl = (VOPFUNC)NULL }
1c79356b 153};
cb323159
A
154const struct vnodeopv_desc dead_vnodeop_opv_desc =
155{ .opv_desc_vector_p = &dead_vnodeop_p, .opv_desc_ops = dead_vnodeop_entries };
1c79356b
A
156
157/*
158 * Trivial lookup routine that always fails.
159 */
160/* ARGSUSED */
161int
2d21ac55 162dead_lookup(struct vnop_lookup_args *ap)
1c79356b 163{
1c79356b 164 *ap->a_vpp = NULL;
0a7de745 165 return ENOTDIR;
1c79356b
A
166}
167
168/*
169 * Open always fails as if device did not exist.
170 */
171/* ARGSUSED */
172int
2d21ac55 173dead_open(__unused struct vnop_open_args *ap)
1c79356b 174{
0a7de745 175 return ENXIO;
1c79356b
A
176}
177
178/*
179 * Vnode op for read
180 */
181/* ARGSUSED */
182int
2d21ac55 183dead_read(struct vnop_read_args *ap)
1c79356b 184{
0a7de745 185 if (chkvnlock(ap->a_vp)) {
1c79356b 186 panic("dead_read: lock");
0a7de745 187 }
1c79356b
A
188 /*
189 * Return EOF for character devices, EIO for others
190 */
0a7de745
A
191 if (ap->a_vp->v_type != VCHR) {
192 return EIO;
193 }
194 return 0;
1c79356b
A
195}
196
197/*
198 * Vnode op for write
199 */
200/* ARGSUSED */
201int
2d21ac55 202dead_write(struct vnop_write_args *ap)
1c79356b 203{
0a7de745 204 if (chkvnlock(ap->a_vp)) {
1c79356b 205 panic("dead_write: lock");
0a7de745
A
206 }
207 return EIO;
1c79356b
A
208}
209
210/*
211 * Device ioctl operation.
212 */
213/* ARGSUSED */
214int
2d21ac55 215dead_ioctl(struct vnop_ioctl_args *ap)
1c79356b 216{
0a7de745
A
217 if (!chkvnlock(ap->a_vp)) {
218 return EBADF;
219 }
220 return VCALL(ap->a_vp, VOFFSET(vnop_ioctl), ap);
1c79356b
A
221}
222
223/* ARGSUSED */
224int
2d21ac55 225dead_select(__unused struct vnop_select_args *ap)
1c79356b 226{
1c79356b
A
227 /*
228 * Let the user find out that the descriptor is gone.
229 */
0a7de745 230 return 1;
1c79356b
A
231}
232
233/*
234 * Just call the device strategy routine
235 */
236int
2d21ac55 237dead_strategy(struct vnop_strategy_args *ap)
1c79356b 238{
91447636 239 if (buf_vnode(ap->a_bp) == NULL || !chkvnlock(buf_vnode(ap->a_bp))) {
0a7de745 240 buf_seterror(ap->a_bp, EIO);
91447636 241 buf_biodone(ap->a_bp);
0a7de745 242 return EIO;
1c79356b 243 }
0a7de745 244 return VNOP_STRATEGY(ap->a_bp);
1c79356b
A
245}
246
247/*
248 * Wait until the vnode has finished changing state.
249 */
250int
2d21ac55 251dead_blockmap(struct vnop_blockmap_args *ap)
1c79356b 252{
0a7de745
A
253 if (!chkvnlock(ap->a_vp)) {
254 return EIO;
255 }
256 return VNOP_BLOCKMAP(ap->a_vp, ap->a_foffset, ap->a_size, ap->a_bpn,
257 ap->a_run, ap->a_poff, ap->a_flags, ap->a_context);
1c79356b
A
258}
259
260/*
261 * Empty vnode failed operation
262 */
91447636 263/* ARGSUSED */
1c79356b 264int
2d21ac55 265dead_ebadf(__unused void *dummy)
1c79356b 266{
0a7de745 267 return EBADF;
1c79356b
A
268}
269
270/*
271 * Empty vnode bad operation
272 */
91447636 273/* ARGSUSED */
1c79356b 274int
2d21ac55 275dead_badop(__unused void *dummy)
1c79356b 276{
1c79356b
A
277 panic("dead_badop called");
278 /* NOTREACHED */
0a7de745 279 return -1;
1c79356b
A
280}
281
282/*
283 * We have to wait during times when the vnode is
284 * in a state of change.
285 */
286int
91447636 287chkvnlock(__unused vnode_t vp)
1c79356b 288{
0a7de745 289 return 0;
1c79356b
A
290}
291
292
293/* Blktooff */
294int
2d21ac55 295dead_blktooff(struct vnop_blktooff_args *ap)
1c79356b 296{
0a7de745
A
297 if (!chkvnlock(ap->a_vp)) {
298 return EIO;
299 }
1c79356b 300
0a7de745
A
301 *ap->a_offset = (off_t)-1; /* failure */
302 return 0;
1c79356b
A
303}
304/* Blktooff */
305int
2d21ac55 306dead_offtoblk(struct vnop_offtoblk_args *ap)
1c79356b 307{
0a7de745
A
308 if (!chkvnlock(ap->a_vp)) {
309 return EIO;
310 }
1c79356b 311
0a7de745
A
312 *ap->a_lblkno = (daddr64_t)-1; /* failure */
313 return 0;
1c79356b 314}