2 * Copyright (c) 2000-2017 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>
106 #include <sys/kdebug.h>
108 #include <kern/assert.h>
109 #include <kern/kalloc.h>
110 #include <kern/task.h>
111 #include <kern/policy_internal.h>
113 #include <libkern/OSByteOrder.h>
115 #include <miscfs/specfs/specdev.h>
117 #include <mach/mach_types.h>
118 #include <mach/memory_object_types.h>
119 #include <mach/task.h>
122 #include <security/mac_framework.h>
126 #include <miscfs/nullfs/nullfs.h>
137 #define NATIVE_XATTR(VP) \
138 ((VP)->v_mount ? (VP)->v_mount->mnt_kern_flag & MNTK_EXTENDED_ATTRS : 0)
140 #if CONFIG_APPLEDOUBLE
141 static void xattrfile_remove(vnode_t dvp
, const char *basename
,
142 vfs_context_t ctx
, int force
);
143 static void xattrfile_setattr(vnode_t dvp
, const char * basename
,
144 struct vnode_attr
* vap
, vfs_context_t ctx
);
145 #endif /* CONFIG_APPLEDOUBLE */
147 static errno_t
post_rename(vnode_t fdvp
, vnode_t fvp
, vnode_t tdvp
, vnode_t tvp
);
150 * vnode_setneedinactive
152 * Description: Indicate that when the last iocount on this vnode goes away,
153 * and the usecount is also zero, we should inform the filesystem
156 * Parameters: vnode_t vnode to mark
160 * Notes: Notably used when we're deleting a file--we need not have a
161 * usecount, so VNOP_INACTIVE may not get called by anyone. We
162 * want it called when we drop our iocount.
165 vnode_setneedinactive(vnode_t vp
)
170 vp
->v_lflag
|= VL_NEEDINACTIVE
;
175 /* ====================================================================== */
176 /* ************ EXTERNAL KERNEL APIS ********************************** */
177 /* ====================================================================== */
180 * implementations of exported VFS operations
183 VFS_MOUNT(mount_t mp
, vnode_t devvp
, user_addr_t data
, vfs_context_t ctx
)
187 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_mount
== 0)) {
191 if (vfs_context_is64bit(ctx
)) {
192 if (vfs_64bitready(mp
)) {
193 error
= (*mp
->mnt_op
->vfs_mount
)(mp
, devvp
, data
, ctx
);
198 error
= (*mp
->mnt_op
->vfs_mount
)(mp
, devvp
, data
, ctx
);
205 VFS_START(mount_t mp
, int flags
, vfs_context_t ctx
)
209 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_start
== 0)) {
213 error
= (*mp
->mnt_op
->vfs_start
)(mp
, flags
, ctx
);
219 VFS_UNMOUNT(mount_t mp
, int flags
, vfs_context_t ctx
)
223 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_unmount
== 0)) {
227 error
= (*mp
->mnt_op
->vfs_unmount
)(mp
, flags
, ctx
);
234 * ENOTSUP Not supported
238 * Note: The return codes from the underlying VFS's root routine can't
239 * be fully enumerated here, since third party VFS authors may not
240 * limit their error returns to the ones documented here, even
241 * though this may result in some programs functioning incorrectly.
243 * The return codes documented above are those which may currently
244 * be returned by HFS from hfs_vfs_root, which is a simple wrapper
245 * for a call to hfs_vget on the volume mount point, not including
246 * additional error codes which may be propagated from underlying
247 * routines called by hfs_vget.
250 VFS_ROOT(mount_t mp
, struct vnode
** vpp
, vfs_context_t ctx
)
254 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_root
== 0)) {
259 ctx
= vfs_context_current();
262 error
= (*mp
->mnt_op
->vfs_root
)(mp
, vpp
, ctx
);
268 VFS_QUOTACTL(mount_t mp
, int cmd
, uid_t uid
, caddr_t datap
, vfs_context_t ctx
)
272 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_quotactl
== 0)) {
276 error
= (*mp
->mnt_op
->vfs_quotactl
)(mp
, cmd
, uid
, datap
, ctx
);
282 VFS_GETATTR(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
286 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_getattr
== 0)) {
291 ctx
= vfs_context_current();
294 error
= (*mp
->mnt_op
->vfs_getattr
)(mp
, vfa
, ctx
);
300 VFS_SETATTR(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
304 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_setattr
== 0)) {
309 ctx
= vfs_context_current();
312 error
= (*mp
->mnt_op
->vfs_setattr
)(mp
, vfa
, ctx
);
318 VFS_SYNC(mount_t mp
, int flags
, vfs_context_t ctx
)
322 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_sync
== 0)) {
327 ctx
= vfs_context_current();
330 error
= (*mp
->mnt_op
->vfs_sync
)(mp
, flags
, ctx
);
336 VFS_VGET(mount_t mp
, ino64_t ino
, struct vnode
**vpp
, vfs_context_t ctx
)
340 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_vget
== 0)) {
345 ctx
= vfs_context_current();
348 error
= (*mp
->mnt_op
->vfs_vget
)(mp
, ino
, vpp
, ctx
);
354 VFS_FHTOVP(mount_t mp
, int fhlen
, unsigned char *fhp
, vnode_t
*vpp
, vfs_context_t ctx
)
358 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_fhtovp
== 0)) {
363 ctx
= vfs_context_current();
366 error
= (*mp
->mnt_op
->vfs_fhtovp
)(mp
, fhlen
, fhp
, vpp
, ctx
);
372 VFS_VPTOFH(struct vnode
*vp
, int *fhlenp
, unsigned char *fhp
, vfs_context_t ctx
)
376 if ((vp
->v_mount
== dead_mountp
) || (vp
->v_mount
->mnt_op
->vfs_vptofh
== 0)) {
381 ctx
= vfs_context_current();
384 error
= (*vp
->v_mount
->mnt_op
->vfs_vptofh
)(vp
, fhlenp
, fhp
, ctx
);
390 VFS_IOCTL(struct mount
*mp
, u_long command
, caddr_t data
,
391 int flags
, vfs_context_t context
)
393 if (mp
== dead_mountp
|| !mp
->mnt_op
->vfs_ioctl
) {
397 return mp
->mnt_op
->vfs_ioctl(mp
, command
, data
, flags
,
398 context
?: vfs_context_current());
402 VFS_VGET_SNAPDIR(mount_t mp
, vnode_t
*vpp
, vfs_context_t ctx
)
406 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_vget_snapdir
== 0)) {
411 ctx
= vfs_context_current();
414 error
= (*mp
->mnt_op
->vfs_vget_snapdir
)(mp
, vpp
, ctx
);
419 /* returns the cached throttle mask for the mount_t */
421 vfs_throttle_mask(mount_t mp
)
423 return mp
->mnt_throttle_mask
;
426 /* returns a copy of vfs type name for the mount_t */
428 vfs_name(mount_t mp
, char *buffer
)
430 strncpy(buffer
, mp
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
433 /* returns vfs type number for the mount_t */
435 vfs_typenum(mount_t mp
)
437 return mp
->mnt_vtable
->vfc_typenum
;
440 /* Safe to cast to "struct label*"; returns "void*" to limit dependence of mount.h on security headers. */
442 vfs_mntlabel(mount_t mp
)
444 return (void*)mp
->mnt_mntlabel
;
447 /* returns command modifier flags of mount_t ie. MNT_CMDFLAGS */
449 vfs_flags(mount_t mp
)
451 return (uint64_t)(mp
->mnt_flag
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
));
454 /* set any of the command modifier flags(MNT_CMDFLAGS) in mount_t */
456 vfs_setflags(mount_t mp
, uint64_t flags
)
458 uint32_t lflags
= (uint32_t)(flags
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
));
461 mp
->mnt_flag
|= lflags
;
465 /* clear any of the command modifier flags(MNT_CMDFLAGS) in mount_t */
467 vfs_clearflags(mount_t mp
, uint64_t flags
)
469 uint32_t lflags
= (uint32_t)(flags
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
));
472 mp
->mnt_flag
&= ~lflags
;
476 /* Is the mount_t ronly and upgrade read/write requested? */
478 vfs_iswriteupgrade(mount_t mp
) /* ronly && MNTK_WANTRDWR */
480 return (mp
->mnt_flag
& MNT_RDONLY
) && (mp
->mnt_kern_flag
& MNTK_WANTRDWR
);
484 /* Is the mount_t mounted ronly */
486 vfs_isrdonly(mount_t mp
)
488 return mp
->mnt_flag
& MNT_RDONLY
;
491 /* Is the mount_t mounted for filesystem synchronous writes? */
493 vfs_issynchronous(mount_t mp
)
495 return mp
->mnt_flag
& MNT_SYNCHRONOUS
;
498 /* Is the mount_t mounted read/write? */
500 vfs_isrdwr(mount_t mp
)
502 return (mp
->mnt_flag
& MNT_RDONLY
) == 0;
506 /* Is mount_t marked for update (ie MNT_UPDATE) */
508 vfs_isupdate(mount_t mp
)
510 return mp
->mnt_flag
& MNT_UPDATE
;
514 /* Is mount_t marked for reload (ie MNT_RELOAD) */
516 vfs_isreload(mount_t mp
)
518 return (mp
->mnt_flag
& MNT_UPDATE
) && (mp
->mnt_flag
& MNT_RELOAD
);
521 /* Is mount_t marked for forced unmount (ie MNT_FORCE or MNTK_FRCUNMOUNT) */
523 vfs_isforce(mount_t mp
)
525 if (mp
->mnt_lflag
& MNT_LFORCE
) {
533 vfs_isunmount(mount_t mp
)
535 if ((mp
->mnt_lflag
& MNT_LUNMOUNT
)) {
543 vfs_64bitready(mount_t mp
)
545 if ((mp
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
)) {
554 vfs_authcache_ttl(mount_t mp
)
556 if ((mp
->mnt_kern_flag
& (MNTK_AUTH_OPAQUE
| MNTK_AUTH_CACHE_TTL
))) {
557 return mp
->mnt_authcache_ttl
;
559 return CACHED_RIGHT_INFINITE_TTL
;
564 vfs_setauthcache_ttl(mount_t mp
, int ttl
)
567 mp
->mnt_kern_flag
|= MNTK_AUTH_CACHE_TTL
;
568 mp
->mnt_authcache_ttl
= ttl
;
573 vfs_clearauthcache_ttl(mount_t mp
)
576 mp
->mnt_kern_flag
&= ~MNTK_AUTH_CACHE_TTL
;
578 * back to the default TTL value in case
579 * MNTK_AUTH_OPAQUE is set on this mount
581 mp
->mnt_authcache_ttl
= CACHED_LOOKUP_RIGHT_TTL
;
586 vfs_authopaque(mount_t mp
)
588 if ((mp
->mnt_kern_flag
& MNTK_AUTH_OPAQUE
)) {
596 vfs_authopaqueaccess(mount_t mp
)
598 if ((mp
->mnt_kern_flag
& MNTK_AUTH_OPAQUE_ACCESS
)) {
606 vfs_setauthopaque(mount_t mp
)
609 mp
->mnt_kern_flag
|= MNTK_AUTH_OPAQUE
;
614 vfs_setauthopaqueaccess(mount_t mp
)
617 mp
->mnt_kern_flag
|= MNTK_AUTH_OPAQUE_ACCESS
;
622 vfs_clearauthopaque(mount_t mp
)
625 mp
->mnt_kern_flag
&= ~MNTK_AUTH_OPAQUE
;
630 vfs_clearauthopaqueaccess(mount_t mp
)
633 mp
->mnt_kern_flag
&= ~MNTK_AUTH_OPAQUE_ACCESS
;
638 vfs_setextendedsecurity(mount_t mp
)
641 mp
->mnt_kern_flag
|= MNTK_EXTENDED_SECURITY
;
646 vfs_clearextendedsecurity(mount_t mp
)
649 mp
->mnt_kern_flag
&= ~MNTK_EXTENDED_SECURITY
;
654 vfs_setnoswap(mount_t mp
)
657 mp
->mnt_kern_flag
|= MNTK_NOSWAP
;
662 vfs_clearnoswap(mount_t mp
)
665 mp
->mnt_kern_flag
&= ~MNTK_NOSWAP
;
670 vfs_extendedsecurity(mount_t mp
)
672 return mp
->mnt_kern_flag
& MNTK_EXTENDED_SECURITY
;
675 /* returns the max size of short symlink in this mount_t */
677 vfs_maxsymlen(mount_t mp
)
679 return mp
->mnt_maxsymlinklen
;
682 /* set max size of short symlink on mount_t */
684 vfs_setmaxsymlen(mount_t mp
, uint32_t symlen
)
686 mp
->mnt_maxsymlinklen
= symlen
;
689 /* return a pointer to the RO vfs_statfs associated with mount_t */
691 vfs_statfs(mount_t mp
)
693 return &mp
->mnt_vfsstat
;
697 vfs_getattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
701 if ((error
= VFS_GETATTR(mp
, vfa
, ctx
)) != 0) {
706 * If we have a filesystem create time, use it to default some others.
708 if (VFSATTR_IS_SUPPORTED(vfa
, f_create_time
)) {
709 if (VFSATTR_IS_ACTIVE(vfa
, f_modify_time
) && !VFSATTR_IS_SUPPORTED(vfa
, f_modify_time
)) {
710 VFSATTR_RETURN(vfa
, f_modify_time
, vfa
->f_create_time
);
718 vfs_setattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
723 * with a read-only system volume, we need to allow rename of the root volume
724 * even if it's read-only. Don't return EROFS here if setattr changes only
727 if (vfs_isrdonly(mp
) &&
728 !((mp
->mnt_flag
& MNT_ROOTFS
) && (vfa
->f_active
== VFSATTR_f_vol_name
))) {
732 error
= VFS_SETATTR(mp
, vfa
, ctx
);
735 * If we had alternate ways of setting vfs attributes, we'd
742 /* return the private data handle stored in mount_t */
744 vfs_fsprivate(mount_t mp
)
749 /* set the private data handle in mount_t */
751 vfs_setfsprivate(mount_t mp
, void *mntdata
)
754 mp
->mnt_data
= mntdata
;
758 /* query whether the mount point supports native EAs */
760 vfs_nativexattrs(mount_t mp
)
762 return mp
->mnt_kern_flag
& MNTK_EXTENDED_ATTRS
;
766 * return the block size of the underlying
767 * device associated with mount_t
770 vfs_devblocksize(mount_t mp
)
772 return mp
->mnt_devblocksize
;
776 * Returns vnode with an iocount that must be released with vnode_put()
779 vfs_vnodecovered(mount_t mp
)
781 vnode_t vp
= mp
->mnt_vnodecovered
;
782 if ((vp
== NULL
) || (vnode_getwithref(vp
) != 0)) {
790 * Returns device vnode backing a mountpoint with an iocount (if valid vnode exists).
791 * The iocount must be released with vnode_put(). Note that this KPI is subtle
792 * with respect to the validity of using this device vnode for anything substantial
793 * (which is discouraged). If commands are sent to the device driver without
794 * taking proper steps to ensure that the device is still open, chaos may ensue.
795 * Similarly, this routine should only be called if there is some guarantee that
796 * the mount itself is still valid.
799 vfs_devvp(mount_t mp
)
801 vnode_t vp
= mp
->mnt_devvp
;
803 if ((vp
!= NULLVP
) && (vnode_get(vp
) == 0)) {
811 * return the io attributes associated with mount_t
814 vfs_ioattr(mount_t mp
, struct vfsioattr
*ioattrp
)
816 ioattrp
->io_reserved
[0] = NULL
;
817 ioattrp
->io_reserved
[1] = NULL
;
819 ioattrp
->io_maxreadcnt
= MAXPHYS
;
820 ioattrp
->io_maxwritecnt
= MAXPHYS
;
821 ioattrp
->io_segreadcnt
= 32;
822 ioattrp
->io_segwritecnt
= 32;
823 ioattrp
->io_maxsegreadsize
= MAXPHYS
;
824 ioattrp
->io_maxsegwritesize
= MAXPHYS
;
825 ioattrp
->io_devblocksize
= DEV_BSIZE
;
826 ioattrp
->io_flags
= 0;
827 ioattrp
->io_max_swappin_available
= 0;
829 ioattrp
->io_maxreadcnt
= mp
->mnt_maxreadcnt
;
830 ioattrp
->io_maxwritecnt
= mp
->mnt_maxwritecnt
;
831 ioattrp
->io_segreadcnt
= mp
->mnt_segreadcnt
;
832 ioattrp
->io_segwritecnt
= mp
->mnt_segwritecnt
;
833 ioattrp
->io_maxsegreadsize
= mp
->mnt_maxsegreadsize
;
834 ioattrp
->io_maxsegwritesize
= mp
->mnt_maxsegwritesize
;
835 ioattrp
->io_devblocksize
= mp
->mnt_devblocksize
;
836 ioattrp
->io_flags
= mp
->mnt_ioflags
;
837 ioattrp
->io_max_swappin_available
= mp
->mnt_max_swappin_available
;
843 * set the IO attributes associated with mount_t
846 vfs_setioattr(mount_t mp
, struct vfsioattr
* ioattrp
)
851 mp
->mnt_maxreadcnt
= ioattrp
->io_maxreadcnt
;
852 mp
->mnt_maxwritecnt
= ioattrp
->io_maxwritecnt
;
853 mp
->mnt_segreadcnt
= ioattrp
->io_segreadcnt
;
854 mp
->mnt_segwritecnt
= ioattrp
->io_segwritecnt
;
855 mp
->mnt_maxsegreadsize
= ioattrp
->io_maxsegreadsize
;
856 mp
->mnt_maxsegwritesize
= ioattrp
->io_maxsegwritesize
;
857 mp
->mnt_devblocksize
= ioattrp
->io_devblocksize
;
858 mp
->mnt_ioflags
= ioattrp
->io_flags
;
859 mp
->mnt_max_swappin_available
= ioattrp
->io_max_swappin_available
;
863 * Add a new filesystem into the kernel specified in passed in
864 * vfstable structure. It fills in the vnode
865 * dispatch vector that is to be passed to when vnodes are created.
866 * It returns a handle which is to be used to when the FS is to be removed
868 typedef int (*PFI
)(void *);
869 extern int vfs_opv_numops
;
871 vfs_fsadd(struct vfs_fsentry
*vfe
, vfstable_t
*handle
)
873 struct vfstable
*newvfstbl
= NULL
;
875 int(***opv_desc_vector_p
)(void *);
876 int(**opv_desc_vector
)(void *);
877 const struct vnodeopv_entry_desc
*opve_descp
;
883 * This routine is responsible for all the initialization that would
884 * ordinarily be done as part of the system startup;
887 if (vfe
== (struct vfs_fsentry
*)0) {
891 desccount
= vfe
->vfe_vopcnt
;
892 if ((desccount
<= 0) || ((desccount
> 8)) || (vfe
->vfe_vfsops
== (struct vfsops
*)NULL
)
893 || (vfe
->vfe_opvdescs
== (struct vnodeopv_desc
**)NULL
)) {
897 /* Non-threadsafe filesystems are not supported */
898 if ((vfe
->vfe_flags
& (VFS_TBLTHREADSAFE
| VFS_TBLFSNODELOCK
)) == 0) {
902 MALLOC(newvfstbl
, void *, sizeof(struct vfstable
), M_TEMP
,
904 bzero(newvfstbl
, sizeof(struct vfstable
));
905 newvfstbl
->vfc_vfsops
= vfe
->vfe_vfsops
;
906 strncpy(&newvfstbl
->vfc_name
[0], vfe
->vfe_fsname
, MFSNAMELEN
);
907 if ((vfe
->vfe_flags
& VFS_TBLNOTYPENUM
)) {
908 newvfstbl
->vfc_typenum
= maxvfstypenum
++;
910 newvfstbl
->vfc_typenum
= vfe
->vfe_fstypenum
;
913 newvfstbl
->vfc_refcount
= 0;
914 newvfstbl
->vfc_flags
= 0;
915 newvfstbl
->vfc_mountroot
= NULL
;
916 newvfstbl
->vfc_next
= NULL
;
917 newvfstbl
->vfc_vfsflags
= 0;
918 if (vfe
->vfe_flags
& VFS_TBL64BITREADY
) {
919 newvfstbl
->vfc_vfsflags
|= VFC_VFS64BITREADY
;
921 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEINV2
) {
922 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEINV2
;
924 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEOUTV2
) {
925 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEOUTV2
;
927 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) == VFS_TBLLOCALVOL
) {
928 newvfstbl
->vfc_flags
|= MNT_LOCAL
;
930 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) && (vfe
->vfe_flags
& VFS_TBLGENERICMNTARGS
) == 0) {
931 newvfstbl
->vfc_vfsflags
|= VFC_VFSLOCALARGS
;
933 newvfstbl
->vfc_vfsflags
|= VFC_VFSGENERICARGS
;
936 if (vfe
->vfe_flags
& VFS_TBLNATIVEXATTR
) {
937 newvfstbl
->vfc_vfsflags
|= VFC_VFSNATIVEXATTR
;
939 if (vfe
->vfe_flags
& VFS_TBLUNMOUNT_PREFLIGHT
) {
940 newvfstbl
->vfc_vfsflags
|= VFC_VFSPREFLIGHT
;
942 if (vfe
->vfe_flags
& VFS_TBLREADDIR_EXTENDED
) {
943 newvfstbl
->vfc_vfsflags
|= VFC_VFSREADDIR_EXTENDED
;
945 if (vfe
->vfe_flags
& VFS_TBLNOMACLABEL
) {
946 newvfstbl
->vfc_vfsflags
|= VFC_VFSNOMACLABEL
;
948 if (vfe
->vfe_flags
& VFS_TBLVNOP_NOUPDATEID_RENAME
) {
949 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_NOUPDATEID_RENAME
;
951 if (vfe
->vfe_flags
& VFS_TBLVNOP_SECLUDE_RENAME
) {
952 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_SECLUDE_RENAME
;
954 if (vfe
->vfe_flags
& VFS_TBLCANMOUNTROOT
) {
955 newvfstbl
->vfc_vfsflags
|= VFC_VFSCANMOUNTROOT
;
959 * Allocate and init the vectors.
960 * Also handle backwards compatibility.
962 * We allocate one large block to hold all <desccount>
963 * vnode operation vectors stored contiguously.
965 /* XXX - shouldn't be M_TEMP */
967 descsize
= desccount
* vfs_opv_numops
* sizeof(PFI
);
968 MALLOC(descptr
, PFI
*, descsize
,
970 bzero(descptr
, descsize
);
972 newvfstbl
->vfc_descptr
= descptr
;
973 newvfstbl
->vfc_descsize
= descsize
;
975 newvfstbl
->vfc_sysctl
= NULL
;
977 for (i
= 0; i
< desccount
; i
++) {
978 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
980 * Fill in the caller's pointer to the start of the i'th vector.
981 * They'll need to supply it when calling vnode_create.
983 opv_desc_vector
= descptr
+ i
* vfs_opv_numops
;
984 *opv_desc_vector_p
= opv_desc_vector
;
986 for (j
= 0; vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
].opve_op
; j
++) {
987 opve_descp
= &(vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
]);
989 /* Silently skip known-disabled operations */
990 if (opve_descp
->opve_op
->vdesc_flags
& VDESC_DISABLED
) {
991 printf("vfs_fsadd: Ignoring reference in %p to disabled operation %s.\n",
992 vfe
->vfe_opvdescs
[i
], opve_descp
->opve_op
->vdesc_name
);
997 * Sanity check: is this operation listed
998 * in the list of operations? We check this
999 * by seeing if its offset is zero. Since
1000 * the default routine should always be listed
1001 * first, it should be the only one with a zero
1002 * offset. Any other operation with a zero
1003 * offset is probably not listed in
1004 * vfs_op_descs, and so is probably an error.
1006 * A panic here means the layer programmer
1007 * has committed the all-too common bug
1008 * of adding a new operation to the layer's
1009 * list of vnode operations but
1010 * not adding the operation to the system-wide
1011 * list of supported operations.
1013 if (opve_descp
->opve_op
->vdesc_offset
== 0 &&
1014 opve_descp
->opve_op
!= VDESC(vnop_default
)) {
1015 printf("vfs_fsadd: operation %s not listed in %s.\n",
1016 opve_descp
->opve_op
->vdesc_name
,
1018 panic("vfs_fsadd: bad operation");
1021 * Fill in this entry.
1023 opv_desc_vector
[opve_descp
->opve_op
->vdesc_offset
] =
1024 opve_descp
->opve_impl
;
1029 * Finally, go back and replace unfilled routines
1030 * with their default. (Sigh, an O(n^3) algorithm. I
1031 * could make it better, but that'd be work, and n is small.)
1033 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
1036 * Force every operations vector to have a default routine.
1038 opv_desc_vector
= *opv_desc_vector_p
;
1039 if (opv_desc_vector
[VOFFSET(vnop_default
)] == NULL
) {
1040 panic("vfs_fsadd: operation vector without default routine.");
1042 for (j
= 0; j
< vfs_opv_numops
; j
++) {
1043 if (opv_desc_vector
[j
] == NULL
) {
1044 opv_desc_vector
[j
] =
1045 opv_desc_vector
[VOFFSET(vnop_default
)];
1048 } /* end of each vnodeopv_desc parsing */
1052 *handle
= vfstable_add(newvfstbl
);
1054 if (newvfstbl
->vfc_typenum
<= maxvfstypenum
) {
1055 maxvfstypenum
= newvfstbl
->vfc_typenum
+ 1;
1058 if (newvfstbl
->vfc_vfsops
->vfs_init
) {
1059 struct vfsconf vfsc
;
1060 bzero(&vfsc
, sizeof(struct vfsconf
));
1061 vfsc
.vfc_reserved1
= 0;
1062 bcopy((*handle
)->vfc_name
, vfsc
.vfc_name
, sizeof(vfsc
.vfc_name
));
1063 vfsc
.vfc_typenum
= (*handle
)->vfc_typenum
;
1064 vfsc
.vfc_refcount
= (*handle
)->vfc_refcount
;
1065 vfsc
.vfc_flags
= (*handle
)->vfc_flags
;
1066 vfsc
.vfc_reserved2
= 0;
1067 vfsc
.vfc_reserved3
= 0;
1069 (*newvfstbl
->vfc_vfsops
->vfs_init
)(&vfsc
);
1072 FREE(newvfstbl
, M_TEMP
);
1078 * Removes the filesystem from kernel.
1079 * The argument passed in is the handle that was given when
1080 * file system was added
1083 vfs_fsremove(vfstable_t handle
)
1085 struct vfstable
* vfstbl
= (struct vfstable
*)handle
;
1086 void *old_desc
= NULL
;
1089 /* Preflight check for any mounts */
1091 if (vfstbl
->vfc_refcount
!= 0) {
1092 mount_list_unlock();
1097 * save the old descriptor; the free cannot occur unconditionally,
1098 * since vfstable_del() may fail.
1100 if (vfstbl
->vfc_descptr
&& vfstbl
->vfc_descsize
) {
1101 old_desc
= vfstbl
->vfc_descptr
;
1103 err
= vfstable_del(vfstbl
);
1105 mount_list_unlock();
1107 /* free the descriptor if the delete was successful */
1108 if (err
== 0 && old_desc
) {
1109 FREE(old_desc
, M_TEMP
);
1116 vfs_setowner(mount_t mp
, uid_t uid
, gid_t gid
)
1118 mp
->mnt_fsowner
= uid
;
1119 mp
->mnt_fsgroup
= gid
;
1123 * Callers should be careful how they use this; accessing
1124 * mnt_last_write_completed_timestamp is not thread-safe. Writing to
1125 * it isn't either. Point is: be prepared to deal with strange values
1129 vfs_idle_time(mount_t mp
)
1131 if (mp
->mnt_pending_write_size
) {
1140 - mp
->mnt_last_write_completed_timestamp
.tv_sec
) * 1000000
1141 + now
.tv_usec
- mp
->mnt_last_write_completed_timestamp
.tv_usec
;
1145 vfs_context_pid(vfs_context_t ctx
)
1147 return proc_pid(vfs_context_proc(ctx
));
1151 vfs_context_suser(vfs_context_t ctx
)
1153 return suser(ctx
->vc_ucred
, NULL
);
1157 * Return bit field of signals posted to all threads in the context's process.
1159 * XXX Signals should be tied to threads, not processes, for most uses of this
1163 vfs_context_issignal(vfs_context_t ctx
, sigset_t mask
)
1165 proc_t p
= vfs_context_proc(ctx
);
1167 return proc_pendingsignals(p
, mask
);
1173 vfs_context_is64bit(vfs_context_t ctx
)
1175 proc_t proc
= vfs_context_proc(ctx
);
1178 return proc_is64bit(proc
);
1187 * Description: Given a vfs_context_t, return the proc_t associated with it.
1189 * Parameters: vfs_context_t The context to use
1191 * Returns: proc_t The process for this context
1193 * Notes: This function will return the current_proc() if any of the
1194 * following conditions are true:
1196 * o The supplied context pointer is NULL
1197 * o There is no Mach thread associated with the context
1198 * o There is no Mach task associated with the Mach thread
1199 * o There is no proc_t associated with the Mach task
1200 * o The proc_t has no per process open file table
1201 * o The proc_t is post-vfork()
1203 * This causes this function to return a value matching as
1204 * closely as possible the previous behaviour, while at the
1205 * same time avoiding the task lending that results from vfork()
1208 vfs_context_proc(vfs_context_t ctx
)
1212 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1213 proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
);
1215 if (proc
!= NULL
&& (proc
->p_fd
== NULL
|| (proc
->p_lflag
& P_LVFORK
))) {
1219 return proc
== NULL
? current_proc() : proc
;
1223 * vfs_context_get_special_port
1225 * Description: Return the requested special port from the task associated
1226 * with the given context.
1228 * Parameters: vfs_context_t The context to use
1229 * int Index of special port
1230 * ipc_port_t * Pointer to returned port
1232 * Returns: kern_return_t see task_get_special_port()
1235 vfs_context_get_special_port(vfs_context_t ctx
, int which
, ipc_port_t
*portp
)
1239 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1240 task
= get_threadtask(ctx
->vc_thread
);
1243 return task_get_special_port(task
, which
, portp
);
1247 * vfs_context_set_special_port
1249 * Description: Set the requested special port in the task associated
1250 * with the given context.
1252 * Parameters: vfs_context_t The context to use
1253 * int Index of special port
1254 * ipc_port_t New special port
1256 * Returns: kern_return_t see task_set_special_port()
1259 vfs_context_set_special_port(vfs_context_t ctx
, int which
, ipc_port_t port
)
1263 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1264 task
= get_threadtask(ctx
->vc_thread
);
1267 return task_set_special_port(task
, which
, port
);
1271 * vfs_context_thread
1273 * Description: Return the Mach thread associated with a vfs_context_t
1275 * Parameters: vfs_context_t The context to use
1277 * Returns: thread_t The thread for this context, or
1278 * NULL, if there is not one.
1280 * Notes: NULL thread_t's are legal, but discouraged. They occur only
1281 * as a result of a static vfs_context_t declaration in a function
1282 * and will result in this function returning NULL.
1284 * This is intentional; this function should NOT return the
1285 * current_thread() in this case.
1288 vfs_context_thread(vfs_context_t ctx
)
1290 return ctx
->vc_thread
;
1297 * Description: Returns a reference on the vnode for the current working
1298 * directory for the supplied context
1300 * Parameters: vfs_context_t The context to use
1302 * Returns: vnode_t The current working directory
1305 * Notes: The function first attempts to obtain the current directory
1306 * from the thread, and if it is not present there, falls back
1307 * to obtaining it from the process instead. If it can't be
1308 * obtained from either place, we return NULLVP.
1311 vfs_context_cwd(vfs_context_t ctx
)
1313 vnode_t cwd
= NULLVP
;
1315 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1316 uthread_t uth
= get_bsdthread_info(ctx
->vc_thread
);
1320 * Get the cwd from the thread; if there isn't one, get it
1321 * from the process, instead.
1323 if ((cwd
= uth
->uu_cdir
) == NULLVP
&&
1324 (proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
)) != NULL
&&
1325 proc
->p_fd
!= NULL
) {
1326 cwd
= proc
->p_fd
->fd_cdir
;
1334 * vfs_context_get_cwd
1336 * Description: Returns a vnode for the current working directory for the
1337 * supplied context. The returned vnode has an iocount on it
1338 * which must be released with a vnode_put().
1340 * Parameters: vfs_context_t The context to use
1342 * Returns: vnode_t The current working directory
1345 * Notes: The function first attempts to obtain the current directory
1346 * from the thread, and if it is not present there, falls back
1347 * to obtaining it from the process instead. If it can't be
1348 * obtained from either place, we return NULLVP.
1351 vfs_context_get_cwd(vfs_context_t ctx
)
1353 vnode_t cwd
= NULLVP
;
1355 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1356 uthread_t uth
= get_bsdthread_info(ctx
->vc_thread
);
1360 * Get the cwd from the thread; if there isn't one, get it
1361 * from the process, instead.
1366 if ((vnode_get(cwd
) != 0)) {
1369 } else if ((proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
)) != NULL
&&
1370 proc
->p_fd
!= NULL
) {
1372 cwd
= proc
->p_fd
->fd_cdir
;
1373 if (cwd
&& (vnode_get(cwd
) != 0)) {
1376 proc_fdunlock(proc
);
1384 * vfs_context_create
1386 * Description: Allocate and initialize a new context.
1388 * Parameters: vfs_context_t: Context to copy, or NULL for new
1390 * Returns: Pointer to new context
1392 * Notes: Copy cred and thread from argument, if available; else
1393 * initialize with current thread and new cred. Returns
1394 * with a reference held on the credential.
1397 vfs_context_create(vfs_context_t ctx
)
1399 vfs_context_t newcontext
;
1401 newcontext
= (vfs_context_t
)kalloc(sizeof(struct vfs_context
));
1404 kauth_cred_t safecred
;
1406 newcontext
->vc_thread
= ctx
->vc_thread
;
1407 safecred
= ctx
->vc_ucred
;
1409 newcontext
->vc_thread
= current_thread();
1410 safecred
= kauth_cred_get();
1412 if (IS_VALID_CRED(safecred
)) {
1413 kauth_cred_ref(safecred
);
1415 newcontext
->vc_ucred
= safecred
;
1423 vfs_context_current(void)
1425 vfs_context_t ctx
= NULL
;
1426 volatile uthread_t ut
= (uthread_t
)get_bsdthread_info(current_thread());
1429 if (ut
->uu_context
.vc_ucred
!= NULL
) {
1430 ctx
= &ut
->uu_context
;
1434 return ctx
== NULL
? vfs_context_kernel() : ctx
;
1441 * Dangerous hack - adopt the first kernel thread as the current thread, to
1442 * get to the vfs_context_t in the uthread associated with a kernel thread.
1443 * This is used by UDF to make the call into IOCDMediaBSDClient,
1444 * IOBDMediaBSDClient, and IODVDMediaBSDClient to determine whether the
1445 * ioctl() is being called from kernel or user space (and all this because
1446 * we do not pass threads into our ioctl()'s, instead of processes).
1448 * This is also used by imageboot_setup(), called early from bsd_init() after
1449 * kernproc has been given a credential.
1451 * Note: The use of proc_thread() here is a convenience to avoid inclusion
1452 * of many Mach headers to do the reference directly rather than indirectly;
1453 * we will need to forego this convenience when we reture proc_thread().
1455 static struct vfs_context kerncontext
;
1457 vfs_context_kernel(void)
1459 if (kerncontext
.vc_ucred
== NOCRED
) {
1460 kerncontext
.vc_ucred
= kernproc
->p_ucred
;
1462 if (kerncontext
.vc_thread
== NULL
) {
1463 kerncontext
.vc_thread
= proc_thread(kernproc
);
1466 return &kerncontext
;
1471 vfs_context_rele(vfs_context_t ctx
)
1474 if (IS_VALID_CRED(ctx
->vc_ucred
)) {
1475 kauth_cred_unref(&ctx
->vc_ucred
);
1477 kfree(ctx
, sizeof(struct vfs_context
));
1484 vfs_context_ucred(vfs_context_t ctx
)
1486 return ctx
->vc_ucred
;
1490 * Return true if the context is owned by the superuser.
1493 vfs_context_issuser(vfs_context_t ctx
)
1495 return kauth_cred_issuser(vfs_context_ucred(ctx
));
1499 vfs_context_iskernel(vfs_context_t ctx
)
1501 return ctx
== &kerncontext
;
1505 * Given a context, for all fields of vfs_context_t which
1506 * are not held with a reference, set those fields to the
1507 * values for the current execution context. Currently, this
1508 * just means the vc_thread.
1510 * Returns: 0 for success, nonzero for failure
1512 * The intended use is:
1513 * 1. vfs_context_create() gets the caller a context
1514 * 2. vfs_context_bind() sets the unrefcounted data
1515 * 3. vfs_context_rele() releases the context
1519 vfs_context_bind(vfs_context_t ctx
)
1521 ctx
->vc_thread
= current_thread();
1526 vfs_isswapmount(mount_t mnt
)
1528 return mnt
&& ISSET(mnt
->mnt_kern_flag
, MNTK_SWAP_MOUNT
) ? 1 : 0;
1531 /* XXXXXXXXXXXXXX VNODE KAPIS XXXXXXXXXXXXXXXXXXXXXXXXX */
1535 * Convert between vnode types and inode formats (since POSIX.1
1536 * defines mode word of stat structure in terms of inode formats).
1539 vnode_iftovt(int mode
)
1541 return iftovt_tab
[((mode
) & S_IFMT
) >> 12];
1545 vnode_vttoif(enum vtype indx
)
1547 return vttoif_tab
[(int)(indx
)];
1551 vnode_makeimode(int indx
, int mode
)
1553 return (int)(VTTOIF(indx
) | (mode
));
1558 * vnode manipulation functions.
1561 /* returns system root vnode iocount; It should be released using vnode_put() */
1567 error
= vnode_get(rootvnode
);
1577 vnode_vid(vnode_t vp
)
1579 return (uint32_t)(vp
->v_id
);
1583 vnode_mount(vnode_t vp
)
1590 vnode_mountdevvp(vnode_t vp
)
1593 return vp
->v_mount
->mnt_devvp
;
1601 vnode_isonexternalstorage(vnode_t vp
)
1605 if (vp
->v_mount
->mnt_ioflags
& MNT_IOFLAGS_PERIPHERAL_DRIVE
) {
1614 vnode_mountedhere(vnode_t vp
)
1618 if ((vp
->v_type
== VDIR
) && ((mp
= vp
->v_mountedhere
) != NULL
) &&
1619 (mp
->mnt_vnodecovered
== vp
)) {
1622 return (mount_t
)NULL
;
1626 /* returns vnode type of vnode_t */
1628 vnode_vtype(vnode_t vp
)
1633 /* returns FS specific node saved in vnode */
1635 vnode_fsnode(vnode_t vp
)
1641 vnode_clearfsnode(vnode_t vp
)
1647 vnode_specrdev(vnode_t vp
)
1653 /* Accessor functions */
1654 /* is vnode_t a root vnode */
1656 vnode_isvroot(vnode_t vp
)
1658 return (vp
->v_flag
& VROOT
)? 1 : 0;
1661 /* is vnode_t a system vnode */
1663 vnode_issystem(vnode_t vp
)
1665 return (vp
->v_flag
& VSYSTEM
)? 1 : 0;
1668 /* is vnode_t a swap file vnode */
1670 vnode_isswap(vnode_t vp
)
1672 return (vp
->v_flag
& VSWAP
)? 1 : 0;
1675 /* is vnode_t a tty */
1677 vnode_istty(vnode_t vp
)
1679 return (vp
->v_flag
& VISTTY
) ? 1 : 0;
1682 /* if vnode_t mount operation in progress */
1684 vnode_ismount(vnode_t vp
)
1686 return (vp
->v_flag
& VMOUNT
)? 1 : 0;
1689 /* is this vnode under recyle now */
1691 vnode_isrecycled(vnode_t vp
)
1695 vnode_lock_spin(vp
);
1696 ret
= (vp
->v_lflag
& (VL_TERMINATE
| VL_DEAD
))? 1 : 0;
1701 /* vnode was created by background task requesting rapid aging
1702 * and has not since been referenced by a normal task */
1704 vnode_israge(vnode_t vp
)
1706 return (vp
->v_flag
& VRAGE
)? 1 : 0;
1710 vnode_needssnapshots(vnode_t vp
)
1712 return (vp
->v_flag
& VNEEDSSNAPSHOT
)? 1 : 0;
1716 /* Check the process/thread to see if we should skip atime updates */
1718 vfs_ctx_skipatime(vfs_context_t ctx
)
1724 proc
= vfs_context_proc(ctx
);
1725 thr
= vfs_context_thread(ctx
);
1727 /* Validate pointers in case we were invoked via a kernel context */
1729 ut
= get_bsdthread_info(thr
);
1731 if (proc
->p_lflag
& P_LRAGE_VNODES
) {
1736 if (ut
->uu_flag
& (UT_RAGE_VNODES
| UT_ATIME_UPDATE
)) {
1741 if (proc
->p_vfs_iopolicy
& P_VFS_IOPOLICY_ATIME_UPDATES
) {
1748 /* is vnode_t marked to not keep data cached once it's been consumed */
1750 vnode_isnocache(vnode_t vp
)
1752 return (vp
->v_flag
& VNOCACHE_DATA
)? 1 : 0;
1756 * has sequential readahead been disabled on this vnode
1759 vnode_isnoreadahead(vnode_t vp
)
1761 return (vp
->v_flag
& VRAOFF
)? 1 : 0;
1765 vnode_is_openevt(vnode_t vp
)
1767 return (vp
->v_flag
& VOPENEVT
)? 1 : 0;
1770 /* is vnode_t a standard one? */
1772 vnode_isstandard(vnode_t vp
)
1774 return (vp
->v_flag
& VSTANDARD
)? 1 : 0;
1777 /* don't vflush() if SKIPSYSTEM */
1779 vnode_isnoflush(vnode_t vp
)
1781 return (vp
->v_flag
& VNOFLUSH
)? 1 : 0;
1784 /* is vnode_t a regular file */
1786 vnode_isreg(vnode_t vp
)
1788 return (vp
->v_type
== VREG
)? 1 : 0;
1791 /* is vnode_t a directory? */
1793 vnode_isdir(vnode_t vp
)
1795 return (vp
->v_type
== VDIR
)? 1 : 0;
1798 /* is vnode_t a symbolic link ? */
1800 vnode_islnk(vnode_t vp
)
1802 return (vp
->v_type
== VLNK
)? 1 : 0;
1806 vnode_lookup_continue_needed(vnode_t vp
, struct componentname
*cnp
)
1808 struct nameidata
*ndp
= cnp
->cn_ndp
;
1811 panic("vnode_lookup_continue_needed(): cnp->cn_ndp is NULL\n");
1814 if (vnode_isdir(vp
)) {
1815 if (vp
->v_mountedhere
!= NULL
) {
1820 if (vp
->v_resolve
) {
1823 #endif /* CONFIG_TRIGGERS */
1827 if (vnode_islnk(vp
)) {
1828 /* From lookup(): || *ndp->ni_next == '/') No need for this, we know we're NULL-terminated here */
1829 if (cnp
->cn_flags
& FOLLOW
) {
1832 if (ndp
->ni_flag
& NAMEI_TRAILINGSLASH
) {
1840 ndp
->ni_flag
|= NAMEI_CONTLOOKUP
;
1841 return EKEEPLOOKING
;
1844 /* is vnode_t a fifo ? */
1846 vnode_isfifo(vnode_t vp
)
1848 return (vp
->v_type
== VFIFO
)? 1 : 0;
1851 /* is vnode_t a block device? */
1853 vnode_isblk(vnode_t vp
)
1855 return (vp
->v_type
== VBLK
)? 1 : 0;
1859 vnode_isspec(vnode_t vp
)
1861 return ((vp
->v_type
== VCHR
) || (vp
->v_type
== VBLK
)) ? 1 : 0;
1864 /* is vnode_t a char device? */
1866 vnode_ischr(vnode_t vp
)
1868 return (vp
->v_type
== VCHR
)? 1 : 0;
1871 /* is vnode_t a socket? */
1873 vnode_issock(vnode_t vp
)
1875 return (vp
->v_type
== VSOCK
)? 1 : 0;
1878 /* is vnode_t a device with multiple active vnodes referring to it? */
1880 vnode_isaliased(vnode_t vp
)
1882 enum vtype vt
= vp
->v_type
;
1883 if (!((vt
== VCHR
) || (vt
== VBLK
))) {
1886 return vp
->v_specflags
& SI_ALIASED
;
1890 /* is vnode_t a named stream? */
1892 vnode_isnamedstream(
1901 return (vp
->v_flag
& VISNAMEDSTREAM
) ? 1 : 0;
1917 return (vp
->v_flag
& VISSHADOW
) ? 1 : 0;
1923 /* does vnode have associated named stream vnodes ? */
1925 vnode_hasnamedstreams(
1934 return (vp
->v_lflag
& VL_HASSTREAMS
) ? 1 : 0;
1939 /* TBD: set vnode_t to not cache data after it is consumed once; used for quota */
1941 vnode_setnocache(vnode_t vp
)
1943 vnode_lock_spin(vp
);
1944 vp
->v_flag
|= VNOCACHE_DATA
;
1949 vnode_clearnocache(vnode_t vp
)
1951 vnode_lock_spin(vp
);
1952 vp
->v_flag
&= ~VNOCACHE_DATA
;
1957 vnode_set_openevt(vnode_t vp
)
1959 vnode_lock_spin(vp
);
1960 vp
->v_flag
|= VOPENEVT
;
1965 vnode_clear_openevt(vnode_t vp
)
1967 vnode_lock_spin(vp
);
1968 vp
->v_flag
&= ~VOPENEVT
;
1974 vnode_setnoreadahead(vnode_t vp
)
1976 vnode_lock_spin(vp
);
1977 vp
->v_flag
|= VRAOFF
;
1982 vnode_clearnoreadahead(vnode_t vp
)
1984 vnode_lock_spin(vp
);
1985 vp
->v_flag
&= ~VRAOFF
;
1990 vnode_isfastdevicecandidate(vnode_t vp
)
1992 return (vp
->v_flag
& VFASTDEVCANDIDATE
)? 1 : 0;
1996 vnode_setfastdevicecandidate(vnode_t vp
)
1998 vnode_lock_spin(vp
);
1999 vp
->v_flag
|= VFASTDEVCANDIDATE
;
2004 vnode_clearfastdevicecandidate(vnode_t vp
)
2006 vnode_lock_spin(vp
);
2007 vp
->v_flag
&= ~VFASTDEVCANDIDATE
;
2012 vnode_isautocandidate(vnode_t vp
)
2014 return (vp
->v_flag
& VAUTOCANDIDATE
)? 1 : 0;
2018 vnode_setautocandidate(vnode_t vp
)
2020 vnode_lock_spin(vp
);
2021 vp
->v_flag
|= VAUTOCANDIDATE
;
2026 vnode_clearautocandidate(vnode_t vp
)
2028 vnode_lock_spin(vp
);
2029 vp
->v_flag
&= ~VAUTOCANDIDATE
;
2036 /* mark vnode_t to skip vflush() is SKIPSYSTEM */
2038 vnode_setnoflush(vnode_t vp
)
2040 vnode_lock_spin(vp
);
2041 vp
->v_flag
|= VNOFLUSH
;
2046 vnode_clearnoflush(vnode_t vp
)
2048 vnode_lock_spin(vp
);
2049 vp
->v_flag
&= ~VNOFLUSH
;
2054 /* is vnode_t a blkdevice and has a FS mounted on it */
2056 vnode_ismountedon(vnode_t vp
)
2058 return (vp
->v_specflags
& SI_MOUNTEDON
)? 1 : 0;
2062 vnode_setmountedon(vnode_t vp
)
2064 vnode_lock_spin(vp
);
2065 vp
->v_specflags
|= SI_MOUNTEDON
;
2070 vnode_clearmountedon(vnode_t vp
)
2072 vnode_lock_spin(vp
);
2073 vp
->v_specflags
&= ~SI_MOUNTEDON
;
2079 vnode_settag(vnode_t vp
, int tag
)
2085 vnode_tag(vnode_t vp
)
2091 vnode_parent(vnode_t vp
)
2093 return vp
->v_parent
;
2097 vnode_setparent(vnode_t vp
, vnode_t dvp
)
2103 vnode_setname(vnode_t vp
, char * name
)
2108 /* return the registered FS name when adding the FS to kernel */
2110 vnode_vfsname(vnode_t vp
, char * buf
)
2112 strlcpy(buf
, vp
->v_mount
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
2115 /* return the FS type number */
2117 vnode_vfstypenum(vnode_t vp
)
2119 return vp
->v_mount
->mnt_vtable
->vfc_typenum
;
2123 vnode_vfs64bitready(vnode_t vp
)
2126 * Checking for dead_mountp is a bit of a hack for SnowLeopard: <rdar://problem/6269051>
2128 if ((vp
->v_mount
!= dead_mountp
) && (vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
)) {
2137 /* return the visible flags on associated mount point of vnode_t */
2139 vnode_vfsvisflags(vnode_t vp
)
2141 return vp
->v_mount
->mnt_flag
& MNT_VISFLAGMASK
;
2144 /* return the command modifier flags on associated mount point of vnode_t */
2146 vnode_vfscmdflags(vnode_t vp
)
2148 return vp
->v_mount
->mnt_flag
& MNT_CMDFLAGS
;
2151 /* return the max symlink of short links of vnode_t */
2153 vnode_vfsmaxsymlen(vnode_t vp
)
2155 return vp
->v_mount
->mnt_maxsymlinklen
;
2158 /* return a pointer to the RO vfs_statfs associated with vnode_t's mount point */
2160 vnode_vfsstatfs(vnode_t vp
)
2162 return &vp
->v_mount
->mnt_vfsstat
;
2165 /* return a handle to the FSs specific private handle associated with vnode_t's mount point */
2167 vnode_vfsfsprivate(vnode_t vp
)
2169 return vp
->v_mount
->mnt_data
;
2172 /* is vnode_t in a rdonly mounted FS */
2174 vnode_vfsisrdonly(vnode_t vp
)
2176 return (vp
->v_mount
->mnt_flag
& MNT_RDONLY
)? 1 : 0;
2180 vnode_compound_rename_available(vnode_t vp
)
2182 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RENAME
);
2185 vnode_compound_rmdir_available(vnode_t vp
)
2187 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RMDIR
);
2190 vnode_compound_mkdir_available(vnode_t vp
)
2192 return vnode_compound_op_available(vp
, COMPOUND_VNOP_MKDIR
);
2195 vnode_compound_remove_available(vnode_t vp
)
2197 return vnode_compound_op_available(vp
, COMPOUND_VNOP_REMOVE
);
2200 vnode_compound_open_available(vnode_t vp
)
2202 return vnode_compound_op_available(vp
, COMPOUND_VNOP_OPEN
);
2206 vnode_compound_op_available(vnode_t vp
, compound_vnop_id_t opid
)
2208 return (vp
->v_mount
->mnt_compound_ops
& opid
) != 0;
2212 * Returns vnode ref to current working directory; if a per-thread current
2213 * working directory is in effect, return that instead of the per process one.
2215 * XXX Published, but not used.
2218 current_workingdir(void)
2220 return vfs_context_cwd(vfs_context_current());
2223 /* returns vnode ref to current root(chroot) directory */
2225 current_rootdir(void)
2227 proc_t proc
= current_proc();
2230 if ((vp
= proc
->p_fd
->fd_rdir
)) {
2231 if ((vnode_getwithref(vp
))) {
2239 * Get a filesec and optional acl contents from an extended attribute.
2240 * Function will attempt to retrive ACL, UUID, and GUID information using a
2241 * read of a named extended attribute (KAUTH_FILESEC_XATTR).
2243 * Parameters: vp The vnode on which to operate.
2244 * fsecp The filesec (and ACL, if any) being
2246 * ctx The vnode context in which the
2247 * operation is to be attempted.
2249 * Returns: 0 Success
2252 * Notes: The kauth_filesec_t in '*fsecp', if retrieved, will be in
2253 * host byte order, as will be the ACL contents, if any.
2254 * Internally, we will cannonize these values from network (PPC)
2255 * byte order after we retrieve them so that the on-disk contents
2256 * of the extended attribute are identical for both PPC and Intel
2257 * (if we were not being required to provide this service via
2258 * fallback, this would be the job of the filesystem
2259 * 'VNOP_GETATTR' call).
2261 * We use ntohl() because it has a transitive property on Intel
2262 * machines and no effect on PPC mancines. This guarantees us
2264 * XXX: Deleting rather than ignoreing a corrupt security structure is
2265 * probably the only way to reset it without assistance from an
2266 * file system integrity checking tool. Right now we ignore it.
2268 * XXX: We should enummerate the possible errno values here, and where
2269 * in the code they originated.
2272 vnode_get_filesec(vnode_t vp
, kauth_filesec_t
*fsecp
, vfs_context_t ctx
)
2274 kauth_filesec_t fsec
;
2277 size_t xsize
, rsize
;
2279 uint32_t host_fsec_magic
;
2280 uint32_t host_acl_entrycount
;
2285 /* find out how big the EA is */
2286 error
= vn_getxattr(vp
, KAUTH_FILESEC_XATTR
, NULL
, &xsize
, XATTR_NOSECURITY
, ctx
);
2288 /* no EA, no filesec */
2289 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
)) {
2292 /* either way, we are done */
2297 * To be valid, a kauth_filesec_t must be large enough to hold a zero
2298 * ACE entrly ACL, and if it's larger than that, it must have the right
2299 * number of bytes such that it contains an atomic number of ACEs,
2300 * rather than partial entries. Otherwise, we ignore it.
2302 if (!KAUTH_FILESEC_VALID(xsize
)) {
2303 KAUTH_DEBUG(" ERROR - Bogus kauth_fiilesec_t: %ld bytes", xsize
);
2308 /* how many entries would fit? */
2309 fsec_size
= KAUTH_FILESEC_COUNT(xsize
);
2310 if (fsec_size
> KAUTH_ACL_MAX_ENTRIES
) {
2311 KAUTH_DEBUG(" ERROR - Bogus (too large) kauth_fiilesec_t: %ld bytes", xsize
);
2316 /* get buffer and uio */
2317 if (((fsec
= kauth_filesec_alloc(fsec_size
)) == NULL
) ||
2318 ((fsec_uio
= uio_create(1, 0, UIO_SYSSPACE
, UIO_READ
)) == NULL
) ||
2319 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), xsize
)) {
2320 KAUTH_DEBUG(" ERROR - could not allocate iov to read ACL");
2325 /* read security attribute */
2327 if ((error
= vn_getxattr(vp
,
2328 KAUTH_FILESEC_XATTR
,
2333 /* no attribute - no security data */
2334 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
)) {
2337 /* either way, we are done */
2342 * Validate security structure; the validation must take place in host
2343 * byte order. If it's corrupt, we will just ignore it.
2346 /* Validate the size before trying to convert it */
2347 if (rsize
< KAUTH_FILESEC_SIZE(0)) {
2348 KAUTH_DEBUG("ACL - DATA TOO SMALL (%d)", rsize
);
2352 /* Validate the magic number before trying to convert it */
2353 host_fsec_magic
= ntohl(KAUTH_FILESEC_MAGIC
);
2354 if (fsec
->fsec_magic
!= host_fsec_magic
) {
2355 KAUTH_DEBUG("ACL - BAD MAGIC %x", host_fsec_magic
);
2359 /* Validate the entry count before trying to convert it. */
2360 host_acl_entrycount
= ntohl(fsec
->fsec_acl
.acl_entrycount
);
2361 if (host_acl_entrycount
!= KAUTH_FILESEC_NOACL
) {
2362 if (host_acl_entrycount
> KAUTH_ACL_MAX_ENTRIES
) {
2363 KAUTH_DEBUG("ACL - BAD ENTRYCOUNT %x", host_acl_entrycount
);
2366 if (KAUTH_FILESEC_SIZE(host_acl_entrycount
) > rsize
) {
2367 KAUTH_DEBUG("ACL - BUFFER OVERFLOW (%d entries too big for %d)", host_acl_entrycount
, rsize
);
2372 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, NULL
);
2379 kauth_filesec_free(fsec
);
2381 if (fsec_uio
!= NULL
) {
2391 * Set a filesec and optional acl contents into an extended attribute.
2392 * function will attempt to store ACL, UUID, and GUID information using a
2393 * write to a named extended attribute (KAUTH_FILESEC_XATTR). The 'acl'
2394 * may or may not point to the `fsec->fsec_acl`, depending on whether the
2395 * original caller supplied an acl.
2397 * Parameters: vp The vnode on which to operate.
2398 * fsec The filesec being set.
2399 * acl The acl to be associated with 'fsec'.
2400 * ctx The vnode context in which the
2401 * operation is to be attempted.
2403 * Returns: 0 Success
2406 * Notes: Both the fsec and the acl are always valid.
2408 * The kauth_filesec_t in 'fsec', if any, is in host byte order,
2409 * as are the acl contents, if they are used. Internally, we will
2410 * cannonize these values into network (PPC) byte order before we
2411 * attempt to write them so that the on-disk contents of the
2412 * extended attribute are identical for both PPC and Intel (if we
2413 * were not being required to provide this service via fallback,
2414 * this would be the job of the filesystem 'VNOP_SETATTR' call).
2415 * We reverse this process on the way out, so we leave with the
2416 * same byte order we started with.
2418 * XXX: We should enummerate the possible errno values here, and where
2419 * in the code they originated.
2422 vnode_set_filesec(vnode_t vp
, kauth_filesec_t fsec
, kauth_acl_t acl
, vfs_context_t ctx
)
2426 uint32_t saved_acl_copysize
;
2430 if ((fsec_uio
= uio_create(2, 0, UIO_SYSSPACE
, UIO_WRITE
)) == NULL
) {
2431 KAUTH_DEBUG(" ERROR - could not allocate iov to write ACL");
2436 * Save the pre-converted ACL copysize, because it gets swapped too
2437 * if we are running with the wrong endianness.
2439 saved_acl_copysize
= KAUTH_ACL_COPYSIZE(acl
);
2441 kauth_filesec_acl_setendian(KAUTH_ENDIAN_DISK
, fsec
, acl
);
2443 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), KAUTH_FILESEC_SIZE(0) - KAUTH_ACL_SIZE(KAUTH_FILESEC_NOACL
));
2444 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(acl
), saved_acl_copysize
);
2445 error
= vn_setxattr(vp
,
2446 KAUTH_FILESEC_XATTR
,
2448 XATTR_NOSECURITY
, /* we have auth'ed already */
2450 VFS_DEBUG(ctx
, vp
, "SETATTR - set ACL returning %d", error
);
2452 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, acl
);
2455 if (fsec_uio
!= NULL
) {
2463 * Returns: 0 Success
2464 * ENOMEM Not enough space [only if has filesec]
2465 * EINVAL Requested unknown attributes
2467 * vnode_get_filesec: ???
2468 * kauth_cred_guid2uid: ???
2469 * kauth_cred_guid2gid: ???
2470 * vfs_update_vfsstat: ???
2473 vnode_getattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2475 kauth_filesec_t fsec
;
2482 * Reject attempts to fetch unknown attributes.
2484 if (vap
->va_active
& ~VNODE_ATTR_ALL
) {
2488 /* don't ask for extended security data if the filesystem doesn't support it */
2489 if (!vfs_extendedsecurity(vnode_mount(vp
))) {
2490 VATTR_CLEAR_ACTIVE(vap
, va_acl
);
2491 VATTR_CLEAR_ACTIVE(vap
, va_uuuid
);
2492 VATTR_CLEAR_ACTIVE(vap
, va_guuid
);
2496 * If the caller wants size values we might have to synthesise, give the
2497 * filesystem the opportunity to supply better intermediate results.
2499 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2500 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2501 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2502 VATTR_SET_ACTIVE(vap
, va_data_size
);
2503 VATTR_SET_ACTIVE(vap
, va_data_alloc
);
2504 VATTR_SET_ACTIVE(vap
, va_total_size
);
2505 VATTR_SET_ACTIVE(vap
, va_total_alloc
);
2508 vap
->va_vaflags
&= ~VA_USEFSID
;
2510 error
= VNOP_GETATTR(vp
, vap
, ctx
);
2512 KAUTH_DEBUG("ERROR - returning %d", error
);
2517 * If extended security data was requested but not returned, try the fallback
2520 if (VATTR_NOT_RETURNED(vap
, va_acl
) || VATTR_NOT_RETURNED(vap
, va_uuuid
) || VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2523 if (XATTR_VNODE_SUPPORTED(vp
)) {
2524 /* try to get the filesec */
2525 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0) {
2529 /* if no filesec, no attributes */
2531 VATTR_RETURN(vap
, va_acl
, NULL
);
2532 VATTR_RETURN(vap
, va_uuuid
, kauth_null_guid
);
2533 VATTR_RETURN(vap
, va_guuid
, kauth_null_guid
);
2535 /* looks good, try to return what we were asked for */
2536 VATTR_RETURN(vap
, va_uuuid
, fsec
->fsec_owner
);
2537 VATTR_RETURN(vap
, va_guuid
, fsec
->fsec_group
);
2539 /* only return the ACL if we were actually asked for it */
2540 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2541 if (fsec
->fsec_acl
.acl_entrycount
== KAUTH_FILESEC_NOACL
) {
2542 VATTR_RETURN(vap
, va_acl
, NULL
);
2544 facl
= kauth_acl_alloc(fsec
->fsec_acl
.acl_entrycount
);
2546 kauth_filesec_free(fsec
);
2550 __nochk_bcopy(&fsec
->fsec_acl
, facl
, KAUTH_ACL_COPYSIZE(&fsec
->fsec_acl
));
2551 VATTR_RETURN(vap
, va_acl
, facl
);
2554 kauth_filesec_free(fsec
);
2558 * If someone gave us an unsolicited filesec, toss it. We promise that
2559 * we're OK with a filesystem giving us anything back, but our callers
2560 * only expect what they asked for.
2562 if (VATTR_IS_SUPPORTED(vap
, va_acl
) && !VATTR_IS_ACTIVE(vap
, va_acl
)) {
2563 if (vap
->va_acl
!= NULL
) {
2564 kauth_acl_free(vap
->va_acl
);
2566 VATTR_CLEAR_SUPPORTED(vap
, va_acl
);
2569 #if 0 /* enable when we have a filesystem only supporting UUIDs */
2571 * Handle the case where we need a UID/GID, but only have extended
2572 * security information.
2574 if (VATTR_NOT_RETURNED(vap
, va_uid
) &&
2575 VATTR_IS_SUPPORTED(vap
, va_uuuid
) &&
2576 !kauth_guid_equal(&vap
->va_uuuid
, &kauth_null_guid
)) {
2577 if ((error
= kauth_cred_guid2uid(&vap
->va_uuuid
, &nuid
)) == 0) {
2578 VATTR_RETURN(vap
, va_uid
, nuid
);
2581 if (VATTR_NOT_RETURNED(vap
, va_gid
) &&
2582 VATTR_IS_SUPPORTED(vap
, va_guuid
) &&
2583 !kauth_guid_equal(&vap
->va_guuid
, &kauth_null_guid
)) {
2584 if ((error
= kauth_cred_guid2gid(&vap
->va_guuid
, &ngid
)) == 0) {
2585 VATTR_RETURN(vap
, va_gid
, ngid
);
2591 * Handle uid/gid == 99 and MNT_IGNORE_OWNERSHIP here.
2593 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
2594 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2596 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2597 nuid
= vp
->v_mount
->mnt_fsowner
;
2598 if (nuid
== KAUTH_UID_NONE
) {
2601 } else if (VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2604 /* this will always be something sensible */
2605 nuid
= vp
->v_mount
->mnt_fsowner
;
2607 if ((nuid
== 99) && !vfs_context_issuser(ctx
)) {
2608 nuid
= kauth_cred_getuid(vfs_context_ucred(ctx
));
2610 VATTR_RETURN(vap
, va_uid
, nuid
);
2612 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
2613 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2615 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2616 ngid
= vp
->v_mount
->mnt_fsgroup
;
2617 if (ngid
== KAUTH_GID_NONE
) {
2620 } else if (VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2623 /* this will always be something sensible */
2624 ngid
= vp
->v_mount
->mnt_fsgroup
;
2626 if ((ngid
== 99) && !vfs_context_issuser(ctx
)) {
2627 ngid
= kauth_cred_getgid(vfs_context_ucred(ctx
));
2629 VATTR_RETURN(vap
, va_gid
, ngid
);
2633 * Synthesise some values that can be reasonably guessed.
2635 if (!VATTR_IS_SUPPORTED(vap
, va_iosize
)) {
2636 VATTR_RETURN(vap
, va_iosize
, vp
->v_mount
->mnt_vfsstat
.f_iosize
);
2639 if (!VATTR_IS_SUPPORTED(vap
, va_flags
)) {
2640 VATTR_RETURN(vap
, va_flags
, 0);
2643 if (!VATTR_IS_SUPPORTED(vap
, va_filerev
)) {
2644 VATTR_RETURN(vap
, va_filerev
, 0);
2647 if (!VATTR_IS_SUPPORTED(vap
, va_gen
)) {
2648 VATTR_RETURN(vap
, va_gen
, 0);
2652 * Default sizes. Ordering here is important, as later defaults build on earlier ones.
2654 if (!VATTR_IS_SUPPORTED(vap
, va_data_size
)) {
2655 VATTR_RETURN(vap
, va_data_size
, 0);
2658 /* do we want any of the possibly-computed values? */
2659 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2660 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2661 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2662 /* make sure f_bsize is valid */
2663 if (vp
->v_mount
->mnt_vfsstat
.f_bsize
== 0) {
2664 if ((error
= vfs_update_vfsstat(vp
->v_mount
, ctx
, VFS_KERNEL_EVENT
)) != 0) {
2669 /* default va_data_alloc from va_data_size */
2670 if (!VATTR_IS_SUPPORTED(vap
, va_data_alloc
)) {
2671 VATTR_RETURN(vap
, va_data_alloc
, roundup(vap
->va_data_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2674 /* default va_total_size from va_data_size */
2675 if (!VATTR_IS_SUPPORTED(vap
, va_total_size
)) {
2676 VATTR_RETURN(vap
, va_total_size
, vap
->va_data_size
);
2679 /* default va_total_alloc from va_total_size which is guaranteed at this point */
2680 if (!VATTR_IS_SUPPORTED(vap
, va_total_alloc
)) {
2681 VATTR_RETURN(vap
, va_total_alloc
, roundup(vap
->va_total_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2686 * If we don't have a change time, pull it from the modtime.
2688 if (!VATTR_IS_SUPPORTED(vap
, va_change_time
) && VATTR_IS_SUPPORTED(vap
, va_modify_time
)) {
2689 VATTR_RETURN(vap
, va_change_time
, vap
->va_modify_time
);
2693 * This is really only supported for the creation VNOPs, but since the field is there
2694 * we should populate it correctly.
2696 VATTR_RETURN(vap
, va_type
, vp
->v_type
);
2699 * The fsid can be obtained from the mountpoint directly.
2701 if (VATTR_IS_ACTIVE(vap
, va_fsid
) &&
2702 (!VATTR_IS_SUPPORTED(vap
, va_fsid
) ||
2703 vap
->va_vaflags
& VA_REALFSID
|| !(vap
->va_vaflags
& VA_USEFSID
))) {
2704 VATTR_RETURN(vap
, va_fsid
, vp
->v_mount
->mnt_vfsstat
.f_fsid
.val
[0]);
2708 vap
->va_vaflags
&= ~VA_USEFSID
;
2714 * Choose 32 bit or 64 bit fsid
2717 vnode_get_va_fsid(struct vnode_attr
*vap
)
2719 if (VATTR_IS_SUPPORTED(vap
, va_fsid64
)) {
2720 return (uint64_t)vap
->va_fsid64
.val
[0] + ((uint64_t)vap
->va_fsid64
.val
[1] << 32);
2722 return vap
->va_fsid
;
2726 * Set the attributes on a vnode in a vnode context.
2728 * Parameters: vp The vnode whose attributes to set.
2729 * vap A pointer to the attributes to set.
2730 * ctx The vnode context in which the
2731 * operation is to be attempted.
2733 * Returns: 0 Success
2736 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order.
2738 * The contents of the data area pointed to by 'vap' may be
2739 * modified if the vnode is on a filesystem which has been
2740 * mounted with ingore ownership flags, or by the underlyng
2741 * VFS itself, or by the fallback code, if the underlying VFS
2742 * does not support ACL, UUID, or GUUID attributes directly.
2744 * XXX: We should enummerate the possible errno values here, and where
2745 * in the code they originated.
2748 vnode_setattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2753 int is_perm_change
= 0;
2754 int is_stat_change
= 0;
2758 * Reject attempts to set unknown attributes.
2760 if (vap
->va_active
& ~VNODE_ATTR_ALL
) {
2765 * Make sure the filesystem is mounted R/W.
2766 * If not, return an error.
2768 if (vfs_isrdonly(vp
->v_mount
)) {
2773 #if DEVELOPMENT || DEBUG
2775 * XXX VSWAP: Check for entitlements or special flag here
2776 * so we can restrict access appropriately.
2778 #else /* DEVELOPMENT || DEBUG */
2780 if (vnode_isswap(vp
) && (ctx
!= vfs_context_kernel())) {
2784 #endif /* DEVELOPMENT || DEBUG */
2787 /* For streams, va_data_size is the only setable attribute. */
2788 if ((vp
->v_flag
& VISNAMEDSTREAM
) && (vap
->va_active
!= VNODE_ATTR_va_data_size
)) {
2793 /* Check for truncation */
2794 if (VATTR_IS_ACTIVE(vap
, va_data_size
)) {
2795 switch (vp
->v_type
) {
2797 /* For regular files it's ok */
2800 /* Not allowed to truncate directories */
2804 /* For everything else we will clear the bit and let underlying FS decide on the rest */
2805 VATTR_CLEAR_ACTIVE(vap
, va_data_size
);
2806 if (vap
->va_active
) {
2809 /* If it was the only bit set, return success, to handle cases like redirect to /dev/null */
2815 * If ownership is being ignored on this volume, we silently discard
2816 * ownership changes.
2818 if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2819 VATTR_CLEAR_ACTIVE(vap
, va_uid
);
2820 VATTR_CLEAR_ACTIVE(vap
, va_gid
);
2824 * Make sure that extended security is enabled if we're going to try
2827 if (!vfs_extendedsecurity(vnode_mount(vp
)) &&
2828 (VATTR_IS_ACTIVE(vap
, va_acl
) || VATTR_IS_ACTIVE(vap
, va_uuuid
) || VATTR_IS_ACTIVE(vap
, va_guuid
))) {
2829 KAUTH_DEBUG("SETATTR - returning ENOTSUP to request to set extended security");
2834 /* Never allow the setting of any unsupported superuser flags. */
2835 if (VATTR_IS_ACTIVE(vap
, va_flags
)) {
2836 vap
->va_flags
&= (SF_SUPPORTED
| UF_SETTABLE
);
2841 * Remember all of the active attributes that we're
2842 * attempting to modify.
2844 active
= vap
->va_active
& ~VNODE_ATTR_RDONLY
;
2847 error
= VNOP_SETATTR(vp
, vap
, ctx
);
2849 if ((error
== 0) && !VATTR_ALL_SUPPORTED(vap
)) {
2850 error
= vnode_setattr_fallback(vp
, vap
, ctx
);
2854 #define PERMISSION_BITS (VNODE_ATTR_BIT(va_uid) | VNODE_ATTR_BIT(va_uuuid) | \
2855 VNODE_ATTR_BIT(va_gid) | VNODE_ATTR_BIT(va_guuid) | \
2856 VNODE_ATTR_BIT(va_mode) | VNODE_ATTR_BIT(va_acl))
2859 * Now that we've changed them, decide whether to send an
2862 if ((active
& PERMISSION_BITS
) & vap
->va_supported
) {
2866 * We've already checked the permission bits, and we
2867 * also want to filter out access time / backup time
2870 active
&= ~(PERMISSION_BITS
|
2871 VNODE_ATTR_BIT(va_access_time
) |
2872 VNODE_ATTR_BIT(va_backup_time
));
2874 /* Anything left to notify about? */
2875 if (active
& vap
->va_supported
) {
2881 if (is_perm_change
) {
2882 if (need_fsevent(FSE_CHOWN
, vp
)) {
2883 add_fsevent(FSE_CHOWN
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2885 } else if (is_stat_change
&& need_fsevent(FSE_STAT_CHANGED
, vp
)) {
2886 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2889 #undef PERMISSION_BITS
2897 * Fallback for setting the attributes on a vnode in a vnode context. This
2898 * Function will attempt to store ACL, UUID, and GUID information utilizing
2899 * a read/modify/write operation against an EA used as a backing store for
2902 * Parameters: vp The vnode whose attributes to set.
2903 * vap A pointer to the attributes to set.
2904 * ctx The vnode context in which the
2905 * operation is to be attempted.
2907 * Returns: 0 Success
2910 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order,
2911 * as are the fsec and lfsec, if they are used.
2913 * The contents of the data area pointed to by 'vap' may be
2914 * modified to indicate that the attribute is supported for
2915 * any given requested attribute.
2917 * XXX: We should enummerate the possible errno values here, and where
2918 * in the code they originated.
2921 vnode_setattr_fallback(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2923 kauth_filesec_t fsec
;
2925 struct kauth_filesec lfsec
;
2931 * Extended security fallback via extended attributes.
2933 * Note that we do not free the filesec; the caller is expected to
2936 if (VATTR_NOT_RETURNED(vap
, va_acl
) ||
2937 VATTR_NOT_RETURNED(vap
, va_uuuid
) ||
2938 VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2939 VFS_DEBUG(ctx
, vp
, "SETATTR - doing filesec fallback");
2942 * Fail for file types that we don't permit extended security
2945 if (!XATTR_VNODE_SUPPORTED(vp
)) {
2946 VFS_DEBUG(ctx
, vp
, "SETATTR - Can't write ACL to file type %d", vnode_vtype(vp
));
2952 * If we don't have all the extended security items, we need
2953 * to fetch the existing data to perform a read-modify-write
2957 if (!VATTR_IS_ACTIVE(vap
, va_acl
) ||
2958 !VATTR_IS_ACTIVE(vap
, va_uuuid
) ||
2959 !VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2960 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0) {
2961 KAUTH_DEBUG("SETATTR - ERROR %d fetching filesec for update", error
);
2965 /* if we didn't get a filesec, use our local one */
2967 KAUTH_DEBUG("SETATTR - using local filesec for new/full update");
2970 KAUTH_DEBUG("SETATTR - updating existing filesec");
2973 facl
= &fsec
->fsec_acl
;
2975 /* if we're using the local filesec, we need to initialise it */
2976 if (fsec
== &lfsec
) {
2977 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
2978 fsec
->fsec_owner
= kauth_null_guid
;
2979 fsec
->fsec_group
= kauth_null_guid
;
2980 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2981 facl
->acl_flags
= 0;
2985 * Update with the supplied attributes.
2987 if (VATTR_IS_ACTIVE(vap
, va_uuuid
)) {
2988 KAUTH_DEBUG("SETATTR - updating owner UUID");
2989 fsec
->fsec_owner
= vap
->va_uuuid
;
2990 VATTR_SET_SUPPORTED(vap
, va_uuuid
);
2992 if (VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2993 KAUTH_DEBUG("SETATTR - updating group UUID");
2994 fsec
->fsec_group
= vap
->va_guuid
;
2995 VATTR_SET_SUPPORTED(vap
, va_guuid
);
2997 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2998 if (vap
->va_acl
== NULL
) {
2999 KAUTH_DEBUG("SETATTR - removing ACL");
3000 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
3002 KAUTH_DEBUG("SETATTR - setting ACL with %d entries", vap
->va_acl
->acl_entrycount
);
3005 VATTR_SET_SUPPORTED(vap
, va_acl
);
3009 * If the filesec data is all invalid, we can just remove
3010 * the EA completely.
3012 if ((facl
->acl_entrycount
== KAUTH_FILESEC_NOACL
) &&
3013 kauth_guid_equal(&fsec
->fsec_owner
, &kauth_null_guid
) &&
3014 kauth_guid_equal(&fsec
->fsec_group
, &kauth_null_guid
)) {
3015 error
= vn_removexattr(vp
, KAUTH_FILESEC_XATTR
, XATTR_NOSECURITY
, ctx
);
3016 /* no attribute is ok, nothing to delete */
3017 if (error
== ENOATTR
) {
3020 VFS_DEBUG(ctx
, vp
, "SETATTR - remove filesec returning %d", error
);
3023 error
= vnode_set_filesec(vp
, fsec
, facl
, ctx
);
3024 VFS_DEBUG(ctx
, vp
, "SETATTR - update filesec returning %d", error
);
3027 /* if we fetched a filesec, dispose of the buffer */
3028 if (fsec
!= &lfsec
) {
3029 kauth_filesec_free(fsec
);
3038 * Upcall for a filesystem to tell VFS about an EVFILT_VNODE-type
3042 vnode_notify(vnode_t vp
, uint32_t events
, struct vnode_attr
*vap
)
3044 /* These are the same as the corresponding knotes, at least for now. Cheating a little. */
3045 uint32_t knote_mask
= (VNODE_EVENT_WRITE
| VNODE_EVENT_DELETE
| VNODE_EVENT_RENAME
3046 | VNODE_EVENT_LINK
| VNODE_EVENT_EXTEND
| VNODE_EVENT_ATTRIB
);
3047 uint32_t dir_contents_mask
= (VNODE_EVENT_DIR_CREATED
| VNODE_EVENT_FILE_CREATED
3048 | VNODE_EVENT_DIR_REMOVED
| VNODE_EVENT_FILE_REMOVED
);
3049 uint32_t knote_events
= (events
& knote_mask
);
3051 /* Permissions are not explicitly part of the kqueue model */
3052 if (events
& VNODE_EVENT_PERMS
) {
3053 knote_events
|= NOTE_ATTRIB
;
3056 /* Directory contents information just becomes NOTE_WRITE */
3057 if ((vnode_isdir(vp
)) && (events
& dir_contents_mask
)) {
3058 knote_events
|= NOTE_WRITE
;
3062 lock_vnode_and_post(vp
, knote_events
);
3065 create_fsevent_from_kevent(vp
, events
, vap
);
3078 vnode_isdyldsharedcache(vnode_t vp
)
3080 return (vp
->v_flag
& VSHARED_DYLD
) ? 1 : 0;
3085 * For a filesystem that isn't tracking its own vnode watchers:
3086 * check whether a vnode is being monitored.
3089 vnode_ismonitored(vnode_t vp
)
3091 return vp
->v_knotes
.slh_first
!= NULL
;
3095 vnode_getbackingvnode(vnode_t in_vp
, vnode_t
* out_vpp
)
3101 return nullfs_getbackingvnode(in_vp
, out_vpp
);
3103 #pragma unused(in_vp)
3109 * Initialize a struct vnode_attr and activate the attributes required
3110 * by the vnode_notify() call.
3113 vfs_get_notify_attributes(struct vnode_attr
*vap
)
3116 vap
->va_active
= VNODE_NOTIFY_ATTRS
;
3122 vfs_settriggercallback(fsid_t
*fsid
, vfs_trigger_callback_t vtc
, void *data
, uint32_t flags __unused
, vfs_context_t ctx
)
3127 mp
= mount_list_lookupby_fsid(fsid
, 0 /* locked */, 1 /* withref */);
3132 error
= vfs_busy(mp
, LK_NOWAIT
);
3140 if (mp
->mnt_triggercallback
!= NULL
) {
3146 mp
->mnt_triggercallback
= vtc
;
3147 mp
->mnt_triggerdata
= data
;
3150 mp
->mnt_triggercallback(mp
, VTC_REPLACE
, data
, ctx
);
3156 #endif /* CONFIG_TRIGGERS */
3159 * Definition of vnode operations.
3165 *#% lookup dvp L ? ?
3166 *#% lookup vpp - L -
3168 struct vnop_lookup_args
{
3169 struct vnodeop_desc
*a_desc
;
3172 struct componentname
*a_cnp
;
3173 vfs_context_t a_context
;
3178 * Returns: 0 Success
3179 * lock_fsnode:ENOENT No such file or directory [only for VFS
3180 * that is not thread safe & vnode is
3181 * currently being/has been terminated]
3182 * <vfs_lookup>:ENAMETOOLONG
3183 * <vfs_lookup>:ENOENT
3184 * <vfs_lookup>:EJUSTRETURN
3185 * <vfs_lookup>:EPERM
3186 * <vfs_lookup>:EISDIR
3187 * <vfs_lookup>:ENOTDIR
3190 * Note: The return codes from the underlying VFS's lookup routine can't
3191 * be fully enumerated here, since third party VFS authors may not
3192 * limit their error returns to the ones documented here, even
3193 * though this may result in some programs functioning incorrectly.
3195 * The return codes documented above are those which may currently
3196 * be returned by HFS from hfs_lookup, not including additional
3197 * error code which may be propagated from underlying routines.
3200 VNOP_LOOKUP(vnode_t dvp
, vnode_t
*vpp
, struct componentname
*cnp
, vfs_context_t ctx
)
3203 struct vnop_lookup_args a
;
3205 a
.a_desc
= &vnop_lookup_desc
;
3211 _err
= (*dvp
->v_op
[vnop_lookup_desc
.vdesc_offset
])(&a
);
3212 if (_err
== 0 && *vpp
) {
3213 DTRACE_FSINFO(lookup
, vnode_t
, *vpp
);
3220 struct vnop_compound_open_args
{
3221 struct vnodeop_desc
*a_desc
;
3224 struct componentname
*a_cnp
;
3227 struct vnode_attr
*a_vap
;
3228 vfs_context_t a_context
;
3234 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
)
3237 struct vnop_compound_open_args a
;
3240 uint32_t tmp_status
= 0;
3241 struct componentname
*cnp
= &ndp
->ni_cnd
;
3243 want_create
= (flags
& O_CREAT
);
3245 a
.a_desc
= &vnop_compound_open_desc
;
3247 a
.a_vpp
= vpp
; /* Could be NULL */
3251 a
.a_status
= (statusp
!= NULL
) ? statusp
: &tmp_status
;
3254 a
.a_open_create_authorizer
= vn_authorize_create
;
3255 a
.a_open_existing_authorizer
= vn_authorize_open_existing
;
3256 a
.a_reserved
= NULL
;
3258 if (dvp
== NULLVP
) {
3261 if (want_create
&& !vap
) {
3262 panic("Want create, but no vap?");
3264 if (!want_create
&& vap
) {
3265 panic("Don't want create, but have a vap?");
3268 _err
= (*dvp
->v_op
[vnop_compound_open_desc
.vdesc_offset
])(&a
);
3270 if (_err
== 0 && *vpp
) {
3271 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
3273 DTRACE_FSINFO(compound_open
, vnode_t
, dvp
);
3276 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
3279 did_create
= (*a
.a_status
& COMPOUND_OPEN_STATUS_DID_CREATE
);
3281 if (did_create
&& !want_create
) {
3282 panic("Filesystem did a create, even though none was requested?");
3286 #if CONFIG_APPLEDOUBLE
3287 if (!NATIVE_XATTR(dvp
)) {
3289 * Remove stale Apple Double file (if any).
3291 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
3293 #endif /* CONFIG_APPLEDOUBLE */
3294 /* On create, provide kqueue notification */
3295 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3298 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, did_create
);
3299 #if 0 /* FSEvents... */
3300 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
3310 struct vnop_create_args
{
3311 struct vnodeop_desc
*a_desc
;
3314 struct componentname
*a_cnp
;
3315 struct vnode_attr
*a_vap
;
3316 vfs_context_t a_context
;
3320 VNOP_CREATE(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3323 struct vnop_create_args a
;
3325 a
.a_desc
= &vnop_create_desc
;
3332 _err
= (*dvp
->v_op
[vnop_create_desc
.vdesc_offset
])(&a
);
3333 if (_err
== 0 && *vpp
) {
3334 DTRACE_FSINFO(create
, vnode_t
, *vpp
);
3337 #if CONFIG_APPLEDOUBLE
3338 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
3340 * Remove stale Apple Double file (if any).
3342 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
3344 #endif /* CONFIG_APPLEDOUBLE */
3346 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3354 *#% whiteout dvp L L L
3355 *#% whiteout cnp - - -
3356 *#% whiteout flag - - -
3359 struct vnop_whiteout_args
{
3360 struct vnodeop_desc
*a_desc
;
3362 struct componentname
*a_cnp
;
3364 vfs_context_t a_context
;
3368 VNOP_WHITEOUT(__unused vnode_t dvp
, __unused
struct componentname
*cnp
,
3369 __unused
int flags
, __unused vfs_context_t ctx
)
3371 return ENOTSUP
; // XXX OBSOLETE
3381 struct vnop_mknod_args
{
3382 struct vnodeop_desc
*a_desc
;
3385 struct componentname
*a_cnp
;
3386 struct vnode_attr
*a_vap
;
3387 vfs_context_t a_context
;
3391 VNOP_MKNOD(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3394 struct vnop_mknod_args a
;
3396 a
.a_desc
= &vnop_mknod_desc
;
3403 _err
= (*dvp
->v_op
[vnop_mknod_desc
.vdesc_offset
])(&a
);
3404 if (_err
== 0 && *vpp
) {
3405 DTRACE_FSINFO(mknod
, vnode_t
, *vpp
);
3408 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3419 struct vnop_open_args
{
3420 struct vnodeop_desc
*a_desc
;
3423 vfs_context_t a_context
;
3427 VNOP_OPEN(vnode_t vp
, int mode
, vfs_context_t ctx
)
3430 struct vnop_open_args a
;
3433 ctx
= vfs_context_current();
3435 a
.a_desc
= &vnop_open_desc
;
3440 _err
= (*vp
->v_op
[vnop_open_desc
.vdesc_offset
])(&a
);
3441 DTRACE_FSINFO(open
, vnode_t
, vp
);
3452 struct vnop_close_args
{
3453 struct vnodeop_desc
*a_desc
;
3456 vfs_context_t a_context
;
3460 VNOP_CLOSE(vnode_t vp
, int fflag
, vfs_context_t ctx
)
3463 struct vnop_close_args a
;
3466 ctx
= vfs_context_current();
3468 a
.a_desc
= &vnop_close_desc
;
3473 _err
= (*vp
->v_op
[vnop_close_desc
.vdesc_offset
])(&a
);
3474 DTRACE_FSINFO(close
, vnode_t
, vp
);
3485 struct vnop_access_args
{
3486 struct vnodeop_desc
*a_desc
;
3489 vfs_context_t a_context
;
3493 VNOP_ACCESS(vnode_t vp
, int action
, vfs_context_t ctx
)
3496 struct vnop_access_args a
;
3499 ctx
= vfs_context_current();
3501 a
.a_desc
= &vnop_access_desc
;
3503 a
.a_action
= action
;
3506 _err
= (*vp
->v_op
[vnop_access_desc
.vdesc_offset
])(&a
);
3507 DTRACE_FSINFO(access
, vnode_t
, vp
);
3515 *#% getattr vp = = =
3518 struct vnop_getattr_args
{
3519 struct vnodeop_desc
*a_desc
;
3521 struct vnode_attr
*a_vap
;
3522 vfs_context_t a_context
;
3526 VNOP_GETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3529 struct vnop_getattr_args a
;
3531 a
.a_desc
= &vnop_getattr_desc
;
3536 _err
= (*vp
->v_op
[vnop_getattr_desc
.vdesc_offset
])(&a
);
3537 DTRACE_FSINFO(getattr
, vnode_t
, vp
);
3545 *#% setattr vp L L L
3548 struct vnop_setattr_args
{
3549 struct vnodeop_desc
*a_desc
;
3551 struct vnode_attr
*a_vap
;
3552 vfs_context_t a_context
;
3556 VNOP_SETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3559 struct vnop_setattr_args a
;
3561 a
.a_desc
= &vnop_setattr_desc
;
3566 _err
= (*vp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
3567 DTRACE_FSINFO(setattr
, vnode_t
, vp
);
3569 #if CONFIG_APPLEDOUBLE
3571 * Shadow uid/gid/mod change to extended attribute file.
3573 if (_err
== 0 && !NATIVE_XATTR(vp
)) {
3574 struct vnode_attr va
;
3578 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
3579 VATTR_SET(&va
, va_uid
, vap
->va_uid
);
3582 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
3583 VATTR_SET(&va
, va_gid
, vap
->va_gid
);
3586 if (VATTR_IS_ACTIVE(vap
, va_mode
)) {
3587 VATTR_SET(&va
, va_mode
, vap
->va_mode
);
3594 dvp
= vnode_getparent(vp
);
3595 vname
= vnode_getname(vp
);
3597 xattrfile_setattr(dvp
, vname
, &va
, ctx
);
3598 if (dvp
!= NULLVP
) {
3601 if (vname
!= NULL
) {
3602 vnode_putname(vname
);
3606 #endif /* CONFIG_APPLEDOUBLE */
3609 * If we have changed any of the things about the file that are likely
3610 * to result in changes to authorization results, blow the vnode auth
3614 VATTR_IS_SUPPORTED(vap
, va_mode
) ||
3615 VATTR_IS_SUPPORTED(vap
, va_uid
) ||
3616 VATTR_IS_SUPPORTED(vap
, va_gid
) ||
3617 VATTR_IS_SUPPORTED(vap
, va_flags
) ||
3618 VATTR_IS_SUPPORTED(vap
, va_acl
) ||
3619 VATTR_IS_SUPPORTED(vap
, va_uuuid
) ||
3620 VATTR_IS_SUPPORTED(vap
, va_guuid
))) {
3621 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3624 if (vfs_authopaque(vp
->v_mount
) && vnode_hasnamedstreams(vp
)) {
3626 if (vnode_getnamedstream(vp
, &svp
, XATTR_RESOURCEFORK_NAME
, NS_OPEN
, 0, ctx
) == 0) {
3627 vnode_uncache_authorized_action(svp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3631 #endif /* NAMEDSTREAMS */
3635 post_event_if_success(vp
, _err
, NOTE_ATTRIB
);
3647 struct vnop_read_args
{
3648 struct vnodeop_desc
*a_desc
;
3652 vfs_context_t a_context
;
3656 VNOP_READ(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3659 struct vnop_read_args a
;
3661 user_ssize_t resid
= uio_resid(uio
);
3668 a
.a_desc
= &vnop_read_desc
;
3671 a
.a_ioflag
= ioflag
;
3674 _err
= (*vp
->v_op
[vnop_read_desc
.vdesc_offset
])(&a
);
3675 DTRACE_FSINFO_IO(read
,
3676 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3688 struct vnop_write_args
{
3689 struct vnodeop_desc
*a_desc
;
3693 vfs_context_t a_context
;
3697 VNOP_WRITE(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3699 struct vnop_write_args a
;
3702 user_ssize_t resid
= uio_resid(uio
);
3709 a
.a_desc
= &vnop_write_desc
;
3712 a
.a_ioflag
= ioflag
;
3715 _err
= (*vp
->v_op
[vnop_write_desc
.vdesc_offset
])(&a
);
3716 DTRACE_FSINFO_IO(write
,
3717 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3719 post_event_if_success(vp
, _err
, NOTE_WRITE
);
3731 struct vnop_ioctl_args
{
3732 struct vnodeop_desc
*a_desc
;
3737 vfs_context_t a_context
;
3741 VNOP_IOCTL(vnode_t vp
, u_long command
, caddr_t data
, int fflag
, vfs_context_t ctx
)
3744 struct vnop_ioctl_args a
;
3747 ctx
= vfs_context_current();
3751 * This check should probably have been put in the TTY code instead...
3753 * We have to be careful about what we assume during startup and shutdown.
3754 * We have to be able to use the root filesystem's device vnode even when
3755 * devfs isn't mounted (yet/anymore), so we can't go looking at its mount
3756 * structure. If there is no data pointer, it doesn't matter whether
3757 * the device is 64-bit ready. Any command (like DKIOCSYNCHRONIZE)
3758 * which passes NULL for its data pointer can therefore be used during
3759 * mount or unmount of the root filesystem.
3761 * Depending on what root filesystems need to do during mount/unmount, we
3762 * may need to loosen this check again in the future.
3764 if (vfs_context_is64bit(ctx
) && !(vnode_ischr(vp
) || vnode_isblk(vp
))) {
3765 if (data
!= NULL
&& !vnode_vfs64bitready(vp
)) {
3770 a
.a_desc
= &vnop_ioctl_desc
;
3772 a
.a_command
= command
;
3777 _err
= (*vp
->v_op
[vnop_ioctl_desc
.vdesc_offset
])(&a
);
3778 DTRACE_FSINFO(ioctl
, vnode_t
, vp
);
3790 struct vnop_select_args
{
3791 struct vnodeop_desc
*a_desc
;
3796 vfs_context_t a_context
;
3800 VNOP_SELECT(vnode_t vp
, int which
, int fflags
, void * wql
, vfs_context_t ctx
)
3803 struct vnop_select_args a
;
3806 ctx
= vfs_context_current();
3808 a
.a_desc
= &vnop_select_desc
;
3811 a
.a_fflags
= fflags
;
3815 _err
= (*vp
->v_op
[vnop_select_desc
.vdesc_offset
])(&a
);
3816 DTRACE_FSINFO(select
, vnode_t
, vp
);
3825 *#% exchange fvp L L L
3826 *#% exchange tvp L L L
3829 struct vnop_exchange_args
{
3830 struct vnodeop_desc
*a_desc
;
3834 vfs_context_t a_context
;
3838 VNOP_EXCHANGE(vnode_t fvp
, vnode_t tvp
, int options
, vfs_context_t ctx
)
3841 struct vnop_exchange_args a
;
3843 a
.a_desc
= &vnop_exchange_desc
;
3846 a
.a_options
= options
;
3849 _err
= (*fvp
->v_op
[vnop_exchange_desc
.vdesc_offset
])(&a
);
3850 DTRACE_FSINFO(exchange
, vnode_t
, fvp
);
3852 /* Don't post NOTE_WRITE because file descriptors follow the data ... */
3853 post_event_if_success(fvp
, _err
, NOTE_ATTRIB
);
3854 post_event_if_success(tvp
, _err
, NOTE_ATTRIB
);
3866 struct vnop_revoke_args
{
3867 struct vnodeop_desc
*a_desc
;
3870 vfs_context_t a_context
;
3874 VNOP_REVOKE(vnode_t vp
, int flags
, vfs_context_t ctx
)
3876 struct vnop_revoke_args a
;
3879 a
.a_desc
= &vnop_revoke_desc
;
3884 _err
= (*vp
->v_op
[vnop_revoke_desc
.vdesc_offset
])(&a
);
3885 DTRACE_FSINFO(revoke
, vnode_t
, vp
);
3894 *# mmap_check - vp U U U
3897 struct vnop_mmap_check_args
{
3898 struct vnodeop_desc
*a_desc
;
3901 vfs_context_t a_context
;
3905 VNOP_MMAP_CHECK(vnode_t vp
, int flags
, vfs_context_t ctx
)
3908 struct vnop_mmap_check_args a
;
3910 a
.a_desc
= &vnop_mmap_check_desc
;
3915 _err
= (*vp
->v_op
[vnop_mmap_check_desc
.vdesc_offset
])(&a
);
3916 if (_err
== ENOTSUP
) {
3919 DTRACE_FSINFO(mmap_check
, vnode_t
, vp
);
3930 struct vnop_mmap_args
{
3931 struct vnodeop_desc
*a_desc
;
3934 vfs_context_t a_context
;
3938 VNOP_MMAP(vnode_t vp
, int fflags
, vfs_context_t ctx
)
3941 struct vnop_mmap_args a
;
3943 a
.a_desc
= &vnop_mmap_desc
;
3945 a
.a_fflags
= fflags
;
3948 _err
= (*vp
->v_op
[vnop_mmap_desc
.vdesc_offset
])(&a
);
3949 DTRACE_FSINFO(mmap
, vnode_t
, vp
);
3958 *# mnomap - vp U U U
3961 struct vnop_mnomap_args
{
3962 struct vnodeop_desc
*a_desc
;
3964 vfs_context_t a_context
;
3968 VNOP_MNOMAP(vnode_t vp
, vfs_context_t ctx
)
3971 struct vnop_mnomap_args a
;
3973 a
.a_desc
= &vnop_mnomap_desc
;
3977 _err
= (*vp
->v_op
[vnop_mnomap_desc
.vdesc_offset
])(&a
);
3978 DTRACE_FSINFO(mnomap
, vnode_t
, vp
);
3990 struct vnop_fsync_args
{
3991 struct vnodeop_desc
*a_desc
;
3994 vfs_context_t a_context
;
3998 VNOP_FSYNC(vnode_t vp
, int waitfor
, vfs_context_t ctx
)
4000 struct vnop_fsync_args a
;
4003 a
.a_desc
= &vnop_fsync_desc
;
4005 a
.a_waitfor
= waitfor
;
4008 _err
= (*vp
->v_op
[vnop_fsync_desc
.vdesc_offset
])(&a
);
4009 DTRACE_FSINFO(fsync
, vnode_t
, vp
);
4018 *#% remove dvp L U U
4022 struct vnop_remove_args
{
4023 struct vnodeop_desc
*a_desc
;
4026 struct componentname
*a_cnp
;
4028 vfs_context_t a_context
;
4032 VNOP_REMOVE(vnode_t dvp
, vnode_t vp
, struct componentname
* cnp
, int flags
, vfs_context_t ctx
)
4035 struct vnop_remove_args a
;
4037 a
.a_desc
= &vnop_remove_desc
;
4044 _err
= (*dvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&a
);
4045 DTRACE_FSINFO(remove
, vnode_t
, vp
);
4048 vnode_setneedinactive(vp
);
4049 #if CONFIG_APPLEDOUBLE
4050 if (!(NATIVE_XATTR(dvp
))) {
4052 * Remove any associated extended attribute file (._ AppleDouble file).
4054 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
4056 #endif /* CONFIG_APPLEDOUBLE */
4059 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4060 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
4066 VNOP_COMPOUND_REMOVE(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4069 struct vnop_compound_remove_args a
;
4070 int no_vp
= (*vpp
== NULLVP
);
4072 a
.a_desc
= &vnop_compound_remove_desc
;
4075 a
.a_cnp
= &ndp
->ni_cnd
;
4079 a
.a_remove_authorizer
= vn_authorize_unlink
;
4081 _err
= (*dvp
->v_op
[vnop_compound_remove_desc
.vdesc_offset
])(&a
);
4082 if (_err
== 0 && *vpp
) {
4083 DTRACE_FSINFO(compound_remove
, vnode_t
, *vpp
);
4085 DTRACE_FSINFO(compound_remove
, vnode_t
, dvp
);
4088 vnode_setneedinactive(*vpp
);
4089 #if CONFIG_APPLEDOUBLE
4090 if (!(NATIVE_XATTR(dvp
))) {
4092 * Remove any associated extended attribute file (._ AppleDouble file).
4094 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 1);
4096 #endif /* CONFIG_APPLEDOUBLE */
4099 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4100 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
4103 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
4104 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4110 //printf("VNOP_COMPOUND_REMOVE() returning %d\n", _err);
4122 struct vnop_link_args
{
4123 struct vnodeop_desc
*a_desc
;
4126 struct componentname
*a_cnp
;
4127 vfs_context_t a_context
;
4131 VNOP_LINK(vnode_t vp
, vnode_t tdvp
, struct componentname
* cnp
, vfs_context_t ctx
)
4134 struct vnop_link_args a
;
4136 #if CONFIG_APPLEDOUBLE
4138 * For file systems with non-native extended attributes,
4139 * disallow linking to an existing "._" Apple Double file.
4141 if (!NATIVE_XATTR(tdvp
) && (vp
->v_type
== VREG
)) {
4144 vname
= vnode_getname(vp
);
4145 if (vname
!= NULL
) {
4147 if (vname
[0] == '.' && vname
[1] == '_' && vname
[2] != '\0') {
4150 vnode_putname(vname
);
4156 #endif /* CONFIG_APPLEDOUBLE */
4158 a
.a_desc
= &vnop_link_desc
;
4164 _err
= (*tdvp
->v_op
[vnop_link_desc
.vdesc_offset
])(&a
);
4165 DTRACE_FSINFO(link
, vnode_t
, vp
);
4167 post_event_if_success(vp
, _err
, NOTE_LINK
);
4168 post_event_if_success(tdvp
, _err
, NOTE_WRITE
);
4174 vn_rename(struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
4175 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
4176 vfs_rename_flags_t flags
, vfs_context_t ctx
)
4179 struct nameidata
*fromnd
= NULL
;
4180 struct nameidata
*tond
= NULL
;
4181 #if CONFIG_APPLEDOUBLE
4182 vnode_t src_attr_vp
= NULLVP
;
4183 vnode_t dst_attr_vp
= NULLVP
;
4184 char smallname1
[48];
4185 char smallname2
[48];
4186 char *xfromname
= NULL
;
4187 char *xtoname
= NULL
;
4188 #endif /* CONFIG_APPLEDOUBLE */
4190 uint32_t tdfflags
; // Target directory file flags
4192 batched
= vnode_compound_rename_available(fdvp
);
4195 if (*fvpp
== NULLVP
) {
4196 panic("Not batched, and no fvp?");
4200 #if CONFIG_APPLEDOUBLE
4202 * We need to preflight any potential AppleDouble file for the source file
4203 * before doing the rename operation, since we could potentially be doing
4204 * this operation on a network filesystem, and would end up duplicating
4205 * the work. Also, save the source and destination names. Skip it if the
4206 * source has a "._" prefix.
4209 if (!NATIVE_XATTR(fdvp
) &&
4210 !(fcnp
->cn_nameptr
[0] == '.' && fcnp
->cn_nameptr
[1] == '_')) {
4214 /* Get source attribute file name. */
4215 len
= fcnp
->cn_namelen
+ 3;
4216 if (len
> sizeof(smallname1
)) {
4217 MALLOC(xfromname
, char *, len
, M_TEMP
, M_WAITOK
);
4219 xfromname
= &smallname1
[0];
4221 strlcpy(xfromname
, "._", len
);
4222 strlcat(xfromname
, fcnp
->cn_nameptr
, len
);
4224 /* Get destination attribute file name. */
4225 len
= tcnp
->cn_namelen
+ 3;
4226 if (len
> sizeof(smallname2
)) {
4227 MALLOC(xtoname
, char *, len
, M_TEMP
, M_WAITOK
);
4229 xtoname
= &smallname2
[0];
4231 strlcpy(xtoname
, "._", len
);
4232 strlcat(xtoname
, tcnp
->cn_nameptr
, len
);
4235 * Look up source attribute file, keep reference on it if exists.
4236 * Note that we do the namei with the nameiop of RENAME, which is different than
4237 * in the rename syscall. It's OK if the source file does not exist, since this
4238 * is only for AppleDouble files.
4240 MALLOC(fromnd
, struct nameidata
*, sizeof(struct nameidata
), M_TEMP
, M_WAITOK
);
4241 NDINIT(fromnd
, RENAME
, OP_RENAME
, NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
,
4242 UIO_SYSSPACE
, CAST_USER_ADDR_T(xfromname
), ctx
);
4243 fromnd
->ni_dvp
= fdvp
;
4244 error
= namei(fromnd
);
4247 * If there was an error looking up source attribute file,
4248 * we'll behave as if it didn't exist.
4252 if (fromnd
->ni_vp
) {
4253 /* src_attr_vp indicates need to call vnode_put / nameidone later */
4254 src_attr_vp
= fromnd
->ni_vp
;
4256 if (fromnd
->ni_vp
->v_type
!= VREG
) {
4257 src_attr_vp
= NULLVP
;
4258 vnode_put(fromnd
->ni_vp
);
4262 * Either we got an invalid vnode type (not a regular file) or the namei lookup
4263 * suppressed ENOENT as a valid error since we're renaming. Either way, we don't
4264 * have a vnode here, so we drop our namei buffer for the source attribute file
4266 if (src_attr_vp
== NULLVP
) {
4271 #endif /* CONFIG_APPLEDOUBLE */
4274 _err
= VNOP_COMPOUND_RENAME(fdvp
, fvpp
, fcnp
, fvap
, tdvp
, tvpp
, tcnp
, tvap
, flags
, ctx
);
4276 printf("VNOP_COMPOUND_RENAME() returned %d\n", _err
);
4280 _err
= VNOP_RENAMEX(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, flags
, ctx
);
4281 if (_err
== ENOTSUP
&& flags
== VFS_RENAME_SECLUDE
) {
4283 if ((*fvpp
)->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_SECLUDE_RENAME
) {
4284 fcnp
->cn_flags
|= CN_SECLUDE_RENAME
;
4285 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
4289 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
4294 * If moved to a new directory that is restricted,
4295 * set the restricted flag on the item moved.
4298 _err
= vnode_flags(tdvp
, &tdfflags
, ctx
);
4300 uint32_t inherit_flags
= tdfflags
& (UF_DATAVAULT
| SF_RESTRICTED
);
4301 if (inherit_flags
) {
4303 _err
= vnode_flags(*fvpp
, &fflags
, ctx
);
4304 if (_err
== 0 && fflags
!= (fflags
| inherit_flags
)) {
4305 struct vnode_attr va
;
4307 VATTR_SET(&va
, va_flags
, fflags
| inherit_flags
);
4308 _err
= vnode_setattr(*fvpp
, &va
, ctx
);
4316 mac_vnode_notify_rename(ctx
, *fvpp
, tdvp
, tcnp
);
4317 if (flags
& VFS_RENAME_SWAP
) {
4318 mac_vnode_notify_rename(ctx
, *tvpp
, fdvp
, fcnp
);
4323 #if CONFIG_APPLEDOUBLE
4325 * Rename any associated extended attribute file (._ AppleDouble file).
4327 if (_err
== 0 && !NATIVE_XATTR(fdvp
) && xfromname
!= NULL
) {
4331 * Get destination attribute file vnode.
4332 * Note that tdvp already has an iocount reference. Make sure to check that we
4333 * get a valid vnode from namei.
4335 MALLOC(tond
, struct nameidata
*, sizeof(struct nameidata
), M_TEMP
, M_WAITOK
);
4336 NDINIT(tond
, RENAME
, OP_RENAME
,
4337 NOCACHE
| NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
, UIO_SYSSPACE
,
4338 CAST_USER_ADDR_T(xtoname
), ctx
);
4339 tond
->ni_dvp
= tdvp
;
4340 error
= namei(tond
);
4347 dst_attr_vp
= tond
->ni_vp
;
4351 const char *old_name
= src_attr_vp
->v_name
;
4352 vnode_t old_parent
= src_attr_vp
->v_parent
;
4355 error
= VNOP_COMPOUND_RENAME(fdvp
, &src_attr_vp
, &fromnd
->ni_cnd
, NULL
,
4356 tdvp
, &dst_attr_vp
, &tond
->ni_cnd
, NULL
,
4359 error
= VNOP_RENAME(fdvp
, src_attr_vp
, &fromnd
->ni_cnd
,
4360 tdvp
, dst_attr_vp
, &tond
->ni_cnd
, ctx
);
4363 if (error
== 0 && old_name
== src_attr_vp
->v_name
&&
4364 old_parent
== src_attr_vp
->v_parent
) {
4365 int update_flags
= VNODE_UPDATE_NAME
;
4368 update_flags
|= VNODE_UPDATE_PARENT
;
4371 if ((src_attr_vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_NOUPDATEID_RENAME
) == 0) {
4372 vnode_update_identity(src_attr_vp
, tdvp
,
4373 tond
->ni_cnd
.cn_nameptr
,
4374 tond
->ni_cnd
.cn_namelen
,
4375 tond
->ni_cnd
.cn_hash
,
4380 /* kevent notifications for moving resource files
4381 * _err is zero if we're here, so no need to notify directories, code
4382 * below will do that. only need to post the rename on the source and
4383 * possibly a delete on the dest
4385 post_event_if_success(src_attr_vp
, error
, NOTE_RENAME
);
4387 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4389 } else if (dst_attr_vp
) {
4391 * Just delete destination attribute file vnode if it exists, since
4392 * we didn't have a source attribute file.
4393 * Note that tdvp already has an iocount reference.
4396 struct vnop_remove_args args
;
4398 args
.a_desc
= &vnop_remove_desc
;
4400 args
.a_vp
= dst_attr_vp
;
4401 args
.a_cnp
= &tond
->ni_cnd
;
4402 args
.a_context
= ctx
;
4405 error
= (*tdvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&args
);
4408 vnode_setneedinactive(dst_attr_vp
);
4412 /* kevent notification for deleting the destination's attribute file
4413 * if it existed. Only need to post the delete on the destination, since
4414 * the code below will handle the directories.
4416 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4421 vnode_put(src_attr_vp
);
4425 vnode_put(dst_attr_vp
);
4428 if (xfromname
&& xfromname
!= &smallname1
[0]) {
4429 FREE(xfromname
, M_TEMP
);
4431 if (xtoname
&& xtoname
!= &smallname2
[0]) {
4432 FREE(xtoname
, M_TEMP
);
4434 #endif /* CONFIG_APPLEDOUBLE */
4436 FREE(fromnd
, M_TEMP
);
4448 *#% rename fdvp U U U
4449 *#% rename fvp U U U
4450 *#% rename tdvp L U U
4451 *#% rename tvp X U U
4454 struct vnop_rename_args
{
4455 struct vnodeop_desc
*a_desc
;
4458 struct componentname
*a_fcnp
;
4461 struct componentname
*a_tcnp
;
4462 vfs_context_t a_context
;
4466 VNOP_RENAME(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4467 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4471 struct vnop_rename_args a
;
4473 a
.a_desc
= &vnop_rename_desc
;
4482 /* do the rename of the main file. */
4483 _err
= (*fdvp
->v_op
[vnop_rename_desc
.vdesc_offset
])(&a
);
4484 DTRACE_FSINFO(rename
, vnode_t
, fdvp
);
4490 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4494 post_rename(vnode_t fdvp
, vnode_t fvp
, vnode_t tdvp
, vnode_t tvp
)
4496 if (tvp
&& tvp
!= fvp
) {
4497 vnode_setneedinactive(tvp
);
4500 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4501 int events
= NOTE_WRITE
;
4502 if (vnode_isdir(fvp
)) {
4503 /* Link count on dir changed only if we are moving a dir and...
4504 * --Moved to new dir, not overwriting there
4505 * --Kept in same dir and DID overwrite
4507 if (((fdvp
!= tdvp
) && (!tvp
)) || ((fdvp
== tdvp
) && (tvp
))) {
4508 events
|= NOTE_LINK
;
4512 lock_vnode_and_post(fdvp
, events
);
4514 lock_vnode_and_post(tdvp
, events
);
4517 /* If you're replacing the target, post a deletion for it */
4519 lock_vnode_and_post(tvp
, NOTE_DELETE
);
4522 lock_vnode_and_post(fvp
, NOTE_RENAME
);
4530 *#% renamex fdvp U U U
4531 *#% renamex fvp U U U
4532 *#% renamex tdvp L U U
4533 *#% renamex tvp X U U
4536 struct vnop_renamex_args
{
4537 struct vnodeop_desc
*a_desc
;
4540 struct componentname
*a_fcnp
;
4543 struct componentname
*a_tcnp
;
4544 vfs_rename_flags_t a_flags
;
4545 vfs_context_t a_context
;
4549 VNOP_RENAMEX(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4550 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4551 vfs_rename_flags_t flags
, vfs_context_t ctx
)
4554 struct vnop_renamex_args a
;
4556 a
.a_desc
= &vnop_renamex_desc
;
4566 /* do the rename of the main file. */
4567 _err
= (*fdvp
->v_op
[vnop_renamex_desc
.vdesc_offset
])(&a
);
4568 DTRACE_FSINFO(renamex
, vnode_t
, fdvp
);
4574 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4579 VNOP_COMPOUND_RENAME(
4580 struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
4581 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
4582 uint32_t flags
, vfs_context_t ctx
)
4586 struct vnop_compound_rename_args a
;
4589 no_fvp
= (*fvpp
) == NULLVP
;
4590 no_tvp
= (*tvpp
) == NULLVP
;
4592 a
.a_desc
= &vnop_compound_rename_desc
;
4606 a
.a_rename_authorizer
= vn_authorize_rename
;
4607 a
.a_reserved
= NULL
;
4609 /* do the rename of the main file. */
4610 _err
= (*fdvp
->v_op
[vnop_compound_rename_desc
.vdesc_offset
])(&a
);
4611 DTRACE_FSINFO(compound_rename
, vnode_t
, fdvp
);
4614 if (*tvpp
&& *tvpp
!= *fvpp
) {
4615 vnode_setneedinactive(*tvpp
);
4619 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4620 if (_err
== 0 && *fvpp
!= *tvpp
) {
4622 panic("No fvpp after compound rename?");
4625 events
= NOTE_WRITE
;
4626 if (vnode_isdir(*fvpp
)) {
4627 /* Link count on dir changed only if we are moving a dir and...
4628 * --Moved to new dir, not overwriting there
4629 * --Kept in same dir and DID overwrite
4631 if (((fdvp
!= tdvp
) && (!*tvpp
)) || ((fdvp
== tdvp
) && (*tvpp
))) {
4632 events
|= NOTE_LINK
;
4636 lock_vnode_and_post(fdvp
, events
);
4638 lock_vnode_and_post(tdvp
, events
);
4641 /* If you're replacing the target, post a deletion for it */
4643 lock_vnode_and_post(*tvpp
, NOTE_DELETE
);
4646 lock_vnode_and_post(*fvpp
, NOTE_RENAME
);
4650 lookup_compound_vnop_post_hook(_err
, fdvp
, *fvpp
, fcnp
->cn_ndp
, 0);
4652 if (no_tvp
&& *tvpp
!= NULLVP
) {
4653 lookup_compound_vnop_post_hook(_err
, tdvp
, *tvpp
, tcnp
->cn_ndp
, 0);
4656 if (_err
&& _err
!= EKEEPLOOKING
) {
4671 vn_mkdir(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4672 struct vnode_attr
*vap
, vfs_context_t ctx
)
4674 if (ndp
->ni_cnd
.cn_nameiop
!= CREATE
) {
4675 panic("Non-CREATE nameiop in vn_mkdir()?");
4678 if (vnode_compound_mkdir_available(dvp
)) {
4679 return VNOP_COMPOUND_MKDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4681 return VNOP_MKDIR(dvp
, vpp
, &ndp
->ni_cnd
, vap
, ctx
);
4692 struct vnop_mkdir_args
{
4693 struct vnodeop_desc
*a_desc
;
4696 struct componentname
*a_cnp
;
4697 struct vnode_attr
*a_vap
;
4698 vfs_context_t a_context
;
4702 VNOP_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4703 struct vnode_attr
*vap
, vfs_context_t ctx
)
4706 struct vnop_mkdir_args a
;
4708 a
.a_desc
= &vnop_mkdir_desc
;
4715 _err
= (*dvp
->v_op
[vnop_mkdir_desc
.vdesc_offset
])(&a
);
4716 if (_err
== 0 && *vpp
) {
4717 DTRACE_FSINFO(mkdir
, vnode_t
, *vpp
);
4719 #if CONFIG_APPLEDOUBLE
4720 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4722 * Remove stale Apple Double file (if any).
4724 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4726 #endif /* CONFIG_APPLEDOUBLE */
4728 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4734 VNOP_COMPOUND_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4735 struct vnode_attr
*vap
, vfs_context_t ctx
)
4738 struct vnop_compound_mkdir_args a
;
4740 a
.a_desc
= &vnop_compound_mkdir_desc
;
4743 a
.a_cnp
= &ndp
->ni_cnd
;
4748 a
.a_mkdir_authorizer
= vn_authorize_mkdir
;
4750 a
.a_reserved
= NULL
;
4752 _err
= (*dvp
->v_op
[vnop_compound_mkdir_desc
.vdesc_offset
])(&a
);
4753 if (_err
== 0 && *vpp
) {
4754 DTRACE_FSINFO(compound_mkdir
, vnode_t
, *vpp
);
4756 #if CONFIG_APPLEDOUBLE
4757 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4759 * Remove stale Apple Double file (if any).
4761 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4763 #endif /* CONFIG_APPLEDOUBLE */
4765 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4767 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, (_err
== 0));
4768 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4777 vn_rmdir(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4779 if (vnode_compound_rmdir_available(dvp
)) {
4780 return VNOP_COMPOUND_RMDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4782 if (*vpp
== NULLVP
) {
4783 panic("NULL vp, but not a compound VNOP?");
4786 panic("Non-NULL vap, but not a compound VNOP?");
4788 return VNOP_RMDIR(dvp
, *vpp
, &ndp
->ni_cnd
, ctx
);
4799 struct vnop_rmdir_args
{
4800 struct vnodeop_desc
*a_desc
;
4803 struct componentname
*a_cnp
;
4804 vfs_context_t a_context
;
4809 VNOP_RMDIR(struct vnode
*dvp
, struct vnode
*vp
, struct componentname
*cnp
, vfs_context_t ctx
)
4812 struct vnop_rmdir_args a
;
4814 a
.a_desc
= &vnop_rmdir_desc
;
4820 _err
= (*vp
->v_op
[vnop_rmdir_desc
.vdesc_offset
])(&a
);
4821 DTRACE_FSINFO(rmdir
, vnode_t
, vp
);
4824 vnode_setneedinactive(vp
);
4825 #if CONFIG_APPLEDOUBLE
4826 if (!(NATIVE_XATTR(dvp
))) {
4828 * Remove any associated extended attribute file (._ AppleDouble file).
4830 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
4835 /* If you delete a dir, it loses its "." reference --> NOTE_LINK */
4836 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4837 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4843 VNOP_COMPOUND_RMDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4844 struct vnode_attr
*vap
, vfs_context_t ctx
)
4847 struct vnop_compound_rmdir_args a
;
4850 a
.a_desc
= &vnop_mkdir_desc
;
4853 a
.a_cnp
= &ndp
->ni_cnd
;
4857 a
.a_rmdir_authorizer
= vn_authorize_rmdir
;
4858 a
.a_reserved
= NULL
;
4860 no_vp
= (*vpp
== NULLVP
);
4862 _err
= (*dvp
->v_op
[vnop_compound_rmdir_desc
.vdesc_offset
])(&a
);
4863 if (_err
== 0 && *vpp
) {
4864 DTRACE_FSINFO(compound_rmdir
, vnode_t
, *vpp
);
4866 #if CONFIG_APPLEDOUBLE
4867 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4869 * Remove stale Apple Double file (if any).
4871 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4876 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4878 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4881 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
4883 #if 0 /* Removing orphaned ._ files requires a vp.... */
4884 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4894 #if CONFIG_APPLEDOUBLE
4896 * Remove a ._ AppleDouble file
4898 #define AD_STALE_SECS (180)
4900 xattrfile_remove(vnode_t dvp
, const char * basename
, vfs_context_t ctx
, int force
)
4903 struct nameidata nd
;
4905 char *filename
= NULL
;
4908 if ((basename
== NULL
) || (basename
[0] == '\0') ||
4909 (basename
[0] == '.' && basename
[1] == '_')) {
4912 filename
= &smallname
[0];
4913 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4914 if (len
>= sizeof(smallname
)) {
4915 len
++; /* snprintf result doesn't include '\0' */
4916 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4917 len
= snprintf(filename
, len
, "._%s", basename
);
4919 NDINIT(&nd
, DELETE
, OP_UNLINK
, WANTPARENT
| LOCKLEAF
| NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4920 CAST_USER_ADDR_T(filename
), ctx
);
4922 if (namei(&nd
) != 0) {
4928 if (xvp
->v_type
!= VREG
) {
4933 * When creating a new object and a "._" file already
4934 * exists, check to see if its a stale "._" file.
4938 struct vnode_attr va
;
4941 VATTR_WANTED(&va
, va_data_size
);
4942 VATTR_WANTED(&va
, va_modify_time
);
4943 if (VNOP_GETATTR(xvp
, &va
, ctx
) == 0 &&
4944 VATTR_IS_SUPPORTED(&va
, va_data_size
) &&
4945 VATTR_IS_SUPPORTED(&va
, va_modify_time
) &&
4946 va
.va_data_size
!= 0) {
4950 if ((tv
.tv_sec
> va
.va_modify_time
.tv_sec
) &&
4951 (tv
.tv_sec
- va
.va_modify_time
.tv_sec
) > AD_STALE_SECS
) {
4952 force
= 1; /* must be stale */
4959 error
= VNOP_REMOVE(dvp
, xvp
, &nd
.ni_cnd
, 0, ctx
);
4961 vnode_setneedinactive(xvp
);
4964 post_event_if_success(xvp
, error
, NOTE_DELETE
);
4965 post_event_if_success(dvp
, error
, NOTE_WRITE
);
4972 if (filename
&& filename
!= &smallname
[0]) {
4973 FREE(filename
, M_TEMP
);
4978 * Shadow uid/gid/mod to a ._ AppleDouble file
4981 xattrfile_setattr(vnode_t dvp
, const char * basename
, struct vnode_attr
* vap
,
4985 struct nameidata nd
;
4987 char *filename
= NULL
;
4990 if ((dvp
== NULLVP
) ||
4991 (basename
== NULL
) || (basename
[0] == '\0') ||
4992 (basename
[0] == '.' && basename
[1] == '_')) {
4995 filename
= &smallname
[0];
4996 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4997 if (len
>= sizeof(smallname
)) {
4998 len
++; /* snprintf result doesn't include '\0' */
4999 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
5000 len
= snprintf(filename
, len
, "._%s", basename
);
5002 NDINIT(&nd
, LOOKUP
, OP_SETATTR
, NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
5003 CAST_USER_ADDR_T(filename
), ctx
);
5005 if (namei(&nd
) != 0) {
5012 if (xvp
->v_type
== VREG
) {
5013 struct vnop_setattr_args a
;
5015 a
.a_desc
= &vnop_setattr_desc
;
5020 (void) (*xvp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
5025 if (filename
&& filename
!= &smallname
[0]) {
5026 FREE(filename
, M_TEMP
);
5029 #endif /* CONFIG_APPLEDOUBLE */
5034 *#% symlink dvp L U U
5035 *#% symlink vpp - U -
5038 struct vnop_symlink_args
{
5039 struct vnodeop_desc
*a_desc
;
5042 struct componentname
*a_cnp
;
5043 struct vnode_attr
*a_vap
;
5045 vfs_context_t a_context
;
5050 VNOP_SYMLINK(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
5051 struct vnode_attr
*vap
, char *target
, vfs_context_t ctx
)
5054 struct vnop_symlink_args a
;
5056 a
.a_desc
= &vnop_symlink_desc
;
5061 a
.a_target
= target
;
5064 _err
= (*dvp
->v_op
[vnop_symlink_desc
.vdesc_offset
])(&a
);
5065 DTRACE_FSINFO(symlink
, vnode_t
, dvp
);
5066 #if CONFIG_APPLEDOUBLE
5067 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
5069 * Remove stale Apple Double file (if any). Posts its own knotes
5071 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
5073 #endif /* CONFIG_APPLEDOUBLE */
5075 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
5083 *#% readdir vp L L L
5086 struct vnop_readdir_args
{
5087 struct vnodeop_desc
*a_desc
;
5093 vfs_context_t a_context
;
5098 VNOP_READDIR(struct vnode
*vp
, struct uio
*uio
, int flags
, int *eofflag
,
5099 int *numdirent
, vfs_context_t ctx
)
5102 struct vnop_readdir_args a
;
5104 user_ssize_t resid
= uio_resid(uio
);
5107 a
.a_desc
= &vnop_readdir_desc
;
5111 a
.a_eofflag
= eofflag
;
5112 a
.a_numdirent
= numdirent
;
5115 _err
= (*vp
->v_op
[vnop_readdir_desc
.vdesc_offset
])(&a
);
5116 DTRACE_FSINFO_IO(readdir
,
5117 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5125 *#% readdirattr vp L L L
5128 struct vnop_readdirattr_args
{
5129 struct vnodeop_desc
*a_desc
;
5131 struct attrlist
*a_alist
;
5133 uint32_t a_maxcount
;
5135 uint32_t *a_newstate
;
5137 uint32_t *a_actualcount
;
5138 vfs_context_t a_context
;
5143 VNOP_READDIRATTR(struct vnode
*vp
, struct attrlist
*alist
, struct uio
*uio
, uint32_t maxcount
,
5144 uint32_t options
, uint32_t *newstate
, int *eofflag
, uint32_t *actualcount
, vfs_context_t ctx
)
5147 struct vnop_readdirattr_args a
;
5149 user_ssize_t resid
= uio_resid(uio
);
5152 a
.a_desc
= &vnop_readdirattr_desc
;
5156 a
.a_maxcount
= maxcount
;
5157 a
.a_options
= options
;
5158 a
.a_newstate
= newstate
;
5159 a
.a_eofflag
= eofflag
;
5160 a
.a_actualcount
= actualcount
;
5163 _err
= (*vp
->v_op
[vnop_readdirattr_desc
.vdesc_offset
])(&a
);
5164 DTRACE_FSINFO_IO(readdirattr
,
5165 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5171 struct vnop_getttrlistbulk_args
{
5172 struct vnodeop_desc
*a_desc
;
5174 struct attrlist
*a_alist
;
5175 struct vnode_attr
*a_vap
;
5180 uint32_t *a_actualcount
;
5181 vfs_context_t a_context
;
5185 VNOP_GETATTRLISTBULK(struct vnode
*vp
, struct attrlist
*alist
,
5186 struct vnode_attr
*vap
, struct uio
*uio
, void *private, uint64_t options
,
5187 int32_t *eofflag
, int32_t *actualcount
, vfs_context_t ctx
)
5190 struct vnop_getattrlistbulk_args a
;
5192 user_ssize_t resid
= uio_resid(uio
);
5195 a
.a_desc
= &vnop_getattrlistbulk_desc
;
5200 a
.a_private
= private;
5201 a
.a_options
= options
;
5202 a
.a_eofflag
= eofflag
;
5203 a
.a_actualcount
= actualcount
;
5206 _err
= (*vp
->v_op
[vnop_getattrlistbulk_desc
.vdesc_offset
])(&a
);
5207 DTRACE_FSINFO_IO(getattrlistbulk
,
5208 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5216 *#% readlink vp L L L
5219 struct vnop_readlink_args
{
5220 struct vnodeop_desc
*a_desc
;
5223 vfs_context_t a_context
;
5228 * Returns: 0 Success
5229 * lock_fsnode:ENOENT No such file or directory [only for VFS
5230 * that is not thread safe & vnode is
5231 * currently being/has been terminated]
5232 * <vfs_readlink>:EINVAL
5233 * <vfs_readlink>:???
5235 * Note: The return codes from the underlying VFS's readlink routine
5236 * can't be fully enumerated here, since third party VFS authors
5237 * may not limit their error returns to the ones documented here,
5238 * even though this may result in some programs functioning
5241 * The return codes documented above are those which may currently
5242 * be returned by HFS from hfs_vnop_readlink, not including
5243 * additional error code which may be propagated from underlying
5247 VNOP_READLINK(struct vnode
*vp
, struct uio
*uio
, vfs_context_t ctx
)
5250 struct vnop_readlink_args a
;
5252 user_ssize_t resid
= uio_resid(uio
);
5254 a
.a_desc
= &vnop_readlink_desc
;
5259 _err
= (*vp
->v_op
[vnop_readlink_desc
.vdesc_offset
])(&a
);
5260 DTRACE_FSINFO_IO(readlink
,
5261 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5269 *#% inactive vp L U U
5272 struct vnop_inactive_args
{
5273 struct vnodeop_desc
*a_desc
;
5275 vfs_context_t a_context
;
5279 VNOP_INACTIVE(struct vnode
*vp
, vfs_context_t ctx
)
5282 struct vnop_inactive_args a
;
5284 a
.a_desc
= &vnop_inactive_desc
;
5288 _err
= (*vp
->v_op
[vnop_inactive_desc
.vdesc_offset
])(&a
);
5289 DTRACE_FSINFO(inactive
, vnode_t
, vp
);
5292 /* For file systems that do not support namedstream natively, mark
5293 * the shadow stream file vnode to be recycled as soon as the last
5294 * reference goes away. To avoid re-entering reclaim code, do not
5295 * call recycle on terminating namedstream vnodes.
5297 if (vnode_isnamedstream(vp
) &&
5298 (vp
->v_parent
!= NULLVP
) &&
5299 vnode_isshadow(vp
) &&
5300 ((vp
->v_lflag
& VL_TERMINATE
) == 0)) {
5312 *#% reclaim vp U U U
5315 struct vnop_reclaim_args
{
5316 struct vnodeop_desc
*a_desc
;
5318 vfs_context_t a_context
;
5322 VNOP_RECLAIM(struct vnode
*vp
, vfs_context_t ctx
)
5325 struct vnop_reclaim_args a
;
5327 a
.a_desc
= &vnop_reclaim_desc
;
5331 _err
= (*vp
->v_op
[vnop_reclaim_desc
.vdesc_offset
])(&a
);
5332 DTRACE_FSINFO(reclaim
, vnode_t
, vp
);
5339 * Returns: 0 Success
5340 * lock_fsnode:ENOENT No such file or directory [only for VFS
5341 * that is not thread safe & vnode is
5342 * currently being/has been terminated]
5343 * <vnop_pathconf_desc>:??? [per FS implementation specific]
5348 *#% pathconf vp L L L
5351 struct vnop_pathconf_args
{
5352 struct vnodeop_desc
*a_desc
;
5356 vfs_context_t a_context
;
5360 VNOP_PATHCONF(struct vnode
*vp
, int name
, int32_t *retval
, vfs_context_t ctx
)
5363 struct vnop_pathconf_args a
;
5365 a
.a_desc
= &vnop_pathconf_desc
;
5368 a
.a_retval
= retval
;
5371 _err
= (*vp
->v_op
[vnop_pathconf_desc
.vdesc_offset
])(&a
);
5372 DTRACE_FSINFO(pathconf
, vnode_t
, vp
);
5378 * Returns: 0 Success
5379 * err_advlock:ENOTSUP
5381 * <vnop_advlock_desc>:???
5383 * Notes: VFS implementations of advisory locking using calls through
5384 * <vnop_advlock_desc> because lock enforcement does not occur
5385 * locally should try to limit themselves to the return codes
5386 * documented above for lf_advlock and err_advlock.
5391 *#% advlock vp U U U
5394 struct vnop_advlock_args
{
5395 struct vnodeop_desc
*a_desc
;
5401 vfs_context_t a_context
;
5405 VNOP_ADVLOCK(struct vnode
*vp
, caddr_t id
, int op
, struct flock
*fl
, int flags
, vfs_context_t ctx
, struct timespec
*timeout
)
5408 struct vnop_advlock_args a
;
5410 a
.a_desc
= &vnop_advlock_desc
;
5417 a
.a_timeout
= timeout
;
5419 /* Disallow advisory locking on non-seekable vnodes */
5420 if (vnode_isfifo(vp
)) {
5421 _err
= err_advlock(&a
);
5423 if ((vp
->v_flag
& VLOCKLOCAL
)) {
5424 /* Advisory locking done at this layer */
5425 _err
= lf_advlock(&a
);
5426 } else if (flags
& F_OFD_LOCK
) {
5427 /* Non-local locking doesn't work for OFD locks */
5428 _err
= err_advlock(&a
);
5430 /* Advisory locking done by underlying filesystem */
5431 _err
= (*vp
->v_op
[vnop_advlock_desc
.vdesc_offset
])(&a
);
5433 DTRACE_FSINFO(advlock
, vnode_t
, vp
);
5434 if (op
== F_UNLCK
&& flags
== F_FLOCK
) {
5435 post_event_if_success(vp
, _err
, NOTE_FUNLOCK
);
5447 *#% allocate vp L L L
5450 struct vnop_allocate_args
{
5451 struct vnodeop_desc
*a_desc
;
5455 off_t
*a_bytesallocated
;
5457 vfs_context_t a_context
;
5462 VNOP_ALLOCATE(struct vnode
*vp
, off_t length
, u_int32_t flags
, off_t
*bytesallocated
, off_t offset
, vfs_context_t ctx
)
5465 struct vnop_allocate_args a
;
5467 a
.a_desc
= &vnop_allocate_desc
;
5469 a
.a_length
= length
;
5471 a
.a_bytesallocated
= bytesallocated
;
5472 a
.a_offset
= offset
;
5475 _err
= (*vp
->v_op
[vnop_allocate_desc
.vdesc_offset
])(&a
);
5476 DTRACE_FSINFO(allocate
, vnode_t
, vp
);
5479 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
5492 struct vnop_pagein_args
{
5493 struct vnodeop_desc
*a_desc
;
5496 upl_offset_t a_pl_offset
;
5500 vfs_context_t a_context
;
5504 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
)
5507 struct vnop_pagein_args a
;
5509 a
.a_desc
= &vnop_pagein_desc
;
5512 a
.a_pl_offset
= pl_offset
;
5513 a
.a_f_offset
= f_offset
;
5518 _err
= (*vp
->v_op
[vnop_pagein_desc
.vdesc_offset
])(&a
);
5519 DTRACE_FSINFO(pagein
, vnode_t
, vp
);
5527 *#% pageout vp = = =
5530 struct vnop_pageout_args
{
5531 struct vnodeop_desc
*a_desc
;
5534 upl_offset_t a_pl_offset
;
5538 vfs_context_t a_context
;
5543 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
)
5546 struct vnop_pageout_args a
;
5548 a
.a_desc
= &vnop_pageout_desc
;
5551 a
.a_pl_offset
= pl_offset
;
5552 a
.a_f_offset
= f_offset
;
5557 _err
= (*vp
->v_op
[vnop_pageout_desc
.vdesc_offset
])(&a
);
5558 DTRACE_FSINFO(pageout
, vnode_t
, vp
);
5560 post_event_if_success(vp
, _err
, NOTE_WRITE
);
5566 vn_remove(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
5568 if (vnode_compound_remove_available(dvp
)) {
5569 return VNOP_COMPOUND_REMOVE(dvp
, vpp
, ndp
, flags
, vap
, ctx
);
5571 return VNOP_REMOVE(dvp
, *vpp
, &ndp
->ni_cnd
, flags
, ctx
);
5580 *#% searchfs vp L L L
5583 struct vnop_searchfs_args
{
5584 struct vnodeop_desc
*a_desc
;
5586 void *a_searchparams1
;
5587 void *a_searchparams2
;
5588 struct attrlist
*a_searchattrs
;
5589 uint32_t a_maxmatches
;
5590 struct timeval
*a_timelimit
;
5591 struct attrlist
*a_returnattrs
;
5592 uint32_t *a_nummatches
;
5593 uint32_t a_scriptcode
;
5596 struct searchstate
*a_searchstate
;
5597 vfs_context_t a_context
;
5602 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
)
5605 struct vnop_searchfs_args a
;
5607 a
.a_desc
= &vnop_searchfs_desc
;
5609 a
.a_searchparams1
= searchparams1
;
5610 a
.a_searchparams2
= searchparams2
;
5611 a
.a_searchattrs
= searchattrs
;
5612 a
.a_maxmatches
= maxmatches
;
5613 a
.a_timelimit
= timelimit
;
5614 a
.a_returnattrs
= returnattrs
;
5615 a
.a_nummatches
= nummatches
;
5616 a
.a_scriptcode
= scriptcode
;
5617 a
.a_options
= options
;
5619 a
.a_searchstate
= searchstate
;
5622 _err
= (*vp
->v_op
[vnop_searchfs_desc
.vdesc_offset
])(&a
);
5623 DTRACE_FSINFO(searchfs
, vnode_t
, vp
);
5627 #endif /* CONFIG_SEARCHFS */
5632 *#% copyfile fvp U U U
5633 *#% copyfile tdvp L U U
5634 *#% copyfile tvp X U U
5637 struct vnop_copyfile_args
{
5638 struct vnodeop_desc
*a_desc
;
5642 struct componentname
*a_tcnp
;
5645 vfs_context_t a_context
;
5649 VNOP_COPYFILE(struct vnode
*fvp
, struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
5650 int mode
, int flags
, vfs_context_t ctx
)
5653 struct vnop_copyfile_args a
;
5654 a
.a_desc
= &vnop_copyfile_desc
;
5662 _err
= (*fvp
->v_op
[vnop_copyfile_desc
.vdesc_offset
])(&a
);
5663 DTRACE_FSINFO(copyfile
, vnode_t
, fvp
);
5668 struct vnop_clonefile_args
{
5669 struct vnodeop_desc
*a_desc
;
5673 struct componentname
*a_cnp
;
5674 struct vnode_attr
*a_vap
;
5676 vfs_context_t a_context
;
5677 int (*a_dir_clone_authorizer
)( /* Authorization callback */
5678 struct vnode_attr
*vap
, /* attribute to be authorized */
5679 kauth_action_t action
, /* action for which attribute is to be authorized */
5680 struct vnode_attr
*dvap
, /* target directory attributes */
5681 vnode_t sdvp
, /* source directory vnode pointer (optional) */
5682 mount_t mp
, /* mount point of filesystem */
5683 dir_clone_authorizer_op_t vattr_op
, /* specific operation requested : setup, authorization or cleanup */
5684 uint32_t flags
; /* value passed in a_flags to the VNOP */
5685 vfs_context_t ctx
, /* As passed to VNOP */
5686 void *reserved
); /* Always NULL */
5687 void *a_reserved
; /* Currently unused */
5692 VNOP_CLONEFILE(vnode_t fvp
, vnode_t dvp
, vnode_t
*vpp
,
5693 struct componentname
*cnp
, struct vnode_attr
*vap
, uint32_t flags
,
5697 struct vnop_clonefile_args a
;
5698 a
.a_desc
= &vnop_clonefile_desc
;
5707 if (vnode_vtype(fvp
) == VDIR
) {
5708 a
.a_dir_clone_authorizer
= vnode_attr_authorize_dir_clone
;
5710 a
.a_dir_clone_authorizer
= NULL
;
5713 _err
= (*dvp
->v_op
[vnop_clonefile_desc
.vdesc_offset
])(&a
);
5715 if (_err
== 0 && *vpp
) {
5716 DTRACE_FSINFO(clonefile
, vnode_t
, *vpp
);
5717 if (kdebug_enable
) {
5718 kdebug_lookup(*vpp
, cnp
);
5722 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
5728 VNOP_GETXATTR(vnode_t vp
, const char *name
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5730 struct vnop_getxattr_args a
;
5733 a
.a_desc
= &vnop_getxattr_desc
;
5738 a
.a_options
= options
;
5741 error
= (*vp
->v_op
[vnop_getxattr_desc
.vdesc_offset
])(&a
);
5742 DTRACE_FSINFO(getxattr
, vnode_t
, vp
);
5748 VNOP_SETXATTR(vnode_t vp
, const char *name
, uio_t uio
, int options
, vfs_context_t ctx
)
5750 struct vnop_setxattr_args a
;
5753 a
.a_desc
= &vnop_setxattr_desc
;
5757 a
.a_options
= options
;
5760 error
= (*vp
->v_op
[vnop_setxattr_desc
.vdesc_offset
])(&a
);
5761 DTRACE_FSINFO(setxattr
, vnode_t
, vp
);
5764 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
5767 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5773 VNOP_REMOVEXATTR(vnode_t vp
, const char *name
, int options
, vfs_context_t ctx
)
5775 struct vnop_removexattr_args a
;
5778 a
.a_desc
= &vnop_removexattr_desc
;
5781 a
.a_options
= options
;
5784 error
= (*vp
->v_op
[vnop_removexattr_desc
.vdesc_offset
])(&a
);
5785 DTRACE_FSINFO(removexattr
, vnode_t
, vp
);
5787 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5793 VNOP_LISTXATTR(vnode_t vp
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5795 struct vnop_listxattr_args a
;
5798 a
.a_desc
= &vnop_listxattr_desc
;
5802 a
.a_options
= options
;
5805 error
= (*vp
->v_op
[vnop_listxattr_desc
.vdesc_offset
])(&a
);
5806 DTRACE_FSINFO(listxattr
, vnode_t
, vp
);
5815 *#% blktooff vp = = =
5818 struct vnop_blktooff_args
{
5819 struct vnodeop_desc
*a_desc
;
5826 VNOP_BLKTOOFF(struct vnode
*vp
, daddr64_t lblkno
, off_t
*offset
)
5829 struct vnop_blktooff_args a
;
5831 a
.a_desc
= &vnop_blktooff_desc
;
5833 a
.a_lblkno
= lblkno
;
5834 a
.a_offset
= offset
;
5836 _err
= (*vp
->v_op
[vnop_blktooff_desc
.vdesc_offset
])(&a
);
5837 DTRACE_FSINFO(blktooff
, vnode_t
, vp
);
5845 *#% offtoblk vp = = =
5848 struct vnop_offtoblk_args
{
5849 struct vnodeop_desc
*a_desc
;
5852 daddr64_t
*a_lblkno
;
5856 VNOP_OFFTOBLK(struct vnode
*vp
, off_t offset
, daddr64_t
*lblkno
)
5859 struct vnop_offtoblk_args a
;
5861 a
.a_desc
= &vnop_offtoblk_desc
;
5863 a
.a_offset
= offset
;
5864 a
.a_lblkno
= lblkno
;
5866 _err
= (*vp
->v_op
[vnop_offtoblk_desc
.vdesc_offset
])(&a
);
5867 DTRACE_FSINFO(offtoblk
, vnode_t
, vp
);
5875 *#% blockmap vp L L L
5878 struct vnop_blockmap_args
{
5879 struct vnodeop_desc
*a_desc
;
5887 vfs_context_t a_context
;
5891 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
)
5894 struct vnop_blockmap_args a
;
5895 size_t localrun
= 0;
5898 ctx
= vfs_context_current();
5900 a
.a_desc
= &vnop_blockmap_desc
;
5902 a
.a_foffset
= foffset
;
5905 a
.a_run
= &localrun
;
5910 _err
= (*vp
->v_op
[vnop_blockmap_desc
.vdesc_offset
])(&a
);
5911 DTRACE_FSINFO(blockmap
, vnode_t
, vp
);
5914 * We used a local variable to request information from the underlying
5915 * filesystem about the length of the I/O run in question. If
5916 * we get malformed output from the filesystem, we cap it to the length
5917 * requested, at most. Update 'run' on the way out.
5920 if (localrun
> size
) {
5933 struct vnop_strategy_args
{
5934 struct vnodeop_desc
*a_desc
;
5940 VNOP_STRATEGY(struct buf
*bp
)
5943 struct vnop_strategy_args a
;
5944 vnode_t vp
= buf_vnode(bp
);
5945 a
.a_desc
= &vnop_strategy_desc
;
5947 _err
= (*vp
->v_op
[vnop_strategy_desc
.vdesc_offset
])(&a
);
5948 DTRACE_FSINFO(strategy
, vnode_t
, vp
);
5953 struct vnop_bwrite_args
{
5954 struct vnodeop_desc
*a_desc
;
5959 VNOP_BWRITE(struct buf
*bp
)
5962 struct vnop_bwrite_args a
;
5963 vnode_t vp
= buf_vnode(bp
);
5964 a
.a_desc
= &vnop_bwrite_desc
;
5966 _err
= (*vp
->v_op
[vnop_bwrite_desc
.vdesc_offset
])(&a
);
5967 DTRACE_FSINFO(bwrite
, vnode_t
, vp
);
5972 struct vnop_kqfilt_add_args
{
5973 struct vnodeop_desc
*a_desc
;
5976 vfs_context_t a_context
;
5980 VNOP_KQFILT_ADD(struct vnode
*vp
, struct knote
*kn
, vfs_context_t ctx
)
5983 struct vnop_kqfilt_add_args a
;
5985 a
.a_desc
= VDESC(vnop_kqfilt_add
);
5990 _err
= (*vp
->v_op
[vnop_kqfilt_add_desc
.vdesc_offset
])(&a
);
5991 DTRACE_FSINFO(kqfilt_add
, vnode_t
, vp
);
5997 struct vnop_kqfilt_remove_args
{
5998 struct vnodeop_desc
*a_desc
;
6001 vfs_context_t a_context
;
6005 VNOP_KQFILT_REMOVE(struct vnode
*vp
, uintptr_t ident
, vfs_context_t ctx
)
6008 struct vnop_kqfilt_remove_args a
;
6010 a
.a_desc
= VDESC(vnop_kqfilt_remove
);
6015 _err
= (*vp
->v_op
[vnop_kqfilt_remove_desc
.vdesc_offset
])(&a
);
6016 DTRACE_FSINFO(kqfilt_remove
, vnode_t
, vp
);
6022 VNOP_MONITOR(vnode_t vp
, uint32_t events
, uint32_t flags
, void *handle
, vfs_context_t ctx
)
6025 struct vnop_monitor_args a
;
6027 a
.a_desc
= VDESC(vnop_monitor
);
6029 a
.a_events
= events
;
6031 a
.a_handle
= handle
;
6034 _err
= (*vp
->v_op
[vnop_monitor_desc
.vdesc_offset
])(&a
);
6035 DTRACE_FSINFO(monitor
, vnode_t
, vp
);
6041 struct vnop_setlabel_args
{
6042 struct vnodeop_desc
*a_desc
;
6045 vfs_context_t a_context
;
6049 VNOP_SETLABEL(struct vnode
*vp
, struct label
*label
, vfs_context_t ctx
)
6052 struct vnop_setlabel_args a
;
6054 a
.a_desc
= VDESC(vnop_setlabel
);
6059 _err
= (*vp
->v_op
[vnop_setlabel_desc
.vdesc_offset
])(&a
);
6060 DTRACE_FSINFO(setlabel
, vnode_t
, vp
);
6068 * Get a named streamed
6071 VNOP_GETNAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, enum nsoperation operation
, int flags
, vfs_context_t ctx
)
6074 struct vnop_getnamedstream_args a
;
6076 a
.a_desc
= &vnop_getnamedstream_desc
;
6080 a
.a_operation
= operation
;
6084 _err
= (*vp
->v_op
[vnop_getnamedstream_desc
.vdesc_offset
])(&a
);
6085 DTRACE_FSINFO(getnamedstream
, vnode_t
, vp
);
6090 * Create a named streamed
6093 VNOP_MAKENAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, int flags
, vfs_context_t ctx
)
6096 struct vnop_makenamedstream_args a
;
6098 a
.a_desc
= &vnop_makenamedstream_desc
;
6105 _err
= (*vp
->v_op
[vnop_makenamedstream_desc
.vdesc_offset
])(&a
);
6106 DTRACE_FSINFO(makenamedstream
, vnode_t
, vp
);
6112 * Remove a named streamed
6115 VNOP_REMOVENAMEDSTREAM(vnode_t vp
, vnode_t svp
, const char *name
, int flags
, vfs_context_t ctx
)
6118 struct vnop_removenamedstream_args a
;
6120 a
.a_desc
= &vnop_removenamedstream_desc
;
6127 _err
= (*vp
->v_op
[vnop_removenamedstream_desc
.vdesc_offset
])(&a
);
6128 DTRACE_FSINFO(removenamedstream
, vnode_t
, vp
);