2 * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1989, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
70 * support for mandatory and extensible security protections. This notice
71 * is included in support of clause 2.2 (b) of the Apple Public License,
76 * External virtual filesystem routines
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/proc_internal.h>
83 #include <sys/kauth.h>
84 #include <sys/mount.h>
85 #include <sys/mount_internal.h>
87 #include <sys/vnode_internal.h>
89 #include <sys/namei.h>
90 #include <sys/ucred.h>
92 #include <sys/errno.h>
93 #include <sys/malloc.h>
94 #include <sys/domain.h>
96 #include <sys/syslog.h>
99 #include <sys/sysctl.h>
100 #include <sys/filedesc.h>
101 #include <sys/event.h>
102 #include <sys/fsevents.h>
103 #include <sys/user.h>
104 #include <sys/lockf.h>
105 #include <sys/xattr.h>
107 #include <kern/assert.h>
108 #include <kern/kalloc.h>
109 #include <kern/task.h>
111 #include <libkern/OSByteOrder.h>
113 #include <miscfs/specfs/specdev.h>
115 #include <mach/mach_types.h>
116 #include <mach/memory_object_types.h>
117 #include <mach/task.h>
120 #include <security/mac_framework.h>
131 #define NATIVE_XATTR(VP) \
132 ((VP)->v_mount ? (VP)->v_mount->mnt_kern_flag & MNTK_EXTENDED_ATTRS : 0)
134 #if CONFIG_APPLEDOUBLE
135 static void xattrfile_remove(vnode_t dvp
, const char *basename
,
136 vfs_context_t ctx
, int force
);
137 static void xattrfile_setattr(vnode_t dvp
, const char * basename
,
138 struct vnode_attr
* vap
, vfs_context_t ctx
);
139 #endif /* CONFIG_APPLEDOUBLE */
142 * vnode_setneedinactive
144 * Description: Indicate that when the last iocount on this vnode goes away,
145 * and the usecount is also zero, we should inform the filesystem
148 * Parameters: vnode_t vnode to mark
152 * Notes: Notably used when we're deleting a file--we need not have a
153 * usecount, so VNOP_INACTIVE may not get called by anyone. We
154 * want it called when we drop our iocount.
157 vnode_setneedinactive(vnode_t vp
)
162 vp
->v_lflag
|= VL_NEEDINACTIVE
;
167 /* ====================================================================== */
168 /* ************ EXTERNAL KERNEL APIS ********************************** */
169 /* ====================================================================== */
172 * implementations of exported VFS operations
175 VFS_MOUNT(mount_t mp
, vnode_t devvp
, user_addr_t data
, vfs_context_t ctx
)
179 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_mount
== 0))
182 if (vfs_context_is64bit(ctx
)) {
183 if (vfs_64bitready(mp
)) {
184 error
= (*mp
->mnt_op
->vfs_mount
)(mp
, devvp
, data
, ctx
);
191 error
= (*mp
->mnt_op
->vfs_mount
)(mp
, devvp
, data
, ctx
);
198 VFS_START(mount_t mp
, int flags
, vfs_context_t ctx
)
202 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_start
== 0))
205 error
= (*mp
->mnt_op
->vfs_start
)(mp
, flags
, ctx
);
211 VFS_UNMOUNT(mount_t mp
, int flags
, vfs_context_t ctx
)
215 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_unmount
== 0))
218 error
= (*mp
->mnt_op
->vfs_unmount
)(mp
, flags
, ctx
);
225 * ENOTSUP Not supported
229 * Note: The return codes from the underlying VFS's root routine can't
230 * be fully enumerated here, since third party VFS authors may not
231 * limit their error returns to the ones documented here, even
232 * though this may result in some programs functioning incorrectly.
234 * The return codes documented above are those which may currently
235 * be returned by HFS from hfs_vfs_root, which is a simple wrapper
236 * for a call to hfs_vget on the volume mount poit, not including
237 * additional error codes which may be propagated from underlying
238 * routines called by hfs_vget.
241 VFS_ROOT(mount_t mp
, struct vnode
** vpp
, vfs_context_t ctx
)
245 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_root
== 0))
249 ctx
= vfs_context_current();
252 error
= (*mp
->mnt_op
->vfs_root
)(mp
, vpp
, ctx
);
258 VFS_QUOTACTL(mount_t mp
, int cmd
, uid_t uid
, caddr_t datap
, vfs_context_t ctx
)
262 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_quotactl
== 0))
265 error
= (*mp
->mnt_op
->vfs_quotactl
)(mp
, cmd
, uid
, datap
, ctx
);
271 VFS_GETATTR(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
275 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_getattr
== 0))
279 ctx
= vfs_context_current();
282 error
= (*mp
->mnt_op
->vfs_getattr
)(mp
, vfa
, ctx
);
288 VFS_SETATTR(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
292 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_setattr
== 0))
296 ctx
= vfs_context_current();
299 error
= (*mp
->mnt_op
->vfs_setattr
)(mp
, vfa
, ctx
);
305 VFS_SYNC(mount_t mp
, int flags
, vfs_context_t ctx
)
309 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_sync
== 0))
313 ctx
= vfs_context_current();
316 error
= (*mp
->mnt_op
->vfs_sync
)(mp
, flags
, ctx
);
322 VFS_VGET(mount_t mp
, ino64_t ino
, struct vnode
**vpp
, vfs_context_t ctx
)
326 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_vget
== 0))
330 ctx
= vfs_context_current();
333 error
= (*mp
->mnt_op
->vfs_vget
)(mp
, ino
, vpp
, ctx
);
339 VFS_FHTOVP(mount_t mp
, int fhlen
, unsigned char * fhp
, vnode_t
* vpp
, vfs_context_t ctx
)
343 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_fhtovp
== 0))
347 ctx
= vfs_context_current();
350 error
= (*mp
->mnt_op
->vfs_fhtovp
)(mp
, fhlen
, fhp
, vpp
, ctx
);
356 VFS_VPTOFH(struct vnode
* vp
, int *fhlenp
, unsigned char * fhp
, vfs_context_t ctx
)
360 if ((vp
->v_mount
== dead_mountp
) || (vp
->v_mount
->mnt_op
->vfs_vptofh
== 0))
364 ctx
= vfs_context_current();
367 error
= (*vp
->v_mount
->mnt_op
->vfs_vptofh
)(vp
, fhlenp
, fhp
, ctx
);
373 /* returns the cached throttle mask for the mount_t */
375 vfs_throttle_mask(mount_t mp
)
377 return(mp
->mnt_throttle_mask
);
380 /* returns a copy of vfs type name for the mount_t */
382 vfs_name(mount_t mp
, char * buffer
)
384 strncpy(buffer
, mp
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
387 /* returns vfs type number for the mount_t */
389 vfs_typenum(mount_t mp
)
391 return(mp
->mnt_vtable
->vfc_typenum
);
394 /* Safe to cast to "struct label*"; returns "void*" to limit dependence of mount.h on security headers. */
396 vfs_mntlabel(mount_t mp
)
398 return (void*)mp
->mnt_mntlabel
;
401 /* returns command modifier flags of mount_t ie. MNT_CMDFLAGS */
403 vfs_flags(mount_t mp
)
405 return((uint64_t)(mp
->mnt_flag
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
)));
408 /* set any of the command modifier flags(MNT_CMDFLAGS) in mount_t */
410 vfs_setflags(mount_t mp
, uint64_t flags
)
412 uint32_t lflags
= (uint32_t)(flags
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
));
415 mp
->mnt_flag
|= lflags
;
419 /* clear any of the command modifier flags(MNT_CMDFLAGS) in mount_t */
421 vfs_clearflags(mount_t mp
, uint64_t flags
)
423 uint32_t lflags
= (uint32_t)(flags
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
));
426 mp
->mnt_flag
&= ~lflags
;
430 /* Is the mount_t ronly and upgrade read/write requested? */
432 vfs_iswriteupgrade(mount_t mp
) /* ronly && MNTK_WANTRDWR */
434 return ((mp
->mnt_flag
& MNT_RDONLY
) && (mp
->mnt_kern_flag
& MNTK_WANTRDWR
));
438 /* Is the mount_t mounted ronly */
440 vfs_isrdonly(mount_t mp
)
442 return (mp
->mnt_flag
& MNT_RDONLY
);
445 /* Is the mount_t mounted for filesystem synchronous writes? */
447 vfs_issynchronous(mount_t mp
)
449 return (mp
->mnt_flag
& MNT_SYNCHRONOUS
);
452 /* Is the mount_t mounted read/write? */
454 vfs_isrdwr(mount_t mp
)
456 return ((mp
->mnt_flag
& MNT_RDONLY
) == 0);
460 /* Is mount_t marked for update (ie MNT_UPDATE) */
462 vfs_isupdate(mount_t mp
)
464 return (mp
->mnt_flag
& MNT_UPDATE
);
468 /* Is mount_t marked for reload (ie MNT_RELOAD) */
470 vfs_isreload(mount_t mp
)
472 return ((mp
->mnt_flag
& MNT_UPDATE
) && (mp
->mnt_flag
& MNT_RELOAD
));
475 /* Is mount_t marked for forced unmount (ie MNT_FORCE or MNTK_FRCUNMOUNT) */
477 vfs_isforce(mount_t mp
)
479 if ((mp
->mnt_lflag
& MNT_LFORCE
) || (mp
->mnt_kern_flag
& MNTK_FRCUNMOUNT
))
486 vfs_isunmount(mount_t mp
)
488 if ((mp
->mnt_lflag
& MNT_LUNMOUNT
)) {
496 vfs_64bitready(mount_t mp
)
498 if ((mp
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
))
506 vfs_authcache_ttl(mount_t mp
)
508 if ( (mp
->mnt_kern_flag
& (MNTK_AUTH_OPAQUE
| MNTK_AUTH_CACHE_TTL
)) )
509 return (mp
->mnt_authcache_ttl
);
511 return (CACHED_RIGHT_INFINITE_TTL
);
515 vfs_setauthcache_ttl(mount_t mp
, int ttl
)
518 mp
->mnt_kern_flag
|= MNTK_AUTH_CACHE_TTL
;
519 mp
->mnt_authcache_ttl
= ttl
;
524 vfs_clearauthcache_ttl(mount_t mp
)
527 mp
->mnt_kern_flag
&= ~MNTK_AUTH_CACHE_TTL
;
529 * back to the default TTL value in case
530 * MNTK_AUTH_OPAQUE is set on this mount
532 mp
->mnt_authcache_ttl
= CACHED_LOOKUP_RIGHT_TTL
;
537 vfs_authopaque(mount_t mp
)
539 if ((mp
->mnt_kern_flag
& MNTK_AUTH_OPAQUE
))
546 vfs_authopaqueaccess(mount_t mp
)
548 if ((mp
->mnt_kern_flag
& MNTK_AUTH_OPAQUE_ACCESS
))
555 vfs_setauthopaque(mount_t mp
)
558 mp
->mnt_kern_flag
|= MNTK_AUTH_OPAQUE
;
563 vfs_setauthopaqueaccess(mount_t mp
)
566 mp
->mnt_kern_flag
|= MNTK_AUTH_OPAQUE_ACCESS
;
571 vfs_clearauthopaque(mount_t mp
)
574 mp
->mnt_kern_flag
&= ~MNTK_AUTH_OPAQUE
;
579 vfs_clearauthopaqueaccess(mount_t mp
)
582 mp
->mnt_kern_flag
&= ~MNTK_AUTH_OPAQUE_ACCESS
;
587 vfs_setextendedsecurity(mount_t mp
)
590 mp
->mnt_kern_flag
|= MNTK_EXTENDED_SECURITY
;
595 vfs_clearextendedsecurity(mount_t mp
)
598 mp
->mnt_kern_flag
&= ~MNTK_EXTENDED_SECURITY
;
603 vfs_extendedsecurity(mount_t mp
)
605 return(mp
->mnt_kern_flag
& MNTK_EXTENDED_SECURITY
);
608 /* returns the max size of short symlink in this mount_t */
610 vfs_maxsymlen(mount_t mp
)
612 return(mp
->mnt_maxsymlinklen
);
615 /* set max size of short symlink on mount_t */
617 vfs_setmaxsymlen(mount_t mp
, uint32_t symlen
)
619 mp
->mnt_maxsymlinklen
= symlen
;
622 /* return a pointer to the RO vfs_statfs associated with mount_t */
624 vfs_statfs(mount_t mp
)
626 return(&mp
->mnt_vfsstat
);
630 vfs_getattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
634 if ((error
= VFS_GETATTR(mp
, vfa
, ctx
)) != 0)
638 * If we have a filesystem create time, use it to default some others.
640 if (VFSATTR_IS_SUPPORTED(vfa
, f_create_time
)) {
641 if (VFSATTR_IS_ACTIVE(vfa
, f_modify_time
) && !VFSATTR_IS_SUPPORTED(vfa
, f_modify_time
))
642 VFSATTR_RETURN(vfa
, f_modify_time
, vfa
->f_create_time
);
649 vfs_setattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
653 if (vfs_isrdonly(mp
))
656 error
= VFS_SETATTR(mp
, vfa
, ctx
);
659 * If we had alternate ways of setting vfs attributes, we'd
666 /* return the private data handle stored in mount_t */
668 vfs_fsprivate(mount_t mp
)
670 return(mp
->mnt_data
);
673 /* set the private data handle in mount_t */
675 vfs_setfsprivate(mount_t mp
, void *mntdata
)
678 mp
->mnt_data
= mntdata
;
682 /* query whether the mount point supports native EAs */
684 vfs_nativexattrs(mount_t mp
) {
685 return (mp
->mnt_kern_flag
& MNTK_EXTENDED_ATTRS
);
689 * return the block size of the underlying
690 * device associated with mount_t
693 vfs_devblocksize(mount_t mp
) {
695 return(mp
->mnt_devblocksize
);
699 * Returns vnode with an iocount that must be released with vnode_put()
702 vfs_vnodecovered(mount_t mp
)
704 vnode_t vp
= mp
->mnt_vnodecovered
;
705 if ((vp
== NULL
) || (vnode_getwithref(vp
) != 0)) {
713 * Returns device vnode backing a mountpoint with an iocount (if valid vnode exists).
714 * The iocount must be released with vnode_put(). Note that this KPI is subtle
715 * with respect to the validity of using this device vnode for anything substantial
716 * (which is discouraged). If commands are sent to the device driver without
717 * taking proper steps to ensure that the device is still open, chaos may ensue.
718 * Similarly, this routine should only be called if there is some guarantee that
719 * the mount itself is still valid.
722 vfs_devvp(mount_t mp
)
724 vnode_t vp
= mp
->mnt_devvp
;
726 if ((vp
!= NULLVP
) && (vnode_get(vp
) == 0)) {
734 * return the io attributes associated with mount_t
737 vfs_ioattr(mount_t mp
, struct vfsioattr
*ioattrp
)
740 ioattrp
->io_maxreadcnt
= MAXPHYS
;
741 ioattrp
->io_maxwritecnt
= MAXPHYS
;
742 ioattrp
->io_segreadcnt
= 32;
743 ioattrp
->io_segwritecnt
= 32;
744 ioattrp
->io_maxsegreadsize
= MAXPHYS
;
745 ioattrp
->io_maxsegwritesize
= MAXPHYS
;
746 ioattrp
->io_devblocksize
= DEV_BSIZE
;
747 ioattrp
->io_flags
= 0;
749 ioattrp
->io_maxreadcnt
= mp
->mnt_maxreadcnt
;
750 ioattrp
->io_maxwritecnt
= mp
->mnt_maxwritecnt
;
751 ioattrp
->io_segreadcnt
= mp
->mnt_segreadcnt
;
752 ioattrp
->io_segwritecnt
= mp
->mnt_segwritecnt
;
753 ioattrp
->io_maxsegreadsize
= mp
->mnt_maxsegreadsize
;
754 ioattrp
->io_maxsegwritesize
= mp
->mnt_maxsegwritesize
;
755 ioattrp
->io_devblocksize
= mp
->mnt_devblocksize
;
756 ioattrp
->io_flags
= mp
->mnt_ioflags
;
758 ioattrp
->io_reserved
[0] = NULL
;
759 ioattrp
->io_reserved
[1] = NULL
;
764 * set the IO attributes associated with mount_t
767 vfs_setioattr(mount_t mp
, struct vfsioattr
* ioattrp
)
771 mp
->mnt_maxreadcnt
= ioattrp
->io_maxreadcnt
;
772 mp
->mnt_maxwritecnt
= ioattrp
->io_maxwritecnt
;
773 mp
->mnt_segreadcnt
= ioattrp
->io_segreadcnt
;
774 mp
->mnt_segwritecnt
= ioattrp
->io_segwritecnt
;
775 mp
->mnt_maxsegreadsize
= ioattrp
->io_maxsegreadsize
;
776 mp
->mnt_maxsegwritesize
= ioattrp
->io_maxsegwritesize
;
777 mp
->mnt_devblocksize
= ioattrp
->io_devblocksize
;
778 mp
->mnt_ioflags
= ioattrp
->io_flags
;
782 * Add a new filesystem into the kernel specified in passed in
783 * vfstable structure. It fills in the vnode
784 * dispatch vector that is to be passed to when vnodes are created.
785 * It returns a handle which is to be used to when the FS is to be removed
787 typedef int (*PFI
)(void *);
788 extern int vfs_opv_numops
;
790 vfs_fsadd(struct vfs_fsentry
*vfe
, vfstable_t
* handle
)
792 struct vfstable
*newvfstbl
= NULL
;
794 int (***opv_desc_vector_p
)(void *);
795 int (**opv_desc_vector
)(void *);
796 struct vnodeopv_entry_desc
*opve_descp
;
802 * This routine is responsible for all the initialization that would
803 * ordinarily be done as part of the system startup;
806 if (vfe
== (struct vfs_fsentry
*)0)
809 desccount
= vfe
->vfe_vopcnt
;
810 if ((desccount
<=0) || ((desccount
> 8)) || (vfe
->vfe_vfsops
== (struct vfsops
*)NULL
)
811 || (vfe
->vfe_opvdescs
== (struct vnodeopv_desc
**)NULL
))
814 /* Non-threadsafe filesystems are not supported */
815 if ((vfe
->vfe_flags
& (VFS_TBLTHREADSAFE
| VFS_TBLFSNODELOCK
)) == 0) {
819 MALLOC(newvfstbl
, void *, sizeof(struct vfstable
), M_TEMP
,
821 bzero(newvfstbl
, sizeof(struct vfstable
));
822 newvfstbl
->vfc_vfsops
= vfe
->vfe_vfsops
;
823 strncpy(&newvfstbl
->vfc_name
[0], vfe
->vfe_fsname
, MFSNAMELEN
);
824 if ((vfe
->vfe_flags
& VFS_TBLNOTYPENUM
))
825 newvfstbl
->vfc_typenum
= maxvfsconf
++;
827 newvfstbl
->vfc_typenum
= vfe
->vfe_fstypenum
;
829 newvfstbl
->vfc_refcount
= 0;
830 newvfstbl
->vfc_flags
= 0;
831 newvfstbl
->vfc_mountroot
= NULL
;
832 newvfstbl
->vfc_next
= NULL
;
833 newvfstbl
->vfc_vfsflags
= 0;
834 if (vfe
->vfe_flags
& VFS_TBL64BITREADY
)
835 newvfstbl
->vfc_vfsflags
|= VFC_VFS64BITREADY
;
836 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEINV2
)
837 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEINV2
;
838 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEOUTV2
)
839 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEOUTV2
;
840 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) == VFS_TBLLOCALVOL
)
841 newvfstbl
->vfc_flags
|= MNT_LOCAL
;
842 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) && (vfe
->vfe_flags
& VFS_TBLGENERICMNTARGS
) == 0)
843 newvfstbl
->vfc_vfsflags
|= VFC_VFSLOCALARGS
;
845 newvfstbl
->vfc_vfsflags
|= VFC_VFSGENERICARGS
;
847 if (vfe
->vfe_flags
& VFS_TBLNATIVEXATTR
)
848 newvfstbl
->vfc_vfsflags
|= VFC_VFSNATIVEXATTR
;
849 if (vfe
->vfe_flags
& VFS_TBLUNMOUNT_PREFLIGHT
)
850 newvfstbl
->vfc_vfsflags
|= VFC_VFSPREFLIGHT
;
851 if (vfe
->vfe_flags
& VFS_TBLREADDIR_EXTENDED
)
852 newvfstbl
->vfc_vfsflags
|= VFC_VFSREADDIR_EXTENDED
;
853 if (vfe
->vfe_flags
& VFS_TBLNOMACLABEL
)
854 newvfstbl
->vfc_vfsflags
|= VFC_VFSNOMACLABEL
;
855 if (vfe
->vfe_flags
& VFS_TBLVNOP_NOUPDATEID_RENAME
)
856 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_NOUPDATEID_RENAME
;
859 * Allocate and init the vectors.
860 * Also handle backwards compatibility.
862 * We allocate one large block to hold all <desccount>
863 * vnode operation vectors stored contiguously.
865 /* XXX - shouldn't be M_TEMP */
867 descsize
= desccount
* vfs_opv_numops
* sizeof(PFI
);
868 MALLOC(descptr
, PFI
*, descsize
,
870 bzero(descptr
, descsize
);
872 newvfstbl
->vfc_descptr
= descptr
;
873 newvfstbl
->vfc_descsize
= descsize
;
876 for (i
= 0; i
< desccount
; i
++ ) {
877 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
879 * Fill in the caller's pointer to the start of the i'th vector.
880 * They'll need to supply it when calling vnode_create.
882 opv_desc_vector
= descptr
+ i
* vfs_opv_numops
;
883 *opv_desc_vector_p
= opv_desc_vector
;
885 for (j
= 0; vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
].opve_op
; j
++) {
886 opve_descp
= &(vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
]);
889 * Sanity check: is this operation listed
890 * in the list of operations? We check this
891 * by seeing if its offset is zero. Since
892 * the default routine should always be listed
893 * first, it should be the only one with a zero
894 * offset. Any other operation with a zero
895 * offset is probably not listed in
896 * vfs_op_descs, and so is probably an error.
898 * A panic here means the layer programmer
899 * has committed the all-too common bug
900 * of adding a new operation to the layer's
901 * list of vnode operations but
902 * not adding the operation to the system-wide
903 * list of supported operations.
905 if (opve_descp
->opve_op
->vdesc_offset
== 0 &&
906 opve_descp
->opve_op
->vdesc_offset
!= VOFFSET(vnop_default
)) {
907 printf("vfs_fsadd: operation %s not listed in %s.\n",
908 opve_descp
->opve_op
->vdesc_name
,
910 panic("vfs_fsadd: bad operation");
913 * Fill in this entry.
915 opv_desc_vector
[opve_descp
->opve_op
->vdesc_offset
] =
916 opve_descp
->opve_impl
;
921 * Finally, go back and replace unfilled routines
922 * with their default. (Sigh, an O(n^3) algorithm. I
923 * could make it better, but that'd be work, and n is small.)
925 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
928 * Force every operations vector to have a default routine.
930 opv_desc_vector
= *opv_desc_vector_p
;
931 if (opv_desc_vector
[VOFFSET(vnop_default
)] == NULL
)
932 panic("vfs_fsadd: operation vector without default routine.");
933 for (j
= 0; j
< vfs_opv_numops
; j
++)
934 if (opv_desc_vector
[j
] == NULL
)
936 opv_desc_vector
[VOFFSET(vnop_default
)];
938 } /* end of each vnodeopv_desc parsing */
942 *handle
= vfstable_add(newvfstbl
);
944 if (newvfstbl
->vfc_typenum
<= maxvfsconf
)
945 maxvfsconf
= newvfstbl
->vfc_typenum
+ 1;
947 if (newvfstbl
->vfc_vfsops
->vfs_init
) {
949 bzero(&vfsc
, sizeof(struct vfsconf
));
950 vfsc
.vfc_reserved1
= 0;
951 bcopy((*handle
)->vfc_name
, vfsc
.vfc_name
, sizeof(vfsc
.vfc_name
));
952 vfsc
.vfc_typenum
= (*handle
)->vfc_typenum
;
953 vfsc
.vfc_refcount
= (*handle
)->vfc_refcount
;
954 vfsc
.vfc_flags
= (*handle
)->vfc_flags
;
955 vfsc
.vfc_reserved2
= 0;
956 vfsc
.vfc_reserved3
= 0;
958 (*newvfstbl
->vfc_vfsops
->vfs_init
)(&vfsc
);
961 FREE(newvfstbl
, M_TEMP
);
967 * Removes the filesystem from kernel.
968 * The argument passed in is the handle that was given when
969 * file system was added
972 vfs_fsremove(vfstable_t handle
)
974 struct vfstable
* vfstbl
= (struct vfstable
*)handle
;
975 void *old_desc
= NULL
;
978 /* Preflight check for any mounts */
980 if ( vfstbl
->vfc_refcount
!= 0 ) {
986 * save the old descriptor; the free cannot occur unconditionally,
987 * since vfstable_del() may fail.
989 if (vfstbl
->vfc_descptr
&& vfstbl
->vfc_descsize
) {
990 old_desc
= vfstbl
->vfc_descptr
;
992 err
= vfstable_del(vfstbl
);
996 /* free the descriptor if the delete was successful */
997 if (err
== 0 && old_desc
) {
998 FREE(old_desc
, M_TEMP
);
1005 vfs_context_pid(vfs_context_t ctx
)
1007 return (proc_pid(vfs_context_proc(ctx
)));
1011 vfs_context_suser(vfs_context_t ctx
)
1013 return (suser(ctx
->vc_ucred
, NULL
));
1017 * Return bit field of signals posted to all threads in the context's process.
1019 * XXX Signals should be tied to threads, not processes, for most uses of this
1023 vfs_context_issignal(vfs_context_t ctx
, sigset_t mask
)
1025 proc_t p
= vfs_context_proc(ctx
);
1027 return(proc_pendingsignals(p
, mask
));
1032 vfs_context_is64bit(vfs_context_t ctx
)
1034 proc_t proc
= vfs_context_proc(ctx
);
1037 return(proc_is64bit(proc
));
1045 * Description: Given a vfs_context_t, return the proc_t associated with it.
1047 * Parameters: vfs_context_t The context to use
1049 * Returns: proc_t The process for this context
1051 * Notes: This function will return the current_proc() if any of the
1052 * following conditions are true:
1054 * o The supplied context pointer is NULL
1055 * o There is no Mach thread associated with the context
1056 * o There is no Mach task associated with the Mach thread
1057 * o There is no proc_t associated with the Mach task
1058 * o The proc_t has no per process open file table
1059 * o The proc_t is post-vfork()
1061 * This causes this function to return a value matching as
1062 * closely as possible the previous behaviour, while at the
1063 * same time avoiding the task lending that results from vfork()
1066 vfs_context_proc(vfs_context_t ctx
)
1070 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1071 proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
);
1072 if (proc
!= NULL
&& (proc
->p_fd
== NULL
|| (proc
->p_lflag
& P_LVFORK
)))
1075 return(proc
== NULL
? current_proc() : proc
);
1079 * vfs_context_get_special_port
1081 * Description: Return the requested special port from the task associated
1082 * with the given context.
1084 * Parameters: vfs_context_t The context to use
1085 * int Index of special port
1086 * ipc_port_t * Pointer to returned port
1088 * Returns: kern_return_t see task_get_special_port()
1091 vfs_context_get_special_port(vfs_context_t ctx
, int which
, ipc_port_t
*portp
)
1095 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1096 task
= get_threadtask(ctx
->vc_thread
);
1098 return task_get_special_port(task
, which
, portp
);
1102 * vfs_context_set_special_port
1104 * Description: Set the requested special port in the task associated
1105 * with the given context.
1107 * Parameters: vfs_context_t The context to use
1108 * int Index of special port
1109 * ipc_port_t New special port
1111 * Returns: kern_return_t see task_set_special_port()
1114 vfs_context_set_special_port(vfs_context_t ctx
, int which
, ipc_port_t port
)
1118 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1119 task
= get_threadtask(ctx
->vc_thread
);
1121 return task_set_special_port(task
, which
, port
);
1125 * vfs_context_thread
1127 * Description: Return the Mach thread associated with a vfs_context_t
1129 * Parameters: vfs_context_t The context to use
1131 * Returns: thread_t The thread for this context, or
1132 * NULL, if there is not one.
1134 * Notes: NULL thread_t's are legal, but discouraged. They occur only
1135 * as a result of a static vfs_context_t declaration in a function
1136 * and will result in this function returning NULL.
1138 * This is intentional; this function should NOT return the
1139 * current_thread() in this case.
1142 vfs_context_thread(vfs_context_t ctx
)
1144 return(ctx
->vc_thread
);
1151 * Description: Returns a reference on the vnode for the current working
1152 * directory for the supplied context
1154 * Parameters: vfs_context_t The context to use
1156 * Returns: vnode_t The current working directory
1159 * Notes: The function first attempts to obtain the current directory
1160 * from the thread, and if it is not present there, falls back
1161 * to obtaining it from the process instead. If it can't be
1162 * obtained from either place, we return NULLVP.
1165 vfs_context_cwd(vfs_context_t ctx
)
1167 vnode_t cwd
= NULLVP
;
1169 if(ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1170 uthread_t uth
= get_bsdthread_info(ctx
->vc_thread
);
1174 * Get the cwd from the thread; if there isn't one, get it
1175 * from the process, instead.
1177 if ((cwd
= uth
->uu_cdir
) == NULLVP
&&
1178 (proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
)) != NULL
&&
1180 cwd
= proc
->p_fd
->fd_cdir
;
1187 * vfs_context_create
1189 * Description: Allocate and initialize a new context.
1191 * Parameters: vfs_context_t: Context to copy, or NULL for new
1193 * Returns: Pointer to new context
1195 * Notes: Copy cred and thread from argument, if available; else
1196 * initialize with current thread and new cred. Returns
1197 * with a reference held on the credential.
1200 vfs_context_create(vfs_context_t ctx
)
1202 vfs_context_t newcontext
;
1204 newcontext
= (vfs_context_t
)kalloc(sizeof(struct vfs_context
));
1207 kauth_cred_t safecred
;
1209 newcontext
->vc_thread
= ctx
->vc_thread
;
1210 safecred
= ctx
->vc_ucred
;
1212 newcontext
->vc_thread
= current_thread();
1213 safecred
= kauth_cred_get();
1215 if (IS_VALID_CRED(safecred
))
1216 kauth_cred_ref(safecred
);
1217 newcontext
->vc_ucred
= safecred
;
1225 vfs_context_current(void)
1227 vfs_context_t ctx
= NULL
;
1228 volatile uthread_t ut
= (uthread_t
)get_bsdthread_info(current_thread());
1231 if (ut
->uu_context
.vc_ucred
!= NULL
) {
1232 ctx
= &ut
->uu_context
;
1236 return(ctx
== NULL
? vfs_context_kernel() : ctx
);
1243 * Dangerous hack - adopt the first kernel thread as the current thread, to
1244 * get to the vfs_context_t in the uthread associated with a kernel thread.
1245 * This is used by UDF to make the call into IOCDMediaBSDClient,
1246 * IOBDMediaBSDClient, and IODVDMediaBSDClient to determine whether the
1247 * ioctl() is being called from kernel or user space (and all this because
1248 * we do not pass threads into our ioctl()'s, instead of processes).
1250 * This is also used by imageboot_setup(), called early from bsd_init() after
1251 * kernproc has been given a credential.
1253 * Note: The use of proc_thread() here is a convenience to avoid inclusion
1254 * of many Mach headers to do the reference directly rather than indirectly;
1255 * we will need to forego this convenience when we reture proc_thread().
1257 static struct vfs_context kerncontext
;
1259 vfs_context_kernel(void)
1261 if (kerncontext
.vc_ucred
== NOCRED
)
1262 kerncontext
.vc_ucred
= kernproc
->p_ucred
;
1263 if (kerncontext
.vc_thread
== NULL
)
1264 kerncontext
.vc_thread
= proc_thread(kernproc
);
1266 return(&kerncontext
);
1271 vfs_context_rele(vfs_context_t ctx
)
1274 if (IS_VALID_CRED(ctx
->vc_ucred
))
1275 kauth_cred_unref(&ctx
->vc_ucred
);
1276 kfree(ctx
, sizeof(struct vfs_context
));
1283 vfs_context_ucred(vfs_context_t ctx
)
1285 return (ctx
->vc_ucred
);
1289 * Return true if the context is owned by the superuser.
1292 vfs_context_issuser(vfs_context_t ctx
)
1294 return(kauth_cred_issuser(vfs_context_ucred(ctx
)));
1298 * Given a context, for all fields of vfs_context_t which
1299 * are not held with a reference, set those fields to the
1300 * values for the current execution context. Currently, this
1301 * just means the vc_thread.
1303 * Returns: 0 for success, nonzero for failure
1305 * The intended use is:
1306 * 1. vfs_context_create() gets the caller a context
1307 * 2. vfs_context_bind() sets the unrefcounted data
1308 * 3. vfs_context_rele() releases the context
1312 vfs_context_bind(vfs_context_t ctx
)
1314 ctx
->vc_thread
= current_thread();
1318 /* XXXXXXXXXXXXXX VNODE KAPIS XXXXXXXXXXXXXXXXXXXXXXXXX */
1322 * Convert between vnode types and inode formats (since POSIX.1
1323 * defines mode word of stat structure in terms of inode formats).
1326 vnode_iftovt(int mode
)
1328 return(iftovt_tab
[((mode
) & S_IFMT
) >> 12]);
1332 vnode_vttoif(enum vtype indx
)
1334 return(vttoif_tab
[(int)(indx
)]);
1338 vnode_makeimode(int indx
, int mode
)
1340 return (int)(VTTOIF(indx
) | (mode
));
1345 * vnode manipulation functions.
1348 /* returns system root vnode iocount; It should be released using vnode_put() */
1354 error
= vnode_get(rootvnode
);
1356 return ((vnode_t
)0);
1363 vnode_vid(vnode_t vp
)
1365 return ((uint32_t)(vp
->v_id
));
1369 vnode_mount(vnode_t vp
)
1371 return (vp
->v_mount
);
1375 vnode_mountedhere(vnode_t vp
)
1379 if ((vp
->v_type
== VDIR
) && ((mp
= vp
->v_mountedhere
) != NULL
) &&
1380 (mp
->mnt_vnodecovered
== vp
))
1383 return (mount_t
)NULL
;
1386 /* returns vnode type of vnode_t */
1388 vnode_vtype(vnode_t vp
)
1390 return (vp
->v_type
);
1393 /* returns FS specific node saved in vnode */
1395 vnode_fsnode(vnode_t vp
)
1397 return (vp
->v_data
);
1401 vnode_clearfsnode(vnode_t vp
)
1407 vnode_specrdev(vnode_t vp
)
1413 /* Accessor functions */
1414 /* is vnode_t a root vnode */
1416 vnode_isvroot(vnode_t vp
)
1418 return ((vp
->v_flag
& VROOT
)? 1 : 0);
1421 /* is vnode_t a system vnode */
1423 vnode_issystem(vnode_t vp
)
1425 return ((vp
->v_flag
& VSYSTEM
)? 1 : 0);
1428 /* is vnode_t a swap file vnode */
1430 vnode_isswap(vnode_t vp
)
1432 return ((vp
->v_flag
& VSWAP
)? 1 : 0);
1435 /* is vnode_t a tty */
1437 vnode_istty(vnode_t vp
)
1439 return ((vp
->v_flag
& VISTTY
) ? 1 : 0);
1442 /* if vnode_t mount operation in progress */
1444 vnode_ismount(vnode_t vp
)
1446 return ((vp
->v_flag
& VMOUNT
)? 1 : 0);
1449 /* is this vnode under recyle now */
1451 vnode_isrecycled(vnode_t vp
)
1455 vnode_lock_spin(vp
);
1456 ret
= (vp
->v_lflag
& (VL_TERMINATE
|VL_DEAD
))? 1 : 0;
1461 /* vnode was created by background task requesting rapid aging
1462 and has not since been referenced by a normal task */
1464 vnode_israge(vnode_t vp
)
1466 return ((vp
->v_flag
& VRAGE
)? 1 : 0);
1470 vnode_needssnapshots(vnode_t vp
)
1472 return ((vp
->v_flag
& VNEEDSSNAPSHOT
)? 1 : 0);
1476 /* Check the process/thread to see if we should skip atime updates */
1478 vfs_ctx_skipatime (vfs_context_t ctx
) {
1483 proc
= vfs_context_proc(ctx
);
1484 thr
= vfs_context_thread (ctx
);
1486 /* Validate pointers in case we were invoked via a kernel context */
1488 ut
= get_bsdthread_info (thr
);
1490 if (proc
->p_lflag
& P_LRAGE_VNODES
) {
1495 if (ut
->uu_flag
& UT_RAGE_VNODES
) {
1503 /* is vnode_t marked to not keep data cached once it's been consumed */
1505 vnode_isnocache(vnode_t vp
)
1507 return ((vp
->v_flag
& VNOCACHE_DATA
)? 1 : 0);
1511 * has sequential readahead been disabled on this vnode
1514 vnode_isnoreadahead(vnode_t vp
)
1516 return ((vp
->v_flag
& VRAOFF
)? 1 : 0);
1520 vnode_is_openevt(vnode_t vp
)
1522 return ((vp
->v_flag
& VOPENEVT
)? 1 : 0);
1525 /* is vnode_t a standard one? */
1527 vnode_isstandard(vnode_t vp
)
1529 return ((vp
->v_flag
& VSTANDARD
)? 1 : 0);
1532 /* don't vflush() if SKIPSYSTEM */
1534 vnode_isnoflush(vnode_t vp
)
1536 return ((vp
->v_flag
& VNOFLUSH
)? 1 : 0);
1539 /* is vnode_t a regular file */
1541 vnode_isreg(vnode_t vp
)
1543 return ((vp
->v_type
== VREG
)? 1 : 0);
1546 /* is vnode_t a directory? */
1548 vnode_isdir(vnode_t vp
)
1550 return ((vp
->v_type
== VDIR
)? 1 : 0);
1553 /* is vnode_t a symbolic link ? */
1555 vnode_islnk(vnode_t vp
)
1557 return ((vp
->v_type
== VLNK
)? 1 : 0);
1561 vnode_lookup_continue_needed(vnode_t vp
, struct componentname
*cnp
)
1563 struct nameidata
*ndp
= cnp
->cn_ndp
;
1566 panic("vnode_lookup_continue_needed(): cnp->cn_ndp is NULL\n");
1569 if (vnode_isdir(vp
)) {
1570 if (vp
->v_mountedhere
!= NULL
) {
1575 if (vp
->v_resolve
) {
1578 #endif /* CONFIG_TRIGGERS */
1583 if (vnode_islnk(vp
)) {
1584 /* From lookup(): || *ndp->ni_next == '/') No need for this, we know we're NULL-terminated here */
1585 if (cnp
->cn_flags
& FOLLOW
) {
1588 if (ndp
->ni_flag
& NAMEI_TRAILINGSLASH
) {
1596 ndp
->ni_flag
|= NAMEI_CONTLOOKUP
;
1597 return EKEEPLOOKING
;
1600 /* is vnode_t a fifo ? */
1602 vnode_isfifo(vnode_t vp
)
1604 return ((vp
->v_type
== VFIFO
)? 1 : 0);
1607 /* is vnode_t a block device? */
1609 vnode_isblk(vnode_t vp
)
1611 return ((vp
->v_type
== VBLK
)? 1 : 0);
1615 vnode_isspec(vnode_t vp
)
1617 return (((vp
->v_type
== VCHR
) || (vp
->v_type
== VBLK
)) ? 1 : 0);
1620 /* is vnode_t a char device? */
1622 vnode_ischr(vnode_t vp
)
1624 return ((vp
->v_type
== VCHR
)? 1 : 0);
1627 /* is vnode_t a socket? */
1629 vnode_issock(vnode_t vp
)
1631 return ((vp
->v_type
== VSOCK
)? 1 : 0);
1634 /* is vnode_t a device with multiple active vnodes referring to it? */
1636 vnode_isaliased(vnode_t vp
)
1638 enum vtype vt
= vp
->v_type
;
1639 if (!((vt
== VCHR
) || (vt
== VBLK
))) {
1642 return (vp
->v_specflags
& SI_ALIASED
);
1646 /* is vnode_t a named stream? */
1648 vnode_isnamedstream(
1657 return ((vp
->v_flag
& VISNAMEDSTREAM
) ? 1 : 0);
1673 return ((vp
->v_flag
& VISSHADOW
) ? 1 : 0);
1679 /* does vnode have associated named stream vnodes ? */
1681 vnode_hasnamedstreams(
1690 return ((vp
->v_lflag
& VL_HASSTREAMS
) ? 1 : 0);
1695 /* TBD: set vnode_t to not cache data after it is consumed once; used for quota */
1697 vnode_setnocache(vnode_t vp
)
1699 vnode_lock_spin(vp
);
1700 vp
->v_flag
|= VNOCACHE_DATA
;
1705 vnode_clearnocache(vnode_t vp
)
1707 vnode_lock_spin(vp
);
1708 vp
->v_flag
&= ~VNOCACHE_DATA
;
1713 vnode_set_openevt(vnode_t vp
)
1715 vnode_lock_spin(vp
);
1716 vp
->v_flag
|= VOPENEVT
;
1721 vnode_clear_openevt(vnode_t vp
)
1723 vnode_lock_spin(vp
);
1724 vp
->v_flag
&= ~VOPENEVT
;
1730 vnode_setnoreadahead(vnode_t vp
)
1732 vnode_lock_spin(vp
);
1733 vp
->v_flag
|= VRAOFF
;
1738 vnode_clearnoreadahead(vnode_t vp
)
1740 vnode_lock_spin(vp
);
1741 vp
->v_flag
&= ~VRAOFF
;
1746 /* mark vnode_t to skip vflush() is SKIPSYSTEM */
1748 vnode_setnoflush(vnode_t vp
)
1750 vnode_lock_spin(vp
);
1751 vp
->v_flag
|= VNOFLUSH
;
1756 vnode_clearnoflush(vnode_t vp
)
1758 vnode_lock_spin(vp
);
1759 vp
->v_flag
&= ~VNOFLUSH
;
1764 /* is vnode_t a blkdevice and has a FS mounted on it */
1766 vnode_ismountedon(vnode_t vp
)
1768 return ((vp
->v_specflags
& SI_MOUNTEDON
)? 1 : 0);
1772 vnode_setmountedon(vnode_t vp
)
1774 vnode_lock_spin(vp
);
1775 vp
->v_specflags
|= SI_MOUNTEDON
;
1780 vnode_clearmountedon(vnode_t vp
)
1782 vnode_lock_spin(vp
);
1783 vp
->v_specflags
&= ~SI_MOUNTEDON
;
1789 vnode_settag(vnode_t vp
, int tag
)
1796 vnode_tag(vnode_t vp
)
1802 vnode_parent(vnode_t vp
)
1805 return(vp
->v_parent
);
1809 vnode_setparent(vnode_t vp
, vnode_t dvp
)
1815 vnode_setname(vnode_t vp
, char * name
)
1820 /* return the registered FS name when adding the FS to kernel */
1822 vnode_vfsname(vnode_t vp
, char * buf
)
1824 strncpy(buf
, vp
->v_mount
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
1827 /* return the FS type number */
1829 vnode_vfstypenum(vnode_t vp
)
1831 return(vp
->v_mount
->mnt_vtable
->vfc_typenum
);
1835 vnode_vfs64bitready(vnode_t vp
)
1839 * Checking for dead_mountp is a bit of a hack for SnowLeopard: <rdar://problem/6269051>
1841 if ((vp
->v_mount
!= dead_mountp
) && (vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
))
1849 /* return the visible flags on associated mount point of vnode_t */
1851 vnode_vfsvisflags(vnode_t vp
)
1853 return(vp
->v_mount
->mnt_flag
& MNT_VISFLAGMASK
);
1856 /* return the command modifier flags on associated mount point of vnode_t */
1858 vnode_vfscmdflags(vnode_t vp
)
1860 return(vp
->v_mount
->mnt_flag
& MNT_CMDFLAGS
);
1863 /* return the max symlink of short links of vnode_t */
1865 vnode_vfsmaxsymlen(vnode_t vp
)
1867 return(vp
->v_mount
->mnt_maxsymlinklen
);
1870 /* return a pointer to the RO vfs_statfs associated with vnode_t's mount point */
1872 vnode_vfsstatfs(vnode_t vp
)
1874 return(&vp
->v_mount
->mnt_vfsstat
);
1877 /* return a handle to the FSs specific private handle associated with vnode_t's mount point */
1879 vnode_vfsfsprivate(vnode_t vp
)
1881 return(vp
->v_mount
->mnt_data
);
1884 /* is vnode_t in a rdonly mounted FS */
1886 vnode_vfsisrdonly(vnode_t vp
)
1888 return ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
)? 1 : 0);
1892 vnode_compound_rename_available(vnode_t vp
)
1894 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RENAME
);
1897 vnode_compound_rmdir_available(vnode_t vp
)
1899 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RMDIR
);
1902 vnode_compound_mkdir_available(vnode_t vp
)
1904 return vnode_compound_op_available(vp
, COMPOUND_VNOP_MKDIR
);
1907 vnode_compound_remove_available(vnode_t vp
)
1909 return vnode_compound_op_available(vp
, COMPOUND_VNOP_REMOVE
);
1912 vnode_compound_open_available(vnode_t vp
)
1914 return vnode_compound_op_available(vp
, COMPOUND_VNOP_OPEN
);
1918 vnode_compound_op_available(vnode_t vp
, compound_vnop_id_t opid
)
1920 return ((vp
->v_mount
->mnt_compound_ops
& opid
) != 0);
1924 * Returns vnode ref to current working directory; if a per-thread current
1925 * working directory is in effect, return that instead of the per process one.
1927 * XXX Published, but not used.
1930 current_workingdir(void)
1932 return vfs_context_cwd(vfs_context_current());
1935 /* returns vnode ref to current root(chroot) directory */
1937 current_rootdir(void)
1939 proc_t proc
= current_proc();
1942 if ( (vp
= proc
->p_fd
->fd_rdir
) ) {
1943 if ( (vnode_getwithref(vp
)) )
1950 * Get a filesec and optional acl contents from an extended attribute.
1951 * Function will attempt to retrive ACL, UUID, and GUID information using a
1952 * read of a named extended attribute (KAUTH_FILESEC_XATTR).
1954 * Parameters: vp The vnode on which to operate.
1955 * fsecp The filesec (and ACL, if any) being
1957 * ctx The vnode context in which the
1958 * operation is to be attempted.
1960 * Returns: 0 Success
1963 * Notes: The kauth_filesec_t in '*fsecp', if retrieved, will be in
1964 * host byte order, as will be the ACL contents, if any.
1965 * Internally, we will cannonize these values from network (PPC)
1966 * byte order after we retrieve them so that the on-disk contents
1967 * of the extended attribute are identical for both PPC and Intel
1968 * (if we were not being required to provide this service via
1969 * fallback, this would be the job of the filesystem
1970 * 'VNOP_GETATTR' call).
1972 * We use ntohl() because it has a transitive property on Intel
1973 * machines and no effect on PPC mancines. This guarantees us
1975 * XXX: Deleting rather than ignoreing a corrupt security structure is
1976 * probably the only way to reset it without assistance from an
1977 * file system integrity checking tool. Right now we ignore it.
1979 * XXX: We should enummerate the possible errno values here, and where
1980 * in the code they originated.
1983 vnode_get_filesec(vnode_t vp
, kauth_filesec_t
*fsecp
, vfs_context_t ctx
)
1985 kauth_filesec_t fsec
;
1988 size_t xsize
, rsize
;
1990 uint32_t host_fsec_magic
;
1991 uint32_t host_acl_entrycount
;
1997 /* find out how big the EA is */
1998 if (vn_getxattr(vp
, KAUTH_FILESEC_XATTR
, NULL
, &xsize
, XATTR_NOSECURITY
, ctx
) != 0) {
1999 /* no EA, no filesec */
2000 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
))
2002 /* either way, we are done */
2007 * To be valid, a kauth_filesec_t must be large enough to hold a zero
2008 * ACE entrly ACL, and if it's larger than that, it must have the right
2009 * number of bytes such that it contains an atomic number of ACEs,
2010 * rather than partial entries. Otherwise, we ignore it.
2012 if (!KAUTH_FILESEC_VALID(xsize
)) {
2013 KAUTH_DEBUG(" ERROR - Bogus kauth_fiilesec_t: %ld bytes", xsize
);
2018 /* how many entries would fit? */
2019 fsec_size
= KAUTH_FILESEC_COUNT(xsize
);
2021 /* get buffer and uio */
2022 if (((fsec
= kauth_filesec_alloc(fsec_size
)) == NULL
) ||
2023 ((fsec_uio
= uio_create(1, 0, UIO_SYSSPACE
, UIO_READ
)) == NULL
) ||
2024 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), xsize
)) {
2025 KAUTH_DEBUG(" ERROR - could not allocate iov to read ACL");
2030 /* read security attribute */
2032 if ((error
= vn_getxattr(vp
,
2033 KAUTH_FILESEC_XATTR
,
2039 /* no attribute - no security data */
2040 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
))
2042 /* either way, we are done */
2047 * Validate security structure; the validation must take place in host
2048 * byte order. If it's corrupt, we will just ignore it.
2051 /* Validate the size before trying to convert it */
2052 if (rsize
< KAUTH_FILESEC_SIZE(0)) {
2053 KAUTH_DEBUG("ACL - DATA TOO SMALL (%d)", rsize
);
2057 /* Validate the magic number before trying to convert it */
2058 host_fsec_magic
= ntohl(KAUTH_FILESEC_MAGIC
);
2059 if (fsec
->fsec_magic
!= host_fsec_magic
) {
2060 KAUTH_DEBUG("ACL - BAD MAGIC %x", host_fsec_magic
);
2064 /* Validate the entry count before trying to convert it. */
2065 host_acl_entrycount
= ntohl(fsec
->fsec_acl
.acl_entrycount
);
2066 if (host_acl_entrycount
!= KAUTH_FILESEC_NOACL
) {
2067 if (host_acl_entrycount
> KAUTH_ACL_MAX_ENTRIES
) {
2068 KAUTH_DEBUG("ACL - BAD ENTRYCOUNT %x", host_acl_entrycount
);
2071 if (KAUTH_FILESEC_SIZE(host_acl_entrycount
) > rsize
) {
2072 KAUTH_DEBUG("ACL - BUFFER OVERFLOW (%d entries too big for %d)", host_acl_entrycount
, rsize
);
2077 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, NULL
);
2084 kauth_filesec_free(fsec
);
2085 if (fsec_uio
!= NULL
)
2093 * Set a filesec and optional acl contents into an extended attribute.
2094 * function will attempt to store ACL, UUID, and GUID information using a
2095 * write to a named extended attribute (KAUTH_FILESEC_XATTR). The 'acl'
2096 * may or may not point to the `fsec->fsec_acl`, depending on whether the
2097 * original caller supplied an acl.
2099 * Parameters: vp The vnode on which to operate.
2100 * fsec The filesec being set.
2101 * acl The acl to be associated with 'fsec'.
2102 * ctx The vnode context in which the
2103 * operation is to be attempted.
2105 * Returns: 0 Success
2108 * Notes: Both the fsec and the acl are always valid.
2110 * The kauth_filesec_t in 'fsec', if any, is in host byte order,
2111 * as are the acl contents, if they are used. Internally, we will
2112 * cannonize these values into network (PPC) byte order before we
2113 * attempt to write them so that the on-disk contents of the
2114 * extended attribute are identical for both PPC and Intel (if we
2115 * were not being required to provide this service via fallback,
2116 * this would be the job of the filesystem 'VNOP_SETATTR' call).
2117 * We reverse this process on the way out, so we leave with the
2118 * same byte order we started with.
2120 * XXX: We should enummerate the possible errno values here, and where
2121 * in the code they originated.
2124 vnode_set_filesec(vnode_t vp
, kauth_filesec_t fsec
, kauth_acl_t acl
, vfs_context_t ctx
)
2128 uint32_t saved_acl_copysize
;
2132 if ((fsec_uio
= uio_create(2, 0, UIO_SYSSPACE
, UIO_WRITE
)) == NULL
) {
2133 KAUTH_DEBUG(" ERROR - could not allocate iov to write ACL");
2138 * Save the pre-converted ACL copysize, because it gets swapped too
2139 * if we are running with the wrong endianness.
2141 saved_acl_copysize
= KAUTH_ACL_COPYSIZE(acl
);
2143 kauth_filesec_acl_setendian(KAUTH_ENDIAN_DISK
, fsec
, acl
);
2145 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), KAUTH_FILESEC_SIZE(0) - KAUTH_ACL_SIZE(KAUTH_FILESEC_NOACL
));
2146 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(acl
), saved_acl_copysize
);
2147 error
= vn_setxattr(vp
,
2148 KAUTH_FILESEC_XATTR
,
2150 XATTR_NOSECURITY
, /* we have auth'ed already */
2152 VFS_DEBUG(ctx
, vp
, "SETATTR - set ACL returning %d", error
);
2154 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, acl
);
2157 if (fsec_uio
!= NULL
)
2164 * Returns: 0 Success
2165 * ENOMEM Not enough space [only if has filesec]
2167 * vnode_get_filesec: ???
2168 * kauth_cred_guid2uid: ???
2169 * kauth_cred_guid2gid: ???
2170 * vfs_update_vfsstat: ???
2173 vnode_getattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2175 kauth_filesec_t fsec
;
2181 /* don't ask for extended security data if the filesystem doesn't support it */
2182 if (!vfs_extendedsecurity(vnode_mount(vp
))) {
2183 VATTR_CLEAR_ACTIVE(vap
, va_acl
);
2184 VATTR_CLEAR_ACTIVE(vap
, va_uuuid
);
2185 VATTR_CLEAR_ACTIVE(vap
, va_guuid
);
2189 * If the caller wants size values we might have to synthesise, give the
2190 * filesystem the opportunity to supply better intermediate results.
2192 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2193 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2194 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2195 VATTR_SET_ACTIVE(vap
, va_data_size
);
2196 VATTR_SET_ACTIVE(vap
, va_data_alloc
);
2197 VATTR_SET_ACTIVE(vap
, va_total_size
);
2198 VATTR_SET_ACTIVE(vap
, va_total_alloc
);
2201 error
= VNOP_GETATTR(vp
, vap
, ctx
);
2203 KAUTH_DEBUG("ERROR - returning %d", error
);
2208 * If extended security data was requested but not returned, try the fallback
2211 if (VATTR_NOT_RETURNED(vap
, va_acl
) || VATTR_NOT_RETURNED(vap
, va_uuuid
) || VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2214 if (XATTR_VNODE_SUPPORTED(vp
)) {
2215 /* try to get the filesec */
2216 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0)
2219 /* if no filesec, no attributes */
2221 VATTR_RETURN(vap
, va_acl
, NULL
);
2222 VATTR_RETURN(vap
, va_uuuid
, kauth_null_guid
);
2223 VATTR_RETURN(vap
, va_guuid
, kauth_null_guid
);
2226 /* looks good, try to return what we were asked for */
2227 VATTR_RETURN(vap
, va_uuuid
, fsec
->fsec_owner
);
2228 VATTR_RETURN(vap
, va_guuid
, fsec
->fsec_group
);
2230 /* only return the ACL if we were actually asked for it */
2231 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2232 if (fsec
->fsec_acl
.acl_entrycount
== KAUTH_FILESEC_NOACL
) {
2233 VATTR_RETURN(vap
, va_acl
, NULL
);
2235 facl
= kauth_acl_alloc(fsec
->fsec_acl
.acl_entrycount
);
2237 kauth_filesec_free(fsec
);
2241 bcopy(&fsec
->fsec_acl
, facl
, KAUTH_ACL_COPYSIZE(&fsec
->fsec_acl
));
2242 VATTR_RETURN(vap
, va_acl
, facl
);
2245 kauth_filesec_free(fsec
);
2249 * If someone gave us an unsolicited filesec, toss it. We promise that
2250 * we're OK with a filesystem giving us anything back, but our callers
2251 * only expect what they asked for.
2253 if (VATTR_IS_SUPPORTED(vap
, va_acl
) && !VATTR_IS_ACTIVE(vap
, va_acl
)) {
2254 if (vap
->va_acl
!= NULL
)
2255 kauth_acl_free(vap
->va_acl
);
2256 VATTR_CLEAR_SUPPORTED(vap
, va_acl
);
2259 #if 0 /* enable when we have a filesystem only supporting UUIDs */
2261 * Handle the case where we need a UID/GID, but only have extended
2262 * security information.
2264 if (VATTR_NOT_RETURNED(vap
, va_uid
) &&
2265 VATTR_IS_SUPPORTED(vap
, va_uuuid
) &&
2266 !kauth_guid_equal(&vap
->va_uuuid
, &kauth_null_guid
)) {
2267 if ((error
= kauth_cred_guid2uid(&vap
->va_uuuid
, &nuid
)) == 0)
2268 VATTR_RETURN(vap
, va_uid
, nuid
);
2270 if (VATTR_NOT_RETURNED(vap
, va_gid
) &&
2271 VATTR_IS_SUPPORTED(vap
, va_guuid
) &&
2272 !kauth_guid_equal(&vap
->va_guuid
, &kauth_null_guid
)) {
2273 if ((error
= kauth_cred_guid2gid(&vap
->va_guuid
, &ngid
)) == 0)
2274 VATTR_RETURN(vap
, va_gid
, ngid
);
2279 * Handle uid/gid == 99 and MNT_IGNORE_OWNERSHIP here.
2281 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
2282 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2284 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2285 nuid
= vp
->v_mount
->mnt_fsowner
;
2286 if (nuid
== KAUTH_UID_NONE
)
2288 } else if (VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2291 /* this will always be something sensible */
2292 nuid
= vp
->v_mount
->mnt_fsowner
;
2294 if ((nuid
== 99) && !vfs_context_issuser(ctx
))
2295 nuid
= kauth_cred_getuid(vfs_context_ucred(ctx
));
2296 VATTR_RETURN(vap
, va_uid
, nuid
);
2298 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
2299 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2301 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2302 ngid
= vp
->v_mount
->mnt_fsgroup
;
2303 if (ngid
== KAUTH_GID_NONE
)
2305 } else if (VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2308 /* this will always be something sensible */
2309 ngid
= vp
->v_mount
->mnt_fsgroup
;
2311 if ((ngid
== 99) && !vfs_context_issuser(ctx
))
2312 ngid
= kauth_cred_getgid(vfs_context_ucred(ctx
));
2313 VATTR_RETURN(vap
, va_gid
, ngid
);
2317 * Synthesise some values that can be reasonably guessed.
2319 if (!VATTR_IS_SUPPORTED(vap
, va_iosize
))
2320 VATTR_RETURN(vap
, va_iosize
, vp
->v_mount
->mnt_vfsstat
.f_iosize
);
2322 if (!VATTR_IS_SUPPORTED(vap
, va_flags
))
2323 VATTR_RETURN(vap
, va_flags
, 0);
2325 if (!VATTR_IS_SUPPORTED(vap
, va_filerev
))
2326 VATTR_RETURN(vap
, va_filerev
, 0);
2328 if (!VATTR_IS_SUPPORTED(vap
, va_gen
))
2329 VATTR_RETURN(vap
, va_gen
, 0);
2332 * Default sizes. Ordering here is important, as later defaults build on earlier ones.
2334 if (!VATTR_IS_SUPPORTED(vap
, va_data_size
))
2335 VATTR_RETURN(vap
, va_data_size
, 0);
2337 /* do we want any of the possibly-computed values? */
2338 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2339 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2340 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2341 /* make sure f_bsize is valid */
2342 if (vp
->v_mount
->mnt_vfsstat
.f_bsize
== 0) {
2343 if ((error
= vfs_update_vfsstat(vp
->v_mount
, ctx
, VFS_KERNEL_EVENT
)) != 0)
2347 /* default va_data_alloc from va_data_size */
2348 if (!VATTR_IS_SUPPORTED(vap
, va_data_alloc
))
2349 VATTR_RETURN(vap
, va_data_alloc
, roundup(vap
->va_data_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2351 /* default va_total_size from va_data_size */
2352 if (!VATTR_IS_SUPPORTED(vap
, va_total_size
))
2353 VATTR_RETURN(vap
, va_total_size
, vap
->va_data_size
);
2355 /* default va_total_alloc from va_total_size which is guaranteed at this point */
2356 if (!VATTR_IS_SUPPORTED(vap
, va_total_alloc
))
2357 VATTR_RETURN(vap
, va_total_alloc
, roundup(vap
->va_total_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2361 * If we don't have a change time, pull it from the modtime.
2363 if (!VATTR_IS_SUPPORTED(vap
, va_change_time
) && VATTR_IS_SUPPORTED(vap
, va_modify_time
))
2364 VATTR_RETURN(vap
, va_change_time
, vap
->va_modify_time
);
2367 * This is really only supported for the creation VNOPs, but since the field is there
2368 * we should populate it correctly.
2370 VATTR_RETURN(vap
, va_type
, vp
->v_type
);
2373 * The fsid can be obtained from the mountpoint directly.
2375 VATTR_RETURN(vap
, va_fsid
, vp
->v_mount
->mnt_vfsstat
.f_fsid
.val
[0]);
2383 * Set the attributes on a vnode in a vnode context.
2385 * Parameters: vp The vnode whose attributes to set.
2386 * vap A pointer to the attributes to set.
2387 * ctx The vnode context in which the
2388 * operation is to be attempted.
2390 * Returns: 0 Success
2393 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order.
2395 * The contents of the data area pointed to by 'vap' may be
2396 * modified if the vnode is on a filesystem which has been
2397 * mounted with ingore ownership flags, or by the underlyng
2398 * VFS itself, or by the fallback code, if the underlying VFS
2399 * does not support ACL, UUID, or GUUID attributes directly.
2401 * XXX: We should enummerate the possible errno values here, and where
2402 * in the code they originated.
2405 vnode_setattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2407 int error
, is_perm_change
=0;
2410 * Make sure the filesystem is mounted R/W.
2411 * If not, return an error.
2413 if (vfs_isrdonly(vp
->v_mount
)) {
2418 /* For streams, va_data_size is the only setable attribute. */
2419 if ((vp
->v_flag
& VISNAMEDSTREAM
) && (vap
->va_active
!= VNODE_ATTR_va_data_size
)) {
2426 * If ownership is being ignored on this volume, we silently discard
2427 * ownership changes.
2429 if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2430 VATTR_CLEAR_ACTIVE(vap
, va_uid
);
2431 VATTR_CLEAR_ACTIVE(vap
, va_gid
);
2434 if ( VATTR_IS_ACTIVE(vap
, va_uid
) || VATTR_IS_ACTIVE(vap
, va_gid
)
2435 || VATTR_IS_ACTIVE(vap
, va_mode
) || VATTR_IS_ACTIVE(vap
, va_acl
)) {
2440 * Make sure that extended security is enabled if we're going to try
2443 if (!vfs_extendedsecurity(vnode_mount(vp
)) &&
2444 (VATTR_IS_ACTIVE(vap
, va_acl
) || VATTR_IS_ACTIVE(vap
, va_uuuid
) || VATTR_IS_ACTIVE(vap
, va_guuid
))) {
2445 KAUTH_DEBUG("SETATTR - returning ENOTSUP to request to set extended security");
2450 error
= VNOP_SETATTR(vp
, vap
, ctx
);
2452 if ((error
== 0) && !VATTR_ALL_SUPPORTED(vap
))
2453 error
= vnode_setattr_fallback(vp
, vap
, ctx
);
2456 // only send a stat_changed event if this is more than
2457 // just an access or backup time update
2458 if (error
== 0 && (vap
->va_active
!= VNODE_ATTR_BIT(va_access_time
)) && (vap
->va_active
!= VNODE_ATTR_BIT(va_backup_time
))) {
2459 if (is_perm_change
) {
2460 if (need_fsevent(FSE_CHOWN
, vp
)) {
2461 add_fsevent(FSE_CHOWN
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2463 } else if(need_fsevent(FSE_STAT_CHANGED
, vp
)) {
2464 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2474 * Fallback for setting the attributes on a vnode in a vnode context. This
2475 * Function will attempt to store ACL, UUID, and GUID information utilizing
2476 * a read/modify/write operation against an EA used as a backing store for
2479 * Parameters: vp The vnode whose attributes to set.
2480 * vap A pointer to the attributes to set.
2481 * ctx The vnode context in which the
2482 * operation is to be attempted.
2484 * Returns: 0 Success
2487 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order,
2488 * as are the fsec and lfsec, if they are used.
2490 * The contents of the data area pointed to by 'vap' may be
2491 * modified to indicate that the attribute is supported for
2492 * any given requested attribute.
2494 * XXX: We should enummerate the possible errno values here, and where
2495 * in the code they originated.
2498 vnode_setattr_fallback(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2500 kauth_filesec_t fsec
;
2502 struct kauth_filesec lfsec
;
2508 * Extended security fallback via extended attributes.
2510 * Note that we do not free the filesec; the caller is expected to
2513 if (VATTR_NOT_RETURNED(vap
, va_acl
) ||
2514 VATTR_NOT_RETURNED(vap
, va_uuuid
) ||
2515 VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2516 VFS_DEBUG(ctx
, vp
, "SETATTR - doing filesec fallback");
2519 * Fail for file types that we don't permit extended security
2522 if (!XATTR_VNODE_SUPPORTED(vp
)) {
2523 VFS_DEBUG(ctx
, vp
, "SETATTR - Can't write ACL to file type %d", vnode_vtype(vp
));
2529 * If we don't have all the extended security items, we need
2530 * to fetch the existing data to perform a read-modify-write
2534 if (!VATTR_IS_ACTIVE(vap
, va_acl
) ||
2535 !VATTR_IS_ACTIVE(vap
, va_uuuid
) ||
2536 !VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2537 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0) {
2538 KAUTH_DEBUG("SETATTR - ERROR %d fetching filesec for update", error
);
2542 /* if we didn't get a filesec, use our local one */
2544 KAUTH_DEBUG("SETATTR - using local filesec for new/full update");
2547 KAUTH_DEBUG("SETATTR - updating existing filesec");
2550 facl
= &fsec
->fsec_acl
;
2552 /* if we're using the local filesec, we need to initialise it */
2553 if (fsec
== &lfsec
) {
2554 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
2555 fsec
->fsec_owner
= kauth_null_guid
;
2556 fsec
->fsec_group
= kauth_null_guid
;
2557 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2558 facl
->acl_flags
= 0;
2562 * Update with the supplied attributes.
2564 if (VATTR_IS_ACTIVE(vap
, va_uuuid
)) {
2565 KAUTH_DEBUG("SETATTR - updating owner UUID");
2566 fsec
->fsec_owner
= vap
->va_uuuid
;
2567 VATTR_SET_SUPPORTED(vap
, va_uuuid
);
2569 if (VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2570 KAUTH_DEBUG("SETATTR - updating group UUID");
2571 fsec
->fsec_group
= vap
->va_guuid
;
2572 VATTR_SET_SUPPORTED(vap
, va_guuid
);
2574 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2575 if (vap
->va_acl
== NULL
) {
2576 KAUTH_DEBUG("SETATTR - removing ACL");
2577 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2579 KAUTH_DEBUG("SETATTR - setting ACL with %d entries", vap
->va_acl
->acl_entrycount
);
2582 VATTR_SET_SUPPORTED(vap
, va_acl
);
2586 * If the filesec data is all invalid, we can just remove
2587 * the EA completely.
2589 if ((facl
->acl_entrycount
== KAUTH_FILESEC_NOACL
) &&
2590 kauth_guid_equal(&fsec
->fsec_owner
, &kauth_null_guid
) &&
2591 kauth_guid_equal(&fsec
->fsec_group
, &kauth_null_guid
)) {
2592 error
= vn_removexattr(vp
, KAUTH_FILESEC_XATTR
, XATTR_NOSECURITY
, ctx
);
2593 /* no attribute is ok, nothing to delete */
2594 if (error
== ENOATTR
)
2596 VFS_DEBUG(ctx
, vp
, "SETATTR - remove filesec returning %d", error
);
2599 error
= vnode_set_filesec(vp
, fsec
, facl
, ctx
);
2600 VFS_DEBUG(ctx
, vp
, "SETATTR - update filesec returning %d", error
);
2603 /* if we fetched a filesec, dispose of the buffer */
2605 kauth_filesec_free(fsec
);
2613 * Upcall for a filesystem to tell VFS about an EVFILT_VNODE-type
2617 vnode_notify(vnode_t vp
, uint32_t events
, struct vnode_attr
*vap
)
2619 /* These are the same as the corresponding knotes, at least for now. Cheating a little. */
2620 uint32_t knote_mask
= (VNODE_EVENT_WRITE
| VNODE_EVENT_DELETE
| VNODE_EVENT_RENAME
2621 | VNODE_EVENT_LINK
| VNODE_EVENT_EXTEND
| VNODE_EVENT_ATTRIB
);
2622 uint32_t dir_contents_mask
= (VNODE_EVENT_DIR_CREATED
| VNODE_EVENT_FILE_CREATED
2623 | VNODE_EVENT_DIR_REMOVED
| VNODE_EVENT_FILE_REMOVED
);
2624 uint32_t knote_events
= (events
& knote_mask
);
2626 /* Permissions are not explicitly part of the kqueue model */
2627 if (events
& VNODE_EVENT_PERMS
) {
2628 knote_events
|= NOTE_ATTRIB
;
2631 /* Directory contents information just becomes NOTE_WRITE */
2632 if ((vnode_isdir(vp
)) && (events
& dir_contents_mask
)) {
2633 knote_events
|= NOTE_WRITE
;
2637 lock_vnode_and_post(vp
, knote_events
);
2640 create_fsevent_from_kevent(vp
, events
, vap
);
2653 vnode_isdyldsharedcache(vnode_t vp
)
2655 return ((vp
->v_flag
& VSHARED_DYLD
) ? 1 : 0);
2660 * For a filesystem that isn't tracking its own vnode watchers:
2661 * check whether a vnode is being monitored.
2664 vnode_ismonitored(vnode_t vp
) {
2665 return (vp
->v_knotes
.slh_first
!= NULL
);
2669 * Initialize a struct vnode_attr and activate the attributes required
2670 * by the vnode_notify() call.
2673 vfs_get_notify_attributes(struct vnode_attr
*vap
)
2676 vap
->va_active
= VNODE_NOTIFY_ATTRS
;
2682 vfs_settriggercallback(fsid_t
*fsid
, vfs_trigger_callback_t vtc
, void *data
, uint32_t flags __unused
, vfs_context_t ctx
)
2687 mp
= mount_list_lookupby_fsid(fsid
, 0 /* locked */, 1 /* withref */);
2692 error
= vfs_busy(mp
, LK_NOWAIT
);
2700 if (mp
->mnt_triggercallback
!= NULL
) {
2706 mp
->mnt_triggercallback
= vtc
;
2707 mp
->mnt_triggerdata
= data
;
2710 mp
->mnt_triggercallback(mp
, VTC_REPLACE
, data
, ctx
);
2716 #endif /* CONFIG_TRIGGERS */
2719 * Definition of vnode operations.
2725 *#% lookup dvp L ? ?
2726 *#% lookup vpp - L -
2728 struct vnop_lookup_args
{
2729 struct vnodeop_desc
*a_desc
;
2732 struct componentname
*a_cnp
;
2733 vfs_context_t a_context
;
2738 * Returns: 0 Success
2739 * lock_fsnode:ENOENT No such file or directory [only for VFS
2740 * that is not thread safe & vnode is
2741 * currently being/has been terminated]
2742 * <vfs_lookup>:ENAMETOOLONG
2743 * <vfs_lookup>:ENOENT
2744 * <vfs_lookup>:EJUSTRETURN
2745 * <vfs_lookup>:EPERM
2746 * <vfs_lookup>:EISDIR
2747 * <vfs_lookup>:ENOTDIR
2750 * Note: The return codes from the underlying VFS's lookup routine can't
2751 * be fully enumerated here, since third party VFS authors may not
2752 * limit their error returns to the ones documented here, even
2753 * though this may result in some programs functioning incorrectly.
2755 * The return codes documented above are those which may currently
2756 * be returned by HFS from hfs_lookup, not including additional
2757 * error code which may be propagated from underlying routines.
2760 VNOP_LOOKUP(vnode_t dvp
, vnode_t
*vpp
, struct componentname
*cnp
, vfs_context_t ctx
)
2763 struct vnop_lookup_args a
;
2765 a
.a_desc
= &vnop_lookup_desc
;
2771 _err
= (*dvp
->v_op
[vnop_lookup_desc
.vdesc_offset
])(&a
);
2772 if (_err
== 0 && *vpp
) {
2773 DTRACE_FSINFO(lookup
, vnode_t
, *vpp
);
2780 struct vnop_compound_open_args
{
2781 struct vnodeop_desc
*a_desc
;
2784 struct componentname
*a_cnp
;
2787 struct vnode_attr
*a_vap
;
2788 vfs_context_t a_context
;
2794 VNOP_COMPOUND_OPEN(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, int32_t fmode
, uint32_t *statusp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2797 struct vnop_compound_open_args a
;
2800 uint32_t tmp_status
= 0;
2801 struct componentname
*cnp
= &ndp
->ni_cnd
;
2803 want_create
= (flags
& VNOP_COMPOUND_OPEN_DO_CREATE
);
2805 a
.a_desc
= &vnop_compound_open_desc
;
2807 a
.a_vpp
= vpp
; /* Could be NULL */
2811 a
.a_status
= (statusp
!= NULL
) ? statusp
: &tmp_status
;
2814 a
.a_open_create_authorizer
= vn_authorize_create
;
2815 a
.a_open_existing_authorizer
= vn_authorize_open_existing
;
2816 a
.a_reserved
= NULL
;
2818 if (dvp
== NULLVP
) {
2821 if (want_create
&& !vap
) {
2822 panic("Want create, but no vap?");
2824 if (!want_create
&& vap
) {
2825 panic("Don't want create, but have a vap?");
2828 _err
= (*dvp
->v_op
[vnop_compound_open_desc
.vdesc_offset
])(&a
);
2830 if (_err
== 0 && *vpp
) {
2831 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
2833 DTRACE_FSINFO(compound_open
, vnode_t
, dvp
);
2836 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
2839 did_create
= (*a
.a_status
& COMPOUND_OPEN_STATUS_DID_CREATE
);
2841 if (did_create
&& !want_create
) {
2842 panic("Filesystem did a create, even though none was requested?");
2846 #if CONFIG_APPLEDOUBLE
2847 if (!NATIVE_XATTR(dvp
)) {
2849 * Remove stale Apple Double file (if any).
2851 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
2853 #endif /* CONFIG_APPLEDOUBLE */
2854 /* On create, provide kqueue notification */
2855 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
2858 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, did_create
);
2859 #if 0 /* FSEvents... */
2860 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
2871 struct vnop_create_args
{
2872 struct vnodeop_desc
*a_desc
;
2875 struct componentname
*a_cnp
;
2876 struct vnode_attr
*a_vap
;
2877 vfs_context_t a_context
;
2881 VNOP_CREATE(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
2884 struct vnop_create_args a
;
2886 a
.a_desc
= &vnop_create_desc
;
2893 _err
= (*dvp
->v_op
[vnop_create_desc
.vdesc_offset
])(&a
);
2894 if (_err
== 0 && *vpp
) {
2895 DTRACE_FSINFO(create
, vnode_t
, *vpp
);
2898 #if CONFIG_APPLEDOUBLE
2899 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
2901 * Remove stale Apple Double file (if any).
2903 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
2905 #endif /* CONFIG_APPLEDOUBLE */
2907 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
2915 *#% whiteout dvp L L L
2916 *#% whiteout cnp - - -
2917 *#% whiteout flag - - -
2920 struct vnop_whiteout_args
{
2921 struct vnodeop_desc
*a_desc
;
2923 struct componentname
*a_cnp
;
2925 vfs_context_t a_context
;
2929 VNOP_WHITEOUT(vnode_t dvp
, struct componentname
* cnp
, int flags
, vfs_context_t ctx
)
2932 struct vnop_whiteout_args a
;
2934 a
.a_desc
= &vnop_whiteout_desc
;
2940 _err
= (*dvp
->v_op
[vnop_whiteout_desc
.vdesc_offset
])(&a
);
2941 DTRACE_FSINFO(whiteout
, vnode_t
, dvp
);
2943 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
2955 struct vnop_mknod_args
{
2956 struct vnodeop_desc
*a_desc
;
2959 struct componentname
*a_cnp
;
2960 struct vnode_attr
*a_vap
;
2961 vfs_context_t a_context
;
2965 VNOP_MKNOD(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
2969 struct vnop_mknod_args a
;
2971 a
.a_desc
= &vnop_mknod_desc
;
2978 _err
= (*dvp
->v_op
[vnop_mknod_desc
.vdesc_offset
])(&a
);
2979 if (_err
== 0 && *vpp
) {
2980 DTRACE_FSINFO(mknod
, vnode_t
, *vpp
);
2983 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
2994 struct vnop_open_args
{
2995 struct vnodeop_desc
*a_desc
;
2998 vfs_context_t a_context
;
3002 VNOP_OPEN(vnode_t vp
, int mode
, vfs_context_t ctx
)
3005 struct vnop_open_args a
;
3008 ctx
= vfs_context_current();
3010 a
.a_desc
= &vnop_open_desc
;
3015 _err
= (*vp
->v_op
[vnop_open_desc
.vdesc_offset
])(&a
);
3016 DTRACE_FSINFO(open
, vnode_t
, vp
);
3027 struct vnop_close_args
{
3028 struct vnodeop_desc
*a_desc
;
3031 vfs_context_t a_context
;
3035 VNOP_CLOSE(vnode_t vp
, int fflag
, vfs_context_t ctx
)
3038 struct vnop_close_args a
;
3041 ctx
= vfs_context_current();
3043 a
.a_desc
= &vnop_close_desc
;
3048 _err
= (*vp
->v_op
[vnop_close_desc
.vdesc_offset
])(&a
);
3049 DTRACE_FSINFO(close
, vnode_t
, vp
);
3060 struct vnop_access_args
{
3061 struct vnodeop_desc
*a_desc
;
3064 vfs_context_t a_context
;
3068 VNOP_ACCESS(vnode_t vp
, int action
, vfs_context_t ctx
)
3071 struct vnop_access_args a
;
3074 ctx
= vfs_context_current();
3076 a
.a_desc
= &vnop_access_desc
;
3078 a
.a_action
= action
;
3081 _err
= (*vp
->v_op
[vnop_access_desc
.vdesc_offset
])(&a
);
3082 DTRACE_FSINFO(access
, vnode_t
, vp
);
3090 *#% getattr vp = = =
3093 struct vnop_getattr_args
{
3094 struct vnodeop_desc
*a_desc
;
3096 struct vnode_attr
*a_vap
;
3097 vfs_context_t a_context
;
3101 VNOP_GETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3104 struct vnop_getattr_args a
;
3106 a
.a_desc
= &vnop_getattr_desc
;
3111 _err
= (*vp
->v_op
[vnop_getattr_desc
.vdesc_offset
])(&a
);
3112 DTRACE_FSINFO(getattr
, vnode_t
, vp
);
3120 *#% setattr vp L L L
3123 struct vnop_setattr_args
{
3124 struct vnodeop_desc
*a_desc
;
3126 struct vnode_attr
*a_vap
;
3127 vfs_context_t a_context
;
3131 VNOP_SETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3134 struct vnop_setattr_args a
;
3136 a
.a_desc
= &vnop_setattr_desc
;
3141 _err
= (*vp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
3142 DTRACE_FSINFO(setattr
, vnode_t
, vp
);
3144 #if CONFIG_APPLEDOUBLE
3146 * Shadow uid/gid/mod change to extended attribute file.
3148 if (_err
== 0 && !NATIVE_XATTR(vp
)) {
3149 struct vnode_attr va
;
3153 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
3154 VATTR_SET(&va
, va_uid
, vap
->va_uid
);
3157 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
3158 VATTR_SET(&va
, va_gid
, vap
->va_gid
);
3161 if (VATTR_IS_ACTIVE(vap
, va_mode
)) {
3162 VATTR_SET(&va
, va_mode
, vap
->va_mode
);
3169 dvp
= vnode_getparent(vp
);
3170 vname
= vnode_getname(vp
);
3172 xattrfile_setattr(dvp
, vname
, &va
, ctx
);
3176 vnode_putname(vname
);
3179 #endif /* CONFIG_APPLEDOUBLE */
3182 * If we have changed any of the things about the file that are likely
3183 * to result in changes to authorization results, blow the vnode auth
3187 VATTR_IS_SUPPORTED(vap
, va_mode
) ||
3188 VATTR_IS_SUPPORTED(vap
, va_uid
) ||
3189 VATTR_IS_SUPPORTED(vap
, va_gid
) ||
3190 VATTR_IS_SUPPORTED(vap
, va_flags
) ||
3191 VATTR_IS_SUPPORTED(vap
, va_acl
) ||
3192 VATTR_IS_SUPPORTED(vap
, va_uuuid
) ||
3193 VATTR_IS_SUPPORTED(vap
, va_guuid
))) {
3194 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3197 if (vfs_authopaque(vp
->v_mount
) && vnode_hasnamedstreams(vp
)) {
3199 if (vnode_getnamedstream(vp
, &svp
, XATTR_RESOURCEFORK_NAME
, NS_OPEN
, 0, ctx
) == 0) {
3200 vnode_uncache_authorized_action(svp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3204 #endif /* NAMEDSTREAMS */
3208 post_event_if_success(vp
, _err
, NOTE_ATTRIB
);
3220 struct vnop_read_args
{
3221 struct vnodeop_desc
*a_desc
;
3225 vfs_context_t a_context
;
3229 VNOP_READ(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3232 struct vnop_read_args a
;
3234 user_ssize_t resid
= uio_resid(uio
);
3238 ctx
= vfs_context_current();
3241 a
.a_desc
= &vnop_read_desc
;
3244 a
.a_ioflag
= ioflag
;
3247 _err
= (*vp
->v_op
[vnop_read_desc
.vdesc_offset
])(&a
);
3248 DTRACE_FSINFO_IO(read
,
3249 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3261 struct vnop_write_args
{
3262 struct vnodeop_desc
*a_desc
;
3266 vfs_context_t a_context
;
3270 VNOP_WRITE(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3272 struct vnop_write_args a
;
3275 user_ssize_t resid
= uio_resid(uio
);
3279 ctx
= vfs_context_current();
3282 a
.a_desc
= &vnop_write_desc
;
3285 a
.a_ioflag
= ioflag
;
3288 _err
= (*vp
->v_op
[vnop_write_desc
.vdesc_offset
])(&a
);
3289 DTRACE_FSINFO_IO(write
,
3290 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3292 post_event_if_success(vp
, _err
, NOTE_WRITE
);
3304 struct vnop_ioctl_args
{
3305 struct vnodeop_desc
*a_desc
;
3310 vfs_context_t a_context
;
3314 VNOP_IOCTL(vnode_t vp
, u_long command
, caddr_t data
, int fflag
, vfs_context_t ctx
)
3317 struct vnop_ioctl_args a
;
3320 ctx
= vfs_context_current();
3324 * This check should probably have been put in the TTY code instead...
3326 * We have to be careful about what we assume during startup and shutdown.
3327 * We have to be able to use the root filesystem's device vnode even when
3328 * devfs isn't mounted (yet/anymore), so we can't go looking at its mount
3329 * structure. If there is no data pointer, it doesn't matter whether
3330 * the device is 64-bit ready. Any command (like DKIOCSYNCHRONIZECACHE)
3331 * which passes NULL for its data pointer can therefore be used during
3332 * mount or unmount of the root filesystem.
3334 * Depending on what root filesystems need to do during mount/unmount, we
3335 * may need to loosen this check again in the future.
3337 if (vfs_context_is64bit(ctx
) && !(vnode_ischr(vp
) || vnode_isblk(vp
))) {
3338 if (data
!= NULL
&& !vnode_vfs64bitready(vp
)) {
3343 a
.a_desc
= &vnop_ioctl_desc
;
3345 a
.a_command
= command
;
3350 _err
= (*vp
->v_op
[vnop_ioctl_desc
.vdesc_offset
])(&a
);
3351 DTRACE_FSINFO(ioctl
, vnode_t
, vp
);
3363 struct vnop_select_args
{
3364 struct vnodeop_desc
*a_desc
;
3369 vfs_context_t a_context
;
3373 VNOP_SELECT(vnode_t vp
, int which
, int fflags
, void * wql
, vfs_context_t ctx
)
3376 struct vnop_select_args a
;
3379 ctx
= vfs_context_current();
3381 a
.a_desc
= &vnop_select_desc
;
3384 a
.a_fflags
= fflags
;
3388 _err
= (*vp
->v_op
[vnop_select_desc
.vdesc_offset
])(&a
);
3389 DTRACE_FSINFO(select
, vnode_t
, vp
);
3398 *#% exchange fvp L L L
3399 *#% exchange tvp L L L
3402 struct vnop_exchange_args
{
3403 struct vnodeop_desc
*a_desc
;
3407 vfs_context_t a_context
;
3411 VNOP_EXCHANGE(vnode_t fvp
, vnode_t tvp
, int options
, vfs_context_t ctx
)
3414 struct vnop_exchange_args a
;
3416 a
.a_desc
= &vnop_exchange_desc
;
3419 a
.a_options
= options
;
3422 _err
= (*fvp
->v_op
[vnop_exchange_desc
.vdesc_offset
])(&a
);
3423 DTRACE_FSINFO(exchange
, vnode_t
, fvp
);
3425 /* Don't post NOTE_WRITE because file descriptors follow the data ... */
3426 post_event_if_success(fvp
, _err
, NOTE_ATTRIB
);
3427 post_event_if_success(tvp
, _err
, NOTE_ATTRIB
);
3439 struct vnop_revoke_args
{
3440 struct vnodeop_desc
*a_desc
;
3443 vfs_context_t a_context
;
3447 VNOP_REVOKE(vnode_t vp
, int flags
, vfs_context_t ctx
)
3449 struct vnop_revoke_args a
;
3452 a
.a_desc
= &vnop_revoke_desc
;
3457 _err
= (*vp
->v_op
[vnop_revoke_desc
.vdesc_offset
])(&a
);
3458 DTRACE_FSINFO(revoke
, vnode_t
, vp
);
3470 struct vnop_mmap_args
{
3471 struct vnodeop_desc
*a_desc
;
3474 vfs_context_t a_context
;
3478 VNOP_MMAP(vnode_t vp
, int fflags
, vfs_context_t ctx
)
3481 struct vnop_mmap_args a
;
3483 a
.a_desc
= &vnop_mmap_desc
;
3485 a
.a_fflags
= fflags
;
3488 _err
= (*vp
->v_op
[vnop_mmap_desc
.vdesc_offset
])(&a
);
3489 DTRACE_FSINFO(mmap
, vnode_t
, vp
);
3498 *# mnomap - vp U U U
3501 struct vnop_mnomap_args
{
3502 struct vnodeop_desc
*a_desc
;
3504 vfs_context_t a_context
;
3508 VNOP_MNOMAP(vnode_t vp
, vfs_context_t ctx
)
3511 struct vnop_mnomap_args a
;
3513 a
.a_desc
= &vnop_mnomap_desc
;
3517 _err
= (*vp
->v_op
[vnop_mnomap_desc
.vdesc_offset
])(&a
);
3518 DTRACE_FSINFO(mnomap
, vnode_t
, vp
);
3530 struct vnop_fsync_args
{
3531 struct vnodeop_desc
*a_desc
;
3534 vfs_context_t a_context
;
3538 VNOP_FSYNC(vnode_t vp
, int waitfor
, vfs_context_t ctx
)
3540 struct vnop_fsync_args a
;
3543 a
.a_desc
= &vnop_fsync_desc
;
3545 a
.a_waitfor
= waitfor
;
3548 _err
= (*vp
->v_op
[vnop_fsync_desc
.vdesc_offset
])(&a
);
3549 DTRACE_FSINFO(fsync
, vnode_t
, vp
);
3558 *#% remove dvp L U U
3562 struct vnop_remove_args
{
3563 struct vnodeop_desc
*a_desc
;
3566 struct componentname
*a_cnp
;
3568 vfs_context_t a_context
;
3572 VNOP_REMOVE(vnode_t dvp
, vnode_t vp
, struct componentname
* cnp
, int flags
, vfs_context_t ctx
)
3575 struct vnop_remove_args a
;
3577 a
.a_desc
= &vnop_remove_desc
;
3584 _err
= (*dvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&a
);
3585 DTRACE_FSINFO(remove
, vnode_t
, vp
);
3588 vnode_setneedinactive(vp
);
3589 #if CONFIG_APPLEDOUBLE
3590 if ( !(NATIVE_XATTR(dvp
)) ) {
3592 * Remove any associated extended attribute file (._ AppleDouble file).
3594 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
3596 #endif /* CONFIG_APPLEDOUBLE */
3599 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
3600 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3606 VNOP_COMPOUND_REMOVE(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
3609 struct vnop_compound_remove_args a
;
3610 int no_vp
= (*vpp
== NULLVP
);
3612 a
.a_desc
= &vnop_compound_remove_desc
;
3615 a
.a_cnp
= &ndp
->ni_cnd
;
3619 a
.a_remove_authorizer
= vn_authorize_unlink
;
3621 _err
= (*dvp
->v_op
[vnop_compound_remove_desc
.vdesc_offset
])(&a
);
3622 if (_err
== 0 && *vpp
) {
3623 DTRACE_FSINFO(compound_remove
, vnode_t
, *vpp
);
3625 DTRACE_FSINFO(compound_remove
, vnode_t
, dvp
);
3628 vnode_setneedinactive(*vpp
);
3629 #if CONFIG_APPLEDOUBLE
3630 if ( !(NATIVE_XATTR(dvp
)) ) {
3632 * Remove any associated extended attribute file (._ AppleDouble file).
3634 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 1);
3636 #endif /* CONFIG_APPLEDOUBLE */
3639 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
3640 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3643 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
3644 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
3650 //printf("VNOP_COMPOUND_REMOVE() returning %d\n", _err);
3662 struct vnop_link_args
{
3663 struct vnodeop_desc
*a_desc
;
3666 struct componentname
*a_cnp
;
3667 vfs_context_t a_context
;
3671 VNOP_LINK(vnode_t vp
, vnode_t tdvp
, struct componentname
* cnp
, vfs_context_t ctx
)
3674 struct vnop_link_args a
;
3676 #if CONFIG_APPLEDOUBLE
3678 * For file systems with non-native extended attributes,
3679 * disallow linking to an existing "._" Apple Double file.
3681 if ( !NATIVE_XATTR(tdvp
) && (vp
->v_type
== VREG
)) {
3684 vname
= vnode_getname(vp
);
3685 if (vname
!= NULL
) {
3687 if (vname
[0] == '.' && vname
[1] == '_' && vname
[2] != '\0') {
3690 vnode_putname(vname
);
3695 #endif /* CONFIG_APPLEDOUBLE */
3697 a
.a_desc
= &vnop_link_desc
;
3703 _err
= (*tdvp
->v_op
[vnop_link_desc
.vdesc_offset
])(&a
);
3704 DTRACE_FSINFO(link
, vnode_t
, vp
);
3706 post_event_if_success(vp
, _err
, NOTE_LINK
);
3707 post_event_if_success(tdvp
, _err
, NOTE_WRITE
);
3713 vn_rename(struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
3714 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
3715 uint32_t flags
, vfs_context_t ctx
)
3718 struct nameidata
*fromnd
= NULL
;
3719 struct nameidata
*tond
= NULL
;
3720 #if CONFIG_APPLEDOUBLE
3721 vnode_t src_attr_vp
= NULLVP
;
3722 vnode_t dst_attr_vp
= NULLVP
;
3723 char smallname1
[48];
3724 char smallname2
[48];
3725 char *xfromname
= NULL
;
3726 char *xtoname
= NULL
;
3727 #endif /* CONFIG_APPLEDOUBLE */
3730 batched
= vnode_compound_rename_available(fdvp
);
3733 if (*fvpp
== NULLVP
)
3734 panic("Not batched, and no fvp?");
3737 #if CONFIG_APPLEDOUBLE
3739 * We need to preflight any potential AppleDouble file for the source file
3740 * before doing the rename operation, since we could potentially be doing
3741 * this operation on a network filesystem, and would end up duplicating
3742 * the work. Also, save the source and destination names. Skip it if the
3743 * source has a "._" prefix.
3746 if (!NATIVE_XATTR(fdvp
) &&
3747 !(fcnp
->cn_nameptr
[0] == '.' && fcnp
->cn_nameptr
[1] == '_')) {
3751 /* Get source attribute file name. */
3752 len
= fcnp
->cn_namelen
+ 3;
3753 if (len
> sizeof(smallname1
)) {
3754 MALLOC(xfromname
, char *, len
, M_TEMP
, M_WAITOK
);
3756 xfromname
= &smallname1
[0];
3758 strlcpy(xfromname
, "._", min(sizeof smallname1
, len
));
3759 strncat(xfromname
, fcnp
->cn_nameptr
, fcnp
->cn_namelen
);
3760 xfromname
[len
-1] = '\0';
3762 /* Get destination attribute file name. */
3763 len
= tcnp
->cn_namelen
+ 3;
3764 if (len
> sizeof(smallname2
)) {
3765 MALLOC(xtoname
, char *, len
, M_TEMP
, M_WAITOK
);
3767 xtoname
= &smallname2
[0];
3769 strlcpy(xtoname
, "._", min(sizeof smallname2
, len
));
3770 strncat(xtoname
, tcnp
->cn_nameptr
, tcnp
->cn_namelen
);
3771 xtoname
[len
-1] = '\0';
3774 * Look up source attribute file, keep reference on it if exists.
3775 * Note that we do the namei with the nameiop of RENAME, which is different than
3776 * in the rename syscall. It's OK if the source file does not exist, since this
3777 * is only for AppleDouble files.
3779 if (xfromname
!= NULL
) {
3780 MALLOC(fromnd
, struct nameidata
*, sizeof (struct nameidata
), M_TEMP
, M_WAITOK
);
3781 NDINIT(fromnd
, RENAME
, OP_RENAME
, NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
,
3782 UIO_SYSSPACE
, CAST_USER_ADDR_T(xfromname
), ctx
);
3783 fromnd
->ni_dvp
= fdvp
;
3784 error
= namei(fromnd
);
3787 * If there was an error looking up source attribute file,
3788 * we'll behave as if it didn't exist.
3792 if (fromnd
->ni_vp
) {
3793 /* src_attr_vp indicates need to call vnode_put / nameidone later */
3794 src_attr_vp
= fromnd
->ni_vp
;
3796 if (fromnd
->ni_vp
->v_type
!= VREG
) {
3797 src_attr_vp
= NULLVP
;
3798 vnode_put(fromnd
->ni_vp
);
3802 * Either we got an invalid vnode type (not a regular file) or the namei lookup
3803 * suppressed ENOENT as a valid error since we're renaming. Either way, we don't
3804 * have a vnode here, so we drop our namei buffer for the source attribute file
3806 if (src_attr_vp
== NULLVP
) {
3812 #endif /* CONFIG_APPLEDOUBLE */
3815 _err
= VNOP_COMPOUND_RENAME(fdvp
, fvpp
, fcnp
, fvap
, tdvp
, tvpp
, tcnp
, tvap
, flags
, ctx
);
3817 printf("VNOP_COMPOUND_RENAME() returned %d\n", _err
);
3820 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
3824 mac_vnode_notify_rename(ctx
, *fvpp
, tdvp
, tcnp
);
3828 #if CONFIG_APPLEDOUBLE
3830 * Rename any associated extended attribute file (._ AppleDouble file).
3832 if (_err
== 0 && !NATIVE_XATTR(fdvp
) && xfromname
!= NULL
) {
3836 * Get destination attribute file vnode.
3837 * Note that tdvp already has an iocount reference. Make sure to check that we
3838 * get a valid vnode from namei.
3840 MALLOC(tond
, struct nameidata
*, sizeof(struct nameidata
), M_TEMP
, M_WAITOK
);
3841 NDINIT(tond
, RENAME
, OP_RENAME
,
3842 NOCACHE
| NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
, UIO_SYSSPACE
,
3843 CAST_USER_ADDR_T(xtoname
), ctx
);
3844 tond
->ni_dvp
= tdvp
;
3845 error
= namei(tond
);
3851 dst_attr_vp
= tond
->ni_vp
;
3855 const char *old_name
= src_attr_vp
->v_name
;
3856 vnode_t old_parent
= src_attr_vp
->v_parent
;
3859 error
= VNOP_COMPOUND_RENAME(fdvp
, &src_attr_vp
, &fromnd
->ni_cnd
, NULL
,
3860 tdvp
, &dst_attr_vp
, &tond
->ni_cnd
, NULL
,
3863 error
= VNOP_RENAME(fdvp
, src_attr_vp
, &fromnd
->ni_cnd
,
3864 tdvp
, dst_attr_vp
, &tond
->ni_cnd
, ctx
);
3867 if (error
== 0 && old_name
== src_attr_vp
->v_name
&&
3868 old_parent
== src_attr_vp
->v_parent
) {
3869 int update_flags
= VNODE_UPDATE_NAME
;
3872 update_flags
|= VNODE_UPDATE_PARENT
;
3874 if ((src_attr_vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_NOUPDATEID_RENAME
) == 0) {
3875 vnode_update_identity(src_attr_vp
, tdvp
,
3876 tond
->ni_cnd
.cn_nameptr
,
3877 tond
->ni_cnd
.cn_namelen
,
3878 tond
->ni_cnd
.cn_hash
,
3883 /* kevent notifications for moving resource files
3884 * _err is zero if we're here, so no need to notify directories, code
3885 * below will do that. only need to post the rename on the source and
3886 * possibly a delete on the dest
3888 post_event_if_success(src_attr_vp
, error
, NOTE_RENAME
);
3890 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
3893 } else if (dst_attr_vp
) {
3895 * Just delete destination attribute file vnode if it exists, since
3896 * we didn't have a source attribute file.
3897 * Note that tdvp already has an iocount reference.
3900 struct vnop_remove_args args
;
3902 args
.a_desc
= &vnop_remove_desc
;
3904 args
.a_vp
= dst_attr_vp
;
3905 args
.a_cnp
= &tond
->ni_cnd
;
3906 args
.a_context
= ctx
;
3909 error
= (*tdvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&args
);
3912 vnode_setneedinactive(dst_attr_vp
);
3915 /* kevent notification for deleting the destination's attribute file
3916 * if it existed. Only need to post the delete on the destination, since
3917 * the code below will handle the directories.
3919 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
3924 vnode_put(src_attr_vp
);
3928 vnode_put(dst_attr_vp
);
3931 if (xfromname
&& xfromname
!= &smallname1
[0]) {
3932 FREE(xfromname
, M_TEMP
);
3934 if (xtoname
&& xtoname
!= &smallname2
[0]) {
3935 FREE(xtoname
, M_TEMP
);
3937 #endif /* CONFIG_APPLEDOUBLE */
3939 FREE(fromnd
, M_TEMP
);
3951 *#% rename fdvp U U U
3952 *#% rename fvp U U U
3953 *#% rename tdvp L U U
3954 *#% rename tvp X U U
3957 struct vnop_rename_args
{
3958 struct vnodeop_desc
*a_desc
;
3961 struct componentname
*a_fcnp
;
3964 struct componentname
*a_tcnp
;
3965 vfs_context_t a_context
;
3969 VNOP_RENAME(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
3970 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
3975 struct vnop_rename_args a
;
3977 a
.a_desc
= &vnop_rename_desc
;
3986 /* do the rename of the main file. */
3987 _err
= (*fdvp
->v_op
[vnop_rename_desc
.vdesc_offset
])(&a
);
3988 DTRACE_FSINFO(rename
, vnode_t
, fdvp
);
3991 if (tvp
&& tvp
!= fvp
)
3992 vnode_setneedinactive(tvp
);
3995 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
3997 events
= NOTE_WRITE
;
3998 if (vnode_isdir(fvp
)) {
3999 /* Link count on dir changed only if we are moving a dir and...
4000 * --Moved to new dir, not overwriting there
4001 * --Kept in same dir and DID overwrite
4003 if (((fdvp
!= tdvp
) && (!tvp
)) || ((fdvp
== tdvp
) && (tvp
))) {
4004 events
|= NOTE_LINK
;
4008 lock_vnode_and_post(fdvp
, events
);
4010 lock_vnode_and_post(tdvp
, events
);
4013 /* If you're replacing the target, post a deletion for it */
4016 lock_vnode_and_post(tvp
, NOTE_DELETE
);
4019 lock_vnode_and_post(fvp
, NOTE_RENAME
);
4026 VNOP_COMPOUND_RENAME(
4027 struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
4028 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
4029 uint32_t flags
, vfs_context_t ctx
)
4033 struct vnop_compound_rename_args a
;
4036 no_fvp
= (*fvpp
) == NULLVP
;
4037 no_tvp
= (*tvpp
) == NULLVP
;
4039 a
.a_desc
= &vnop_compound_rename_desc
;
4053 a
.a_rename_authorizer
= vn_authorize_rename
;
4054 a
.a_reserved
= NULL
;
4056 /* do the rename of the main file. */
4057 _err
= (*fdvp
->v_op
[vnop_compound_rename_desc
.vdesc_offset
])(&a
);
4058 DTRACE_FSINFO(compound_rename
, vnode_t
, fdvp
);
4061 if (*tvpp
&& *tvpp
!= *fvpp
)
4062 vnode_setneedinactive(*tvpp
);
4065 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4066 if (_err
== 0 && *fvpp
!= *tvpp
) {
4068 panic("No fvpp after compound rename?");
4071 events
= NOTE_WRITE
;
4072 if (vnode_isdir(*fvpp
)) {
4073 /* Link count on dir changed only if we are moving a dir and...
4074 * --Moved to new dir, not overwriting there
4075 * --Kept in same dir and DID overwrite
4077 if (((fdvp
!= tdvp
) && (!*tvpp
)) || ((fdvp
== tdvp
) && (*tvpp
))) {
4078 events
|= NOTE_LINK
;
4082 lock_vnode_and_post(fdvp
, events
);
4084 lock_vnode_and_post(tdvp
, events
);
4087 /* If you're replacing the target, post a deletion for it */
4090 lock_vnode_and_post(*tvpp
, NOTE_DELETE
);
4093 lock_vnode_and_post(*fvpp
, NOTE_RENAME
);
4097 lookup_compound_vnop_post_hook(_err
, fdvp
, *fvpp
, fcnp
->cn_ndp
, 0);
4099 if (no_tvp
&& *tvpp
!= NULLVP
) {
4100 lookup_compound_vnop_post_hook(_err
, tdvp
, *tvpp
, tcnp
->cn_ndp
, 0);
4103 if (_err
&& _err
!= EKEEPLOOKING
) {
4118 vn_mkdir(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4119 struct vnode_attr
*vap
, vfs_context_t ctx
)
4121 if (ndp
->ni_cnd
.cn_nameiop
!= CREATE
) {
4122 panic("Non-CREATE nameiop in vn_mkdir()?");
4125 if (vnode_compound_mkdir_available(dvp
)) {
4126 return VNOP_COMPOUND_MKDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4128 return VNOP_MKDIR(dvp
, vpp
, &ndp
->ni_cnd
, vap
, ctx
);
4139 struct vnop_mkdir_args
{
4140 struct vnodeop_desc
*a_desc
;
4143 struct componentname
*a_cnp
;
4144 struct vnode_attr
*a_vap
;
4145 vfs_context_t a_context
;
4149 VNOP_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4150 struct vnode_attr
*vap
, vfs_context_t ctx
)
4153 struct vnop_mkdir_args a
;
4155 a
.a_desc
= &vnop_mkdir_desc
;
4162 _err
= (*dvp
->v_op
[vnop_mkdir_desc
.vdesc_offset
])(&a
);
4163 if (_err
== 0 && *vpp
) {
4164 DTRACE_FSINFO(mkdir
, vnode_t
, *vpp
);
4166 #if CONFIG_APPLEDOUBLE
4167 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4169 * Remove stale Apple Double file (if any).
4171 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4173 #endif /* CONFIG_APPLEDOUBLE */
4175 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4181 VNOP_COMPOUND_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4182 struct vnode_attr
*vap
, vfs_context_t ctx
)
4185 struct vnop_compound_mkdir_args a
;
4187 a
.a_desc
= &vnop_compound_mkdir_desc
;
4190 a
.a_cnp
= &ndp
->ni_cnd
;
4195 a
.a_mkdir_authorizer
= vn_authorize_mkdir
;
4197 a
.a_reserved
= NULL
;
4199 _err
= (*dvp
->v_op
[vnop_compound_mkdir_desc
.vdesc_offset
])(&a
);
4200 if (_err
== 0 && *vpp
) {
4201 DTRACE_FSINFO(compound_mkdir
, vnode_t
, *vpp
);
4203 #if CONFIG_APPLEDOUBLE
4204 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4206 * Remove stale Apple Double file (if any).
4208 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4210 #endif /* CONFIG_APPLEDOUBLE */
4212 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4214 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, (_err
== 0));
4215 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4224 vn_rmdir(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4226 if (vnode_compound_rmdir_available(dvp
)) {
4227 return VNOP_COMPOUND_RMDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4229 if (*vpp
== NULLVP
) {
4230 panic("NULL vp, but not a compound VNOP?");
4233 panic("Non-NULL vap, but not a compound VNOP?");
4235 return VNOP_RMDIR(dvp
, *vpp
, &ndp
->ni_cnd
, ctx
);
4246 struct vnop_rmdir_args
{
4247 struct vnodeop_desc
*a_desc
;
4250 struct componentname
*a_cnp
;
4251 vfs_context_t a_context
;
4256 VNOP_RMDIR(struct vnode
*dvp
, struct vnode
*vp
, struct componentname
*cnp
, vfs_context_t ctx
)
4259 struct vnop_rmdir_args a
;
4261 a
.a_desc
= &vnop_rmdir_desc
;
4267 _err
= (*vp
->v_op
[vnop_rmdir_desc
.vdesc_offset
])(&a
);
4268 DTRACE_FSINFO(rmdir
, vnode_t
, vp
);
4271 vnode_setneedinactive(vp
);
4272 #if CONFIG_APPLEDOUBLE
4273 if ( !(NATIVE_XATTR(dvp
)) ) {
4275 * Remove any associated extended attribute file (._ AppleDouble file).
4277 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
4282 /* If you delete a dir, it loses its "." reference --> NOTE_LINK */
4283 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4284 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4290 VNOP_COMPOUND_RMDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4291 struct vnode_attr
*vap
, vfs_context_t ctx
)
4294 struct vnop_compound_rmdir_args a
;
4297 a
.a_desc
= &vnop_mkdir_desc
;
4300 a
.a_cnp
= &ndp
->ni_cnd
;
4304 a
.a_rmdir_authorizer
= vn_authorize_rmdir
;
4305 a
.a_reserved
= NULL
;
4307 no_vp
= (*vpp
== NULLVP
);
4309 _err
= (*dvp
->v_op
[vnop_compound_rmdir_desc
.vdesc_offset
])(&a
);
4310 if (_err
== 0 && *vpp
) {
4311 DTRACE_FSINFO(compound_rmdir
, vnode_t
, *vpp
);
4313 #if CONFIG_APPLEDOUBLE
4314 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4316 * Remove stale Apple Double file (if any).
4318 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4323 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4325 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4328 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
4330 #if 0 /* Removing orphaned ._ files requires a vp.... */
4331 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4341 #if CONFIG_APPLEDOUBLE
4343 * Remove a ._ AppleDouble file
4345 #define AD_STALE_SECS (180)
4347 xattrfile_remove(vnode_t dvp
, const char * basename
, vfs_context_t ctx
, int force
)
4350 struct nameidata nd
;
4352 char *filename
= NULL
;
4355 if ((basename
== NULL
) || (basename
[0] == '\0') ||
4356 (basename
[0] == '.' && basename
[1] == '_')) {
4359 filename
= &smallname
[0];
4360 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4361 if (len
>= sizeof(smallname
)) {
4362 len
++; /* snprintf result doesn't include '\0' */
4363 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4364 len
= snprintf(filename
, len
, "._%s", basename
);
4366 NDINIT(&nd
, DELETE
, OP_UNLINK
, WANTPARENT
| LOCKLEAF
| NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4367 CAST_USER_ADDR_T(filename
), ctx
);
4369 if (namei(&nd
) != 0)
4374 if (xvp
->v_type
!= VREG
)
4378 * When creating a new object and a "._" file already
4379 * exists, check to see if its a stale "._" file.
4383 struct vnode_attr va
;
4386 VATTR_WANTED(&va
, va_data_size
);
4387 VATTR_WANTED(&va
, va_modify_time
);
4388 if (VNOP_GETATTR(xvp
, &va
, ctx
) == 0 &&
4389 VATTR_IS_SUPPORTED(&va
, va_data_size
) &&
4390 VATTR_IS_SUPPORTED(&va
, va_modify_time
) &&
4391 va
.va_data_size
!= 0) {
4395 if ((tv
.tv_sec
> va
.va_modify_time
.tv_sec
) &&
4396 (tv
.tv_sec
- va
.va_modify_time
.tv_sec
) > AD_STALE_SECS
) {
4397 force
= 1; /* must be stale */
4404 error
= VNOP_REMOVE(dvp
, xvp
, &nd
.ni_cnd
, 0, ctx
);
4406 vnode_setneedinactive(xvp
);
4408 post_event_if_success(xvp
, error
, NOTE_DELETE
);
4409 post_event_if_success(dvp
, error
, NOTE_WRITE
);
4416 if (filename
&& filename
!= &smallname
[0]) {
4417 FREE(filename
, M_TEMP
);
4422 * Shadow uid/gid/mod to a ._ AppleDouble file
4425 xattrfile_setattr(vnode_t dvp
, const char * basename
, struct vnode_attr
* vap
,
4429 struct nameidata nd
;
4431 char *filename
= NULL
;
4434 if ((dvp
== NULLVP
) ||
4435 (basename
== NULL
) || (basename
[0] == '\0') ||
4436 (basename
[0] == '.' && basename
[1] == '_')) {
4439 filename
= &smallname
[0];
4440 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4441 if (len
>= sizeof(smallname
)) {
4442 len
++; /* snprintf result doesn't include '\0' */
4443 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4444 len
= snprintf(filename
, len
, "._%s", basename
);
4446 NDINIT(&nd
, LOOKUP
, OP_SETATTR
, NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4447 CAST_USER_ADDR_T(filename
), ctx
);
4449 if (namei(&nd
) != 0)
4455 if (xvp
->v_type
== VREG
) {
4456 struct vnop_setattr_args a
;
4458 a
.a_desc
= &vnop_setattr_desc
;
4463 (void) (*xvp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
4468 if (filename
&& filename
!= &smallname
[0]) {
4469 FREE(filename
, M_TEMP
);
4472 #endif /* CONFIG_APPLEDOUBLE */
4477 *#% symlink dvp L U U
4478 *#% symlink vpp - U -
4481 struct vnop_symlink_args
{
4482 struct vnodeop_desc
*a_desc
;
4485 struct componentname
*a_cnp
;
4486 struct vnode_attr
*a_vap
;
4488 vfs_context_t a_context
;
4493 VNOP_SYMLINK(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4494 struct vnode_attr
*vap
, char *target
, vfs_context_t ctx
)
4497 struct vnop_symlink_args a
;
4499 a
.a_desc
= &vnop_symlink_desc
;
4504 a
.a_target
= target
;
4507 _err
= (*dvp
->v_op
[vnop_symlink_desc
.vdesc_offset
])(&a
);
4508 DTRACE_FSINFO(symlink
, vnode_t
, dvp
);
4509 #if CONFIG_APPLEDOUBLE
4510 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4512 * Remove stale Apple Double file (if any). Posts its own knotes
4514 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4516 #endif /* CONFIG_APPLEDOUBLE */
4518 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
4526 *#% readdir vp L L L
4529 struct vnop_readdir_args
{
4530 struct vnodeop_desc
*a_desc
;
4536 vfs_context_t a_context
;
4541 VNOP_READDIR(struct vnode
*vp
, struct uio
*uio
, int flags
, int *eofflag
,
4542 int *numdirent
, vfs_context_t ctx
)
4545 struct vnop_readdir_args a
;
4547 user_ssize_t resid
= uio_resid(uio
);
4550 a
.a_desc
= &vnop_readdir_desc
;
4554 a
.a_eofflag
= eofflag
;
4555 a
.a_numdirent
= numdirent
;
4558 _err
= (*vp
->v_op
[vnop_readdir_desc
.vdesc_offset
])(&a
);
4559 DTRACE_FSINFO_IO(readdir
,
4560 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4568 *#% readdirattr vp L L L
4571 struct vnop_readdirattr_args
{
4572 struct vnodeop_desc
*a_desc
;
4574 struct attrlist
*a_alist
;
4576 uint32_t a_maxcount
;
4578 uint32_t *a_newstate
;
4580 uint32_t *a_actualcount
;
4581 vfs_context_t a_context
;
4586 VNOP_READDIRATTR(struct vnode
*vp
, struct attrlist
*alist
, struct uio
*uio
, uint32_t maxcount
,
4587 uint32_t options
, uint32_t *newstate
, int *eofflag
, uint32_t *actualcount
, vfs_context_t ctx
)
4590 struct vnop_readdirattr_args a
;
4592 user_ssize_t resid
= uio_resid(uio
);
4595 a
.a_desc
= &vnop_readdirattr_desc
;
4599 a
.a_maxcount
= maxcount
;
4600 a
.a_options
= options
;
4601 a
.a_newstate
= newstate
;
4602 a
.a_eofflag
= eofflag
;
4603 a
.a_actualcount
= actualcount
;
4606 _err
= (*vp
->v_op
[vnop_readdirattr_desc
.vdesc_offset
])(&a
);
4607 DTRACE_FSINFO_IO(readdirattr
,
4608 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4616 *#% readlink vp L L L
4619 struct vnop_readlink_args
{
4620 struct vnodeop_desc
*a_desc
;
4623 vfs_context_t a_context
;
4628 * Returns: 0 Success
4629 * lock_fsnode:ENOENT No such file or directory [only for VFS
4630 * that is not thread safe & vnode is
4631 * currently being/has been terminated]
4632 * <vfs_readlink>:EINVAL
4633 * <vfs_readlink>:???
4635 * Note: The return codes from the underlying VFS's readlink routine
4636 * can't be fully enumerated here, since third party VFS authors
4637 * may not limit their error returns to the ones documented here,
4638 * even though this may result in some programs functioning
4641 * The return codes documented above are those which may currently
4642 * be returned by HFS from hfs_vnop_readlink, not including
4643 * additional error code which may be propagated from underlying
4647 VNOP_READLINK(struct vnode
*vp
, struct uio
*uio
, vfs_context_t ctx
)
4650 struct vnop_readlink_args a
;
4652 user_ssize_t resid
= uio_resid(uio
);
4654 a
.a_desc
= &vnop_readlink_desc
;
4659 _err
= (*vp
->v_op
[vnop_readlink_desc
.vdesc_offset
])(&a
);
4660 DTRACE_FSINFO_IO(readlink
,
4661 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4669 *#% inactive vp L U U
4672 struct vnop_inactive_args
{
4673 struct vnodeop_desc
*a_desc
;
4675 vfs_context_t a_context
;
4679 VNOP_INACTIVE(struct vnode
*vp
, vfs_context_t ctx
)
4682 struct vnop_inactive_args a
;
4684 a
.a_desc
= &vnop_inactive_desc
;
4688 _err
= (*vp
->v_op
[vnop_inactive_desc
.vdesc_offset
])(&a
);
4689 DTRACE_FSINFO(inactive
, vnode_t
, vp
);
4692 /* For file systems that do not support namedstream natively, mark
4693 * the shadow stream file vnode to be recycled as soon as the last
4694 * reference goes away. To avoid re-entering reclaim code, do not
4695 * call recycle on terminating namedstream vnodes.
4697 if (vnode_isnamedstream(vp
) &&
4698 (vp
->v_parent
!= NULLVP
) &&
4699 vnode_isshadow(vp
) &&
4700 ((vp
->v_lflag
& VL_TERMINATE
) == 0)) {
4712 *#% reclaim vp U U U
4715 struct vnop_reclaim_args
{
4716 struct vnodeop_desc
*a_desc
;
4718 vfs_context_t a_context
;
4722 VNOP_RECLAIM(struct vnode
*vp
, vfs_context_t ctx
)
4725 struct vnop_reclaim_args a
;
4727 a
.a_desc
= &vnop_reclaim_desc
;
4731 _err
= (*vp
->v_op
[vnop_reclaim_desc
.vdesc_offset
])(&a
);
4732 DTRACE_FSINFO(reclaim
, vnode_t
, vp
);
4739 * Returns: 0 Success
4740 * lock_fsnode:ENOENT No such file or directory [only for VFS
4741 * that is not thread safe & vnode is
4742 * currently being/has been terminated]
4743 * <vnop_pathconf_desc>:??? [per FS implementation specific]
4748 *#% pathconf vp L L L
4751 struct vnop_pathconf_args
{
4752 struct vnodeop_desc
*a_desc
;
4756 vfs_context_t a_context
;
4760 VNOP_PATHCONF(struct vnode
*vp
, int name
, int32_t *retval
, vfs_context_t ctx
)
4763 struct vnop_pathconf_args a
;
4765 a
.a_desc
= &vnop_pathconf_desc
;
4768 a
.a_retval
= retval
;
4771 _err
= (*vp
->v_op
[vnop_pathconf_desc
.vdesc_offset
])(&a
);
4772 DTRACE_FSINFO(pathconf
, vnode_t
, vp
);
4778 * Returns: 0 Success
4779 * err_advlock:ENOTSUP
4781 * <vnop_advlock_desc>:???
4783 * Notes: VFS implementations of advisory locking using calls through
4784 * <vnop_advlock_desc> because lock enforcement does not occur
4785 * locally should try to limit themselves to the return codes
4786 * documented above for lf_advlock and err_advlock.
4791 *#% advlock vp U U U
4794 struct vnop_advlock_args
{
4795 struct vnodeop_desc
*a_desc
;
4801 vfs_context_t a_context
;
4805 VNOP_ADVLOCK(struct vnode
*vp
, caddr_t id
, int op
, struct flock
*fl
, int flags
, vfs_context_t ctx
, struct timespec
*timeout
)
4808 struct vnop_advlock_args a
;
4810 a
.a_desc
= &vnop_advlock_desc
;
4817 a
.a_timeout
= timeout
;
4819 /* Disallow advisory locking on non-seekable vnodes */
4820 if (vnode_isfifo(vp
)) {
4821 _err
= err_advlock(&a
);
4823 if ((vp
->v_flag
& VLOCKLOCAL
)) {
4824 /* Advisory locking done at this layer */
4825 _err
= lf_advlock(&a
);
4827 /* Advisory locking done by underlying filesystem */
4828 _err
= (*vp
->v_op
[vnop_advlock_desc
.vdesc_offset
])(&a
);
4830 DTRACE_FSINFO(advlock
, vnode_t
, vp
);
4841 *#% allocate vp L L L
4844 struct vnop_allocate_args
{
4845 struct vnodeop_desc
*a_desc
;
4849 off_t
*a_bytesallocated
;
4851 vfs_context_t a_context
;
4856 VNOP_ALLOCATE(struct vnode
*vp
, off_t length
, u_int32_t flags
, off_t
*bytesallocated
, off_t offset
, vfs_context_t ctx
)
4859 struct vnop_allocate_args a
;
4861 a
.a_desc
= &vnop_allocate_desc
;
4863 a
.a_length
= length
;
4865 a
.a_bytesallocated
= bytesallocated
;
4866 a
.a_offset
= offset
;
4869 _err
= (*vp
->v_op
[vnop_allocate_desc
.vdesc_offset
])(&a
);
4870 DTRACE_FSINFO(allocate
, vnode_t
, vp
);
4873 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
4886 struct vnop_pagein_args
{
4887 struct vnodeop_desc
*a_desc
;
4890 upl_offset_t a_pl_offset
;
4894 vfs_context_t a_context
;
4898 VNOP_PAGEIN(struct vnode
*vp
, upl_t pl
, upl_offset_t pl_offset
, off_t f_offset
, size_t size
, int flags
, vfs_context_t ctx
)
4901 struct vnop_pagein_args a
;
4903 a
.a_desc
= &vnop_pagein_desc
;
4906 a
.a_pl_offset
= pl_offset
;
4907 a
.a_f_offset
= f_offset
;
4912 _err
= (*vp
->v_op
[vnop_pagein_desc
.vdesc_offset
])(&a
);
4913 DTRACE_FSINFO(pagein
, vnode_t
, vp
);
4921 *#% pageout vp = = =
4924 struct vnop_pageout_args
{
4925 struct vnodeop_desc
*a_desc
;
4928 upl_offset_t a_pl_offset
;
4932 vfs_context_t a_context
;
4937 VNOP_PAGEOUT(struct vnode
*vp
, upl_t pl
, upl_offset_t pl_offset
, off_t f_offset
, size_t size
, int flags
, vfs_context_t ctx
)
4940 struct vnop_pageout_args a
;
4942 a
.a_desc
= &vnop_pageout_desc
;
4945 a
.a_pl_offset
= pl_offset
;
4946 a
.a_f_offset
= f_offset
;
4951 _err
= (*vp
->v_op
[vnop_pageout_desc
.vdesc_offset
])(&a
);
4952 DTRACE_FSINFO(pageout
, vnode_t
, vp
);
4954 post_event_if_success(vp
, _err
, NOTE_WRITE
);
4960 vn_remove(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4962 if (vnode_compound_remove_available(dvp
)) {
4963 return VNOP_COMPOUND_REMOVE(dvp
, vpp
, ndp
, flags
, vap
, ctx
);
4965 return VNOP_REMOVE(dvp
, *vpp
, &ndp
->ni_cnd
, flags
, ctx
);
4974 *#% searchfs vp L L L
4977 struct vnop_searchfs_args
{
4978 struct vnodeop_desc
*a_desc
;
4980 void *a_searchparams1
;
4981 void *a_searchparams2
;
4982 struct attrlist
*a_searchattrs
;
4983 uint32_t a_maxmatches
;
4984 struct timeval
*a_timelimit
;
4985 struct attrlist
*a_returnattrs
;
4986 uint32_t *a_nummatches
;
4987 uint32_t a_scriptcode
;
4990 struct searchstate
*a_searchstate
;
4991 vfs_context_t a_context
;
4996 VNOP_SEARCHFS(struct vnode
*vp
, void *searchparams1
, void *searchparams2
, struct attrlist
*searchattrs
, uint32_t maxmatches
, struct timeval
*timelimit
, struct attrlist
*returnattrs
, uint32_t *nummatches
, uint32_t scriptcode
, uint32_t options
, struct uio
*uio
, struct searchstate
*searchstate
, vfs_context_t ctx
)
4999 struct vnop_searchfs_args a
;
5001 a
.a_desc
= &vnop_searchfs_desc
;
5003 a
.a_searchparams1
= searchparams1
;
5004 a
.a_searchparams2
= searchparams2
;
5005 a
.a_searchattrs
= searchattrs
;
5006 a
.a_maxmatches
= maxmatches
;
5007 a
.a_timelimit
= timelimit
;
5008 a
.a_returnattrs
= returnattrs
;
5009 a
.a_nummatches
= nummatches
;
5010 a
.a_scriptcode
= scriptcode
;
5011 a
.a_options
= options
;
5013 a
.a_searchstate
= searchstate
;
5016 _err
= (*vp
->v_op
[vnop_searchfs_desc
.vdesc_offset
])(&a
);
5017 DTRACE_FSINFO(searchfs
, vnode_t
, vp
);
5021 #endif /* CONFIG_SEARCHFS */
5026 *#% copyfile fvp U U U
5027 *#% copyfile tdvp L U U
5028 *#% copyfile tvp X U U
5031 struct vnop_copyfile_args
{
5032 struct vnodeop_desc
*a_desc
;
5036 struct componentname
*a_tcnp
;
5039 vfs_context_t a_context
;
5043 VNOP_COPYFILE(struct vnode
*fvp
, struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
5044 int mode
, int flags
, vfs_context_t ctx
)
5047 struct vnop_copyfile_args a
;
5048 a
.a_desc
= &vnop_copyfile_desc
;
5056 _err
= (*fvp
->v_op
[vnop_copyfile_desc
.vdesc_offset
])(&a
);
5057 DTRACE_FSINFO(copyfile
, vnode_t
, fvp
);
5062 VNOP_GETXATTR(vnode_t vp
, const char *name
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5064 struct vnop_getxattr_args a
;
5067 a
.a_desc
= &vnop_getxattr_desc
;
5072 a
.a_options
= options
;
5075 error
= (*vp
->v_op
[vnop_getxattr_desc
.vdesc_offset
])(&a
);
5076 DTRACE_FSINFO(getxattr
, vnode_t
, vp
);
5082 VNOP_SETXATTR(vnode_t vp
, const char *name
, uio_t uio
, int options
, vfs_context_t ctx
)
5084 struct vnop_setxattr_args a
;
5087 a
.a_desc
= &vnop_setxattr_desc
;
5091 a
.a_options
= options
;
5094 error
= (*vp
->v_op
[vnop_setxattr_desc
.vdesc_offset
])(&a
);
5095 DTRACE_FSINFO(setxattr
, vnode_t
, vp
);
5098 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
5100 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5106 VNOP_REMOVEXATTR(vnode_t vp
, const char *name
, int options
, vfs_context_t ctx
)
5108 struct vnop_removexattr_args a
;
5111 a
.a_desc
= &vnop_removexattr_desc
;
5114 a
.a_options
= options
;
5117 error
= (*vp
->v_op
[vnop_removexattr_desc
.vdesc_offset
])(&a
);
5118 DTRACE_FSINFO(removexattr
, vnode_t
, vp
);
5120 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5126 VNOP_LISTXATTR(vnode_t vp
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5128 struct vnop_listxattr_args a
;
5131 a
.a_desc
= &vnop_listxattr_desc
;
5135 a
.a_options
= options
;
5138 error
= (*vp
->v_op
[vnop_listxattr_desc
.vdesc_offset
])(&a
);
5139 DTRACE_FSINFO(listxattr
, vnode_t
, vp
);
5148 *#% blktooff vp = = =
5151 struct vnop_blktooff_args
{
5152 struct vnodeop_desc
*a_desc
;
5159 VNOP_BLKTOOFF(struct vnode
*vp
, daddr64_t lblkno
, off_t
*offset
)
5162 struct vnop_blktooff_args a
;
5164 a
.a_desc
= &vnop_blktooff_desc
;
5166 a
.a_lblkno
= lblkno
;
5167 a
.a_offset
= offset
;
5169 _err
= (*vp
->v_op
[vnop_blktooff_desc
.vdesc_offset
])(&a
);
5170 DTRACE_FSINFO(blktooff
, vnode_t
, vp
);
5178 *#% offtoblk vp = = =
5181 struct vnop_offtoblk_args
{
5182 struct vnodeop_desc
*a_desc
;
5185 daddr64_t
*a_lblkno
;
5189 VNOP_OFFTOBLK(struct vnode
*vp
, off_t offset
, daddr64_t
*lblkno
)
5192 struct vnop_offtoblk_args a
;
5194 a
.a_desc
= &vnop_offtoblk_desc
;
5196 a
.a_offset
= offset
;
5197 a
.a_lblkno
= lblkno
;
5199 _err
= (*vp
->v_op
[vnop_offtoblk_desc
.vdesc_offset
])(&a
);
5200 DTRACE_FSINFO(offtoblk
, vnode_t
, vp
);
5208 *#% blockmap vp L L L
5211 struct vnop_blockmap_args
{
5212 struct vnodeop_desc
*a_desc
;
5220 vfs_context_t a_context
;
5224 VNOP_BLOCKMAP(struct vnode
*vp
, off_t foffset
, size_t size
, daddr64_t
*bpn
, size_t *run
, void *poff
, int flags
, vfs_context_t ctx
)
5227 struct vnop_blockmap_args a
;
5228 size_t localrun
= 0;
5231 ctx
= vfs_context_current();
5233 a
.a_desc
= &vnop_blockmap_desc
;
5235 a
.a_foffset
= foffset
;
5238 a
.a_run
= &localrun
;
5243 _err
= (*vp
->v_op
[vnop_blockmap_desc
.vdesc_offset
])(&a
);
5244 DTRACE_FSINFO(blockmap
, vnode_t
, vp
);
5247 * We used a local variable to request information from the underlying
5248 * filesystem about the length of the I/O run in question. If
5249 * we get malformed output from the filesystem, we cap it to the length
5250 * requested, at most. Update 'run' on the way out.
5253 if (localrun
> size
) {
5266 struct vnop_strategy_args
{
5267 struct vnodeop_desc
*a_desc
;
5273 VNOP_STRATEGY(struct buf
*bp
)
5276 struct vnop_strategy_args a
;
5277 vnode_t vp
= buf_vnode(bp
);
5278 a
.a_desc
= &vnop_strategy_desc
;
5280 _err
= (*vp
->v_op
[vnop_strategy_desc
.vdesc_offset
])(&a
);
5281 DTRACE_FSINFO(strategy
, vnode_t
, vp
);
5286 struct vnop_bwrite_args
{
5287 struct vnodeop_desc
*a_desc
;
5292 VNOP_BWRITE(struct buf
*bp
)
5295 struct vnop_bwrite_args a
;
5296 vnode_t vp
= buf_vnode(bp
);
5297 a
.a_desc
= &vnop_bwrite_desc
;
5299 _err
= (*vp
->v_op
[vnop_bwrite_desc
.vdesc_offset
])(&a
);
5300 DTRACE_FSINFO(bwrite
, vnode_t
, vp
);
5305 struct vnop_kqfilt_add_args
{
5306 struct vnodeop_desc
*a_desc
;
5309 vfs_context_t a_context
;
5313 VNOP_KQFILT_ADD(struct vnode
*vp
, struct knote
*kn
, vfs_context_t ctx
)
5316 struct vnop_kqfilt_add_args a
;
5318 a
.a_desc
= VDESC(vnop_kqfilt_add
);
5323 _err
= (*vp
->v_op
[vnop_kqfilt_add_desc
.vdesc_offset
])(&a
);
5324 DTRACE_FSINFO(kqfilt_add
, vnode_t
, vp
);
5330 struct vnop_kqfilt_remove_args
{
5331 struct vnodeop_desc
*a_desc
;
5334 vfs_context_t a_context
;
5338 VNOP_KQFILT_REMOVE(struct vnode
*vp
, uintptr_t ident
, vfs_context_t ctx
)
5341 struct vnop_kqfilt_remove_args a
;
5343 a
.a_desc
= VDESC(vnop_kqfilt_remove
);
5348 _err
= (*vp
->v_op
[vnop_kqfilt_remove_desc
.vdesc_offset
])(&a
);
5349 DTRACE_FSINFO(kqfilt_remove
, vnode_t
, vp
);
5355 VNOP_MONITOR(vnode_t vp
, uint32_t events
, uint32_t flags
, void *handle
, vfs_context_t ctx
)
5358 struct vnop_monitor_args a
;
5360 a
.a_desc
= VDESC(vnop_monitor
);
5362 a
.a_events
= events
;
5364 a
.a_handle
= handle
;
5367 _err
= (*vp
->v_op
[vnop_monitor_desc
.vdesc_offset
])(&a
);
5368 DTRACE_FSINFO(monitor
, vnode_t
, vp
);
5374 struct vnop_setlabel_args
{
5375 struct vnodeop_desc
*a_desc
;
5378 vfs_context_t a_context
;
5382 VNOP_SETLABEL(struct vnode
*vp
, struct label
*label
, vfs_context_t ctx
)
5385 struct vnop_setlabel_args a
;
5387 a
.a_desc
= VDESC(vnop_setlabel
);
5392 _err
= (*vp
->v_op
[vnop_setlabel_desc
.vdesc_offset
])(&a
);
5393 DTRACE_FSINFO(setlabel
, vnode_t
, vp
);
5401 * Get a named streamed
5404 VNOP_GETNAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, enum nsoperation operation
, int flags
, vfs_context_t ctx
)
5407 struct vnop_getnamedstream_args a
;
5409 a
.a_desc
= &vnop_getnamedstream_desc
;
5413 a
.a_operation
= operation
;
5417 _err
= (*vp
->v_op
[vnop_getnamedstream_desc
.vdesc_offset
])(&a
);
5418 DTRACE_FSINFO(getnamedstream
, vnode_t
, vp
);
5423 * Create a named streamed
5426 VNOP_MAKENAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, int flags
, vfs_context_t ctx
)
5429 struct vnop_makenamedstream_args a
;
5431 a
.a_desc
= &vnop_makenamedstream_desc
;
5438 _err
= (*vp
->v_op
[vnop_makenamedstream_desc
.vdesc_offset
])(&a
);
5439 DTRACE_FSINFO(makenamedstream
, vnode_t
, vp
);
5445 * Remove a named streamed
5448 VNOP_REMOVENAMEDSTREAM(vnode_t vp
, vnode_t svp
, const char *name
, int flags
, vfs_context_t ctx
)
5451 struct vnop_removenamedstream_args a
;
5453 a
.a_desc
= &vnop_removenamedstream_desc
;
5460 _err
= (*vp
->v_op
[vnop_removenamedstream_desc
.vdesc_offset
])(&a
);
5461 DTRACE_FSINFO(removenamedstream
, vnode_t
, vp
);