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_internal()
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_internal(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_create
1336 * Description: Allocate and initialize a new context.
1338 * Parameters: vfs_context_t: Context to copy, or NULL for new
1340 * Returns: Pointer to new context
1342 * Notes: Copy cred and thread from argument, if available; else
1343 * initialize with current thread and new cred. Returns
1344 * with a reference held on the credential.
1347 vfs_context_create(vfs_context_t ctx
)
1349 vfs_context_t newcontext
;
1351 newcontext
= (vfs_context_t
)kalloc(sizeof(struct vfs_context
));
1354 kauth_cred_t safecred
;
1356 newcontext
->vc_thread
= ctx
->vc_thread
;
1357 safecred
= ctx
->vc_ucred
;
1359 newcontext
->vc_thread
= current_thread();
1360 safecred
= kauth_cred_get();
1362 if (IS_VALID_CRED(safecred
)) {
1363 kauth_cred_ref(safecred
);
1365 newcontext
->vc_ucred
= safecred
;
1373 vfs_context_current(void)
1375 vfs_context_t ctx
= NULL
;
1376 volatile uthread_t ut
= (uthread_t
)get_bsdthread_info(current_thread());
1379 if (ut
->uu_context
.vc_ucred
!= NULL
) {
1380 ctx
= &ut
->uu_context
;
1384 return ctx
== NULL
? vfs_context_kernel() : ctx
;
1391 * Dangerous hack - adopt the first kernel thread as the current thread, to
1392 * get to the vfs_context_t in the uthread associated with a kernel thread.
1393 * This is used by UDF to make the call into IOCDMediaBSDClient,
1394 * IOBDMediaBSDClient, and IODVDMediaBSDClient to determine whether the
1395 * ioctl() is being called from kernel or user space (and all this because
1396 * we do not pass threads into our ioctl()'s, instead of processes).
1398 * This is also used by imageboot_setup(), called early from bsd_init() after
1399 * kernproc has been given a credential.
1401 * Note: The use of proc_thread() here is a convenience to avoid inclusion
1402 * of many Mach headers to do the reference directly rather than indirectly;
1403 * we will need to forego this convenience when we reture proc_thread().
1405 static struct vfs_context kerncontext
;
1407 vfs_context_kernel(void)
1409 if (kerncontext
.vc_ucred
== NOCRED
) {
1410 kerncontext
.vc_ucred
= kernproc
->p_ucred
;
1412 if (kerncontext
.vc_thread
== NULL
) {
1413 kerncontext
.vc_thread
= proc_thread(kernproc
);
1416 return &kerncontext
;
1421 vfs_context_rele(vfs_context_t ctx
)
1424 if (IS_VALID_CRED(ctx
->vc_ucred
)) {
1425 kauth_cred_unref(&ctx
->vc_ucred
);
1427 kfree(ctx
, sizeof(struct vfs_context
));
1434 vfs_context_ucred(vfs_context_t ctx
)
1436 return ctx
->vc_ucred
;
1440 * Return true if the context is owned by the superuser.
1443 vfs_context_issuser(vfs_context_t ctx
)
1445 return kauth_cred_issuser(vfs_context_ucred(ctx
));
1449 vfs_context_iskernel(vfs_context_t ctx
)
1451 return ctx
== &kerncontext
;
1455 * Given a context, for all fields of vfs_context_t which
1456 * are not held with a reference, set those fields to the
1457 * values for the current execution context. Currently, this
1458 * just means the vc_thread.
1460 * Returns: 0 for success, nonzero for failure
1462 * The intended use is:
1463 * 1. vfs_context_create() gets the caller a context
1464 * 2. vfs_context_bind() sets the unrefcounted data
1465 * 3. vfs_context_rele() releases the context
1469 vfs_context_bind(vfs_context_t ctx
)
1471 ctx
->vc_thread
= current_thread();
1476 vfs_isswapmount(mount_t mnt
)
1478 return mnt
&& ISSET(mnt
->mnt_kern_flag
, MNTK_SWAP_MOUNT
) ? 1 : 0;
1481 /* XXXXXXXXXXXXXX VNODE KAPIS XXXXXXXXXXXXXXXXXXXXXXXXX */
1485 * Convert between vnode types and inode formats (since POSIX.1
1486 * defines mode word of stat structure in terms of inode formats).
1489 vnode_iftovt(int mode
)
1491 return iftovt_tab
[((mode
) & S_IFMT
) >> 12];
1495 vnode_vttoif(enum vtype indx
)
1497 return vttoif_tab
[(int)(indx
)];
1501 vnode_makeimode(int indx
, int mode
)
1503 return (int)(VTTOIF(indx
) | (mode
));
1508 * vnode manipulation functions.
1511 /* returns system root vnode iocount; It should be released using vnode_put() */
1517 error
= vnode_get(rootvnode
);
1527 vnode_vid(vnode_t vp
)
1529 return (uint32_t)(vp
->v_id
);
1533 vnode_mount(vnode_t vp
)
1540 vnode_mountdevvp(vnode_t vp
)
1543 return vp
->v_mount
->mnt_devvp
;
1551 vnode_isonexternalstorage(vnode_t vp
)
1555 if (vp
->v_mount
->mnt_ioflags
& MNT_IOFLAGS_PERIPHERAL_DRIVE
) {
1564 vnode_mountedhere(vnode_t vp
)
1568 if ((vp
->v_type
== VDIR
) && ((mp
= vp
->v_mountedhere
) != NULL
) &&
1569 (mp
->mnt_vnodecovered
== vp
)) {
1572 return (mount_t
)NULL
;
1576 /* returns vnode type of vnode_t */
1578 vnode_vtype(vnode_t vp
)
1583 /* returns FS specific node saved in vnode */
1585 vnode_fsnode(vnode_t vp
)
1591 vnode_clearfsnode(vnode_t vp
)
1597 vnode_specrdev(vnode_t vp
)
1603 /* Accessor functions */
1604 /* is vnode_t a root vnode */
1606 vnode_isvroot(vnode_t vp
)
1608 return (vp
->v_flag
& VROOT
)? 1 : 0;
1611 /* is vnode_t a system vnode */
1613 vnode_issystem(vnode_t vp
)
1615 return (vp
->v_flag
& VSYSTEM
)? 1 : 0;
1618 /* is vnode_t a swap file vnode */
1620 vnode_isswap(vnode_t vp
)
1622 return (vp
->v_flag
& VSWAP
)? 1 : 0;
1625 /* is vnode_t a tty */
1627 vnode_istty(vnode_t vp
)
1629 return (vp
->v_flag
& VISTTY
) ? 1 : 0;
1632 /* if vnode_t mount operation in progress */
1634 vnode_ismount(vnode_t vp
)
1636 return (vp
->v_flag
& VMOUNT
)? 1 : 0;
1639 /* is this vnode under recyle now */
1641 vnode_isrecycled(vnode_t vp
)
1645 vnode_lock_spin(vp
);
1646 ret
= (vp
->v_lflag
& (VL_TERMINATE
| VL_DEAD
))? 1 : 0;
1651 /* vnode was created by background task requesting rapid aging
1652 * and has not since been referenced by a normal task */
1654 vnode_israge(vnode_t vp
)
1656 return (vp
->v_flag
& VRAGE
)? 1 : 0;
1660 vnode_needssnapshots(vnode_t vp
)
1662 return (vp
->v_flag
& VNEEDSSNAPSHOT
)? 1 : 0;
1666 /* Check the process/thread to see if we should skip atime updates */
1668 vfs_ctx_skipatime(vfs_context_t ctx
)
1674 proc
= vfs_context_proc(ctx
);
1675 thr
= vfs_context_thread(ctx
);
1677 /* Validate pointers in case we were invoked via a kernel context */
1679 ut
= get_bsdthread_info(thr
);
1681 if (proc
->p_lflag
& P_LRAGE_VNODES
) {
1686 if (ut
->uu_flag
& (UT_RAGE_VNODES
| UT_ATIME_UPDATE
)) {
1691 if (proc
->p_vfs_iopolicy
& P_VFS_IOPOLICY_ATIME_UPDATES
) {
1698 /* is vnode_t marked to not keep data cached once it's been consumed */
1700 vnode_isnocache(vnode_t vp
)
1702 return (vp
->v_flag
& VNOCACHE_DATA
)? 1 : 0;
1706 * has sequential readahead been disabled on this vnode
1709 vnode_isnoreadahead(vnode_t vp
)
1711 return (vp
->v_flag
& VRAOFF
)? 1 : 0;
1715 vnode_is_openevt(vnode_t vp
)
1717 return (vp
->v_flag
& VOPENEVT
)? 1 : 0;
1720 /* is vnode_t a standard one? */
1722 vnode_isstandard(vnode_t vp
)
1724 return (vp
->v_flag
& VSTANDARD
)? 1 : 0;
1727 /* don't vflush() if SKIPSYSTEM */
1729 vnode_isnoflush(vnode_t vp
)
1731 return (vp
->v_flag
& VNOFLUSH
)? 1 : 0;
1734 /* is vnode_t a regular file */
1736 vnode_isreg(vnode_t vp
)
1738 return (vp
->v_type
== VREG
)? 1 : 0;
1741 /* is vnode_t a directory? */
1743 vnode_isdir(vnode_t vp
)
1745 return (vp
->v_type
== VDIR
)? 1 : 0;
1748 /* is vnode_t a symbolic link ? */
1750 vnode_islnk(vnode_t vp
)
1752 return (vp
->v_type
== VLNK
)? 1 : 0;
1756 vnode_lookup_continue_needed(vnode_t vp
, struct componentname
*cnp
)
1758 struct nameidata
*ndp
= cnp
->cn_ndp
;
1761 panic("vnode_lookup_continue_needed(): cnp->cn_ndp is NULL\n");
1764 if (vnode_isdir(vp
)) {
1765 if (vp
->v_mountedhere
!= NULL
) {
1770 if (vp
->v_resolve
) {
1773 #endif /* CONFIG_TRIGGERS */
1777 if (vnode_islnk(vp
)) {
1778 /* From lookup(): || *ndp->ni_next == '/') No need for this, we know we're NULL-terminated here */
1779 if (cnp
->cn_flags
& FOLLOW
) {
1782 if (ndp
->ni_flag
& NAMEI_TRAILINGSLASH
) {
1790 ndp
->ni_flag
|= NAMEI_CONTLOOKUP
;
1791 return EKEEPLOOKING
;
1794 /* is vnode_t a fifo ? */
1796 vnode_isfifo(vnode_t vp
)
1798 return (vp
->v_type
== VFIFO
)? 1 : 0;
1801 /* is vnode_t a block device? */
1803 vnode_isblk(vnode_t vp
)
1805 return (vp
->v_type
== VBLK
)? 1 : 0;
1809 vnode_isspec(vnode_t vp
)
1811 return ((vp
->v_type
== VCHR
) || (vp
->v_type
== VBLK
)) ? 1 : 0;
1814 /* is vnode_t a char device? */
1816 vnode_ischr(vnode_t vp
)
1818 return (vp
->v_type
== VCHR
)? 1 : 0;
1821 /* is vnode_t a socket? */
1823 vnode_issock(vnode_t vp
)
1825 return (vp
->v_type
== VSOCK
)? 1 : 0;
1828 /* is vnode_t a device with multiple active vnodes referring to it? */
1830 vnode_isaliased(vnode_t vp
)
1832 enum vtype vt
= vp
->v_type
;
1833 if (!((vt
== VCHR
) || (vt
== VBLK
))) {
1836 return vp
->v_specflags
& SI_ALIASED
;
1840 /* is vnode_t a named stream? */
1842 vnode_isnamedstream(
1851 return (vp
->v_flag
& VISNAMEDSTREAM
) ? 1 : 0;
1867 return (vp
->v_flag
& VISSHADOW
) ? 1 : 0;
1873 /* does vnode have associated named stream vnodes ? */
1875 vnode_hasnamedstreams(
1884 return (vp
->v_lflag
& VL_HASSTREAMS
) ? 1 : 0;
1889 /* TBD: set vnode_t to not cache data after it is consumed once; used for quota */
1891 vnode_setnocache(vnode_t vp
)
1893 vnode_lock_spin(vp
);
1894 vp
->v_flag
|= VNOCACHE_DATA
;
1899 vnode_clearnocache(vnode_t vp
)
1901 vnode_lock_spin(vp
);
1902 vp
->v_flag
&= ~VNOCACHE_DATA
;
1907 vnode_set_openevt(vnode_t vp
)
1909 vnode_lock_spin(vp
);
1910 vp
->v_flag
|= VOPENEVT
;
1915 vnode_clear_openevt(vnode_t vp
)
1917 vnode_lock_spin(vp
);
1918 vp
->v_flag
&= ~VOPENEVT
;
1924 vnode_setnoreadahead(vnode_t vp
)
1926 vnode_lock_spin(vp
);
1927 vp
->v_flag
|= VRAOFF
;
1932 vnode_clearnoreadahead(vnode_t vp
)
1934 vnode_lock_spin(vp
);
1935 vp
->v_flag
&= ~VRAOFF
;
1940 vnode_isfastdevicecandidate(vnode_t vp
)
1942 return (vp
->v_flag
& VFASTDEVCANDIDATE
)? 1 : 0;
1946 vnode_setfastdevicecandidate(vnode_t vp
)
1948 vnode_lock_spin(vp
);
1949 vp
->v_flag
|= VFASTDEVCANDIDATE
;
1954 vnode_clearfastdevicecandidate(vnode_t vp
)
1956 vnode_lock_spin(vp
);
1957 vp
->v_flag
&= ~VFASTDEVCANDIDATE
;
1962 vnode_isautocandidate(vnode_t vp
)
1964 return (vp
->v_flag
& VAUTOCANDIDATE
)? 1 : 0;
1968 vnode_setautocandidate(vnode_t vp
)
1970 vnode_lock_spin(vp
);
1971 vp
->v_flag
|= VAUTOCANDIDATE
;
1976 vnode_clearautocandidate(vnode_t vp
)
1978 vnode_lock_spin(vp
);
1979 vp
->v_flag
&= ~VAUTOCANDIDATE
;
1986 /* mark vnode_t to skip vflush() is SKIPSYSTEM */
1988 vnode_setnoflush(vnode_t vp
)
1990 vnode_lock_spin(vp
);
1991 vp
->v_flag
|= VNOFLUSH
;
1996 vnode_clearnoflush(vnode_t vp
)
1998 vnode_lock_spin(vp
);
1999 vp
->v_flag
&= ~VNOFLUSH
;
2004 /* is vnode_t a blkdevice and has a FS mounted on it */
2006 vnode_ismountedon(vnode_t vp
)
2008 return (vp
->v_specflags
& SI_MOUNTEDON
)? 1 : 0;
2012 vnode_setmountedon(vnode_t vp
)
2014 vnode_lock_spin(vp
);
2015 vp
->v_specflags
|= SI_MOUNTEDON
;
2020 vnode_clearmountedon(vnode_t vp
)
2022 vnode_lock_spin(vp
);
2023 vp
->v_specflags
&= ~SI_MOUNTEDON
;
2029 vnode_settag(vnode_t vp
, int tag
)
2035 vnode_tag(vnode_t vp
)
2041 vnode_parent(vnode_t vp
)
2043 return vp
->v_parent
;
2047 vnode_setparent(vnode_t vp
, vnode_t dvp
)
2053 vnode_setname(vnode_t vp
, char * name
)
2058 /* return the registered FS name when adding the FS to kernel */
2060 vnode_vfsname(vnode_t vp
, char * buf
)
2062 strlcpy(buf
, vp
->v_mount
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
2065 /* return the FS type number */
2067 vnode_vfstypenum(vnode_t vp
)
2069 return vp
->v_mount
->mnt_vtable
->vfc_typenum
;
2073 vnode_vfs64bitready(vnode_t vp
)
2076 * Checking for dead_mountp is a bit of a hack for SnowLeopard: <rdar://problem/6269051>
2078 if ((vp
->v_mount
!= dead_mountp
) && (vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
)) {
2087 /* return the visible flags on associated mount point of vnode_t */
2089 vnode_vfsvisflags(vnode_t vp
)
2091 return vp
->v_mount
->mnt_flag
& MNT_VISFLAGMASK
;
2094 /* return the command modifier flags on associated mount point of vnode_t */
2096 vnode_vfscmdflags(vnode_t vp
)
2098 return vp
->v_mount
->mnt_flag
& MNT_CMDFLAGS
;
2101 /* return the max symlink of short links of vnode_t */
2103 vnode_vfsmaxsymlen(vnode_t vp
)
2105 return vp
->v_mount
->mnt_maxsymlinklen
;
2108 /* return a pointer to the RO vfs_statfs associated with vnode_t's mount point */
2110 vnode_vfsstatfs(vnode_t vp
)
2112 return &vp
->v_mount
->mnt_vfsstat
;
2115 /* return a handle to the FSs specific private handle associated with vnode_t's mount point */
2117 vnode_vfsfsprivate(vnode_t vp
)
2119 return vp
->v_mount
->mnt_data
;
2122 /* is vnode_t in a rdonly mounted FS */
2124 vnode_vfsisrdonly(vnode_t vp
)
2126 return (vp
->v_mount
->mnt_flag
& MNT_RDONLY
)? 1 : 0;
2130 vnode_compound_rename_available(vnode_t vp
)
2132 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RENAME
);
2135 vnode_compound_rmdir_available(vnode_t vp
)
2137 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RMDIR
);
2140 vnode_compound_mkdir_available(vnode_t vp
)
2142 return vnode_compound_op_available(vp
, COMPOUND_VNOP_MKDIR
);
2145 vnode_compound_remove_available(vnode_t vp
)
2147 return vnode_compound_op_available(vp
, COMPOUND_VNOP_REMOVE
);
2150 vnode_compound_open_available(vnode_t vp
)
2152 return vnode_compound_op_available(vp
, COMPOUND_VNOP_OPEN
);
2156 vnode_compound_op_available(vnode_t vp
, compound_vnop_id_t opid
)
2158 return (vp
->v_mount
->mnt_compound_ops
& opid
) != 0;
2162 * Returns vnode ref to current working directory; if a per-thread current
2163 * working directory is in effect, return that instead of the per process one.
2165 * XXX Published, but not used.
2168 current_workingdir(void)
2170 return vfs_context_cwd(vfs_context_current());
2173 /* returns vnode ref to current root(chroot) directory */
2175 current_rootdir(void)
2177 proc_t proc
= current_proc();
2180 if ((vp
= proc
->p_fd
->fd_rdir
)) {
2181 if ((vnode_getwithref(vp
))) {
2189 * Get a filesec and optional acl contents from an extended attribute.
2190 * Function will attempt to retrive ACL, UUID, and GUID information using a
2191 * read of a named extended attribute (KAUTH_FILESEC_XATTR).
2193 * Parameters: vp The vnode on which to operate.
2194 * fsecp The filesec (and ACL, if any) being
2196 * ctx The vnode context in which the
2197 * operation is to be attempted.
2199 * Returns: 0 Success
2202 * Notes: The kauth_filesec_t in '*fsecp', if retrieved, will be in
2203 * host byte order, as will be the ACL contents, if any.
2204 * Internally, we will cannonize these values from network (PPC)
2205 * byte order after we retrieve them so that the on-disk contents
2206 * of the extended attribute are identical for both PPC and Intel
2207 * (if we were not being required to provide this service via
2208 * fallback, this would be the job of the filesystem
2209 * 'VNOP_GETATTR' call).
2211 * We use ntohl() because it has a transitive property on Intel
2212 * machines and no effect on PPC mancines. This guarantees us
2214 * XXX: Deleting rather than ignoreing a corrupt security structure is
2215 * probably the only way to reset it without assistance from an
2216 * file system integrity checking tool. Right now we ignore it.
2218 * XXX: We should enummerate the possible errno values here, and where
2219 * in the code they originated.
2222 vnode_get_filesec(vnode_t vp
, kauth_filesec_t
*fsecp
, vfs_context_t ctx
)
2224 kauth_filesec_t fsec
;
2227 size_t xsize
, rsize
;
2229 uint32_t host_fsec_magic
;
2230 uint32_t host_acl_entrycount
;
2235 /* find out how big the EA is */
2236 error
= vn_getxattr(vp
, KAUTH_FILESEC_XATTR
, NULL
, &xsize
, XATTR_NOSECURITY
, ctx
);
2238 /* no EA, no filesec */
2239 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
)) {
2242 /* either way, we are done */
2247 * To be valid, a kauth_filesec_t must be large enough to hold a zero
2248 * ACE entrly ACL, and if it's larger than that, it must have the right
2249 * number of bytes such that it contains an atomic number of ACEs,
2250 * rather than partial entries. Otherwise, we ignore it.
2252 if (!KAUTH_FILESEC_VALID(xsize
)) {
2253 KAUTH_DEBUG(" ERROR - Bogus kauth_fiilesec_t: %ld bytes", xsize
);
2258 /* how many entries would fit? */
2259 fsec_size
= KAUTH_FILESEC_COUNT(xsize
);
2260 if (fsec_size
> KAUTH_ACL_MAX_ENTRIES
) {
2261 KAUTH_DEBUG(" ERROR - Bogus (too large) kauth_fiilesec_t: %ld bytes", xsize
);
2266 /* get buffer and uio */
2267 if (((fsec
= kauth_filesec_alloc(fsec_size
)) == NULL
) ||
2268 ((fsec_uio
= uio_create(1, 0, UIO_SYSSPACE
, UIO_READ
)) == NULL
) ||
2269 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), xsize
)) {
2270 KAUTH_DEBUG(" ERROR - could not allocate iov to read ACL");
2275 /* read security attribute */
2277 if ((error
= vn_getxattr(vp
,
2278 KAUTH_FILESEC_XATTR
,
2283 /* no attribute - no security data */
2284 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
)) {
2287 /* either way, we are done */
2292 * Validate security structure; the validation must take place in host
2293 * byte order. If it's corrupt, we will just ignore it.
2296 /* Validate the size before trying to convert it */
2297 if (rsize
< KAUTH_FILESEC_SIZE(0)) {
2298 KAUTH_DEBUG("ACL - DATA TOO SMALL (%d)", rsize
);
2302 /* Validate the magic number before trying to convert it */
2303 host_fsec_magic
= ntohl(KAUTH_FILESEC_MAGIC
);
2304 if (fsec
->fsec_magic
!= host_fsec_magic
) {
2305 KAUTH_DEBUG("ACL - BAD MAGIC %x", host_fsec_magic
);
2309 /* Validate the entry count before trying to convert it. */
2310 host_acl_entrycount
= ntohl(fsec
->fsec_acl
.acl_entrycount
);
2311 if (host_acl_entrycount
!= KAUTH_FILESEC_NOACL
) {
2312 if (host_acl_entrycount
> KAUTH_ACL_MAX_ENTRIES
) {
2313 KAUTH_DEBUG("ACL - BAD ENTRYCOUNT %x", host_acl_entrycount
);
2316 if (KAUTH_FILESEC_SIZE(host_acl_entrycount
) > rsize
) {
2317 KAUTH_DEBUG("ACL - BUFFER OVERFLOW (%d entries too big for %d)", host_acl_entrycount
, rsize
);
2322 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, NULL
);
2329 kauth_filesec_free(fsec
);
2331 if (fsec_uio
!= NULL
) {
2341 * Set a filesec and optional acl contents into an extended attribute.
2342 * function will attempt to store ACL, UUID, and GUID information using a
2343 * write to a named extended attribute (KAUTH_FILESEC_XATTR). The 'acl'
2344 * may or may not point to the `fsec->fsec_acl`, depending on whether the
2345 * original caller supplied an acl.
2347 * Parameters: vp The vnode on which to operate.
2348 * fsec The filesec being set.
2349 * acl The acl to be associated with 'fsec'.
2350 * ctx The vnode context in which the
2351 * operation is to be attempted.
2353 * Returns: 0 Success
2356 * Notes: Both the fsec and the acl are always valid.
2358 * The kauth_filesec_t in 'fsec', if any, is in host byte order,
2359 * as are the acl contents, if they are used. Internally, we will
2360 * cannonize these values into network (PPC) byte order before we
2361 * attempt to write them so that the on-disk contents of the
2362 * extended attribute are identical for both PPC and Intel (if we
2363 * were not being required to provide this service via fallback,
2364 * this would be the job of the filesystem 'VNOP_SETATTR' call).
2365 * We reverse this process on the way out, so we leave with the
2366 * same byte order we started with.
2368 * XXX: We should enummerate the possible errno values here, and where
2369 * in the code they originated.
2372 vnode_set_filesec(vnode_t vp
, kauth_filesec_t fsec
, kauth_acl_t acl
, vfs_context_t ctx
)
2376 uint32_t saved_acl_copysize
;
2380 if ((fsec_uio
= uio_create(2, 0, UIO_SYSSPACE
, UIO_WRITE
)) == NULL
) {
2381 KAUTH_DEBUG(" ERROR - could not allocate iov to write ACL");
2386 * Save the pre-converted ACL copysize, because it gets swapped too
2387 * if we are running with the wrong endianness.
2389 saved_acl_copysize
= KAUTH_ACL_COPYSIZE(acl
);
2391 kauth_filesec_acl_setendian(KAUTH_ENDIAN_DISK
, fsec
, acl
);
2393 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), KAUTH_FILESEC_SIZE(0) - KAUTH_ACL_SIZE(KAUTH_FILESEC_NOACL
));
2394 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(acl
), saved_acl_copysize
);
2395 error
= vn_setxattr(vp
,
2396 KAUTH_FILESEC_XATTR
,
2398 XATTR_NOSECURITY
, /* we have auth'ed already */
2400 VFS_DEBUG(ctx
, vp
, "SETATTR - set ACL returning %d", error
);
2402 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, acl
);
2405 if (fsec_uio
!= NULL
) {
2413 * Returns: 0 Success
2414 * ENOMEM Not enough space [only if has filesec]
2415 * EINVAL Requested unknown attributes
2417 * vnode_get_filesec: ???
2418 * kauth_cred_guid2uid: ???
2419 * kauth_cred_guid2gid: ???
2420 * vfs_update_vfsstat: ???
2423 vnode_getattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2425 kauth_filesec_t fsec
;
2432 * Reject attempts to fetch unknown attributes.
2434 if (vap
->va_active
& ~VNODE_ATTR_ALL
) {
2438 /* don't ask for extended security data if the filesystem doesn't support it */
2439 if (!vfs_extendedsecurity(vnode_mount(vp
))) {
2440 VATTR_CLEAR_ACTIVE(vap
, va_acl
);
2441 VATTR_CLEAR_ACTIVE(vap
, va_uuuid
);
2442 VATTR_CLEAR_ACTIVE(vap
, va_guuid
);
2446 * If the caller wants size values we might have to synthesise, give the
2447 * filesystem the opportunity to supply better intermediate results.
2449 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2450 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2451 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2452 VATTR_SET_ACTIVE(vap
, va_data_size
);
2453 VATTR_SET_ACTIVE(vap
, va_data_alloc
);
2454 VATTR_SET_ACTIVE(vap
, va_total_size
);
2455 VATTR_SET_ACTIVE(vap
, va_total_alloc
);
2458 vap
->va_vaflags
&= ~VA_USEFSID
;
2460 error
= VNOP_GETATTR(vp
, vap
, ctx
);
2462 KAUTH_DEBUG("ERROR - returning %d", error
);
2467 * If extended security data was requested but not returned, try the fallback
2470 if (VATTR_NOT_RETURNED(vap
, va_acl
) || VATTR_NOT_RETURNED(vap
, va_uuuid
) || VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2473 if (XATTR_VNODE_SUPPORTED(vp
)) {
2474 /* try to get the filesec */
2475 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0) {
2479 /* if no filesec, no attributes */
2481 VATTR_RETURN(vap
, va_acl
, NULL
);
2482 VATTR_RETURN(vap
, va_uuuid
, kauth_null_guid
);
2483 VATTR_RETURN(vap
, va_guuid
, kauth_null_guid
);
2485 /* looks good, try to return what we were asked for */
2486 VATTR_RETURN(vap
, va_uuuid
, fsec
->fsec_owner
);
2487 VATTR_RETURN(vap
, va_guuid
, fsec
->fsec_group
);
2489 /* only return the ACL if we were actually asked for it */
2490 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2491 if (fsec
->fsec_acl
.acl_entrycount
== KAUTH_FILESEC_NOACL
) {
2492 VATTR_RETURN(vap
, va_acl
, NULL
);
2494 facl
= kauth_acl_alloc(fsec
->fsec_acl
.acl_entrycount
);
2496 kauth_filesec_free(fsec
);
2500 __nochk_bcopy(&fsec
->fsec_acl
, facl
, KAUTH_ACL_COPYSIZE(&fsec
->fsec_acl
));
2501 VATTR_RETURN(vap
, va_acl
, facl
);
2504 kauth_filesec_free(fsec
);
2508 * If someone gave us an unsolicited filesec, toss it. We promise that
2509 * we're OK with a filesystem giving us anything back, but our callers
2510 * only expect what they asked for.
2512 if (VATTR_IS_SUPPORTED(vap
, va_acl
) && !VATTR_IS_ACTIVE(vap
, va_acl
)) {
2513 if (vap
->va_acl
!= NULL
) {
2514 kauth_acl_free(vap
->va_acl
);
2516 VATTR_CLEAR_SUPPORTED(vap
, va_acl
);
2519 #if 0 /* enable when we have a filesystem only supporting UUIDs */
2521 * Handle the case where we need a UID/GID, but only have extended
2522 * security information.
2524 if (VATTR_NOT_RETURNED(vap
, va_uid
) &&
2525 VATTR_IS_SUPPORTED(vap
, va_uuuid
) &&
2526 !kauth_guid_equal(&vap
->va_uuuid
, &kauth_null_guid
)) {
2527 if ((error
= kauth_cred_guid2uid(&vap
->va_uuuid
, &nuid
)) == 0) {
2528 VATTR_RETURN(vap
, va_uid
, nuid
);
2531 if (VATTR_NOT_RETURNED(vap
, va_gid
) &&
2532 VATTR_IS_SUPPORTED(vap
, va_guuid
) &&
2533 !kauth_guid_equal(&vap
->va_guuid
, &kauth_null_guid
)) {
2534 if ((error
= kauth_cred_guid2gid(&vap
->va_guuid
, &ngid
)) == 0) {
2535 VATTR_RETURN(vap
, va_gid
, ngid
);
2541 * Handle uid/gid == 99 and MNT_IGNORE_OWNERSHIP here.
2543 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
2544 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2546 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2547 nuid
= vp
->v_mount
->mnt_fsowner
;
2548 if (nuid
== KAUTH_UID_NONE
) {
2551 } else if (VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2554 /* this will always be something sensible */
2555 nuid
= vp
->v_mount
->mnt_fsowner
;
2557 if ((nuid
== 99) && !vfs_context_issuser(ctx
)) {
2558 nuid
= kauth_cred_getuid(vfs_context_ucred(ctx
));
2560 VATTR_RETURN(vap
, va_uid
, nuid
);
2562 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
2563 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2565 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2566 ngid
= vp
->v_mount
->mnt_fsgroup
;
2567 if (ngid
== KAUTH_GID_NONE
) {
2570 } else if (VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2573 /* this will always be something sensible */
2574 ngid
= vp
->v_mount
->mnt_fsgroup
;
2576 if ((ngid
== 99) && !vfs_context_issuser(ctx
)) {
2577 ngid
= kauth_cred_getgid(vfs_context_ucred(ctx
));
2579 VATTR_RETURN(vap
, va_gid
, ngid
);
2583 * Synthesise some values that can be reasonably guessed.
2585 if (!VATTR_IS_SUPPORTED(vap
, va_iosize
)) {
2586 VATTR_RETURN(vap
, va_iosize
, vp
->v_mount
->mnt_vfsstat
.f_iosize
);
2589 if (!VATTR_IS_SUPPORTED(vap
, va_flags
)) {
2590 VATTR_RETURN(vap
, va_flags
, 0);
2593 if (!VATTR_IS_SUPPORTED(vap
, va_filerev
)) {
2594 VATTR_RETURN(vap
, va_filerev
, 0);
2597 if (!VATTR_IS_SUPPORTED(vap
, va_gen
)) {
2598 VATTR_RETURN(vap
, va_gen
, 0);
2602 * Default sizes. Ordering here is important, as later defaults build on earlier ones.
2604 if (!VATTR_IS_SUPPORTED(vap
, va_data_size
)) {
2605 VATTR_RETURN(vap
, va_data_size
, 0);
2608 /* do we want any of the possibly-computed values? */
2609 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2610 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2611 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2612 /* make sure f_bsize is valid */
2613 if (vp
->v_mount
->mnt_vfsstat
.f_bsize
== 0) {
2614 if ((error
= vfs_update_vfsstat(vp
->v_mount
, ctx
, VFS_KERNEL_EVENT
)) != 0) {
2619 /* default va_data_alloc from va_data_size */
2620 if (!VATTR_IS_SUPPORTED(vap
, va_data_alloc
)) {
2621 VATTR_RETURN(vap
, va_data_alloc
, roundup(vap
->va_data_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2624 /* default va_total_size from va_data_size */
2625 if (!VATTR_IS_SUPPORTED(vap
, va_total_size
)) {
2626 VATTR_RETURN(vap
, va_total_size
, vap
->va_data_size
);
2629 /* default va_total_alloc from va_total_size which is guaranteed at this point */
2630 if (!VATTR_IS_SUPPORTED(vap
, va_total_alloc
)) {
2631 VATTR_RETURN(vap
, va_total_alloc
, roundup(vap
->va_total_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2636 * If we don't have a change time, pull it from the modtime.
2638 if (!VATTR_IS_SUPPORTED(vap
, va_change_time
) && VATTR_IS_SUPPORTED(vap
, va_modify_time
)) {
2639 VATTR_RETURN(vap
, va_change_time
, vap
->va_modify_time
);
2643 * This is really only supported for the creation VNOPs, but since the field is there
2644 * we should populate it correctly.
2646 VATTR_RETURN(vap
, va_type
, vp
->v_type
);
2649 * The fsid can be obtained from the mountpoint directly.
2651 if (VATTR_IS_ACTIVE(vap
, va_fsid
) &&
2652 (!VATTR_IS_SUPPORTED(vap
, va_fsid
) ||
2653 vap
->va_vaflags
& VA_REALFSID
|| !(vap
->va_vaflags
& VA_USEFSID
))) {
2654 VATTR_RETURN(vap
, va_fsid
, vp
->v_mount
->mnt_vfsstat
.f_fsid
.val
[0]);
2658 vap
->va_vaflags
&= ~VA_USEFSID
;
2664 * Choose 32 bit or 64 bit fsid
2667 vnode_get_va_fsid(struct vnode_attr
*vap
)
2669 if (VATTR_IS_SUPPORTED(vap
, va_fsid64
)) {
2670 return (uint64_t)vap
->va_fsid64
.val
[0] + ((uint64_t)vap
->va_fsid64
.val
[1] << 32);
2672 return vap
->va_fsid
;
2676 * Set the attributes on a vnode in a vnode context.
2678 * Parameters: vp The vnode whose attributes to set.
2679 * vap A pointer to the attributes to set.
2680 * ctx The vnode context in which the
2681 * operation is to be attempted.
2683 * Returns: 0 Success
2686 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order.
2688 * The contents of the data area pointed to by 'vap' may be
2689 * modified if the vnode is on a filesystem which has been
2690 * mounted with ingore ownership flags, or by the underlyng
2691 * VFS itself, or by the fallback code, if the underlying VFS
2692 * does not support ACL, UUID, or GUUID attributes directly.
2694 * XXX: We should enummerate the possible errno values here, and where
2695 * in the code they originated.
2698 vnode_setattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2703 int is_perm_change
= 0;
2704 int is_stat_change
= 0;
2708 * Reject attempts to set unknown attributes.
2710 if (vap
->va_active
& ~VNODE_ATTR_ALL
) {
2715 * Make sure the filesystem is mounted R/W.
2716 * If not, return an error.
2718 if (vfs_isrdonly(vp
->v_mount
)) {
2723 #if DEVELOPMENT || DEBUG
2725 * XXX VSWAP: Check for entitlements or special flag here
2726 * so we can restrict access appropriately.
2728 #else /* DEVELOPMENT || DEBUG */
2730 if (vnode_isswap(vp
) && (ctx
!= vfs_context_kernel())) {
2734 #endif /* DEVELOPMENT || DEBUG */
2737 /* For streams, va_data_size is the only setable attribute. */
2738 if ((vp
->v_flag
& VISNAMEDSTREAM
) && (vap
->va_active
!= VNODE_ATTR_va_data_size
)) {
2743 /* Check for truncation */
2744 if (VATTR_IS_ACTIVE(vap
, va_data_size
)) {
2745 switch (vp
->v_type
) {
2747 /* For regular files it's ok */
2750 /* Not allowed to truncate directories */
2754 /* For everything else we will clear the bit and let underlying FS decide on the rest */
2755 VATTR_CLEAR_ACTIVE(vap
, va_data_size
);
2756 if (vap
->va_active
) {
2759 /* If it was the only bit set, return success, to handle cases like redirect to /dev/null */
2765 * If ownership is being ignored on this volume, we silently discard
2766 * ownership changes.
2768 if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2769 VATTR_CLEAR_ACTIVE(vap
, va_uid
);
2770 VATTR_CLEAR_ACTIVE(vap
, va_gid
);
2774 * Make sure that extended security is enabled if we're going to try
2777 if (!vfs_extendedsecurity(vnode_mount(vp
)) &&
2778 (VATTR_IS_ACTIVE(vap
, va_acl
) || VATTR_IS_ACTIVE(vap
, va_uuuid
) || VATTR_IS_ACTIVE(vap
, va_guuid
))) {
2779 KAUTH_DEBUG("SETATTR - returning ENOTSUP to request to set extended security");
2784 /* Never allow the setting of any unsupported superuser flags. */
2785 if (VATTR_IS_ACTIVE(vap
, va_flags
)) {
2786 vap
->va_flags
&= (SF_SUPPORTED
| UF_SETTABLE
);
2791 * Remember all of the active attributes that we're
2792 * attempting to modify.
2794 active
= vap
->va_active
& ~VNODE_ATTR_RDONLY
;
2797 error
= VNOP_SETATTR(vp
, vap
, ctx
);
2799 if ((error
== 0) && !VATTR_ALL_SUPPORTED(vap
)) {
2800 error
= vnode_setattr_fallback(vp
, vap
, ctx
);
2804 #define PERMISSION_BITS (VNODE_ATTR_BIT(va_uid) | VNODE_ATTR_BIT(va_uuuid) | \
2805 VNODE_ATTR_BIT(va_gid) | VNODE_ATTR_BIT(va_guuid) | \
2806 VNODE_ATTR_BIT(va_mode) | VNODE_ATTR_BIT(va_acl))
2809 * Now that we've changed them, decide whether to send an
2812 if ((active
& PERMISSION_BITS
) & vap
->va_supported
) {
2816 * We've already checked the permission bits, and we
2817 * also want to filter out access time / backup time
2820 active
&= ~(PERMISSION_BITS
|
2821 VNODE_ATTR_BIT(va_access_time
) |
2822 VNODE_ATTR_BIT(va_backup_time
));
2824 /* Anything left to notify about? */
2825 if (active
& vap
->va_supported
) {
2831 if (is_perm_change
) {
2832 if (need_fsevent(FSE_CHOWN
, vp
)) {
2833 add_fsevent(FSE_CHOWN
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2835 } else if (is_stat_change
&& need_fsevent(FSE_STAT_CHANGED
, vp
)) {
2836 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2839 #undef PERMISSION_BITS
2847 * Fallback for setting the attributes on a vnode in a vnode context. This
2848 * Function will attempt to store ACL, UUID, and GUID information utilizing
2849 * a read/modify/write operation against an EA used as a backing store for
2852 * Parameters: vp The vnode whose attributes to set.
2853 * vap A pointer to the attributes to set.
2854 * ctx The vnode context in which the
2855 * operation is to be attempted.
2857 * Returns: 0 Success
2860 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order,
2861 * as are the fsec and lfsec, if they are used.
2863 * The contents of the data area pointed to by 'vap' may be
2864 * modified to indicate that the attribute is supported for
2865 * any given requested attribute.
2867 * XXX: We should enummerate the possible errno values here, and where
2868 * in the code they originated.
2871 vnode_setattr_fallback(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2873 kauth_filesec_t fsec
;
2875 struct kauth_filesec lfsec
;
2881 * Extended security fallback via extended attributes.
2883 * Note that we do not free the filesec; the caller is expected to
2886 if (VATTR_NOT_RETURNED(vap
, va_acl
) ||
2887 VATTR_NOT_RETURNED(vap
, va_uuuid
) ||
2888 VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2889 VFS_DEBUG(ctx
, vp
, "SETATTR - doing filesec fallback");
2892 * Fail for file types that we don't permit extended security
2895 if (!XATTR_VNODE_SUPPORTED(vp
)) {
2896 VFS_DEBUG(ctx
, vp
, "SETATTR - Can't write ACL to file type %d", vnode_vtype(vp
));
2902 * If we don't have all the extended security items, we need
2903 * to fetch the existing data to perform a read-modify-write
2907 if (!VATTR_IS_ACTIVE(vap
, va_acl
) ||
2908 !VATTR_IS_ACTIVE(vap
, va_uuuid
) ||
2909 !VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2910 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0) {
2911 KAUTH_DEBUG("SETATTR - ERROR %d fetching filesec for update", error
);
2915 /* if we didn't get a filesec, use our local one */
2917 KAUTH_DEBUG("SETATTR - using local filesec for new/full update");
2920 KAUTH_DEBUG("SETATTR - updating existing filesec");
2923 facl
= &fsec
->fsec_acl
;
2925 /* if we're using the local filesec, we need to initialise it */
2926 if (fsec
== &lfsec
) {
2927 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
2928 fsec
->fsec_owner
= kauth_null_guid
;
2929 fsec
->fsec_group
= kauth_null_guid
;
2930 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2931 facl
->acl_flags
= 0;
2935 * Update with the supplied attributes.
2937 if (VATTR_IS_ACTIVE(vap
, va_uuuid
)) {
2938 KAUTH_DEBUG("SETATTR - updating owner UUID");
2939 fsec
->fsec_owner
= vap
->va_uuuid
;
2940 VATTR_SET_SUPPORTED(vap
, va_uuuid
);
2942 if (VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2943 KAUTH_DEBUG("SETATTR - updating group UUID");
2944 fsec
->fsec_group
= vap
->va_guuid
;
2945 VATTR_SET_SUPPORTED(vap
, va_guuid
);
2947 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2948 if (vap
->va_acl
== NULL
) {
2949 KAUTH_DEBUG("SETATTR - removing ACL");
2950 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2952 KAUTH_DEBUG("SETATTR - setting ACL with %d entries", vap
->va_acl
->acl_entrycount
);
2955 VATTR_SET_SUPPORTED(vap
, va_acl
);
2959 * If the filesec data is all invalid, we can just remove
2960 * the EA completely.
2962 if ((facl
->acl_entrycount
== KAUTH_FILESEC_NOACL
) &&
2963 kauth_guid_equal(&fsec
->fsec_owner
, &kauth_null_guid
) &&
2964 kauth_guid_equal(&fsec
->fsec_group
, &kauth_null_guid
)) {
2965 error
= vn_removexattr(vp
, KAUTH_FILESEC_XATTR
, XATTR_NOSECURITY
, ctx
);
2966 /* no attribute is ok, nothing to delete */
2967 if (error
== ENOATTR
) {
2970 VFS_DEBUG(ctx
, vp
, "SETATTR - remove filesec returning %d", error
);
2973 error
= vnode_set_filesec(vp
, fsec
, facl
, ctx
);
2974 VFS_DEBUG(ctx
, vp
, "SETATTR - update filesec returning %d", error
);
2977 /* if we fetched a filesec, dispose of the buffer */
2978 if (fsec
!= &lfsec
) {
2979 kauth_filesec_free(fsec
);
2988 * Upcall for a filesystem to tell VFS about an EVFILT_VNODE-type
2992 vnode_notify(vnode_t vp
, uint32_t events
, struct vnode_attr
*vap
)
2994 /* These are the same as the corresponding knotes, at least for now. Cheating a little. */
2995 uint32_t knote_mask
= (VNODE_EVENT_WRITE
| VNODE_EVENT_DELETE
| VNODE_EVENT_RENAME
2996 | VNODE_EVENT_LINK
| VNODE_EVENT_EXTEND
| VNODE_EVENT_ATTRIB
);
2997 uint32_t dir_contents_mask
= (VNODE_EVENT_DIR_CREATED
| VNODE_EVENT_FILE_CREATED
2998 | VNODE_EVENT_DIR_REMOVED
| VNODE_EVENT_FILE_REMOVED
);
2999 uint32_t knote_events
= (events
& knote_mask
);
3001 /* Permissions are not explicitly part of the kqueue model */
3002 if (events
& VNODE_EVENT_PERMS
) {
3003 knote_events
|= NOTE_ATTRIB
;
3006 /* Directory contents information just becomes NOTE_WRITE */
3007 if ((vnode_isdir(vp
)) && (events
& dir_contents_mask
)) {
3008 knote_events
|= NOTE_WRITE
;
3012 lock_vnode_and_post(vp
, knote_events
);
3015 create_fsevent_from_kevent(vp
, events
, vap
);
3028 vnode_isdyldsharedcache(vnode_t vp
)
3030 return (vp
->v_flag
& VSHARED_DYLD
) ? 1 : 0;
3035 * For a filesystem that isn't tracking its own vnode watchers:
3036 * check whether a vnode is being monitored.
3039 vnode_ismonitored(vnode_t vp
)
3041 return vp
->v_knotes
.slh_first
!= NULL
;
3045 vnode_getbackingvnode(vnode_t in_vp
, vnode_t
* out_vpp
)
3051 return nullfs_getbackingvnode(in_vp
, out_vpp
);
3053 #pragma unused(in_vp)
3059 * Initialize a struct vnode_attr and activate the attributes required
3060 * by the vnode_notify() call.
3063 vfs_get_notify_attributes(struct vnode_attr
*vap
)
3066 vap
->va_active
= VNODE_NOTIFY_ATTRS
;
3072 vfs_settriggercallback(fsid_t
*fsid
, vfs_trigger_callback_t vtc
, void *data
, uint32_t flags __unused
, vfs_context_t ctx
)
3077 mp
= mount_list_lookupby_fsid(fsid
, 0 /* locked */, 1 /* withref */);
3082 error
= vfs_busy(mp
, LK_NOWAIT
);
3090 if (mp
->mnt_triggercallback
!= NULL
) {
3096 mp
->mnt_triggercallback
= vtc
;
3097 mp
->mnt_triggerdata
= data
;
3100 mp
->mnt_triggercallback(mp
, VTC_REPLACE
, data
, ctx
);
3106 #endif /* CONFIG_TRIGGERS */
3109 * Definition of vnode operations.
3115 *#% lookup dvp L ? ?
3116 *#% lookup vpp - L -
3118 struct vnop_lookup_args
{
3119 struct vnodeop_desc
*a_desc
;
3122 struct componentname
*a_cnp
;
3123 vfs_context_t a_context
;
3128 * Returns: 0 Success
3129 * lock_fsnode:ENOENT No such file or directory [only for VFS
3130 * that is not thread safe & vnode is
3131 * currently being/has been terminated]
3132 * <vfs_lookup>:ENAMETOOLONG
3133 * <vfs_lookup>:ENOENT
3134 * <vfs_lookup>:EJUSTRETURN
3135 * <vfs_lookup>:EPERM
3136 * <vfs_lookup>:EISDIR
3137 * <vfs_lookup>:ENOTDIR
3140 * Note: The return codes from the underlying VFS's lookup routine can't
3141 * be fully enumerated here, since third party VFS authors may not
3142 * limit their error returns to the ones documented here, even
3143 * though this may result in some programs functioning incorrectly.
3145 * The return codes documented above are those which may currently
3146 * be returned by HFS from hfs_lookup, not including additional
3147 * error code which may be propagated from underlying routines.
3150 VNOP_LOOKUP(vnode_t dvp
, vnode_t
*vpp
, struct componentname
*cnp
, vfs_context_t ctx
)
3153 struct vnop_lookup_args a
;
3155 a
.a_desc
= &vnop_lookup_desc
;
3161 _err
= (*dvp
->v_op
[vnop_lookup_desc
.vdesc_offset
])(&a
);
3162 if (_err
== 0 && *vpp
) {
3163 DTRACE_FSINFO(lookup
, vnode_t
, *vpp
);
3170 struct vnop_compound_open_args
{
3171 struct vnodeop_desc
*a_desc
;
3174 struct componentname
*a_cnp
;
3177 struct vnode_attr
*a_vap
;
3178 vfs_context_t a_context
;
3184 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
)
3187 struct vnop_compound_open_args a
;
3190 uint32_t tmp_status
= 0;
3191 struct componentname
*cnp
= &ndp
->ni_cnd
;
3193 want_create
= (flags
& O_CREAT
);
3195 a
.a_desc
= &vnop_compound_open_desc
;
3197 a
.a_vpp
= vpp
; /* Could be NULL */
3201 a
.a_status
= (statusp
!= NULL
) ? statusp
: &tmp_status
;
3204 a
.a_open_create_authorizer
= vn_authorize_create
;
3205 a
.a_open_existing_authorizer
= vn_authorize_open_existing
;
3206 a
.a_reserved
= NULL
;
3208 if (dvp
== NULLVP
) {
3211 if (want_create
&& !vap
) {
3212 panic("Want create, but no vap?");
3214 if (!want_create
&& vap
) {
3215 panic("Don't want create, but have a vap?");
3218 _err
= (*dvp
->v_op
[vnop_compound_open_desc
.vdesc_offset
])(&a
);
3220 if (_err
== 0 && *vpp
) {
3221 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
3223 DTRACE_FSINFO(compound_open
, vnode_t
, dvp
);
3226 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
3229 did_create
= (*a
.a_status
& COMPOUND_OPEN_STATUS_DID_CREATE
);
3231 if (did_create
&& !want_create
) {
3232 panic("Filesystem did a create, even though none was requested?");
3236 #if CONFIG_APPLEDOUBLE
3237 if (!NATIVE_XATTR(dvp
)) {
3239 * Remove stale Apple Double file (if any).
3241 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
3243 #endif /* CONFIG_APPLEDOUBLE */
3244 /* On create, provide kqueue notification */
3245 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3248 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, did_create
);
3249 #if 0 /* FSEvents... */
3250 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
3260 struct vnop_create_args
{
3261 struct vnodeop_desc
*a_desc
;
3264 struct componentname
*a_cnp
;
3265 struct vnode_attr
*a_vap
;
3266 vfs_context_t a_context
;
3270 VNOP_CREATE(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3273 struct vnop_create_args a
;
3275 a
.a_desc
= &vnop_create_desc
;
3282 _err
= (*dvp
->v_op
[vnop_create_desc
.vdesc_offset
])(&a
);
3283 if (_err
== 0 && *vpp
) {
3284 DTRACE_FSINFO(create
, vnode_t
, *vpp
);
3287 #if CONFIG_APPLEDOUBLE
3288 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
3290 * Remove stale Apple Double file (if any).
3292 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
3294 #endif /* CONFIG_APPLEDOUBLE */
3296 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3304 *#% whiteout dvp L L L
3305 *#% whiteout cnp - - -
3306 *#% whiteout flag - - -
3309 struct vnop_whiteout_args
{
3310 struct vnodeop_desc
*a_desc
;
3312 struct componentname
*a_cnp
;
3314 vfs_context_t a_context
;
3318 VNOP_WHITEOUT(__unused vnode_t dvp
, __unused
struct componentname
*cnp
,
3319 __unused
int flags
, __unused vfs_context_t ctx
)
3321 return ENOTSUP
; // XXX OBSOLETE
3331 struct vnop_mknod_args
{
3332 struct vnodeop_desc
*a_desc
;
3335 struct componentname
*a_cnp
;
3336 struct vnode_attr
*a_vap
;
3337 vfs_context_t a_context
;
3341 VNOP_MKNOD(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3344 struct vnop_mknod_args a
;
3346 a
.a_desc
= &vnop_mknod_desc
;
3353 _err
= (*dvp
->v_op
[vnop_mknod_desc
.vdesc_offset
])(&a
);
3354 if (_err
== 0 && *vpp
) {
3355 DTRACE_FSINFO(mknod
, vnode_t
, *vpp
);
3358 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3369 struct vnop_open_args
{
3370 struct vnodeop_desc
*a_desc
;
3373 vfs_context_t a_context
;
3377 VNOP_OPEN(vnode_t vp
, int mode
, vfs_context_t ctx
)
3380 struct vnop_open_args a
;
3383 ctx
= vfs_context_current();
3385 a
.a_desc
= &vnop_open_desc
;
3390 _err
= (*vp
->v_op
[vnop_open_desc
.vdesc_offset
])(&a
);
3391 DTRACE_FSINFO(open
, vnode_t
, vp
);
3402 struct vnop_close_args
{
3403 struct vnodeop_desc
*a_desc
;
3406 vfs_context_t a_context
;
3410 VNOP_CLOSE(vnode_t vp
, int fflag
, vfs_context_t ctx
)
3413 struct vnop_close_args a
;
3416 ctx
= vfs_context_current();
3418 a
.a_desc
= &vnop_close_desc
;
3423 _err
= (*vp
->v_op
[vnop_close_desc
.vdesc_offset
])(&a
);
3424 DTRACE_FSINFO(close
, vnode_t
, vp
);
3435 struct vnop_access_args
{
3436 struct vnodeop_desc
*a_desc
;
3439 vfs_context_t a_context
;
3443 VNOP_ACCESS(vnode_t vp
, int action
, vfs_context_t ctx
)
3446 struct vnop_access_args a
;
3449 ctx
= vfs_context_current();
3451 a
.a_desc
= &vnop_access_desc
;
3453 a
.a_action
= action
;
3456 _err
= (*vp
->v_op
[vnop_access_desc
.vdesc_offset
])(&a
);
3457 DTRACE_FSINFO(access
, vnode_t
, vp
);
3465 *#% getattr vp = = =
3468 struct vnop_getattr_args
{
3469 struct vnodeop_desc
*a_desc
;
3471 struct vnode_attr
*a_vap
;
3472 vfs_context_t a_context
;
3476 VNOP_GETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3479 struct vnop_getattr_args a
;
3481 a
.a_desc
= &vnop_getattr_desc
;
3486 _err
= (*vp
->v_op
[vnop_getattr_desc
.vdesc_offset
])(&a
);
3487 DTRACE_FSINFO(getattr
, vnode_t
, vp
);
3495 *#% setattr vp L L L
3498 struct vnop_setattr_args
{
3499 struct vnodeop_desc
*a_desc
;
3501 struct vnode_attr
*a_vap
;
3502 vfs_context_t a_context
;
3506 VNOP_SETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3509 struct vnop_setattr_args a
;
3511 a
.a_desc
= &vnop_setattr_desc
;
3516 _err
= (*vp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
3517 DTRACE_FSINFO(setattr
, vnode_t
, vp
);
3519 #if CONFIG_APPLEDOUBLE
3521 * Shadow uid/gid/mod change to extended attribute file.
3523 if (_err
== 0 && !NATIVE_XATTR(vp
)) {
3524 struct vnode_attr va
;
3528 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
3529 VATTR_SET(&va
, va_uid
, vap
->va_uid
);
3532 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
3533 VATTR_SET(&va
, va_gid
, vap
->va_gid
);
3536 if (VATTR_IS_ACTIVE(vap
, va_mode
)) {
3537 VATTR_SET(&va
, va_mode
, vap
->va_mode
);
3544 dvp
= vnode_getparent(vp
);
3545 vname
= vnode_getname(vp
);
3547 xattrfile_setattr(dvp
, vname
, &va
, ctx
);
3548 if (dvp
!= NULLVP
) {
3551 if (vname
!= NULL
) {
3552 vnode_putname(vname
);
3556 #endif /* CONFIG_APPLEDOUBLE */
3559 * If we have changed any of the things about the file that are likely
3560 * to result in changes to authorization results, blow the vnode auth
3564 VATTR_IS_SUPPORTED(vap
, va_mode
) ||
3565 VATTR_IS_SUPPORTED(vap
, va_uid
) ||
3566 VATTR_IS_SUPPORTED(vap
, va_gid
) ||
3567 VATTR_IS_SUPPORTED(vap
, va_flags
) ||
3568 VATTR_IS_SUPPORTED(vap
, va_acl
) ||
3569 VATTR_IS_SUPPORTED(vap
, va_uuuid
) ||
3570 VATTR_IS_SUPPORTED(vap
, va_guuid
))) {
3571 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3574 if (vfs_authopaque(vp
->v_mount
) && vnode_hasnamedstreams(vp
)) {
3576 if (vnode_getnamedstream(vp
, &svp
, XATTR_RESOURCEFORK_NAME
, NS_OPEN
, 0, ctx
) == 0) {
3577 vnode_uncache_authorized_action(svp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3581 #endif /* NAMEDSTREAMS */
3585 post_event_if_success(vp
, _err
, NOTE_ATTRIB
);
3597 struct vnop_read_args
{
3598 struct vnodeop_desc
*a_desc
;
3602 vfs_context_t a_context
;
3606 VNOP_READ(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3609 struct vnop_read_args a
;
3611 user_ssize_t resid
= uio_resid(uio
);
3618 a
.a_desc
= &vnop_read_desc
;
3621 a
.a_ioflag
= ioflag
;
3624 _err
= (*vp
->v_op
[vnop_read_desc
.vdesc_offset
])(&a
);
3625 DTRACE_FSINFO_IO(read
,
3626 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3638 struct vnop_write_args
{
3639 struct vnodeop_desc
*a_desc
;
3643 vfs_context_t a_context
;
3647 VNOP_WRITE(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3649 struct vnop_write_args a
;
3652 user_ssize_t resid
= uio_resid(uio
);
3659 a
.a_desc
= &vnop_write_desc
;
3662 a
.a_ioflag
= ioflag
;
3665 _err
= (*vp
->v_op
[vnop_write_desc
.vdesc_offset
])(&a
);
3666 DTRACE_FSINFO_IO(write
,
3667 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3669 post_event_if_success(vp
, _err
, NOTE_WRITE
);
3681 struct vnop_ioctl_args
{
3682 struct vnodeop_desc
*a_desc
;
3687 vfs_context_t a_context
;
3691 VNOP_IOCTL(vnode_t vp
, u_long command
, caddr_t data
, int fflag
, vfs_context_t ctx
)
3694 struct vnop_ioctl_args a
;
3697 ctx
= vfs_context_current();
3701 * This check should probably have been put in the TTY code instead...
3703 * We have to be careful about what we assume during startup and shutdown.
3704 * We have to be able to use the root filesystem's device vnode even when
3705 * devfs isn't mounted (yet/anymore), so we can't go looking at its mount
3706 * structure. If there is no data pointer, it doesn't matter whether
3707 * the device is 64-bit ready. Any command (like DKIOCSYNCHRONIZE)
3708 * which passes NULL for its data pointer can therefore be used during
3709 * mount or unmount of the root filesystem.
3711 * Depending on what root filesystems need to do during mount/unmount, we
3712 * may need to loosen this check again in the future.
3714 if (vfs_context_is64bit(ctx
) && !(vnode_ischr(vp
) || vnode_isblk(vp
))) {
3715 if (data
!= NULL
&& !vnode_vfs64bitready(vp
)) {
3720 a
.a_desc
= &vnop_ioctl_desc
;
3722 a
.a_command
= command
;
3727 _err
= (*vp
->v_op
[vnop_ioctl_desc
.vdesc_offset
])(&a
);
3728 DTRACE_FSINFO(ioctl
, vnode_t
, vp
);
3740 struct vnop_select_args
{
3741 struct vnodeop_desc
*a_desc
;
3746 vfs_context_t a_context
;
3750 VNOP_SELECT(vnode_t vp
, int which
, int fflags
, void * wql
, vfs_context_t ctx
)
3753 struct vnop_select_args a
;
3756 ctx
= vfs_context_current();
3758 a
.a_desc
= &vnop_select_desc
;
3761 a
.a_fflags
= fflags
;
3765 _err
= (*vp
->v_op
[vnop_select_desc
.vdesc_offset
])(&a
);
3766 DTRACE_FSINFO(select
, vnode_t
, vp
);
3775 *#% exchange fvp L L L
3776 *#% exchange tvp L L L
3779 struct vnop_exchange_args
{
3780 struct vnodeop_desc
*a_desc
;
3784 vfs_context_t a_context
;
3788 VNOP_EXCHANGE(vnode_t fvp
, vnode_t tvp
, int options
, vfs_context_t ctx
)
3791 struct vnop_exchange_args a
;
3793 a
.a_desc
= &vnop_exchange_desc
;
3796 a
.a_options
= options
;
3799 _err
= (*fvp
->v_op
[vnop_exchange_desc
.vdesc_offset
])(&a
);
3800 DTRACE_FSINFO(exchange
, vnode_t
, fvp
);
3802 /* Don't post NOTE_WRITE because file descriptors follow the data ... */
3803 post_event_if_success(fvp
, _err
, NOTE_ATTRIB
);
3804 post_event_if_success(tvp
, _err
, NOTE_ATTRIB
);
3816 struct vnop_revoke_args
{
3817 struct vnodeop_desc
*a_desc
;
3820 vfs_context_t a_context
;
3824 VNOP_REVOKE(vnode_t vp
, int flags
, vfs_context_t ctx
)
3826 struct vnop_revoke_args a
;
3829 a
.a_desc
= &vnop_revoke_desc
;
3834 _err
= (*vp
->v_op
[vnop_revoke_desc
.vdesc_offset
])(&a
);
3835 DTRACE_FSINFO(revoke
, vnode_t
, vp
);
3844 *# mmap_check - vp U U U
3847 struct vnop_mmap_check_args
{
3848 struct vnodeop_desc
*a_desc
;
3851 vfs_context_t a_context
;
3855 VNOP_MMAP_CHECK(vnode_t vp
, int flags
, vfs_context_t ctx
)
3858 struct vnop_mmap_check_args a
;
3860 a
.a_desc
= &vnop_mmap_check_desc
;
3865 _err
= (*vp
->v_op
[vnop_mmap_check_desc
.vdesc_offset
])(&a
);
3866 if (_err
== ENOTSUP
) {
3869 DTRACE_FSINFO(mmap_check
, vnode_t
, vp
);
3880 struct vnop_mmap_args
{
3881 struct vnodeop_desc
*a_desc
;
3884 vfs_context_t a_context
;
3888 VNOP_MMAP(vnode_t vp
, int fflags
, vfs_context_t ctx
)
3891 struct vnop_mmap_args a
;
3893 a
.a_desc
= &vnop_mmap_desc
;
3895 a
.a_fflags
= fflags
;
3898 _err
= (*vp
->v_op
[vnop_mmap_desc
.vdesc_offset
])(&a
);
3899 DTRACE_FSINFO(mmap
, vnode_t
, vp
);
3908 *# mnomap - vp U U U
3911 struct vnop_mnomap_args
{
3912 struct vnodeop_desc
*a_desc
;
3914 vfs_context_t a_context
;
3918 VNOP_MNOMAP(vnode_t vp
, vfs_context_t ctx
)
3921 struct vnop_mnomap_args a
;
3923 a
.a_desc
= &vnop_mnomap_desc
;
3927 _err
= (*vp
->v_op
[vnop_mnomap_desc
.vdesc_offset
])(&a
);
3928 DTRACE_FSINFO(mnomap
, vnode_t
, vp
);
3940 struct vnop_fsync_args
{
3941 struct vnodeop_desc
*a_desc
;
3944 vfs_context_t a_context
;
3948 VNOP_FSYNC(vnode_t vp
, int waitfor
, vfs_context_t ctx
)
3950 struct vnop_fsync_args a
;
3953 a
.a_desc
= &vnop_fsync_desc
;
3955 a
.a_waitfor
= waitfor
;
3958 _err
= (*vp
->v_op
[vnop_fsync_desc
.vdesc_offset
])(&a
);
3959 DTRACE_FSINFO(fsync
, vnode_t
, vp
);
3968 *#% remove dvp L U U
3972 struct vnop_remove_args
{
3973 struct vnodeop_desc
*a_desc
;
3976 struct componentname
*a_cnp
;
3978 vfs_context_t a_context
;
3982 VNOP_REMOVE(vnode_t dvp
, vnode_t vp
, struct componentname
* cnp
, int flags
, vfs_context_t ctx
)
3985 struct vnop_remove_args a
;
3987 a
.a_desc
= &vnop_remove_desc
;
3994 _err
= (*dvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&a
);
3995 DTRACE_FSINFO(remove
, vnode_t
, vp
);
3998 vnode_setneedinactive(vp
);
3999 #if CONFIG_APPLEDOUBLE
4000 if (!(NATIVE_XATTR(dvp
))) {
4002 * Remove any associated extended attribute file (._ AppleDouble file).
4004 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
4006 #endif /* CONFIG_APPLEDOUBLE */
4009 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4010 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
4016 VNOP_COMPOUND_REMOVE(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4019 struct vnop_compound_remove_args a
;
4020 int no_vp
= (*vpp
== NULLVP
);
4022 a
.a_desc
= &vnop_compound_remove_desc
;
4025 a
.a_cnp
= &ndp
->ni_cnd
;
4029 a
.a_remove_authorizer
= vn_authorize_unlink
;
4031 _err
= (*dvp
->v_op
[vnop_compound_remove_desc
.vdesc_offset
])(&a
);
4032 if (_err
== 0 && *vpp
) {
4033 DTRACE_FSINFO(compound_remove
, vnode_t
, *vpp
);
4035 DTRACE_FSINFO(compound_remove
, vnode_t
, dvp
);
4038 vnode_setneedinactive(*vpp
);
4039 #if CONFIG_APPLEDOUBLE
4040 if (!(NATIVE_XATTR(dvp
))) {
4042 * Remove any associated extended attribute file (._ AppleDouble file).
4044 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 1);
4046 #endif /* CONFIG_APPLEDOUBLE */
4049 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4050 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
4053 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
4054 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4060 //printf("VNOP_COMPOUND_REMOVE() returning %d\n", _err);
4072 struct vnop_link_args
{
4073 struct vnodeop_desc
*a_desc
;
4076 struct componentname
*a_cnp
;
4077 vfs_context_t a_context
;
4081 VNOP_LINK(vnode_t vp
, vnode_t tdvp
, struct componentname
* cnp
, vfs_context_t ctx
)
4084 struct vnop_link_args a
;
4086 #if CONFIG_APPLEDOUBLE
4088 * For file systems with non-native extended attributes,
4089 * disallow linking to an existing "._" Apple Double file.
4091 if (!NATIVE_XATTR(tdvp
) && (vp
->v_type
== VREG
)) {
4094 vname
= vnode_getname(vp
);
4095 if (vname
!= NULL
) {
4097 if (vname
[0] == '.' && vname
[1] == '_' && vname
[2] != '\0') {
4100 vnode_putname(vname
);
4106 #endif /* CONFIG_APPLEDOUBLE */
4108 a
.a_desc
= &vnop_link_desc
;
4114 _err
= (*tdvp
->v_op
[vnop_link_desc
.vdesc_offset
])(&a
);
4115 DTRACE_FSINFO(link
, vnode_t
, vp
);
4117 post_event_if_success(vp
, _err
, NOTE_LINK
);
4118 post_event_if_success(tdvp
, _err
, NOTE_WRITE
);
4124 vn_rename(struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
4125 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
4126 vfs_rename_flags_t flags
, vfs_context_t ctx
)
4129 struct nameidata
*fromnd
= NULL
;
4130 struct nameidata
*tond
= NULL
;
4131 #if CONFIG_APPLEDOUBLE
4132 vnode_t src_attr_vp
= NULLVP
;
4133 vnode_t dst_attr_vp
= NULLVP
;
4134 char smallname1
[48];
4135 char smallname2
[48];
4136 char *xfromname
= NULL
;
4137 char *xtoname
= NULL
;
4138 #endif /* CONFIG_APPLEDOUBLE */
4140 uint32_t tdfflags
; // Target directory file flags
4142 batched
= vnode_compound_rename_available(fdvp
);
4145 if (*fvpp
== NULLVP
) {
4146 panic("Not batched, and no fvp?");
4150 #if CONFIG_APPLEDOUBLE
4152 * We need to preflight any potential AppleDouble file for the source file
4153 * before doing the rename operation, since we could potentially be doing
4154 * this operation on a network filesystem, and would end up duplicating
4155 * the work. Also, save the source and destination names. Skip it if the
4156 * source has a "._" prefix.
4159 if (!NATIVE_XATTR(fdvp
) &&
4160 !(fcnp
->cn_nameptr
[0] == '.' && fcnp
->cn_nameptr
[1] == '_')) {
4164 /* Get source attribute file name. */
4165 len
= fcnp
->cn_namelen
+ 3;
4166 if (len
> sizeof(smallname1
)) {
4167 MALLOC(xfromname
, char *, len
, M_TEMP
, M_WAITOK
);
4169 xfromname
= &smallname1
[0];
4171 strlcpy(xfromname
, "._", len
);
4172 strlcat(xfromname
, fcnp
->cn_nameptr
, len
);
4174 /* Get destination attribute file name. */
4175 len
= tcnp
->cn_namelen
+ 3;
4176 if (len
> sizeof(smallname2
)) {
4177 MALLOC(xtoname
, char *, len
, M_TEMP
, M_WAITOK
);
4179 xtoname
= &smallname2
[0];
4181 strlcpy(xtoname
, "._", len
);
4182 strlcat(xtoname
, tcnp
->cn_nameptr
, len
);
4185 * Look up source attribute file, keep reference on it if exists.
4186 * Note that we do the namei with the nameiop of RENAME, which is different than
4187 * in the rename syscall. It's OK if the source file does not exist, since this
4188 * is only for AppleDouble files.
4190 MALLOC(fromnd
, struct nameidata
*, sizeof(struct nameidata
), M_TEMP
, M_WAITOK
);
4191 NDINIT(fromnd
, RENAME
, OP_RENAME
, NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
,
4192 UIO_SYSSPACE
, CAST_USER_ADDR_T(xfromname
), ctx
);
4193 fromnd
->ni_dvp
= fdvp
;
4194 error
= namei(fromnd
);
4197 * If there was an error looking up source attribute file,
4198 * we'll behave as if it didn't exist.
4202 if (fromnd
->ni_vp
) {
4203 /* src_attr_vp indicates need to call vnode_put / nameidone later */
4204 src_attr_vp
= fromnd
->ni_vp
;
4206 if (fromnd
->ni_vp
->v_type
!= VREG
) {
4207 src_attr_vp
= NULLVP
;
4208 vnode_put(fromnd
->ni_vp
);
4212 * Either we got an invalid vnode type (not a regular file) or the namei lookup
4213 * suppressed ENOENT as a valid error since we're renaming. Either way, we don't
4214 * have a vnode here, so we drop our namei buffer for the source attribute file
4216 if (src_attr_vp
== NULLVP
) {
4221 #endif /* CONFIG_APPLEDOUBLE */
4224 _err
= VNOP_COMPOUND_RENAME(fdvp
, fvpp
, fcnp
, fvap
, tdvp
, tvpp
, tcnp
, tvap
, flags
, ctx
);
4226 printf("VNOP_COMPOUND_RENAME() returned %d\n", _err
);
4230 _err
= VNOP_RENAMEX(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, flags
, ctx
);
4231 if (_err
== ENOTSUP
&& flags
== VFS_RENAME_SECLUDE
) {
4233 if ((*fvpp
)->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_SECLUDE_RENAME
) {
4234 fcnp
->cn_flags
|= CN_SECLUDE_RENAME
;
4235 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
4239 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
4244 * If moved to a new directory that is restricted,
4245 * set the restricted flag on the item moved.
4248 _err
= vnode_flags(tdvp
, &tdfflags
, ctx
);
4250 uint32_t inherit_flags
= tdfflags
& (UF_DATAVAULT
| SF_RESTRICTED
);
4251 if (inherit_flags
) {
4253 _err
= vnode_flags(*fvpp
, &fflags
, ctx
);
4254 if (_err
== 0 && fflags
!= (fflags
| inherit_flags
)) {
4255 struct vnode_attr va
;
4257 VATTR_SET(&va
, va_flags
, fflags
| inherit_flags
);
4258 _err
= vnode_setattr(*fvpp
, &va
, ctx
);
4266 mac_vnode_notify_rename(ctx
, *fvpp
, tdvp
, tcnp
);
4267 if (flags
& VFS_RENAME_SWAP
) {
4268 mac_vnode_notify_rename(ctx
, *tvpp
, fdvp
, fcnp
);
4273 #if CONFIG_APPLEDOUBLE
4275 * Rename any associated extended attribute file (._ AppleDouble file).
4277 if (_err
== 0 && !NATIVE_XATTR(fdvp
) && xfromname
!= NULL
) {
4281 * Get destination attribute file vnode.
4282 * Note that tdvp already has an iocount reference. Make sure to check that we
4283 * get a valid vnode from namei.
4285 MALLOC(tond
, struct nameidata
*, sizeof(struct nameidata
), M_TEMP
, M_WAITOK
);
4286 NDINIT(tond
, RENAME
, OP_RENAME
,
4287 NOCACHE
| NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
, UIO_SYSSPACE
,
4288 CAST_USER_ADDR_T(xtoname
), ctx
);
4289 tond
->ni_dvp
= tdvp
;
4290 error
= namei(tond
);
4297 dst_attr_vp
= tond
->ni_vp
;
4301 const char *old_name
= src_attr_vp
->v_name
;
4302 vnode_t old_parent
= src_attr_vp
->v_parent
;
4305 error
= VNOP_COMPOUND_RENAME(fdvp
, &src_attr_vp
, &fromnd
->ni_cnd
, NULL
,
4306 tdvp
, &dst_attr_vp
, &tond
->ni_cnd
, NULL
,
4309 error
= VNOP_RENAME(fdvp
, src_attr_vp
, &fromnd
->ni_cnd
,
4310 tdvp
, dst_attr_vp
, &tond
->ni_cnd
, ctx
);
4313 if (error
== 0 && old_name
== src_attr_vp
->v_name
&&
4314 old_parent
== src_attr_vp
->v_parent
) {
4315 int update_flags
= VNODE_UPDATE_NAME
;
4318 update_flags
|= VNODE_UPDATE_PARENT
;
4321 if ((src_attr_vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_NOUPDATEID_RENAME
) == 0) {
4322 vnode_update_identity(src_attr_vp
, tdvp
,
4323 tond
->ni_cnd
.cn_nameptr
,
4324 tond
->ni_cnd
.cn_namelen
,
4325 tond
->ni_cnd
.cn_hash
,
4330 /* kevent notifications for moving resource files
4331 * _err is zero if we're here, so no need to notify directories, code
4332 * below will do that. only need to post the rename on the source and
4333 * possibly a delete on the dest
4335 post_event_if_success(src_attr_vp
, error
, NOTE_RENAME
);
4337 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4339 } else if (dst_attr_vp
) {
4341 * Just delete destination attribute file vnode if it exists, since
4342 * we didn't have a source attribute file.
4343 * Note that tdvp already has an iocount reference.
4346 struct vnop_remove_args args
;
4348 args
.a_desc
= &vnop_remove_desc
;
4350 args
.a_vp
= dst_attr_vp
;
4351 args
.a_cnp
= &tond
->ni_cnd
;
4352 args
.a_context
= ctx
;
4355 error
= (*tdvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&args
);
4358 vnode_setneedinactive(dst_attr_vp
);
4362 /* kevent notification for deleting the destination's attribute file
4363 * if it existed. Only need to post the delete on the destination, since
4364 * the code below will handle the directories.
4366 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4371 vnode_put(src_attr_vp
);
4375 vnode_put(dst_attr_vp
);
4378 if (xfromname
&& xfromname
!= &smallname1
[0]) {
4379 FREE(xfromname
, M_TEMP
);
4381 if (xtoname
&& xtoname
!= &smallname2
[0]) {
4382 FREE(xtoname
, M_TEMP
);
4384 #endif /* CONFIG_APPLEDOUBLE */
4386 FREE(fromnd
, M_TEMP
);
4398 *#% rename fdvp U U U
4399 *#% rename fvp U U U
4400 *#% rename tdvp L U U
4401 *#% rename tvp X U U
4404 struct vnop_rename_args
{
4405 struct vnodeop_desc
*a_desc
;
4408 struct componentname
*a_fcnp
;
4411 struct componentname
*a_tcnp
;
4412 vfs_context_t a_context
;
4416 VNOP_RENAME(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4417 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4421 struct vnop_rename_args a
;
4423 a
.a_desc
= &vnop_rename_desc
;
4432 /* do the rename of the main file. */
4433 _err
= (*fdvp
->v_op
[vnop_rename_desc
.vdesc_offset
])(&a
);
4434 DTRACE_FSINFO(rename
, vnode_t
, fdvp
);
4440 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4444 post_rename(vnode_t fdvp
, vnode_t fvp
, vnode_t tdvp
, vnode_t tvp
)
4446 if (tvp
&& tvp
!= fvp
) {
4447 vnode_setneedinactive(tvp
);
4450 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4451 int events
= NOTE_WRITE
;
4452 if (vnode_isdir(fvp
)) {
4453 /* Link count on dir changed only if we are moving a dir and...
4454 * --Moved to new dir, not overwriting there
4455 * --Kept in same dir and DID overwrite
4457 if (((fdvp
!= tdvp
) && (!tvp
)) || ((fdvp
== tdvp
) && (tvp
))) {
4458 events
|= NOTE_LINK
;
4462 lock_vnode_and_post(fdvp
, events
);
4464 lock_vnode_and_post(tdvp
, events
);
4467 /* If you're replacing the target, post a deletion for it */
4469 lock_vnode_and_post(tvp
, NOTE_DELETE
);
4472 lock_vnode_and_post(fvp
, NOTE_RENAME
);
4480 *#% renamex fdvp U U U
4481 *#% renamex fvp U U U
4482 *#% renamex tdvp L U U
4483 *#% renamex tvp X U U
4486 struct vnop_renamex_args
{
4487 struct vnodeop_desc
*a_desc
;
4490 struct componentname
*a_fcnp
;
4493 struct componentname
*a_tcnp
;
4494 vfs_rename_flags_t a_flags
;
4495 vfs_context_t a_context
;
4499 VNOP_RENAMEX(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4500 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4501 vfs_rename_flags_t flags
, vfs_context_t ctx
)
4504 struct vnop_renamex_args a
;
4506 a
.a_desc
= &vnop_renamex_desc
;
4516 /* do the rename of the main file. */
4517 _err
= (*fdvp
->v_op
[vnop_renamex_desc
.vdesc_offset
])(&a
);
4518 DTRACE_FSINFO(renamex
, vnode_t
, fdvp
);
4524 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4529 VNOP_COMPOUND_RENAME(
4530 struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
4531 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
4532 uint32_t flags
, vfs_context_t ctx
)
4536 struct vnop_compound_rename_args a
;
4539 no_fvp
= (*fvpp
) == NULLVP
;
4540 no_tvp
= (*tvpp
) == NULLVP
;
4542 a
.a_desc
= &vnop_compound_rename_desc
;
4556 a
.a_rename_authorizer
= vn_authorize_rename
;
4557 a
.a_reserved
= NULL
;
4559 /* do the rename of the main file. */
4560 _err
= (*fdvp
->v_op
[vnop_compound_rename_desc
.vdesc_offset
])(&a
);
4561 DTRACE_FSINFO(compound_rename
, vnode_t
, fdvp
);
4564 if (*tvpp
&& *tvpp
!= *fvpp
) {
4565 vnode_setneedinactive(*tvpp
);
4569 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4570 if (_err
== 0 && *fvpp
!= *tvpp
) {
4572 panic("No fvpp after compound rename?");
4575 events
= NOTE_WRITE
;
4576 if (vnode_isdir(*fvpp
)) {
4577 /* Link count on dir changed only if we are moving a dir and...
4578 * --Moved to new dir, not overwriting there
4579 * --Kept in same dir and DID overwrite
4581 if (((fdvp
!= tdvp
) && (!*tvpp
)) || ((fdvp
== tdvp
) && (*tvpp
))) {
4582 events
|= NOTE_LINK
;
4586 lock_vnode_and_post(fdvp
, events
);
4588 lock_vnode_and_post(tdvp
, events
);
4591 /* If you're replacing the target, post a deletion for it */
4593 lock_vnode_and_post(*tvpp
, NOTE_DELETE
);
4596 lock_vnode_and_post(*fvpp
, NOTE_RENAME
);
4600 lookup_compound_vnop_post_hook(_err
, fdvp
, *fvpp
, fcnp
->cn_ndp
, 0);
4602 if (no_tvp
&& *tvpp
!= NULLVP
) {
4603 lookup_compound_vnop_post_hook(_err
, tdvp
, *tvpp
, tcnp
->cn_ndp
, 0);
4606 if (_err
&& _err
!= EKEEPLOOKING
) {
4621 vn_mkdir(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4622 struct vnode_attr
*vap
, vfs_context_t ctx
)
4624 if (ndp
->ni_cnd
.cn_nameiop
!= CREATE
) {
4625 panic("Non-CREATE nameiop in vn_mkdir()?");
4628 if (vnode_compound_mkdir_available(dvp
)) {
4629 return VNOP_COMPOUND_MKDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4631 return VNOP_MKDIR(dvp
, vpp
, &ndp
->ni_cnd
, vap
, ctx
);
4642 struct vnop_mkdir_args
{
4643 struct vnodeop_desc
*a_desc
;
4646 struct componentname
*a_cnp
;
4647 struct vnode_attr
*a_vap
;
4648 vfs_context_t a_context
;
4652 VNOP_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4653 struct vnode_attr
*vap
, vfs_context_t ctx
)
4656 struct vnop_mkdir_args a
;
4658 a
.a_desc
= &vnop_mkdir_desc
;
4665 _err
= (*dvp
->v_op
[vnop_mkdir_desc
.vdesc_offset
])(&a
);
4666 if (_err
== 0 && *vpp
) {
4667 DTRACE_FSINFO(mkdir
, vnode_t
, *vpp
);
4669 #if CONFIG_APPLEDOUBLE
4670 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4672 * Remove stale Apple Double file (if any).
4674 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4676 #endif /* CONFIG_APPLEDOUBLE */
4678 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4684 VNOP_COMPOUND_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4685 struct vnode_attr
*vap
, vfs_context_t ctx
)
4688 struct vnop_compound_mkdir_args a
;
4690 a
.a_desc
= &vnop_compound_mkdir_desc
;
4693 a
.a_cnp
= &ndp
->ni_cnd
;
4698 a
.a_mkdir_authorizer
= vn_authorize_mkdir
;
4700 a
.a_reserved
= NULL
;
4702 _err
= (*dvp
->v_op
[vnop_compound_mkdir_desc
.vdesc_offset
])(&a
);
4703 if (_err
== 0 && *vpp
) {
4704 DTRACE_FSINFO(compound_mkdir
, vnode_t
, *vpp
);
4706 #if CONFIG_APPLEDOUBLE
4707 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4709 * Remove stale Apple Double file (if any).
4711 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4713 #endif /* CONFIG_APPLEDOUBLE */
4715 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4717 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, (_err
== 0));
4718 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4727 vn_rmdir(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4729 if (vnode_compound_rmdir_available(dvp
)) {
4730 return VNOP_COMPOUND_RMDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4732 if (*vpp
== NULLVP
) {
4733 panic("NULL vp, but not a compound VNOP?");
4736 panic("Non-NULL vap, but not a compound VNOP?");
4738 return VNOP_RMDIR(dvp
, *vpp
, &ndp
->ni_cnd
, ctx
);
4749 struct vnop_rmdir_args
{
4750 struct vnodeop_desc
*a_desc
;
4753 struct componentname
*a_cnp
;
4754 vfs_context_t a_context
;
4759 VNOP_RMDIR(struct vnode
*dvp
, struct vnode
*vp
, struct componentname
*cnp
, vfs_context_t ctx
)
4762 struct vnop_rmdir_args a
;
4764 a
.a_desc
= &vnop_rmdir_desc
;
4770 _err
= (*vp
->v_op
[vnop_rmdir_desc
.vdesc_offset
])(&a
);
4771 DTRACE_FSINFO(rmdir
, vnode_t
, vp
);
4774 vnode_setneedinactive(vp
);
4775 #if CONFIG_APPLEDOUBLE
4776 if (!(NATIVE_XATTR(dvp
))) {
4778 * Remove any associated extended attribute file (._ AppleDouble file).
4780 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
4785 /* If you delete a dir, it loses its "." reference --> NOTE_LINK */
4786 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4787 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4793 VNOP_COMPOUND_RMDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4794 struct vnode_attr
*vap
, vfs_context_t ctx
)
4797 struct vnop_compound_rmdir_args a
;
4800 a
.a_desc
= &vnop_mkdir_desc
;
4803 a
.a_cnp
= &ndp
->ni_cnd
;
4807 a
.a_rmdir_authorizer
= vn_authorize_rmdir
;
4808 a
.a_reserved
= NULL
;
4810 no_vp
= (*vpp
== NULLVP
);
4812 _err
= (*dvp
->v_op
[vnop_compound_rmdir_desc
.vdesc_offset
])(&a
);
4813 if (_err
== 0 && *vpp
) {
4814 DTRACE_FSINFO(compound_rmdir
, vnode_t
, *vpp
);
4816 #if CONFIG_APPLEDOUBLE
4817 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4819 * Remove stale Apple Double file (if any).
4821 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4826 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4828 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4831 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
4833 #if 0 /* Removing orphaned ._ files requires a vp.... */
4834 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4844 #if CONFIG_APPLEDOUBLE
4846 * Remove a ._ AppleDouble file
4848 #define AD_STALE_SECS (180)
4850 xattrfile_remove(vnode_t dvp
, const char * basename
, vfs_context_t ctx
, int force
)
4853 struct nameidata nd
;
4855 char *filename
= NULL
;
4858 if ((basename
== NULL
) || (basename
[0] == '\0') ||
4859 (basename
[0] == '.' && basename
[1] == '_')) {
4862 filename
= &smallname
[0];
4863 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4864 if (len
>= sizeof(smallname
)) {
4865 len
++; /* snprintf result doesn't include '\0' */
4866 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4867 len
= snprintf(filename
, len
, "._%s", basename
);
4869 NDINIT(&nd
, DELETE
, OP_UNLINK
, WANTPARENT
| LOCKLEAF
| NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4870 CAST_USER_ADDR_T(filename
), ctx
);
4872 if (namei(&nd
) != 0) {
4878 if (xvp
->v_type
!= VREG
) {
4883 * When creating a new object and a "._" file already
4884 * exists, check to see if its a stale "._" file.
4888 struct vnode_attr va
;
4891 VATTR_WANTED(&va
, va_data_size
);
4892 VATTR_WANTED(&va
, va_modify_time
);
4893 if (VNOP_GETATTR(xvp
, &va
, ctx
) == 0 &&
4894 VATTR_IS_SUPPORTED(&va
, va_data_size
) &&
4895 VATTR_IS_SUPPORTED(&va
, va_modify_time
) &&
4896 va
.va_data_size
!= 0) {
4900 if ((tv
.tv_sec
> va
.va_modify_time
.tv_sec
) &&
4901 (tv
.tv_sec
- va
.va_modify_time
.tv_sec
) > AD_STALE_SECS
) {
4902 force
= 1; /* must be stale */
4909 error
= VNOP_REMOVE(dvp
, xvp
, &nd
.ni_cnd
, 0, ctx
);
4911 vnode_setneedinactive(xvp
);
4914 post_event_if_success(xvp
, error
, NOTE_DELETE
);
4915 post_event_if_success(dvp
, error
, NOTE_WRITE
);
4922 if (filename
&& filename
!= &smallname
[0]) {
4923 FREE(filename
, M_TEMP
);
4928 * Shadow uid/gid/mod to a ._ AppleDouble file
4931 xattrfile_setattr(vnode_t dvp
, const char * basename
, struct vnode_attr
* vap
,
4935 struct nameidata nd
;
4937 char *filename
= NULL
;
4940 if ((dvp
== NULLVP
) ||
4941 (basename
== NULL
) || (basename
[0] == '\0') ||
4942 (basename
[0] == '.' && basename
[1] == '_')) {
4945 filename
= &smallname
[0];
4946 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4947 if (len
>= sizeof(smallname
)) {
4948 len
++; /* snprintf result doesn't include '\0' */
4949 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4950 len
= snprintf(filename
, len
, "._%s", basename
);
4952 NDINIT(&nd
, LOOKUP
, OP_SETATTR
, NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4953 CAST_USER_ADDR_T(filename
), ctx
);
4955 if (namei(&nd
) != 0) {
4962 if (xvp
->v_type
== VREG
) {
4963 struct vnop_setattr_args a
;
4965 a
.a_desc
= &vnop_setattr_desc
;
4970 (void) (*xvp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
4975 if (filename
&& filename
!= &smallname
[0]) {
4976 FREE(filename
, M_TEMP
);
4979 #endif /* CONFIG_APPLEDOUBLE */
4984 *#% symlink dvp L U U
4985 *#% symlink vpp - U -
4988 struct vnop_symlink_args
{
4989 struct vnodeop_desc
*a_desc
;
4992 struct componentname
*a_cnp
;
4993 struct vnode_attr
*a_vap
;
4995 vfs_context_t a_context
;
5000 VNOP_SYMLINK(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
5001 struct vnode_attr
*vap
, char *target
, vfs_context_t ctx
)
5004 struct vnop_symlink_args a
;
5006 a
.a_desc
= &vnop_symlink_desc
;
5011 a
.a_target
= target
;
5014 _err
= (*dvp
->v_op
[vnop_symlink_desc
.vdesc_offset
])(&a
);
5015 DTRACE_FSINFO(symlink
, vnode_t
, dvp
);
5016 #if CONFIG_APPLEDOUBLE
5017 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
5019 * Remove stale Apple Double file (if any). Posts its own knotes
5021 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
5023 #endif /* CONFIG_APPLEDOUBLE */
5025 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
5033 *#% readdir vp L L L
5036 struct vnop_readdir_args
{
5037 struct vnodeop_desc
*a_desc
;
5043 vfs_context_t a_context
;
5048 VNOP_READDIR(struct vnode
*vp
, struct uio
*uio
, int flags
, int *eofflag
,
5049 int *numdirent
, vfs_context_t ctx
)
5052 struct vnop_readdir_args a
;
5054 user_ssize_t resid
= uio_resid(uio
);
5057 a
.a_desc
= &vnop_readdir_desc
;
5061 a
.a_eofflag
= eofflag
;
5062 a
.a_numdirent
= numdirent
;
5065 _err
= (*vp
->v_op
[vnop_readdir_desc
.vdesc_offset
])(&a
);
5066 DTRACE_FSINFO_IO(readdir
,
5067 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5075 *#% readdirattr vp L L L
5078 struct vnop_readdirattr_args
{
5079 struct vnodeop_desc
*a_desc
;
5081 struct attrlist
*a_alist
;
5083 uint32_t a_maxcount
;
5085 uint32_t *a_newstate
;
5087 uint32_t *a_actualcount
;
5088 vfs_context_t a_context
;
5093 VNOP_READDIRATTR(struct vnode
*vp
, struct attrlist
*alist
, struct uio
*uio
, uint32_t maxcount
,
5094 uint32_t options
, uint32_t *newstate
, int *eofflag
, uint32_t *actualcount
, vfs_context_t ctx
)
5097 struct vnop_readdirattr_args a
;
5099 user_ssize_t resid
= uio_resid(uio
);
5102 a
.a_desc
= &vnop_readdirattr_desc
;
5106 a
.a_maxcount
= maxcount
;
5107 a
.a_options
= options
;
5108 a
.a_newstate
= newstate
;
5109 a
.a_eofflag
= eofflag
;
5110 a
.a_actualcount
= actualcount
;
5113 _err
= (*vp
->v_op
[vnop_readdirattr_desc
.vdesc_offset
])(&a
);
5114 DTRACE_FSINFO_IO(readdirattr
,
5115 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5121 struct vnop_getttrlistbulk_args
{
5122 struct vnodeop_desc
*a_desc
;
5124 struct attrlist
*a_alist
;
5125 struct vnode_attr
*a_vap
;
5130 uint32_t *a_actualcount
;
5131 vfs_context_t a_context
;
5135 VNOP_GETATTRLISTBULK(struct vnode
*vp
, struct attrlist
*alist
,
5136 struct vnode_attr
*vap
, struct uio
*uio
, void *private, uint64_t options
,
5137 int32_t *eofflag
, int32_t *actualcount
, vfs_context_t ctx
)
5140 struct vnop_getattrlistbulk_args a
;
5142 user_ssize_t resid
= uio_resid(uio
);
5145 a
.a_desc
= &vnop_getattrlistbulk_desc
;
5150 a
.a_private
= private;
5151 a
.a_options
= options
;
5152 a
.a_eofflag
= eofflag
;
5153 a
.a_actualcount
= actualcount
;
5156 _err
= (*vp
->v_op
[vnop_getattrlistbulk_desc
.vdesc_offset
])(&a
);
5157 DTRACE_FSINFO_IO(getattrlistbulk
,
5158 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5166 *#% readlink vp L L L
5169 struct vnop_readlink_args
{
5170 struct vnodeop_desc
*a_desc
;
5173 vfs_context_t a_context
;
5178 * Returns: 0 Success
5179 * lock_fsnode:ENOENT No such file or directory [only for VFS
5180 * that is not thread safe & vnode is
5181 * currently being/has been terminated]
5182 * <vfs_readlink>:EINVAL
5183 * <vfs_readlink>:???
5185 * Note: The return codes from the underlying VFS's readlink routine
5186 * can't be fully enumerated here, since third party VFS authors
5187 * may not limit their error returns to the ones documented here,
5188 * even though this may result in some programs functioning
5191 * The return codes documented above are those which may currently
5192 * be returned by HFS from hfs_vnop_readlink, not including
5193 * additional error code which may be propagated from underlying
5197 VNOP_READLINK(struct vnode
*vp
, struct uio
*uio
, vfs_context_t ctx
)
5200 struct vnop_readlink_args a
;
5202 user_ssize_t resid
= uio_resid(uio
);
5204 a
.a_desc
= &vnop_readlink_desc
;
5209 _err
= (*vp
->v_op
[vnop_readlink_desc
.vdesc_offset
])(&a
);
5210 DTRACE_FSINFO_IO(readlink
,
5211 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
5219 *#% inactive vp L U U
5222 struct vnop_inactive_args
{
5223 struct vnodeop_desc
*a_desc
;
5225 vfs_context_t a_context
;
5229 VNOP_INACTIVE(struct vnode
*vp
, vfs_context_t ctx
)
5232 struct vnop_inactive_args a
;
5234 a
.a_desc
= &vnop_inactive_desc
;
5238 _err
= (*vp
->v_op
[vnop_inactive_desc
.vdesc_offset
])(&a
);
5239 DTRACE_FSINFO(inactive
, vnode_t
, vp
);
5242 /* For file systems that do not support namedstream natively, mark
5243 * the shadow stream file vnode to be recycled as soon as the last
5244 * reference goes away. To avoid re-entering reclaim code, do not
5245 * call recycle on terminating namedstream vnodes.
5247 if (vnode_isnamedstream(vp
) &&
5248 (vp
->v_parent
!= NULLVP
) &&
5249 vnode_isshadow(vp
) &&
5250 ((vp
->v_lflag
& VL_TERMINATE
) == 0)) {
5262 *#% reclaim vp U U U
5265 struct vnop_reclaim_args
{
5266 struct vnodeop_desc
*a_desc
;
5268 vfs_context_t a_context
;
5272 VNOP_RECLAIM(struct vnode
*vp
, vfs_context_t ctx
)
5275 struct vnop_reclaim_args a
;
5277 a
.a_desc
= &vnop_reclaim_desc
;
5281 _err
= (*vp
->v_op
[vnop_reclaim_desc
.vdesc_offset
])(&a
);
5282 DTRACE_FSINFO(reclaim
, vnode_t
, vp
);
5289 * Returns: 0 Success
5290 * lock_fsnode:ENOENT No such file or directory [only for VFS
5291 * that is not thread safe & vnode is
5292 * currently being/has been terminated]
5293 * <vnop_pathconf_desc>:??? [per FS implementation specific]
5298 *#% pathconf vp L L L
5301 struct vnop_pathconf_args
{
5302 struct vnodeop_desc
*a_desc
;
5306 vfs_context_t a_context
;
5310 VNOP_PATHCONF(struct vnode
*vp
, int name
, int32_t *retval
, vfs_context_t ctx
)
5313 struct vnop_pathconf_args a
;
5315 a
.a_desc
= &vnop_pathconf_desc
;
5318 a
.a_retval
= retval
;
5321 _err
= (*vp
->v_op
[vnop_pathconf_desc
.vdesc_offset
])(&a
);
5322 DTRACE_FSINFO(pathconf
, vnode_t
, vp
);
5328 * Returns: 0 Success
5329 * err_advlock:ENOTSUP
5331 * <vnop_advlock_desc>:???
5333 * Notes: VFS implementations of advisory locking using calls through
5334 * <vnop_advlock_desc> because lock enforcement does not occur
5335 * locally should try to limit themselves to the return codes
5336 * documented above for lf_advlock and err_advlock.
5341 *#% advlock vp U U U
5344 struct vnop_advlock_args
{
5345 struct vnodeop_desc
*a_desc
;
5351 vfs_context_t a_context
;
5355 VNOP_ADVLOCK(struct vnode
*vp
, caddr_t id
, int op
, struct flock
*fl
, int flags
, vfs_context_t ctx
, struct timespec
*timeout
)
5358 struct vnop_advlock_args a
;
5360 a
.a_desc
= &vnop_advlock_desc
;
5367 a
.a_timeout
= timeout
;
5369 /* Disallow advisory locking on non-seekable vnodes */
5370 if (vnode_isfifo(vp
)) {
5371 _err
= err_advlock(&a
);
5373 if ((vp
->v_flag
& VLOCKLOCAL
)) {
5374 /* Advisory locking done at this layer */
5375 _err
= lf_advlock(&a
);
5376 } else if (flags
& F_OFD_LOCK
) {
5377 /* Non-local locking doesn't work for OFD locks */
5378 _err
= err_advlock(&a
);
5380 /* Advisory locking done by underlying filesystem */
5381 _err
= (*vp
->v_op
[vnop_advlock_desc
.vdesc_offset
])(&a
);
5383 DTRACE_FSINFO(advlock
, vnode_t
, vp
);
5384 if (op
== F_UNLCK
&& flags
== F_FLOCK
) {
5385 post_event_if_success(vp
, _err
, NOTE_FUNLOCK
);
5397 *#% allocate vp L L L
5400 struct vnop_allocate_args
{
5401 struct vnodeop_desc
*a_desc
;
5405 off_t
*a_bytesallocated
;
5407 vfs_context_t a_context
;
5412 VNOP_ALLOCATE(struct vnode
*vp
, off_t length
, u_int32_t flags
, off_t
*bytesallocated
, off_t offset
, vfs_context_t ctx
)
5415 struct vnop_allocate_args a
;
5417 a
.a_desc
= &vnop_allocate_desc
;
5419 a
.a_length
= length
;
5421 a
.a_bytesallocated
= bytesallocated
;
5422 a
.a_offset
= offset
;
5425 _err
= (*vp
->v_op
[vnop_allocate_desc
.vdesc_offset
])(&a
);
5426 DTRACE_FSINFO(allocate
, vnode_t
, vp
);
5429 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
5442 struct vnop_pagein_args
{
5443 struct vnodeop_desc
*a_desc
;
5446 upl_offset_t a_pl_offset
;
5450 vfs_context_t a_context
;
5454 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
)
5457 struct vnop_pagein_args a
;
5459 a
.a_desc
= &vnop_pagein_desc
;
5462 a
.a_pl_offset
= pl_offset
;
5463 a
.a_f_offset
= f_offset
;
5468 _err
= (*vp
->v_op
[vnop_pagein_desc
.vdesc_offset
])(&a
);
5469 DTRACE_FSINFO(pagein
, vnode_t
, vp
);
5477 *#% pageout vp = = =
5480 struct vnop_pageout_args
{
5481 struct vnodeop_desc
*a_desc
;
5484 upl_offset_t a_pl_offset
;
5488 vfs_context_t a_context
;
5493 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
)
5496 struct vnop_pageout_args a
;
5498 a
.a_desc
= &vnop_pageout_desc
;
5501 a
.a_pl_offset
= pl_offset
;
5502 a
.a_f_offset
= f_offset
;
5507 _err
= (*vp
->v_op
[vnop_pageout_desc
.vdesc_offset
])(&a
);
5508 DTRACE_FSINFO(pageout
, vnode_t
, vp
);
5510 post_event_if_success(vp
, _err
, NOTE_WRITE
);
5516 vn_remove(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
5518 if (vnode_compound_remove_available(dvp
)) {
5519 return VNOP_COMPOUND_REMOVE(dvp
, vpp
, ndp
, flags
, vap
, ctx
);
5521 return VNOP_REMOVE(dvp
, *vpp
, &ndp
->ni_cnd
, flags
, ctx
);
5530 *#% searchfs vp L L L
5533 struct vnop_searchfs_args
{
5534 struct vnodeop_desc
*a_desc
;
5536 void *a_searchparams1
;
5537 void *a_searchparams2
;
5538 struct attrlist
*a_searchattrs
;
5539 uint32_t a_maxmatches
;
5540 struct timeval
*a_timelimit
;
5541 struct attrlist
*a_returnattrs
;
5542 uint32_t *a_nummatches
;
5543 uint32_t a_scriptcode
;
5546 struct searchstate
*a_searchstate
;
5547 vfs_context_t a_context
;
5552 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
)
5555 struct vnop_searchfs_args a
;
5557 a
.a_desc
= &vnop_searchfs_desc
;
5559 a
.a_searchparams1
= searchparams1
;
5560 a
.a_searchparams2
= searchparams2
;
5561 a
.a_searchattrs
= searchattrs
;
5562 a
.a_maxmatches
= maxmatches
;
5563 a
.a_timelimit
= timelimit
;
5564 a
.a_returnattrs
= returnattrs
;
5565 a
.a_nummatches
= nummatches
;
5566 a
.a_scriptcode
= scriptcode
;
5567 a
.a_options
= options
;
5569 a
.a_searchstate
= searchstate
;
5572 _err
= (*vp
->v_op
[vnop_searchfs_desc
.vdesc_offset
])(&a
);
5573 DTRACE_FSINFO(searchfs
, vnode_t
, vp
);
5577 #endif /* CONFIG_SEARCHFS */
5582 *#% copyfile fvp U U U
5583 *#% copyfile tdvp L U U
5584 *#% copyfile tvp X U U
5587 struct vnop_copyfile_args
{
5588 struct vnodeop_desc
*a_desc
;
5592 struct componentname
*a_tcnp
;
5595 vfs_context_t a_context
;
5599 VNOP_COPYFILE(struct vnode
*fvp
, struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
5600 int mode
, int flags
, vfs_context_t ctx
)
5603 struct vnop_copyfile_args a
;
5604 a
.a_desc
= &vnop_copyfile_desc
;
5612 _err
= (*fvp
->v_op
[vnop_copyfile_desc
.vdesc_offset
])(&a
);
5613 DTRACE_FSINFO(copyfile
, vnode_t
, fvp
);
5618 struct vnop_clonefile_args
{
5619 struct vnodeop_desc
*a_desc
;
5623 struct componentname
*a_cnp
;
5624 struct vnode_attr
*a_vap
;
5626 vfs_context_t a_context
;
5627 int (*a_dir_clone_authorizer
)( /* Authorization callback */
5628 struct vnode_attr
*vap
, /* attribute to be authorized */
5629 kauth_action_t action
, /* action for which attribute is to be authorized */
5630 struct vnode_attr
*dvap
, /* target directory attributes */
5631 vnode_t sdvp
, /* source directory vnode pointer (optional) */
5632 mount_t mp
, /* mount point of filesystem */
5633 dir_clone_authorizer_op_t vattr_op
, /* specific operation requested : setup, authorization or cleanup */
5634 uint32_t flags
; /* value passed in a_flags to the VNOP */
5635 vfs_context_t ctx
, /* As passed to VNOP */
5636 void *reserved
); /* Always NULL */
5637 void *a_reserved
; /* Currently unused */
5642 VNOP_CLONEFILE(vnode_t fvp
, vnode_t dvp
, vnode_t
*vpp
,
5643 struct componentname
*cnp
, struct vnode_attr
*vap
, uint32_t flags
,
5647 struct vnop_clonefile_args a
;
5648 a
.a_desc
= &vnop_clonefile_desc
;
5657 if (vnode_vtype(fvp
) == VDIR
) {
5658 a
.a_dir_clone_authorizer
= vnode_attr_authorize_dir_clone
;
5660 a
.a_dir_clone_authorizer
= NULL
;
5663 _err
= (*dvp
->v_op
[vnop_clonefile_desc
.vdesc_offset
])(&a
);
5665 if (_err
== 0 && *vpp
) {
5666 DTRACE_FSINFO(clonefile
, vnode_t
, *vpp
);
5667 if (kdebug_enable
) {
5668 kdebug_lookup(*vpp
, cnp
);
5672 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
5678 VNOP_GETXATTR(vnode_t vp
, const char *name
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5680 struct vnop_getxattr_args a
;
5683 a
.a_desc
= &vnop_getxattr_desc
;
5688 a
.a_options
= options
;
5691 error
= (*vp
->v_op
[vnop_getxattr_desc
.vdesc_offset
])(&a
);
5692 DTRACE_FSINFO(getxattr
, vnode_t
, vp
);
5698 VNOP_SETXATTR(vnode_t vp
, const char *name
, uio_t uio
, int options
, vfs_context_t ctx
)
5700 struct vnop_setxattr_args a
;
5703 a
.a_desc
= &vnop_setxattr_desc
;
5707 a
.a_options
= options
;
5710 error
= (*vp
->v_op
[vnop_setxattr_desc
.vdesc_offset
])(&a
);
5711 DTRACE_FSINFO(setxattr
, vnode_t
, vp
);
5714 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
5717 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5723 VNOP_REMOVEXATTR(vnode_t vp
, const char *name
, int options
, vfs_context_t ctx
)
5725 struct vnop_removexattr_args a
;
5728 a
.a_desc
= &vnop_removexattr_desc
;
5731 a
.a_options
= options
;
5734 error
= (*vp
->v_op
[vnop_removexattr_desc
.vdesc_offset
])(&a
);
5735 DTRACE_FSINFO(removexattr
, vnode_t
, vp
);
5737 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5743 VNOP_LISTXATTR(vnode_t vp
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5745 struct vnop_listxattr_args a
;
5748 a
.a_desc
= &vnop_listxattr_desc
;
5752 a
.a_options
= options
;
5755 error
= (*vp
->v_op
[vnop_listxattr_desc
.vdesc_offset
])(&a
);
5756 DTRACE_FSINFO(listxattr
, vnode_t
, vp
);
5765 *#% blktooff vp = = =
5768 struct vnop_blktooff_args
{
5769 struct vnodeop_desc
*a_desc
;
5776 VNOP_BLKTOOFF(struct vnode
*vp
, daddr64_t lblkno
, off_t
*offset
)
5779 struct vnop_blktooff_args a
;
5781 a
.a_desc
= &vnop_blktooff_desc
;
5783 a
.a_lblkno
= lblkno
;
5784 a
.a_offset
= offset
;
5786 _err
= (*vp
->v_op
[vnop_blktooff_desc
.vdesc_offset
])(&a
);
5787 DTRACE_FSINFO(blktooff
, vnode_t
, vp
);
5795 *#% offtoblk vp = = =
5798 struct vnop_offtoblk_args
{
5799 struct vnodeop_desc
*a_desc
;
5802 daddr64_t
*a_lblkno
;
5806 VNOP_OFFTOBLK(struct vnode
*vp
, off_t offset
, daddr64_t
*lblkno
)
5809 struct vnop_offtoblk_args a
;
5811 a
.a_desc
= &vnop_offtoblk_desc
;
5813 a
.a_offset
= offset
;
5814 a
.a_lblkno
= lblkno
;
5816 _err
= (*vp
->v_op
[vnop_offtoblk_desc
.vdesc_offset
])(&a
);
5817 DTRACE_FSINFO(offtoblk
, vnode_t
, vp
);
5825 *#% blockmap vp L L L
5828 struct vnop_blockmap_args
{
5829 struct vnodeop_desc
*a_desc
;
5837 vfs_context_t a_context
;
5841 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
)
5844 struct vnop_blockmap_args a
;
5845 size_t localrun
= 0;
5848 ctx
= vfs_context_current();
5850 a
.a_desc
= &vnop_blockmap_desc
;
5852 a
.a_foffset
= foffset
;
5855 a
.a_run
= &localrun
;
5860 _err
= (*vp
->v_op
[vnop_blockmap_desc
.vdesc_offset
])(&a
);
5861 DTRACE_FSINFO(blockmap
, vnode_t
, vp
);
5864 * We used a local variable to request information from the underlying
5865 * filesystem about the length of the I/O run in question. If
5866 * we get malformed output from the filesystem, we cap it to the length
5867 * requested, at most. Update 'run' on the way out.
5870 if (localrun
> size
) {
5883 struct vnop_strategy_args
{
5884 struct vnodeop_desc
*a_desc
;
5890 VNOP_STRATEGY(struct buf
*bp
)
5893 struct vnop_strategy_args a
;
5894 vnode_t vp
= buf_vnode(bp
);
5895 a
.a_desc
= &vnop_strategy_desc
;
5897 _err
= (*vp
->v_op
[vnop_strategy_desc
.vdesc_offset
])(&a
);
5898 DTRACE_FSINFO(strategy
, vnode_t
, vp
);
5903 struct vnop_bwrite_args
{
5904 struct vnodeop_desc
*a_desc
;
5909 VNOP_BWRITE(struct buf
*bp
)
5912 struct vnop_bwrite_args a
;
5913 vnode_t vp
= buf_vnode(bp
);
5914 a
.a_desc
= &vnop_bwrite_desc
;
5916 _err
= (*vp
->v_op
[vnop_bwrite_desc
.vdesc_offset
])(&a
);
5917 DTRACE_FSINFO(bwrite
, vnode_t
, vp
);
5922 struct vnop_kqfilt_add_args
{
5923 struct vnodeop_desc
*a_desc
;
5926 vfs_context_t a_context
;
5930 VNOP_KQFILT_ADD(struct vnode
*vp
, struct knote
*kn
, vfs_context_t ctx
)
5933 struct vnop_kqfilt_add_args a
;
5935 a
.a_desc
= VDESC(vnop_kqfilt_add
);
5940 _err
= (*vp
->v_op
[vnop_kqfilt_add_desc
.vdesc_offset
])(&a
);
5941 DTRACE_FSINFO(kqfilt_add
, vnode_t
, vp
);
5947 struct vnop_kqfilt_remove_args
{
5948 struct vnodeop_desc
*a_desc
;
5951 vfs_context_t a_context
;
5955 VNOP_KQFILT_REMOVE(struct vnode
*vp
, uintptr_t ident
, vfs_context_t ctx
)
5958 struct vnop_kqfilt_remove_args a
;
5960 a
.a_desc
= VDESC(vnop_kqfilt_remove
);
5965 _err
= (*vp
->v_op
[vnop_kqfilt_remove_desc
.vdesc_offset
])(&a
);
5966 DTRACE_FSINFO(kqfilt_remove
, vnode_t
, vp
);
5972 VNOP_MONITOR(vnode_t vp
, uint32_t events
, uint32_t flags
, void *handle
, vfs_context_t ctx
)
5975 struct vnop_monitor_args a
;
5977 a
.a_desc
= VDESC(vnop_monitor
);
5979 a
.a_events
= events
;
5981 a
.a_handle
= handle
;
5984 _err
= (*vp
->v_op
[vnop_monitor_desc
.vdesc_offset
])(&a
);
5985 DTRACE_FSINFO(monitor
, vnode_t
, vp
);
5991 struct vnop_setlabel_args
{
5992 struct vnodeop_desc
*a_desc
;
5995 vfs_context_t a_context
;
5999 VNOP_SETLABEL(struct vnode
*vp
, struct label
*label
, vfs_context_t ctx
)
6002 struct vnop_setlabel_args a
;
6004 a
.a_desc
= VDESC(vnop_setlabel
);
6009 _err
= (*vp
->v_op
[vnop_setlabel_desc
.vdesc_offset
])(&a
);
6010 DTRACE_FSINFO(setlabel
, vnode_t
, vp
);
6018 * Get a named streamed
6021 VNOP_GETNAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, enum nsoperation operation
, int flags
, vfs_context_t ctx
)
6024 struct vnop_getnamedstream_args a
;
6026 a
.a_desc
= &vnop_getnamedstream_desc
;
6030 a
.a_operation
= operation
;
6034 _err
= (*vp
->v_op
[vnop_getnamedstream_desc
.vdesc_offset
])(&a
);
6035 DTRACE_FSINFO(getnamedstream
, vnode_t
, vp
);
6040 * Create a named streamed
6043 VNOP_MAKENAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, int flags
, vfs_context_t ctx
)
6046 struct vnop_makenamedstream_args a
;
6048 a
.a_desc
= &vnop_makenamedstream_desc
;
6055 _err
= (*vp
->v_op
[vnop_makenamedstream_desc
.vdesc_offset
])(&a
);
6056 DTRACE_FSINFO(makenamedstream
, vnode_t
, vp
);
6062 * Remove a named streamed
6065 VNOP_REMOVENAMEDSTREAM(vnode_t vp
, vnode_t svp
, const char *name
, int flags
, vfs_context_t ctx
)
6068 struct vnop_removenamedstream_args a
;
6070 a
.a_desc
= &vnop_removenamedstream_desc
;
6077 _err
= (*vp
->v_op
[vnop_removenamedstream_desc
.vdesc_offset
])(&a
);
6078 DTRACE_FSINFO(removenamedstream
, vnode_t
, vp
);