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