]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
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. | |
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> | |
61 | #include <sys/vnode.h> | |
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 | */ | |
70 | int dead_badop(), | |
71 | dead_ebadf(); | |
72 | int dead_lookup __P((struct vop_lookup_args *)); | |
73 | #define dead_create ((int (*) __P((struct vop_create_args *)))dead_badop) | |
74 | #define dead_mknod ((int (*) __P((struct vop_mknod_args *)))dead_badop) | |
75 | int dead_open __P((struct vop_open_args *)); | |
76 | #define dead_close ((int (*) __P((struct vop_close_args *)))nullop) | |
77 | #define dead_access ((int (*) __P((struct vop_access_args *)))dead_ebadf) | |
78 | #define dead_getattr ((int (*) __P((struct vop_getattr_args *)))dead_ebadf) | |
79 | #define dead_setattr ((int (*) __P((struct vop_setattr_args *)))dead_ebadf) | |
80 | int dead_read __P((struct vop_read_args *)); | |
81 | int dead_write __P((struct vop_write_args *)); | |
82 | int dead_ioctl __P((struct vop_ioctl_args *)); | |
83 | int dead_select __P((struct vop_select_args *)); | |
84 | #define dead_mmap ((int (*) __P((struct vop_mmap_args *)))dead_badop) | |
85 | #define dead_fsync ((int (*) __P((struct vop_fsync_args *)))nullop) | |
86 | #define dead_seek ((int (*) __P((struct vop_seek_args *)))nullop) | |
87 | #define dead_remove ((int (*) __P((struct vop_remove_args *)))dead_badop) | |
88 | #define dead_link ((int (*) __P((struct vop_link_args *)))dead_badop) | |
89 | #define dead_rename ((int (*) __P((struct vop_rename_args *)))dead_badop) | |
90 | #define dead_mkdir ((int (*) __P((struct vop_mkdir_args *)))dead_badop) | |
91 | #define dead_rmdir ((int (*) __P((struct vop_rmdir_args *)))dead_badop) | |
92 | #define dead_symlink ((int (*) __P((struct vop_symlink_args *)))dead_badop) | |
93 | #define dead_readdir ((int (*) __P((struct vop_readdir_args *)))dead_ebadf) | |
94 | #define dead_readlink ((int (*) __P((struct vop_readlink_args *)))dead_ebadf) | |
95 | #define dead_abortop ((int (*) __P((struct vop_abortop_args *)))dead_badop) | |
96 | #define dead_inactive ((int (*) __P((struct vop_inactive_args *)))nullop) | |
97 | #define dead_reclaim ((int (*) __P((struct vop_reclaim_args *)))nullop) | |
98 | int dead_lock __P((struct vop_lock_args *)); | |
99 | #define dead_unlock ((int (*) __P((struct vop_unlock_args *)))nullop) | |
100 | int dead_bmap __P((struct vop_bmap_args *)); | |
101 | int dead_strategy __P((struct vop_strategy_args *)); | |
102 | int dead_print __P((struct vop_print_args *)); | |
103 | #define dead_islocked ((int (*) __P((struct vop_islocked_args *)))nullop) | |
104 | #define dead_pathconf ((int (*) __P((struct vop_pathconf_args *)))dead_ebadf) | |
105 | #define dead_advlock ((int (*) __P((struct vop_advlock_args *)))dead_ebadf) | |
106 | #define dead_blkatoff ((int (*) __P((struct vop_blkatoff_args *)))dead_badop) | |
107 | #define dead_valloc ((int (*) __P((struct vop_valloc_args *)))dead_badop) | |
108 | #define dead_vfree ((int (*) __P((struct vop_vfree_args *)))dead_badop) | |
109 | #define dead_truncate ((int (*) __P((struct vop_truncate_args *)))nullop) | |
110 | #define dead_update ((int (*) __P((struct vop_update_args *)))nullop) | |
111 | #define dead_bwrite ((int (*) __P((struct vop_bwrite_args *)))nullop) | |
112 | int dead_pagein __P((struct vop_pagein_args *)); | |
113 | int dead_pageout __P((struct vop_pageout_args *)); | |
114 | int dead_blktooff __P((struct vop_blktooff_args *)); | |
115 | int dead_offtoblk __P((struct vop_offtoblk_args *)); | |
116 | int dead_cmap __P((struct vop_cmap_args *)); | |
117 | ||
118 | #define VOPFUNC int (*)(void *) | |
119 | int (**dead_vnodeop_p)(void *); | |
120 | struct vnodeopv_entry_desc dead_vnodeop_entries[] = { | |
121 | { &vop_default_desc, (VOPFUNC)vn_default_error }, | |
122 | { &vop_lookup_desc, (VOPFUNC)dead_lookup }, /* lookup */ | |
123 | { &vop_create_desc, (VOPFUNC)dead_create }, /* create */ | |
124 | { &vop_mknod_desc, (VOPFUNC)dead_mknod }, /* mknod */ | |
125 | { &vop_open_desc, (VOPFUNC)dead_open }, /* open */ | |
126 | { &vop_close_desc, (VOPFUNC)dead_close }, /* close */ | |
127 | { &vop_access_desc, (VOPFUNC)dead_access }, /* access */ | |
128 | { &vop_getattr_desc, (VOPFUNC)dead_getattr }, /* getattr */ | |
129 | { &vop_setattr_desc, (VOPFUNC)dead_setattr }, /* setattr */ | |
130 | { &vop_read_desc, (VOPFUNC)dead_read }, /* read */ | |
131 | { &vop_write_desc, (VOPFUNC)dead_write }, /* write */ | |
132 | { &vop_ioctl_desc, (VOPFUNC)dead_ioctl }, /* ioctl */ | |
133 | { &vop_select_desc, (VOPFUNC)dead_select }, /* select */ | |
134 | { &vop_mmap_desc, (VOPFUNC)dead_mmap }, /* mmap */ | |
135 | { &vop_fsync_desc, (VOPFUNC)dead_fsync }, /* fsync */ | |
136 | { &vop_seek_desc, (VOPFUNC)dead_seek }, /* seek */ | |
137 | { &vop_remove_desc, (VOPFUNC)dead_remove }, /* remove */ | |
138 | { &vop_link_desc, (VOPFUNC)dead_link }, /* link */ | |
139 | { &vop_rename_desc, (VOPFUNC)dead_rename }, /* rename */ | |
140 | { &vop_mkdir_desc, (VOPFUNC)dead_mkdir }, /* mkdir */ | |
141 | { &vop_rmdir_desc, (VOPFUNC)dead_rmdir }, /* rmdir */ | |
142 | { &vop_symlink_desc, (VOPFUNC)dead_symlink }, /* symlink */ | |
143 | { &vop_readdir_desc, (VOPFUNC)dead_readdir }, /* readdir */ | |
144 | { &vop_readlink_desc, (VOPFUNC)dead_readlink }, /* readlink */ | |
145 | { &vop_abortop_desc, (VOPFUNC)dead_abortop }, /* abortop */ | |
146 | { &vop_inactive_desc, (VOPFUNC)dead_inactive }, /* inactive */ | |
147 | { &vop_reclaim_desc, (VOPFUNC)dead_reclaim }, /* reclaim */ | |
148 | { &vop_lock_desc, (VOPFUNC)dead_lock }, /* lock */ | |
149 | { &vop_unlock_desc, (VOPFUNC)dead_unlock }, /* unlock */ | |
150 | { &vop_bmap_desc, (VOPFUNC)dead_bmap }, /* bmap */ | |
151 | { &vop_strategy_desc, (VOPFUNC)dead_strategy }, /* strategy */ | |
152 | { &vop_print_desc, (VOPFUNC)dead_print }, /* print */ | |
153 | { &vop_islocked_desc, (VOPFUNC)dead_islocked }, /* islocked */ | |
154 | { &vop_pathconf_desc, (VOPFUNC)dead_pathconf }, /* pathconf */ | |
155 | { &vop_advlock_desc, (VOPFUNC)dead_advlock }, /* advlock */ | |
156 | { &vop_blkatoff_desc, (VOPFUNC)dead_blkatoff }, /* blkatoff */ | |
157 | { &vop_valloc_desc, (VOPFUNC)dead_valloc }, /* valloc */ | |
158 | { &vop_vfree_desc, (VOPFUNC)dead_vfree }, /* vfree */ | |
159 | { &vop_truncate_desc, (VOPFUNC)dead_truncate }, /* truncate */ | |
160 | { &vop_update_desc, (VOPFUNC)dead_update }, /* update */ | |
161 | { &vop_bwrite_desc, (VOPFUNC)dead_bwrite }, /* bwrite */ | |
162 | { &vop_pagein_desc, (VOPFUNC)err_pagein }, /* Pagein */ | |
163 | { &vop_pageout_desc, (VOPFUNC)err_pageout }, /* Pageout */ | |
164 | { &vop_copyfile_desc, (VOPFUNC)err_copyfile }, /* Copyfile */ | |
165 | { &vop_blktooff_desc, (VOPFUNC)dead_blktooff }, /* blktooff */ | |
166 | { &vop_offtoblk_desc, (VOPFUNC)dead_offtoblk }, /* offtoblk */ | |
167 | { &vop_cmap_desc, (VOPFUNC)dead_cmap }, /* cmap */ | |
168 | { (struct vnodeop_desc*)NULL, (VOPFUNC)NULL } | |
169 | }; | |
170 | struct vnodeopv_desc dead_vnodeop_opv_desc = | |
171 | { &dead_vnodeop_p, dead_vnodeop_entries }; | |
172 | ||
173 | /* | |
174 | * Trivial lookup routine that always fails. | |
175 | */ | |
176 | /* ARGSUSED */ | |
177 | int | |
178 | dead_lookup(ap) | |
179 | struct vop_lookup_args /* { | |
180 | struct vnode * a_dvp; | |
181 | struct vnode ** a_vpp; | |
182 | struct componentname * a_cnp; | |
183 | } */ *ap; | |
184 | { | |
185 | ||
186 | *ap->a_vpp = NULL; | |
187 | return (ENOTDIR); | |
188 | } | |
189 | ||
190 | /* | |
191 | * Open always fails as if device did not exist. | |
192 | */ | |
193 | /* ARGSUSED */ | |
194 | int | |
195 | dead_open(ap) | |
196 | struct vop_open_args /* { | |
197 | struct vnode *a_vp; | |
198 | int a_mode; | |
199 | struct ucred *a_cred; | |
200 | struct proc *a_p; | |
201 | } */ *ap; | |
202 | { | |
203 | ||
204 | return (ENXIO); | |
205 | } | |
206 | ||
207 | /* | |
208 | * Vnode op for read | |
209 | */ | |
210 | /* ARGSUSED */ | |
211 | int | |
212 | dead_read(ap) | |
213 | struct vop_read_args /* { | |
214 | struct vnode *a_vp; | |
215 | struct uio *a_uio; | |
216 | int a_ioflag; | |
217 | struct ucred *a_cred; | |
218 | } */ *ap; | |
219 | { | |
220 | ||
221 | if (chkvnlock(ap->a_vp)) | |
222 | panic("dead_read: lock"); | |
223 | /* | |
224 | * Return EOF for character devices, EIO for others | |
225 | */ | |
226 | if (ap->a_vp->v_type != VCHR) | |
227 | return (EIO); | |
228 | return (0); | |
229 | } | |
230 | ||
231 | /* | |
232 | * Vnode op for write | |
233 | */ | |
234 | /* ARGSUSED */ | |
235 | int | |
236 | dead_write(ap) | |
237 | struct vop_write_args /* { | |
238 | struct vnode *a_vp; | |
239 | struct uio *a_uio; | |
240 | int a_ioflag; | |
241 | struct ucred *a_cred; | |
242 | } */ *ap; | |
243 | { | |
244 | ||
245 | if (chkvnlock(ap->a_vp)) | |
246 | panic("dead_write: lock"); | |
247 | return (EIO); | |
248 | } | |
249 | ||
250 | /* | |
251 | * Device ioctl operation. | |
252 | */ | |
253 | /* ARGSUSED */ | |
254 | int | |
255 | dead_ioctl(ap) | |
256 | struct vop_ioctl_args /* { | |
257 | struct vnode *a_vp; | |
258 | u_long a_command; | |
259 | caddr_t a_data; | |
260 | int a_fflag; | |
261 | struct ucred *a_cred; | |
262 | struct proc *a_p; | |
263 | } */ *ap; | |
264 | { | |
265 | ||
266 | if (!chkvnlock(ap->a_vp)) | |
267 | return (EBADF); | |
268 | return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap)); | |
269 | } | |
270 | ||
271 | /* ARGSUSED */ | |
272 | int | |
273 | dead_select(ap) | |
274 | struct vop_select_args /* { | |
275 | struct vnode *a_vp; | |
276 | int a_which; | |
277 | int a_fflags; | |
278 | struct ucred *a_cred; | |
0b4e3aa0 | 279 | void *a_wql; |
1c79356b A |
280 | struct proc *a_p; |
281 | } */ *ap; | |
282 | { | |
283 | ||
284 | /* | |
285 | * Let the user find out that the descriptor is gone. | |
286 | */ | |
287 | return (1); | |
288 | } | |
289 | ||
290 | /* | |
291 | * Just call the device strategy routine | |
292 | */ | |
293 | int | |
294 | dead_strategy(ap) | |
295 | struct vop_strategy_args /* { | |
296 | struct buf *a_bp; | |
297 | } */ *ap; | |
298 | { | |
299 | ||
300 | if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) { | |
301 | ap->a_bp->b_flags |= B_ERROR; | |
302 | biodone(ap->a_bp); | |
303 | return (EIO); | |
304 | } | |
305 | return (VOP_STRATEGY(ap->a_bp)); | |
306 | } | |
307 | ||
308 | /* | |
309 | * Wait until the vnode has finished changing state. | |
310 | */ | |
311 | int | |
312 | dead_lock(ap) | |
313 | struct vop_lock_args /* { | |
314 | struct vnode *a_vp; | |
315 | } */ *ap; | |
316 | { | |
317 | ||
318 | struct vnode *vp = ap->a_vp; | |
319 | ||
320 | /* | |
321 | * Since we are not using the lock manager, we must clear | |
322 | * the interlock here. | |
323 | */ | |
324 | if (ap->a_flags & LK_INTERLOCK) { | |
325 | simple_unlock(&vp->v_interlock); | |
326 | ap->a_flags &= ~LK_INTERLOCK; | |
327 | } | |
328 | if (!chkvnlock(ap->a_vp)) | |
329 | return (0); | |
330 | return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap)); | |
331 | } | |
332 | ||
333 | /* | |
334 | * Wait until the vnode has finished changing state. | |
335 | */ | |
336 | int | |
337 | dead_bmap(ap) | |
338 | struct vop_bmap_args /* { | |
339 | struct vnode *a_vp; | |
340 | daddr_t a_bn; | |
341 | struct vnode **a_vpp; | |
342 | daddr_t *a_bnp; | |
343 | int *a_runp; | |
344 | } */ *ap; | |
345 | { | |
346 | ||
347 | if (!chkvnlock(ap->a_vp)) | |
348 | return (EIO); | |
349 | return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp)); | |
350 | } | |
351 | ||
352 | /* | |
353 | * Wait until the vnode has finished changing state. | |
354 | */ | |
355 | int | |
356 | dead_cmap(ap) | |
357 | struct vop_cmap_args /* { | |
358 | struct vnode *a_vp; | |
359 | off_t a_foffset; | |
360 | size_t a_size; | |
361 | daddr_t *a_bpn; | |
362 | size_t *a_run; | |
363 | void *a_poff; | |
364 | } */ *ap; | |
365 | { | |
366 | ||
367 | if (!chkvnlock(ap->a_vp)) | |
368 | return (EIO); | |
369 | return (VOP_CMAP(ap->a_vp, ap->a_foffset, ap->a_size, ap->a_bpn, ap->a_run, ap->a_poff)); | |
370 | } | |
371 | ||
372 | /* | |
373 | * Print out the contents of a dead vnode. | |
374 | */ | |
375 | /* ARGSUSED */ | |
376 | int | |
377 | dead_print(ap) | |
378 | struct vop_print_args /* { | |
379 | struct vnode *a_vp; | |
380 | } */ *ap; | |
381 | { | |
382 | ||
383 | printf("tag VT_NON, dead vnode\n"); | |
384 | } | |
385 | ||
386 | /* | |
387 | * Empty vnode failed operation | |
388 | */ | |
389 | int | |
390 | dead_ebadf() | |
391 | { | |
392 | ||
393 | return (EBADF); | |
394 | } | |
395 | ||
396 | /* | |
397 | * Empty vnode bad operation | |
398 | */ | |
399 | int | |
400 | dead_badop() | |
401 | { | |
402 | ||
403 | panic("dead_badop called"); | |
404 | /* NOTREACHED */ | |
405 | } | |
406 | ||
407 | /* | |
408 | * Empty vnode null operation | |
409 | */ | |
410 | int | |
411 | dead_nullop() | |
412 | { | |
413 | ||
414 | return (0); | |
415 | } | |
416 | ||
417 | /* | |
418 | * We have to wait during times when the vnode is | |
419 | * in a state of change. | |
420 | */ | |
421 | int | |
422 | chkvnlock(vp) | |
423 | register struct vnode *vp; | |
424 | { | |
425 | int locked = 0; | |
426 | ||
427 | while (vp->v_flag & VXLOCK) { | |
428 | vp->v_flag |= VXWANT; | |
429 | sleep((caddr_t)vp, PINOD); | |
430 | locked = 1; | |
431 | } | |
432 | return (locked); | |
433 | } | |
434 | ||
435 | ||
436 | /* Blktooff */ | |
437 | int | |
438 | dead_blktooff(ap) | |
439 | struct vop_blktooff_args /* { | |
440 | struct vnode *a_vp; | |
441 | daddr_t a_lblkno; | |
442 | off_t *a_offset; | |
443 | } */ *ap; | |
444 | { | |
445 | if (!chkvnlock(ap->a_vp)) | |
446 | return (EIO); | |
447 | ||
448 | *ap->a_offset = (off_t)-1; /* failure */ | |
449 | return (0); | |
450 | } | |
451 | /* Blktooff */ | |
452 | int | |
453 | dead_offtoblk(ap) | |
454 | struct vop_offtoblk_args /* { | |
455 | struct vnode *a_vp; | |
456 | off_t a_offset; | |
457 | daddr_t *a_lblkno; | |
458 | } */ *ap; | |
459 | { | |
460 | if (!chkvnlock(ap->a_vp)) | |
461 | return (EIO); | |
462 | ||
463 | *ap->a_lblkno = (daddr_t)-1; /* failure */ | |
464 | return (0); | |
465 | } |