]> git.saurik.com Git - apple/xnu.git/blob - bsd/vfs/vfs_support.c
xnu-3789.31.2.tar.gz
[apple/xnu.git] / bsd / vfs / vfs_support.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1998-1999 Apple Computer, Inc. All rights reserved.
30 *
31 * File: vfs/vfs_support.c
32 *
33 * The default VFS routines. A VFS plugin can use these
34 * functions in case it does not want to implement all. These functions
35 * take care of releasing locks and free up memory that they are
36 * supposed to.
37 *
38 * nop_* routines always return 0 [success]
39 * err_* routines always return ENOTSUP
40 *
41 * This file could be auto-generated from vnode_if.src. but that needs
42 * support for freeing cnp.
43 *
44 * HISTORY
45 * 15-Jul-1998 Earsh Nandkeshwar (earsh@apple.com)
46 * Fixed up readdirattr for its existance now.
47 * 18-Aug-1998 Umesh Vaishampayan (umeshv@apple.com)
48 * Created.
49 */
50
51 #include <vfs/vfs_support.h>
52 #include <sys/kauth.h>
53 #include <sys/ubc.h> /* ubc_upl_abort_range() */
54
55
56 struct vnop_create_args /* {
57 struct vnode *a_dvp;
58 struct vnode **a_vpp;
59 struct componentname *a_cnp;
60 struct vnode_vattr *a_vap;
61 vfs_context_t a_context;
62 } */;
63
64 int
65 nop_create(__unused struct vnop_create_args *ap)
66 {
67 #if DIAGNOSTIC
68 if ((ap->a_cnp->cn_flags & HASBUF) == 0)
69 panic("nop_create: no name");
70 #endif
71 return (0);
72 }
73
74 int
75 err_create(struct vnop_create_args *ap)
76 {
77 (void)nop_create(ap);
78 return (ENOTSUP);
79 }
80
81
82 struct vnop_whiteout_args /* {
83 struct vnode *a_dvp;
84 struct componentname *a_cnp;
85 int a_flags;
86 vfs_context_t a_context;
87 } */;
88
89 int
90 nop_whiteout(__unused struct vnop_whiteout_args *ap)
91 {
92 return (0);
93 }
94
95 int
96 err_whiteout(__unused struct vnop_whiteout_args *ap)
97 {
98 return (ENOTSUP);
99 }
100
101
102 struct vnop_mknod_args /* {
103 struct vnode *a_dvp;
104 struct vnode **a_vpp;
105 struct componentname *a_cnp;
106 struct vnode_vattr *a_vap;
107 vfs_context_t a_context;
108 } */;
109
110 int
111 nop_mknod(__unused struct vnop_mknod_args *ap)
112 {
113 #if DIAGNOSTIC
114 if ((ap->a_cnp->cn_flags & HASBUF) == 0)
115 panic("nop_mknod: no name");
116 #endif
117 return (0);
118 }
119
120 int
121 err_mknod(struct vnop_mknod_args *ap)
122 {
123 (void)nop_mknod(ap);
124 return (ENOTSUP);
125 }
126
127 struct vnop_open_args /* {
128 struct vnode *a_vp;
129 int a_mode;
130 vfs_context_t a_context;
131 } */;
132
133 int
134 nop_open(__unused struct vnop_open_args *ap)
135 {
136 return (0);
137 }
138
139 int
140 err_open(__unused struct vnop_open_args *ap)
141 {
142 return (ENOTSUP);
143 }
144
145
146 struct vnop_close_args /* {
147 struct vnode *a_vp;
148 int a_fflag;
149 vfs_context_t a_context;
150 } */;
151
152 int
153 nop_close(__unused struct vnop_close_args *ap)
154 {
155 return (0);
156 }
157
158 int
159 err_close(__unused struct vnop_close_args *ap)
160 {
161 return (ENOTSUP);
162 }
163
164
165 struct vnop_access_args /* {
166 struct vnode *a_vp;
167 int a_mode;
168 vfs_context_t a_context;
169 } */;
170
171 int
172 nop_access(__unused struct vnop_access_args *ap)
173 {
174 return (0);
175 }
176
177 int
178 err_access(__unused struct vnop_access_args *ap)
179 {
180 return (ENOTSUP);
181 }
182
183
184 struct vnop_getattr_args /* {
185 struct vnode *a_vp;
186 struct vnode_vattr *a_vap;
187 vfs_context_t a_context;
188 } */;
189
190 int
191 nop_getattr(__unused struct vnop_getattr_args *ap)
192 {
193 return (0);
194 }
195
196 int
197 err_getattr(__unused struct vnop_getattr_args *ap)
198 {
199 return (ENOTSUP);
200 }
201
202
203 struct vnop_setattr_args /* {
204 struct vnode *a_vp;
205 struct vnode_vattr *a_vap;
206 vfs_context_t a_context;
207 } */;
208
209 int
210 nop_setattr(__unused struct vnop_setattr_args *ap)
211 {
212 return (0);
213 }
214
215 int
216 err_setattr(__unused struct vnop_setattr_args *ap)
217 {
218 return (ENOTSUP);
219 }
220
221 struct vnop_read_args /* {
222 struct vnode *a_vp;
223 struct uio *a_uio;
224 int a_ioflag;
225 vfs_context_t a_context;
226 } */;
227
228 int
229 nop_read(__unused struct vnop_read_args *ap)
230 {
231 return (0);
232 }
233
234 int
235 err_read(__unused struct vnop_read_args *ap)
236 {
237 return (ENOTSUP);
238 }
239
240
241 struct vnop_write_args /* {
242 struct vnode *a_vp;
243 struct uio *a_uio;
244 int a_ioflag;
245 vfs_context_t a_context;
246 } */;
247
248 int
249 nop_write(__unused struct vnop_write_args *ap)
250 {
251 return (0);
252 }
253
254 int
255 err_write(__unused struct vnop_write_args *ap)
256 {
257 return (ENOTSUP);
258 }
259
260
261 struct vnop_ioctl_args /* {
262 struct vnode *a_vp;
263 u_long a_command;
264 caddr_t a_data;
265 int a_fflag;
266 kauth_cred_t a_cred;
267 struct proc *a_p;
268 } */;
269
270 int
271 nop_ioctl(__unused struct vnop_ioctl_args *ap)
272 {
273 return (0);
274 }
275
276 int
277 err_ioctl(__unused struct vnop_ioctl_args *ap)
278 {
279 return (ENOTSUP);
280 }
281
282
283 struct vnop_select_args /* {
284 struct vnode *a_vp;
285 int a_which;
286 int a_fflags;
287 kauth_cred_t a_cred;
288 void *a_wql;
289 struct proc *a_p;
290 } */;
291
292 int
293 nop_select(__unused struct vnop_select_args *ap)
294 {
295 return (0);
296 }
297
298 int
299 err_select(__unused struct vnop_select_args *ap)
300 {
301 return (ENOTSUP);
302 }
303
304
305 struct vnop_exchange_args /* {
306 struct vnode *a_fvp;
307 struct vnode *a_tvp;
308 int a_options;
309 vfs_context_t a_context;
310 } */;
311
312 int
313 nop_exchange(__unused struct vnop_exchange_args *ap)
314 {
315 return (0);
316 }
317
318 int
319 err_exchange(__unused struct vnop_exchange_args *ap)
320 {
321 return (ENOTSUP);
322 }
323
324
325 struct vnop_revoke_args /* {
326 struct vnode *a_vp;
327 int a_flags;
328 vfs_context_t a_context;
329 } */;
330
331 int
332 nop_revoke(struct vnop_revoke_args *ap)
333 {
334 return vn_revoke(ap->a_vp, ap->a_flags, ap->a_context);
335 }
336
337 int
338 err_revoke(struct vnop_revoke_args *ap)
339 {
340 (void)nop_revoke(ap);
341 return (ENOTSUP);
342 }
343
344
345 struct vnop_mmap_args /* {
346 struct vnode *a_vp;
347 int a_fflags;
348 kauth_cred_t a_cred;
349 struct proc *a_p;
350 } */;
351
352 int
353 nop_mmap(__unused struct vnop_mmap_args *ap)
354 {
355 return (0);
356 }
357
358 int
359 err_mmap(__unused struct vnop_mmap_args *ap)
360 {
361 return (ENOTSUP);
362 }
363
364
365 struct vnop_fsync_args /* {
366 struct vnode *a_vp;
367 int a_waitfor;
368 vfs_context_t a_context;
369 } */;
370
371 int
372 nop_fsync(__unused struct vnop_fsync_args *ap)
373 {
374 return (0);
375 }
376
377 int
378 err_fsync(__unused struct vnop_fsync_args *ap)
379 {
380 return (ENOTSUP);
381 }
382
383
384 struct vnop_remove_args /* {
385 struct vnode *a_dvp;
386 struct vnode *a_vp;
387 struct componentname *a_cnp;
388 int a_flags;
389 vfs_context_t a_context;
390 } */;
391
392 int
393 nop_remove(__unused struct vnop_remove_args *ap)
394 {
395 return (0);
396 }
397
398 int
399 err_remove(struct vnop_remove_args *ap)
400 {
401 (void)nop_remove(ap);
402 return (ENOTSUP);
403 }
404
405
406 struct vnop_link_args /* {
407 struct vnode *a_vp;
408 struct vnode *a_tdvp;
409 struct componentname *a_cnp;
410 vfs_context_t a_context;
411 } */;
412
413 int
414 nop_link(__unused struct vnop_link_args *ap)
415 {
416 return (0);
417 }
418
419 int
420 err_link(struct vnop_link_args *ap)
421 {
422 (void)nop_link(ap);
423 return (ENOTSUP);
424 }
425
426
427 struct vnop_rename_args /* {
428 struct vnode *a_fdvp;
429 struct vnode *a_fvp;
430 struct componentname *a_fcnp;
431 struct vnode *a_tdvp;
432 struct vnode *a_tvp;
433 struct componentname *a_tcnp;
434 vfs_context_t a_context;
435 } */;
436
437 int
438 nop_rename(__unused struct vnop_rename_args *ap)
439 {
440 return (0);
441 }
442
443 int
444 err_rename(struct vnop_rename_args *ap)
445 {
446 (void)nop_rename(ap);
447 return (ENOTSUP);
448 }
449
450
451 struct vnop_mkdir_args /* {
452 struct vnode *a_dvp;
453 struct vnode **a_vpp;
454 struct componentname *a_cnp;
455 struct vnode_vattr *a_vap;
456 vfs_context_t a_context;
457 } */;
458
459 int
460 nop_mkdir(__unused struct vnop_mkdir_args *ap)
461 {
462 return (0);
463 }
464
465 int
466 err_mkdir(__unused struct vnop_mkdir_args *ap)
467 {
468 return (ENOTSUP);
469 }
470
471
472 struct vnop_rmdir_args /* {
473 struct vnode *a_dvp;
474 struct vnode *a_vp;
475 struct componentname *a_cnp;
476 vfs_context_t a_context;
477 } */;
478
479 int
480 nop_rmdir(__unused struct vnop_rmdir_args *ap)
481 {
482 return (0);
483 }
484
485 int
486 err_rmdir(struct vnop_rmdir_args *ap)
487 {
488 (void)nop_rmdir(ap);
489 return (ENOTSUP);
490 }
491
492
493 struct vnop_symlink_args /* {
494 struct vnode *a_dvp;
495 struct vnode **a_vpp;
496 struct componentname *a_cnp;
497 struct vnode_vattr *a_vap;
498 char *a_target;
499 vfs_context_t a_context;
500 } */;
501
502 int
503 nop_symlink(__unused struct vnop_symlink_args *ap)
504 {
505 #if DIAGNOSTIC
506 if ((ap->a_cnp->cn_flags & HASBUF) == 0)
507 panic("nop_symlink: no name");
508 #endif
509 return (0);
510 }
511
512 int
513 err_symlink(struct vnop_symlink_args *ap)
514 {
515 (void)nop_symlink(ap);
516 return (ENOTSUP);
517 }
518
519
520 struct vnop_readdir_args /* {
521 vnode_t a_vp;
522 struct uio *a_uio;
523 int a_flags;
524 int *a_eofflag;
525 int *a_numdirent;
526 vfs_context_t a_context;
527 } */;
528
529 int
530 nop_readdir(__unused struct vnop_readdir_args *ap)
531 {
532 return (0);
533 }
534
535 int
536 err_readdir(__unused struct vnop_readdir_args *ap)
537 {
538 return (ENOTSUP);
539 }
540
541
542 struct vnop_readdirattr_args /* {
543 struct vnodeop_desc *a_desc;
544 vnode_t a_vp;
545 struct attrlist *a_alist;
546 struct uio *a_uio;
547 u_long a_maxcount;
548 u_long a_options;
549 u_long *a_newstate;
550 int *a_eofflag;
551 u_long *a_actualcount;
552 vfs_context_t a_context;
553 } */ ;
554
555 int
556 nop_readdirattr(struct vnop_readdirattr_args *ap)
557 {
558 *(ap->a_actualcount) = 0;
559 *(ap->a_eofflag) = 0;
560 return (0);
561 }
562
563 int
564 err_readdirattr(struct vnop_readdirattr_args *ap)
565 {
566 (void)nop_readdirattr(ap);
567 return (ENOTSUP);
568 }
569
570
571 struct vnop_readlink_args /* {
572 struct vnode *vp;
573 struct uio *uio;
574 vfs_context_t a_context;
575 } */;
576
577 int
578 nop_readlink(__unused struct vnop_readlink_args *ap)
579 {
580 return (0);
581 }
582
583 int
584 err_readlink(__unused struct vnop_readlink_args *ap)
585 {
586 return (ENOTSUP);
587 }
588
589
590 struct vnop_inactive_args /* {
591 struct vnode *a_vp;
592 vfs_context_t a_context;
593 } */;
594
595 int
596 nop_inactive(__unused struct vnop_inactive_args *ap)
597 {
598 return (0);
599 }
600
601 int
602 err_inactive(struct vnop_inactive_args *ap)
603 {
604 (void)nop_inactive(ap);
605 return (ENOTSUP);
606 }
607
608
609 struct vnop_reclaim_args /* {
610 struct vnode *a_vp;
611 vfs_context_t a_context;
612 } */;
613
614 int
615 nop_reclaim(__unused struct vnop_reclaim_args *ap)
616 {
617 return (0);
618 }
619
620 int
621 err_reclaim(__unused struct vnop_reclaim_args *ap)
622 {
623 return (ENOTSUP);
624 }
625
626
627 struct vnop_strategy_args /* {
628 struct buf *a_bp;
629 } */;
630
631 int
632 nop_strategy(__unused struct vnop_strategy_args *ap)
633 {
634 return (0);
635 }
636
637 int
638 err_strategy(__unused struct vnop_strategy_args *ap)
639 {
640 return (ENOTSUP);
641 }
642
643
644 struct vnop_pathconf_args /* {
645 struct vnode *a_vp;
646 int a_name;
647 int32_t *a_retval;
648 vfs_context_t a_context;
649 } */;
650
651 int
652 nop_pathconf(__unused struct vnop_pathconf_args *ap)
653 {
654 return (0);
655 }
656
657 int
658 err_pathconf(__unused struct vnop_pathconf_args *ap)
659 {
660 return (ENOTSUP);
661 }
662
663
664 struct vnop_advlock_args /* {
665 struct vnode *a_vp;
666 caddr_t a_id;
667 int a_op;
668 struct flock *a_fl;
669 int a_flags;
670 vfs_context_t a_context;
671 } */;
672
673 int
674 nop_advlock(__unused struct vnop_advlock_args *ap)
675 {
676 return (0);
677 }
678
679 int
680 err_advlock(__unused struct vnop_advlock_args *ap)
681 {
682 return (ENOTSUP);
683 }
684
685
686
687 struct vnop_allocate_args /* {
688 struct vnode *a_vp;
689 off_t a_length;
690 u_int32_t a_flags;
691 off_t *a_bytesallocated;
692 off_t a_offset;
693 vfs_context_t a_context;
694 } */;
695
696 int
697 nop_allocate(struct vnop_allocate_args *ap)
698 {
699 *(ap->a_bytesallocated) = 0;
700 return (0);
701 }
702
703 int
704 err_allocate(struct vnop_allocate_args *ap)
705 {
706 (void)nop_allocate(ap);
707 return (ENOTSUP);
708 }
709
710 struct vnop_bwrite_args /* {
711 struct buf *a_bp;
712 } */;
713
714 int
715 nop_bwrite(struct vnop_bwrite_args *ap)
716 {
717 return ((int)buf_bwrite(ap->a_bp));
718 }
719
720 int
721 err_bwrite(__unused struct vnop_bwrite_args *ap)
722 {
723 return (ENOTSUP);
724 }
725
726
727 struct vnop_pagein_args /* {
728 struct vnode *a_vp,
729 upl_t a_pl,
730 vm_offset_t a_pl_offset,
731 off_t a_foffset,
732 size_t a_size,
733 int a_flags
734 vfs_context_t a_context;
735 } */;
736
737 int
738 nop_pagein(struct vnop_pagein_args *ap)
739 {
740 if ( !(ap->a_flags & UPL_NOCOMMIT))
741 ubc_upl_abort_range(ap->a_pl, ap->a_pl_offset, ap->a_size, UPL_ABORT_FREE_ON_EMPTY | UPL_ABORT_ERROR);
742 return (EINVAL);
743 }
744
745 int
746 err_pagein(struct vnop_pagein_args *ap)
747 {
748 if ( !(ap->a_flags & UPL_NOCOMMIT))
749 ubc_upl_abort_range(ap->a_pl, ap->a_pl_offset, ap->a_size, UPL_ABORT_FREE_ON_EMPTY | UPL_ABORT_ERROR);
750 return (ENOTSUP);
751 }
752
753
754 struct vnop_pageout_args /* {
755 struct vnode *a_vp,
756 upl_t a_pl,
757 vm_offset_t a_pl_offset,
758 off_t a_foffset,
759 size_t a_size,
760 int a_flags
761 vfs_context_t a_context;
762 } */;
763
764 int
765 nop_pageout(struct vnop_pageout_args *ap)
766 {
767 if ( !(ap->a_flags & UPL_NOCOMMIT))
768 ubc_upl_abort_range(ap->a_pl, ap->a_pl_offset, ap->a_size, UPL_ABORT_FREE_ON_EMPTY | UPL_ABORT_ERROR);
769 return (EINVAL);
770 }
771
772 int
773 err_pageout(struct vnop_pageout_args *ap)
774 {
775 if ( !(ap->a_flags & UPL_NOCOMMIT))
776 ubc_upl_abort_range(ap->a_pl, ap->a_pl_offset, ap->a_size, UPL_ABORT_FREE_ON_EMPTY | UPL_ABORT_ERROR);
777 return (ENOTSUP);
778 }
779
780
781 struct vnop_searchfs /* {
782 struct vnode *a_vp;
783 void *a_searchparams1;
784 void *a_searchparams2;
785 struct attrlist *a_searchattrs;
786 u_long a_maxmatches;
787 struct timeval *a_timelimit;
788 struct attrlist *a_returnattrs;
789 u_long *a_nummatches;
790 u_long a_scriptcode;
791 u_long a_options;
792 struct uio *a_uio;
793 struct searchstate *a_searchstate;
794 vfs_context_t a_context;
795 } */;
796
797 int
798 nop_searchfs(struct vnop_searchfs_args *ap)
799 {
800 *(ap->a_nummatches) = 0;
801 return (0);
802 }
803
804 int
805 err_searchfs(struct vnop_searchfs_args *ap)
806 {
807 (void)nop_searchfs(ap);
808 return (ENOTSUP);
809 }
810
811 struct vnop_copyfile_args /*{
812 struct vnodeop_desc *a_desc;
813 struct vnode *a_fvp;
814 struct vnode *a_tdvp;
815 struct vnode *a_tvp;
816 struct componentname *a_tcnp;
817 int a_flags;
818 }*/;
819
820 int
821 nop_copyfile(__unused struct vnop_copyfile_args *ap)
822 {
823 return (0);
824 }
825
826
827 int
828 err_copyfile(struct vnop_copyfile_args *ap)
829 {
830 (void)nop_copyfile(ap);
831 return (ENOTSUP);
832 }
833
834
835 struct vnop_blktooff_args /* {
836 struct vnode *a_vp;
837 daddr64_t a_lblkno;
838 off_t *a_offset;
839 } */;
840
841 int
842 nop_blktooff(struct vnop_blktooff_args *ap)
843 {
844 *ap->a_offset = (off_t)-1; /* failure */
845 return (0);
846 }
847
848 int
849 err_blktooff(struct vnop_blktooff_args *ap)
850 {
851 (void)nop_blktooff(ap);
852 return (ENOTSUP);
853 }
854
855 struct vnop_offtoblk_args /* {
856 struct vnode *a_vp;
857 off_t a_offset;
858 daddr64_t *a_lblkno;
859 } */;
860
861 int
862 nop_offtoblk(struct vnop_offtoblk_args *ap)
863 {
864 *ap->a_lblkno = (daddr64_t)-1; /* failure */
865 return (0);
866 }
867
868 int
869 err_offtoblk(struct vnop_offtoblk_args *ap)
870 {
871 (void)nop_offtoblk(ap);
872 return (ENOTSUP);
873 }
874
875 struct vnop_blockmap_args /* {
876 struct vnode *a_vp;
877 off_t a_foffset;
878 size_t a_size;
879 daddr64_t *a_bpn;
880 size_t *a_run;
881 void *a_poff;
882 int a_flags;
883 } */;
884
885 int nop_blockmap(__unused struct vnop_blockmap_args *ap)
886 {
887 return (0);
888 }
889
890 int err_blockmap(__unused struct vnop_blockmap_args *ap)
891 {
892 return (ENOTSUP);
893 }
894