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