2 * Copyright (c) 2000-2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1989, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
70 * support for mandatory and extensible security protections. This notice
71 * is included in support of clause 2.2 (b) of the Apple Public License,
76 * External virtual filesystem routines
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/proc_internal.h>
83 #include <sys/kauth.h>
84 #include <sys/mount.h>
85 #include <sys/mount_internal.h>
87 #include <sys/vnode_internal.h>
89 #include <sys/namei.h>
90 #include <sys/ucred.h>
92 #include <sys/errno.h>
93 #include <sys/malloc.h>
94 #include <sys/domain.h>
96 #include <sys/syslog.h>
99 #include <sys/sysctl.h>
100 #include <sys/filedesc.h>
101 #include <sys/event.h>
102 #include <sys/fsevents.h>
103 #include <sys/user.h>
104 #include <sys/lockf.h>
105 #include <sys/xattr.h>
107 #include <kern/assert.h>
108 #include <kern/kalloc.h>
109 #include <kern/task.h>
111 #include <libkern/OSByteOrder.h>
113 #include <miscfs/specfs/specdev.h>
115 #include <mach/mach_types.h>
116 #include <mach/memory_object_types.h>
117 #include <mach/task.h>
120 #include <security/mac_framework.h>
131 #define NATIVE_XATTR(VP) \
132 ((VP)->v_mount ? (VP)->v_mount->mnt_kern_flag & MNTK_EXTENDED_ATTRS : 0)
134 #if CONFIG_APPLEDOUBLE
135 static void xattrfile_remove(vnode_t dvp
, const char *basename
,
136 vfs_context_t ctx
, int force
);
137 static void xattrfile_setattr(vnode_t dvp
, const char * basename
,
138 struct vnode_attr
* vap
, vfs_context_t ctx
);
139 #endif /* CONFIG_APPLEDOUBLE */
141 static errno_t
post_rename(vnode_t fdvp
, vnode_t fvp
, vnode_t tdvp
, vnode_t tvp
);
144 * vnode_setneedinactive
146 * Description: Indicate that when the last iocount on this vnode goes away,
147 * and the usecount is also zero, we should inform the filesystem
150 * Parameters: vnode_t vnode to mark
154 * Notes: Notably used when we're deleting a file--we need not have a
155 * usecount, so VNOP_INACTIVE may not get called by anyone. We
156 * want it called when we drop our iocount.
159 vnode_setneedinactive(vnode_t vp
)
164 vp
->v_lflag
|= VL_NEEDINACTIVE
;
169 /* ====================================================================== */
170 /* ************ EXTERNAL KERNEL APIS ********************************** */
171 /* ====================================================================== */
174 * implementations of exported VFS operations
177 VFS_MOUNT(mount_t mp
, vnode_t devvp
, user_addr_t data
, vfs_context_t ctx
)
181 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_mount
== 0))
184 if (vfs_context_is64bit(ctx
)) {
185 if (vfs_64bitready(mp
)) {
186 error
= (*mp
->mnt_op
->vfs_mount
)(mp
, devvp
, data
, ctx
);
193 error
= (*mp
->mnt_op
->vfs_mount
)(mp
, devvp
, data
, ctx
);
200 VFS_START(mount_t mp
, int flags
, vfs_context_t ctx
)
204 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_start
== 0))
207 error
= (*mp
->mnt_op
->vfs_start
)(mp
, flags
, ctx
);
213 VFS_UNMOUNT(mount_t mp
, int flags
, vfs_context_t ctx
)
217 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_unmount
== 0))
220 error
= (*mp
->mnt_op
->vfs_unmount
)(mp
, flags
, ctx
);
227 * ENOTSUP Not supported
231 * Note: The return codes from the underlying VFS's root routine can't
232 * be fully enumerated here, since third party VFS authors may not
233 * limit their error returns to the ones documented here, even
234 * though this may result in some programs functioning incorrectly.
236 * The return codes documented above are those which may currently
237 * be returned by HFS from hfs_vfs_root, which is a simple wrapper
238 * for a call to hfs_vget on the volume mount point, not including
239 * additional error codes which may be propagated from underlying
240 * routines called by hfs_vget.
243 VFS_ROOT(mount_t mp
, struct vnode
** vpp
, vfs_context_t ctx
)
247 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_root
== 0))
251 ctx
= vfs_context_current();
254 error
= (*mp
->mnt_op
->vfs_root
)(mp
, vpp
, ctx
);
260 VFS_QUOTACTL(mount_t mp
, int cmd
, uid_t uid
, caddr_t datap
, vfs_context_t ctx
)
264 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_quotactl
== 0))
267 error
= (*mp
->mnt_op
->vfs_quotactl
)(mp
, cmd
, uid
, datap
, ctx
);
273 VFS_GETATTR(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
277 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_getattr
== 0))
281 ctx
= vfs_context_current();
284 error
= (*mp
->mnt_op
->vfs_getattr
)(mp
, vfa
, ctx
);
290 VFS_SETATTR(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
294 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_setattr
== 0))
298 ctx
= vfs_context_current();
301 error
= (*mp
->mnt_op
->vfs_setattr
)(mp
, vfa
, ctx
);
307 VFS_SYNC(mount_t mp
, int flags
, vfs_context_t ctx
)
311 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_sync
== 0))
315 ctx
= vfs_context_current();
318 error
= (*mp
->mnt_op
->vfs_sync
)(mp
, flags
, ctx
);
324 VFS_VGET(mount_t mp
, ino64_t ino
, struct vnode
**vpp
, vfs_context_t ctx
)
328 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_vget
== 0))
332 ctx
= vfs_context_current();
335 error
= (*mp
->mnt_op
->vfs_vget
)(mp
, ino
, vpp
, ctx
);
341 VFS_FHTOVP(mount_t mp
, int fhlen
, unsigned char *fhp
, vnode_t
*vpp
, vfs_context_t ctx
)
345 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_fhtovp
== 0))
349 ctx
= vfs_context_current();
352 error
= (*mp
->mnt_op
->vfs_fhtovp
)(mp
, fhlen
, fhp
, vpp
, ctx
);
358 VFS_VPTOFH(struct vnode
*vp
, int *fhlenp
, unsigned char *fhp
, vfs_context_t ctx
)
362 if ((vp
->v_mount
== dead_mountp
) || (vp
->v_mount
->mnt_op
->vfs_vptofh
== 0))
366 ctx
= vfs_context_current();
369 error
= (*vp
->v_mount
->mnt_op
->vfs_vptofh
)(vp
, fhlenp
, fhp
, ctx
);
374 int VFS_IOCTL(struct mount
*mp
, u_long command
, caddr_t data
,
375 int flags
, vfs_context_t context
)
377 if (mp
== dead_mountp
|| !mp
->mnt_op
->vfs_ioctl
)
380 return mp
->mnt_op
->vfs_ioctl(mp
, command
, data
, flags
,
381 context
?: vfs_context_current());
385 VFS_VGET_SNAPDIR(mount_t mp
, vnode_t
*vpp
, vfs_context_t ctx
)
389 if ((mp
== dead_mountp
) || (mp
->mnt_op
->vfs_vget_snapdir
== 0))
393 ctx
= vfs_context_current();
395 error
= (*mp
->mnt_op
->vfs_vget_snapdir
)(mp
, vpp
, ctx
);
400 /* returns the cached throttle mask for the mount_t */
402 vfs_throttle_mask(mount_t mp
)
404 return(mp
->mnt_throttle_mask
);
407 /* returns a copy of vfs type name for the mount_t */
409 vfs_name(mount_t mp
, char *buffer
)
411 strncpy(buffer
, mp
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
414 /* returns vfs type number for the mount_t */
416 vfs_typenum(mount_t mp
)
418 return(mp
->mnt_vtable
->vfc_typenum
);
421 /* Safe to cast to "struct label*"; returns "void*" to limit dependence of mount.h on security headers. */
423 vfs_mntlabel(mount_t mp
)
425 return (void*)mp
->mnt_mntlabel
;
428 /* returns command modifier flags of mount_t ie. MNT_CMDFLAGS */
430 vfs_flags(mount_t mp
)
432 return((uint64_t)(mp
->mnt_flag
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
)));
435 /* set any of the command modifier flags(MNT_CMDFLAGS) in mount_t */
437 vfs_setflags(mount_t mp
, uint64_t flags
)
439 uint32_t lflags
= (uint32_t)(flags
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
));
442 mp
->mnt_flag
|= lflags
;
446 /* clear any of the command modifier flags(MNT_CMDFLAGS) in mount_t */
448 vfs_clearflags(mount_t mp
, uint64_t flags
)
450 uint32_t lflags
= (uint32_t)(flags
& (MNT_CMDFLAGS
| MNT_VISFLAGMASK
));
453 mp
->mnt_flag
&= ~lflags
;
457 /* Is the mount_t ronly and upgrade read/write requested? */
459 vfs_iswriteupgrade(mount_t mp
) /* ronly && MNTK_WANTRDWR */
461 return ((mp
->mnt_flag
& MNT_RDONLY
) && (mp
->mnt_kern_flag
& MNTK_WANTRDWR
));
465 /* Is the mount_t mounted ronly */
467 vfs_isrdonly(mount_t mp
)
469 return (mp
->mnt_flag
& MNT_RDONLY
);
472 /* Is the mount_t mounted for filesystem synchronous writes? */
474 vfs_issynchronous(mount_t mp
)
476 return (mp
->mnt_flag
& MNT_SYNCHRONOUS
);
479 /* Is the mount_t mounted read/write? */
481 vfs_isrdwr(mount_t mp
)
483 return ((mp
->mnt_flag
& MNT_RDONLY
) == 0);
487 /* Is mount_t marked for update (ie MNT_UPDATE) */
489 vfs_isupdate(mount_t mp
)
491 return (mp
->mnt_flag
& MNT_UPDATE
);
495 /* Is mount_t marked for reload (ie MNT_RELOAD) */
497 vfs_isreload(mount_t mp
)
499 return ((mp
->mnt_flag
& MNT_UPDATE
) && (mp
->mnt_flag
& MNT_RELOAD
));
502 /* Is mount_t marked for forced unmount (ie MNT_FORCE or MNTK_FRCUNMOUNT) */
504 vfs_isforce(mount_t mp
)
506 if (mp
->mnt_lflag
& MNT_LFORCE
)
513 vfs_isunmount(mount_t mp
)
515 if ((mp
->mnt_lflag
& MNT_LUNMOUNT
)) {
523 vfs_64bitready(mount_t mp
)
525 if ((mp
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
))
533 vfs_authcache_ttl(mount_t mp
)
535 if ( (mp
->mnt_kern_flag
& (MNTK_AUTH_OPAQUE
| MNTK_AUTH_CACHE_TTL
)) )
536 return (mp
->mnt_authcache_ttl
);
538 return (CACHED_RIGHT_INFINITE_TTL
);
542 vfs_setauthcache_ttl(mount_t mp
, int ttl
)
545 mp
->mnt_kern_flag
|= MNTK_AUTH_CACHE_TTL
;
546 mp
->mnt_authcache_ttl
= ttl
;
551 vfs_clearauthcache_ttl(mount_t mp
)
554 mp
->mnt_kern_flag
&= ~MNTK_AUTH_CACHE_TTL
;
556 * back to the default TTL value in case
557 * MNTK_AUTH_OPAQUE is set on this mount
559 mp
->mnt_authcache_ttl
= CACHED_LOOKUP_RIGHT_TTL
;
564 vfs_authopaque(mount_t mp
)
566 if ((mp
->mnt_kern_flag
& MNTK_AUTH_OPAQUE
))
573 vfs_authopaqueaccess(mount_t mp
)
575 if ((mp
->mnt_kern_flag
& MNTK_AUTH_OPAQUE_ACCESS
))
582 vfs_setauthopaque(mount_t mp
)
585 mp
->mnt_kern_flag
|= MNTK_AUTH_OPAQUE
;
590 vfs_setauthopaqueaccess(mount_t mp
)
593 mp
->mnt_kern_flag
|= MNTK_AUTH_OPAQUE_ACCESS
;
598 vfs_clearauthopaque(mount_t mp
)
601 mp
->mnt_kern_flag
&= ~MNTK_AUTH_OPAQUE
;
606 vfs_clearauthopaqueaccess(mount_t mp
)
609 mp
->mnt_kern_flag
&= ~MNTK_AUTH_OPAQUE_ACCESS
;
614 vfs_setextendedsecurity(mount_t mp
)
617 mp
->mnt_kern_flag
|= MNTK_EXTENDED_SECURITY
;
622 vfs_clearextendedsecurity(mount_t mp
)
625 mp
->mnt_kern_flag
&= ~MNTK_EXTENDED_SECURITY
;
630 vfs_setnoswap(mount_t mp
)
633 mp
->mnt_kern_flag
|= MNTK_NOSWAP
;
638 vfs_clearnoswap(mount_t mp
)
641 mp
->mnt_kern_flag
&= ~MNTK_NOSWAP
;
646 vfs_extendedsecurity(mount_t mp
)
648 return(mp
->mnt_kern_flag
& MNTK_EXTENDED_SECURITY
);
651 /* returns the max size of short symlink in this mount_t */
653 vfs_maxsymlen(mount_t mp
)
655 return(mp
->mnt_maxsymlinklen
);
658 /* set max size of short symlink on mount_t */
660 vfs_setmaxsymlen(mount_t mp
, uint32_t symlen
)
662 mp
->mnt_maxsymlinklen
= symlen
;
665 /* return a pointer to the RO vfs_statfs associated with mount_t */
667 vfs_statfs(mount_t mp
)
669 return(&mp
->mnt_vfsstat
);
673 vfs_getattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
677 if ((error
= VFS_GETATTR(mp
, vfa
, ctx
)) != 0)
681 * If we have a filesystem create time, use it to default some others.
683 if (VFSATTR_IS_SUPPORTED(vfa
, f_create_time
)) {
684 if (VFSATTR_IS_ACTIVE(vfa
, f_modify_time
) && !VFSATTR_IS_SUPPORTED(vfa
, f_modify_time
))
685 VFSATTR_RETURN(vfa
, f_modify_time
, vfa
->f_create_time
);
692 vfs_setattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
696 if (vfs_isrdonly(mp
))
699 error
= VFS_SETATTR(mp
, vfa
, ctx
);
702 * If we had alternate ways of setting vfs attributes, we'd
709 /* return the private data handle stored in mount_t */
711 vfs_fsprivate(mount_t mp
)
713 return(mp
->mnt_data
);
716 /* set the private data handle in mount_t */
718 vfs_setfsprivate(mount_t mp
, void *mntdata
)
721 mp
->mnt_data
= mntdata
;
725 /* query whether the mount point supports native EAs */
727 vfs_nativexattrs(mount_t mp
) {
728 return (mp
->mnt_kern_flag
& MNTK_EXTENDED_ATTRS
);
732 * return the block size of the underlying
733 * device associated with mount_t
736 vfs_devblocksize(mount_t mp
) {
738 return(mp
->mnt_devblocksize
);
742 * Returns vnode with an iocount that must be released with vnode_put()
745 vfs_vnodecovered(mount_t mp
)
747 vnode_t vp
= mp
->mnt_vnodecovered
;
748 if ((vp
== NULL
) || (vnode_getwithref(vp
) != 0)) {
756 * Returns device vnode backing a mountpoint with an iocount (if valid vnode exists).
757 * The iocount must be released with vnode_put(). Note that this KPI is subtle
758 * with respect to the validity of using this device vnode for anything substantial
759 * (which is discouraged). If commands are sent to the device driver without
760 * taking proper steps to ensure that the device is still open, chaos may ensue.
761 * Similarly, this routine should only be called if there is some guarantee that
762 * the mount itself is still valid.
765 vfs_devvp(mount_t mp
)
767 vnode_t vp
= mp
->mnt_devvp
;
769 if ((vp
!= NULLVP
) && (vnode_get(vp
) == 0)) {
777 * return the io attributes associated with mount_t
780 vfs_ioattr(mount_t mp
, struct vfsioattr
*ioattrp
)
782 ioattrp
->io_reserved
[0] = NULL
;
783 ioattrp
->io_reserved
[1] = NULL
;
785 ioattrp
->io_maxreadcnt
= MAXPHYS
;
786 ioattrp
->io_maxwritecnt
= MAXPHYS
;
787 ioattrp
->io_segreadcnt
= 32;
788 ioattrp
->io_segwritecnt
= 32;
789 ioattrp
->io_maxsegreadsize
= MAXPHYS
;
790 ioattrp
->io_maxsegwritesize
= MAXPHYS
;
791 ioattrp
->io_devblocksize
= DEV_BSIZE
;
792 ioattrp
->io_flags
= 0;
793 ioattrp
->io_max_swappin_available
= 0;
795 ioattrp
->io_maxreadcnt
= mp
->mnt_maxreadcnt
;
796 ioattrp
->io_maxwritecnt
= mp
->mnt_maxwritecnt
;
797 ioattrp
->io_segreadcnt
= mp
->mnt_segreadcnt
;
798 ioattrp
->io_segwritecnt
= mp
->mnt_segwritecnt
;
799 ioattrp
->io_maxsegreadsize
= mp
->mnt_maxsegreadsize
;
800 ioattrp
->io_maxsegwritesize
= mp
->mnt_maxsegwritesize
;
801 ioattrp
->io_devblocksize
= mp
->mnt_devblocksize
;
802 ioattrp
->io_flags
= mp
->mnt_ioflags
;
803 ioattrp
->io_max_swappin_available
= mp
->mnt_max_swappin_available
;
809 * set the IO attributes associated with mount_t
812 vfs_setioattr(mount_t mp
, struct vfsioattr
* ioattrp
)
816 mp
->mnt_maxreadcnt
= ioattrp
->io_maxreadcnt
;
817 mp
->mnt_maxwritecnt
= ioattrp
->io_maxwritecnt
;
818 mp
->mnt_segreadcnt
= ioattrp
->io_segreadcnt
;
819 mp
->mnt_segwritecnt
= ioattrp
->io_segwritecnt
;
820 mp
->mnt_maxsegreadsize
= ioattrp
->io_maxsegreadsize
;
821 mp
->mnt_maxsegwritesize
= ioattrp
->io_maxsegwritesize
;
822 mp
->mnt_devblocksize
= ioattrp
->io_devblocksize
;
823 mp
->mnt_ioflags
= ioattrp
->io_flags
;
824 mp
->mnt_max_swappin_available
= ioattrp
->io_max_swappin_available
;
828 * Add a new filesystem into the kernel specified in passed in
829 * vfstable structure. It fills in the vnode
830 * dispatch vector that is to be passed to when vnodes are created.
831 * It returns a handle which is to be used to when the FS is to be removed
833 typedef int (*PFI
)(void *);
834 extern int vfs_opv_numops
;
836 vfs_fsadd(struct vfs_fsentry
*vfe
, vfstable_t
*handle
)
838 struct vfstable
*newvfstbl
= NULL
;
840 int (***opv_desc_vector_p
)(void *);
841 int (**opv_desc_vector
)(void *);
842 struct vnodeopv_entry_desc
*opve_descp
;
848 * This routine is responsible for all the initialization that would
849 * ordinarily be done as part of the system startup;
852 if (vfe
== (struct vfs_fsentry
*)0)
855 desccount
= vfe
->vfe_vopcnt
;
856 if ((desccount
<=0) || ((desccount
> 8)) || (vfe
->vfe_vfsops
== (struct vfsops
*)NULL
)
857 || (vfe
->vfe_opvdescs
== (struct vnodeopv_desc
**)NULL
))
860 /* Non-threadsafe filesystems are not supported */
861 if ((vfe
->vfe_flags
& (VFS_TBLTHREADSAFE
| VFS_TBLFSNODELOCK
)) == 0) {
865 MALLOC(newvfstbl
, void *, sizeof(struct vfstable
), M_TEMP
,
867 bzero(newvfstbl
, sizeof(struct vfstable
));
868 newvfstbl
->vfc_vfsops
= vfe
->vfe_vfsops
;
869 strncpy(&newvfstbl
->vfc_name
[0], vfe
->vfe_fsname
, MFSNAMELEN
);
870 if ((vfe
->vfe_flags
& VFS_TBLNOTYPENUM
))
871 newvfstbl
->vfc_typenum
= maxvfstypenum
++;
873 newvfstbl
->vfc_typenum
= vfe
->vfe_fstypenum
;
875 newvfstbl
->vfc_refcount
= 0;
876 newvfstbl
->vfc_flags
= 0;
877 newvfstbl
->vfc_mountroot
= NULL
;
878 newvfstbl
->vfc_next
= NULL
;
879 newvfstbl
->vfc_vfsflags
= 0;
880 if (vfe
->vfe_flags
& VFS_TBL64BITREADY
)
881 newvfstbl
->vfc_vfsflags
|= VFC_VFS64BITREADY
;
882 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEINV2
)
883 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEINV2
;
884 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEOUTV2
)
885 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEOUTV2
;
886 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) == VFS_TBLLOCALVOL
)
887 newvfstbl
->vfc_flags
|= MNT_LOCAL
;
888 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) && (vfe
->vfe_flags
& VFS_TBLGENERICMNTARGS
) == 0)
889 newvfstbl
->vfc_vfsflags
|= VFC_VFSLOCALARGS
;
891 newvfstbl
->vfc_vfsflags
|= VFC_VFSGENERICARGS
;
893 if (vfe
->vfe_flags
& VFS_TBLNATIVEXATTR
)
894 newvfstbl
->vfc_vfsflags
|= VFC_VFSNATIVEXATTR
;
895 if (vfe
->vfe_flags
& VFS_TBLUNMOUNT_PREFLIGHT
)
896 newvfstbl
->vfc_vfsflags
|= VFC_VFSPREFLIGHT
;
897 if (vfe
->vfe_flags
& VFS_TBLREADDIR_EXTENDED
)
898 newvfstbl
->vfc_vfsflags
|= VFC_VFSREADDIR_EXTENDED
;
899 if (vfe
->vfe_flags
& VFS_TBLNOMACLABEL
)
900 newvfstbl
->vfc_vfsflags
|= VFC_VFSNOMACLABEL
;
901 if (vfe
->vfe_flags
& VFS_TBLVNOP_NOUPDATEID_RENAME
)
902 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_NOUPDATEID_RENAME
;
903 if (vfe
->vfe_flags
& VFS_TBLVNOP_SECLUDE_RENAME
)
904 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_SECLUDE_RENAME
;
905 if (vfe
->vfe_flags
& VFS_TBLCANMOUNTROOT
)
906 newvfstbl
->vfc_vfsflags
|= VFC_VFSCANMOUNTROOT
;
909 * Allocate and init the vectors.
910 * Also handle backwards compatibility.
912 * We allocate one large block to hold all <desccount>
913 * vnode operation vectors stored contiguously.
915 /* XXX - shouldn't be M_TEMP */
917 descsize
= desccount
* vfs_opv_numops
* sizeof(PFI
);
918 MALLOC(descptr
, PFI
*, descsize
,
920 bzero(descptr
, descsize
);
922 newvfstbl
->vfc_descptr
= descptr
;
923 newvfstbl
->vfc_descsize
= descsize
;
925 newvfstbl
->vfc_sysctl
= NULL
;
927 for (i
= 0; i
< desccount
; i
++ ) {
928 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
930 * Fill in the caller's pointer to the start of the i'th vector.
931 * They'll need to supply it when calling vnode_create.
933 opv_desc_vector
= descptr
+ i
* vfs_opv_numops
;
934 *opv_desc_vector_p
= opv_desc_vector
;
936 for (j
= 0; vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
].opve_op
; j
++) {
937 opve_descp
= &(vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
]);
939 /* Silently skip known-disabled operations */
940 if (opve_descp
->opve_op
->vdesc_flags
& VDESC_DISABLED
) {
941 printf("vfs_fsadd: Ignoring reference in %p to disabled operation %s.\n",
942 vfe
->vfe_opvdescs
[i
], opve_descp
->opve_op
->vdesc_name
);
947 * Sanity check: is this operation listed
948 * in the list of operations? We check this
949 * by seeing if its offset is zero. Since
950 * the default routine should always be listed
951 * first, it should be the only one with a zero
952 * offset. Any other operation with a zero
953 * offset is probably not listed in
954 * vfs_op_descs, and so is probably an error.
956 * A panic here means the layer programmer
957 * has committed the all-too common bug
958 * of adding a new operation to the layer's
959 * list of vnode operations but
960 * not adding the operation to the system-wide
961 * list of supported operations.
963 if (opve_descp
->opve_op
->vdesc_offset
== 0 &&
964 opve_descp
->opve_op
!= VDESC(vnop_default
)) {
965 printf("vfs_fsadd: operation %s not listed in %s.\n",
966 opve_descp
->opve_op
->vdesc_name
,
968 panic("vfs_fsadd: bad operation");
971 * Fill in this entry.
973 opv_desc_vector
[opve_descp
->opve_op
->vdesc_offset
] =
974 opve_descp
->opve_impl
;
979 * Finally, go back and replace unfilled routines
980 * with their default. (Sigh, an O(n^3) algorithm. I
981 * could make it better, but that'd be work, and n is small.)
983 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
986 * Force every operations vector to have a default routine.
988 opv_desc_vector
= *opv_desc_vector_p
;
989 if (opv_desc_vector
[VOFFSET(vnop_default
)] == NULL
)
990 panic("vfs_fsadd: operation vector without default routine.");
991 for (j
= 0; j
< vfs_opv_numops
; j
++)
992 if (opv_desc_vector
[j
] == NULL
)
994 opv_desc_vector
[VOFFSET(vnop_default
)];
996 } /* end of each vnodeopv_desc parsing */
1000 *handle
= vfstable_add(newvfstbl
);
1002 if (newvfstbl
->vfc_typenum
<= maxvfstypenum
)
1003 maxvfstypenum
= newvfstbl
->vfc_typenum
+ 1;
1005 if (newvfstbl
->vfc_vfsops
->vfs_init
) {
1006 struct vfsconf vfsc
;
1007 bzero(&vfsc
, sizeof(struct vfsconf
));
1008 vfsc
.vfc_reserved1
= 0;
1009 bcopy((*handle
)->vfc_name
, vfsc
.vfc_name
, sizeof(vfsc
.vfc_name
));
1010 vfsc
.vfc_typenum
= (*handle
)->vfc_typenum
;
1011 vfsc
.vfc_refcount
= (*handle
)->vfc_refcount
;
1012 vfsc
.vfc_flags
= (*handle
)->vfc_flags
;
1013 vfsc
.vfc_reserved2
= 0;
1014 vfsc
.vfc_reserved3
= 0;
1016 (*newvfstbl
->vfc_vfsops
->vfs_init
)(&vfsc
);
1019 FREE(newvfstbl
, M_TEMP
);
1025 * Removes the filesystem from kernel.
1026 * The argument passed in is the handle that was given when
1027 * file system was added
1030 vfs_fsremove(vfstable_t handle
)
1032 struct vfstable
* vfstbl
= (struct vfstable
*)handle
;
1033 void *old_desc
= NULL
;
1036 /* Preflight check for any mounts */
1038 if ( vfstbl
->vfc_refcount
!= 0 ) {
1039 mount_list_unlock();
1044 * save the old descriptor; the free cannot occur unconditionally,
1045 * since vfstable_del() may fail.
1047 if (vfstbl
->vfc_descptr
&& vfstbl
->vfc_descsize
) {
1048 old_desc
= vfstbl
->vfc_descptr
;
1050 err
= vfstable_del(vfstbl
);
1052 mount_list_unlock();
1054 /* free the descriptor if the delete was successful */
1055 if (err
== 0 && old_desc
) {
1056 FREE(old_desc
, M_TEMP
);
1062 void vfs_setowner(mount_t mp
, uid_t uid
, gid_t gid
)
1064 mp
->mnt_fsowner
= uid
;
1065 mp
->mnt_fsgroup
= gid
;
1069 * Callers should be careful how they use this; accessing
1070 * mnt_last_write_completed_timestamp is not thread-safe. Writing to
1071 * it isn't either. Point is: be prepared to deal with strange values
1074 uint64_t vfs_idle_time(mount_t mp
)
1076 if (mp
->mnt_pending_write_size
)
1084 - mp
->mnt_last_write_completed_timestamp
.tv_sec
) * 1000000
1085 + now
.tv_usec
- mp
->mnt_last_write_completed_timestamp
.tv_usec
);
1089 vfs_context_pid(vfs_context_t ctx
)
1091 return (proc_pid(vfs_context_proc(ctx
)));
1095 vfs_context_suser(vfs_context_t ctx
)
1097 return (suser(ctx
->vc_ucred
, NULL
));
1101 * Return bit field of signals posted to all threads in the context's process.
1103 * XXX Signals should be tied to threads, not processes, for most uses of this
1107 vfs_context_issignal(vfs_context_t ctx
, sigset_t mask
)
1109 proc_t p
= vfs_context_proc(ctx
);
1111 return(proc_pendingsignals(p
, mask
));
1116 vfs_context_is64bit(vfs_context_t ctx
)
1118 proc_t proc
= vfs_context_proc(ctx
);
1121 return(proc_is64bit(proc
));
1129 * Description: Given a vfs_context_t, return the proc_t associated with it.
1131 * Parameters: vfs_context_t The context to use
1133 * Returns: proc_t The process for this context
1135 * Notes: This function will return the current_proc() if any of the
1136 * following conditions are true:
1138 * o The supplied context pointer is NULL
1139 * o There is no Mach thread associated with the context
1140 * o There is no Mach task associated with the Mach thread
1141 * o There is no proc_t associated with the Mach task
1142 * o The proc_t has no per process open file table
1143 * o The proc_t is post-vfork()
1145 * This causes this function to return a value matching as
1146 * closely as possible the previous behaviour, while at the
1147 * same time avoiding the task lending that results from vfork()
1150 vfs_context_proc(vfs_context_t ctx
)
1154 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1155 proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
);
1156 if (proc
!= NULL
&& (proc
->p_fd
== NULL
|| (proc
->p_lflag
& P_LVFORK
)))
1159 return(proc
== NULL
? current_proc() : proc
);
1163 * vfs_context_get_special_port
1165 * Description: Return the requested special port from the task associated
1166 * with the given context.
1168 * Parameters: vfs_context_t The context to use
1169 * int Index of special port
1170 * ipc_port_t * Pointer to returned port
1172 * Returns: kern_return_t see task_get_special_port()
1175 vfs_context_get_special_port(vfs_context_t ctx
, int which
, ipc_port_t
*portp
)
1179 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1180 task
= get_threadtask(ctx
->vc_thread
);
1182 return task_get_special_port(task
, which
, portp
);
1186 * vfs_context_set_special_port
1188 * Description: Set the requested special port in the task associated
1189 * with the given context.
1191 * Parameters: vfs_context_t The context to use
1192 * int Index of special port
1193 * ipc_port_t New special port
1195 * Returns: kern_return_t see task_set_special_port()
1198 vfs_context_set_special_port(vfs_context_t ctx
, int which
, ipc_port_t port
)
1202 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1203 task
= get_threadtask(ctx
->vc_thread
);
1205 return task_set_special_port(task
, which
, port
);
1209 * vfs_context_thread
1211 * Description: Return the Mach thread associated with a vfs_context_t
1213 * Parameters: vfs_context_t The context to use
1215 * Returns: thread_t The thread for this context, or
1216 * NULL, if there is not one.
1218 * Notes: NULL thread_t's are legal, but discouraged. They occur only
1219 * as a result of a static vfs_context_t declaration in a function
1220 * and will result in this function returning NULL.
1222 * This is intentional; this function should NOT return the
1223 * current_thread() in this case.
1226 vfs_context_thread(vfs_context_t ctx
)
1228 return(ctx
->vc_thread
);
1235 * Description: Returns a reference on the vnode for the current working
1236 * directory for the supplied context
1238 * Parameters: vfs_context_t The context to use
1240 * Returns: vnode_t The current working directory
1243 * Notes: The function first attempts to obtain the current directory
1244 * from the thread, and if it is not present there, falls back
1245 * to obtaining it from the process instead. If it can't be
1246 * obtained from either place, we return NULLVP.
1249 vfs_context_cwd(vfs_context_t ctx
)
1251 vnode_t cwd
= NULLVP
;
1253 if(ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1254 uthread_t uth
= get_bsdthread_info(ctx
->vc_thread
);
1258 * Get the cwd from the thread; if there isn't one, get it
1259 * from the process, instead.
1261 if ((cwd
= uth
->uu_cdir
) == NULLVP
&&
1262 (proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
)) != NULL
&&
1264 cwd
= proc
->p_fd
->fd_cdir
;
1271 * vfs_context_create
1273 * Description: Allocate and initialize a new context.
1275 * Parameters: vfs_context_t: Context to copy, or NULL for new
1277 * Returns: Pointer to new context
1279 * Notes: Copy cred and thread from argument, if available; else
1280 * initialize with current thread and new cred. Returns
1281 * with a reference held on the credential.
1284 vfs_context_create(vfs_context_t ctx
)
1286 vfs_context_t newcontext
;
1288 newcontext
= (vfs_context_t
)kalloc(sizeof(struct vfs_context
));
1291 kauth_cred_t safecred
;
1293 newcontext
->vc_thread
= ctx
->vc_thread
;
1294 safecred
= ctx
->vc_ucred
;
1296 newcontext
->vc_thread
= current_thread();
1297 safecred
= kauth_cred_get();
1299 if (IS_VALID_CRED(safecred
))
1300 kauth_cred_ref(safecred
);
1301 newcontext
->vc_ucred
= safecred
;
1309 vfs_context_current(void)
1311 vfs_context_t ctx
= NULL
;
1312 volatile uthread_t ut
= (uthread_t
)get_bsdthread_info(current_thread());
1315 if (ut
->uu_context
.vc_ucred
!= NULL
) {
1316 ctx
= &ut
->uu_context
;
1320 return(ctx
== NULL
? vfs_context_kernel() : ctx
);
1327 * Dangerous hack - adopt the first kernel thread as the current thread, to
1328 * get to the vfs_context_t in the uthread associated with a kernel thread.
1329 * This is used by UDF to make the call into IOCDMediaBSDClient,
1330 * IOBDMediaBSDClient, and IODVDMediaBSDClient to determine whether the
1331 * ioctl() is being called from kernel or user space (and all this because
1332 * we do not pass threads into our ioctl()'s, instead of processes).
1334 * This is also used by imageboot_setup(), called early from bsd_init() after
1335 * kernproc has been given a credential.
1337 * Note: The use of proc_thread() here is a convenience to avoid inclusion
1338 * of many Mach headers to do the reference directly rather than indirectly;
1339 * we will need to forego this convenience when we reture proc_thread().
1341 static struct vfs_context kerncontext
;
1343 vfs_context_kernel(void)
1345 if (kerncontext
.vc_ucred
== NOCRED
)
1346 kerncontext
.vc_ucred
= kernproc
->p_ucred
;
1347 if (kerncontext
.vc_thread
== NULL
)
1348 kerncontext
.vc_thread
= proc_thread(kernproc
);
1350 return(&kerncontext
);
1355 vfs_context_rele(vfs_context_t ctx
)
1358 if (IS_VALID_CRED(ctx
->vc_ucred
))
1359 kauth_cred_unref(&ctx
->vc_ucred
);
1360 kfree(ctx
, sizeof(struct vfs_context
));
1367 vfs_context_ucred(vfs_context_t ctx
)
1369 return (ctx
->vc_ucred
);
1373 * Return true if the context is owned by the superuser.
1376 vfs_context_issuser(vfs_context_t ctx
)
1378 return(kauth_cred_issuser(vfs_context_ucred(ctx
)));
1381 int vfs_context_iskernel(vfs_context_t ctx
)
1383 return ctx
== &kerncontext
;
1387 * Given a context, for all fields of vfs_context_t which
1388 * are not held with a reference, set those fields to the
1389 * values for the current execution context. Currently, this
1390 * just means the vc_thread.
1392 * Returns: 0 for success, nonzero for failure
1394 * The intended use is:
1395 * 1. vfs_context_create() gets the caller a context
1396 * 2. vfs_context_bind() sets the unrefcounted data
1397 * 3. vfs_context_rele() releases the context
1401 vfs_context_bind(vfs_context_t ctx
)
1403 ctx
->vc_thread
= current_thread();
1407 int vfs_isswapmount(mount_t mnt
)
1409 return mnt
&& ISSET(mnt
->mnt_kern_flag
, MNTK_SWAP_MOUNT
) ? 1 : 0;
1412 /* XXXXXXXXXXXXXX VNODE KAPIS XXXXXXXXXXXXXXXXXXXXXXXXX */
1416 * Convert between vnode types and inode formats (since POSIX.1
1417 * defines mode word of stat structure in terms of inode formats).
1420 vnode_iftovt(int mode
)
1422 return(iftovt_tab
[((mode
) & S_IFMT
) >> 12]);
1426 vnode_vttoif(enum vtype indx
)
1428 return(vttoif_tab
[(int)(indx
)]);
1432 vnode_makeimode(int indx
, int mode
)
1434 return (int)(VTTOIF(indx
) | (mode
));
1439 * vnode manipulation functions.
1442 /* returns system root vnode iocount; It should be released using vnode_put() */
1448 error
= vnode_get(rootvnode
);
1450 return ((vnode_t
)0);
1457 vnode_vid(vnode_t vp
)
1459 return ((uint32_t)(vp
->v_id
));
1463 vnode_mount(vnode_t vp
)
1465 return (vp
->v_mount
);
1470 vnode_mountdevvp(vnode_t vp
)
1473 return (vp
->v_mount
->mnt_devvp
);
1475 return ((vnode_t
)0);
1480 vnode_mountedhere(vnode_t vp
)
1484 if ((vp
->v_type
== VDIR
) && ((mp
= vp
->v_mountedhere
) != NULL
) &&
1485 (mp
->mnt_vnodecovered
== vp
))
1488 return (mount_t
)NULL
;
1491 /* returns vnode type of vnode_t */
1493 vnode_vtype(vnode_t vp
)
1495 return (vp
->v_type
);
1498 /* returns FS specific node saved in vnode */
1500 vnode_fsnode(vnode_t vp
)
1502 return (vp
->v_data
);
1506 vnode_clearfsnode(vnode_t vp
)
1512 vnode_specrdev(vnode_t vp
)
1518 /* Accessor functions */
1519 /* is vnode_t a root vnode */
1521 vnode_isvroot(vnode_t vp
)
1523 return ((vp
->v_flag
& VROOT
)? 1 : 0);
1526 /* is vnode_t a system vnode */
1528 vnode_issystem(vnode_t vp
)
1530 return ((vp
->v_flag
& VSYSTEM
)? 1 : 0);
1533 /* is vnode_t a swap file vnode */
1535 vnode_isswap(vnode_t vp
)
1537 return ((vp
->v_flag
& VSWAP
)? 1 : 0);
1540 /* is vnode_t a tty */
1542 vnode_istty(vnode_t vp
)
1544 return ((vp
->v_flag
& VISTTY
) ? 1 : 0);
1547 /* if vnode_t mount operation in progress */
1549 vnode_ismount(vnode_t vp
)
1551 return ((vp
->v_flag
& VMOUNT
)? 1 : 0);
1554 /* is this vnode under recyle now */
1556 vnode_isrecycled(vnode_t vp
)
1560 vnode_lock_spin(vp
);
1561 ret
= (vp
->v_lflag
& (VL_TERMINATE
|VL_DEAD
))? 1 : 0;
1566 /* vnode was created by background task requesting rapid aging
1567 and has not since been referenced by a normal task */
1569 vnode_israge(vnode_t vp
)
1571 return ((vp
->v_flag
& VRAGE
)? 1 : 0);
1575 vnode_needssnapshots(vnode_t vp
)
1577 return ((vp
->v_flag
& VNEEDSSNAPSHOT
)? 1 : 0);
1581 /* Check the process/thread to see if we should skip atime updates */
1583 vfs_ctx_skipatime (vfs_context_t ctx
) {
1588 proc
= vfs_context_proc(ctx
);
1589 thr
= vfs_context_thread (ctx
);
1591 /* Validate pointers in case we were invoked via a kernel context */
1593 ut
= get_bsdthread_info (thr
);
1595 if (proc
->p_lflag
& P_LRAGE_VNODES
) {
1600 if (ut
->uu_flag
& UT_RAGE_VNODES
) {
1608 /* is vnode_t marked to not keep data cached once it's been consumed */
1610 vnode_isnocache(vnode_t vp
)
1612 return ((vp
->v_flag
& VNOCACHE_DATA
)? 1 : 0);
1616 * has sequential readahead been disabled on this vnode
1619 vnode_isnoreadahead(vnode_t vp
)
1621 return ((vp
->v_flag
& VRAOFF
)? 1 : 0);
1625 vnode_is_openevt(vnode_t vp
)
1627 return ((vp
->v_flag
& VOPENEVT
)? 1 : 0);
1630 /* is vnode_t a standard one? */
1632 vnode_isstandard(vnode_t vp
)
1634 return ((vp
->v_flag
& VSTANDARD
)? 1 : 0);
1637 /* don't vflush() if SKIPSYSTEM */
1639 vnode_isnoflush(vnode_t vp
)
1641 return ((vp
->v_flag
& VNOFLUSH
)? 1 : 0);
1644 /* is vnode_t a regular file */
1646 vnode_isreg(vnode_t vp
)
1648 return ((vp
->v_type
== VREG
)? 1 : 0);
1651 /* is vnode_t a directory? */
1653 vnode_isdir(vnode_t vp
)
1655 return ((vp
->v_type
== VDIR
)? 1 : 0);
1658 /* is vnode_t a symbolic link ? */
1660 vnode_islnk(vnode_t vp
)
1662 return ((vp
->v_type
== VLNK
)? 1 : 0);
1666 vnode_lookup_continue_needed(vnode_t vp
, struct componentname
*cnp
)
1668 struct nameidata
*ndp
= cnp
->cn_ndp
;
1671 panic("vnode_lookup_continue_needed(): cnp->cn_ndp is NULL\n");
1674 if (vnode_isdir(vp
)) {
1675 if (vp
->v_mountedhere
!= NULL
) {
1680 if (vp
->v_resolve
) {
1683 #endif /* CONFIG_TRIGGERS */
1688 if (vnode_islnk(vp
)) {
1689 /* From lookup(): || *ndp->ni_next == '/') No need for this, we know we're NULL-terminated here */
1690 if (cnp
->cn_flags
& FOLLOW
) {
1693 if (ndp
->ni_flag
& NAMEI_TRAILINGSLASH
) {
1701 ndp
->ni_flag
|= NAMEI_CONTLOOKUP
;
1702 return EKEEPLOOKING
;
1705 /* is vnode_t a fifo ? */
1707 vnode_isfifo(vnode_t vp
)
1709 return ((vp
->v_type
== VFIFO
)? 1 : 0);
1712 /* is vnode_t a block device? */
1714 vnode_isblk(vnode_t vp
)
1716 return ((vp
->v_type
== VBLK
)? 1 : 0);
1720 vnode_isspec(vnode_t vp
)
1722 return (((vp
->v_type
== VCHR
) || (vp
->v_type
== VBLK
)) ? 1 : 0);
1725 /* is vnode_t a char device? */
1727 vnode_ischr(vnode_t vp
)
1729 return ((vp
->v_type
== VCHR
)? 1 : 0);
1732 /* is vnode_t a socket? */
1734 vnode_issock(vnode_t vp
)
1736 return ((vp
->v_type
== VSOCK
)? 1 : 0);
1739 /* is vnode_t a device with multiple active vnodes referring to it? */
1741 vnode_isaliased(vnode_t vp
)
1743 enum vtype vt
= vp
->v_type
;
1744 if (!((vt
== VCHR
) || (vt
== VBLK
))) {
1747 return (vp
->v_specflags
& SI_ALIASED
);
1751 /* is vnode_t a named stream? */
1753 vnode_isnamedstream(
1762 return ((vp
->v_flag
& VISNAMEDSTREAM
) ? 1 : 0);
1778 return ((vp
->v_flag
& VISSHADOW
) ? 1 : 0);
1784 /* does vnode have associated named stream vnodes ? */
1786 vnode_hasnamedstreams(
1795 return ((vp
->v_lflag
& VL_HASSTREAMS
) ? 1 : 0);
1800 /* TBD: set vnode_t to not cache data after it is consumed once; used for quota */
1802 vnode_setnocache(vnode_t vp
)
1804 vnode_lock_spin(vp
);
1805 vp
->v_flag
|= VNOCACHE_DATA
;
1810 vnode_clearnocache(vnode_t vp
)
1812 vnode_lock_spin(vp
);
1813 vp
->v_flag
&= ~VNOCACHE_DATA
;
1818 vnode_set_openevt(vnode_t vp
)
1820 vnode_lock_spin(vp
);
1821 vp
->v_flag
|= VOPENEVT
;
1826 vnode_clear_openevt(vnode_t vp
)
1828 vnode_lock_spin(vp
);
1829 vp
->v_flag
&= ~VOPENEVT
;
1835 vnode_setnoreadahead(vnode_t vp
)
1837 vnode_lock_spin(vp
);
1838 vp
->v_flag
|= VRAOFF
;
1843 vnode_clearnoreadahead(vnode_t vp
)
1845 vnode_lock_spin(vp
);
1846 vp
->v_flag
&= ~VRAOFF
;
1851 vnode_isfastdevicecandidate(vnode_t vp
)
1853 return ((vp
->v_flag
& VFASTDEVCANDIDATE
)? 1 : 0);
1857 vnode_setfastdevicecandidate(vnode_t vp
)
1859 vnode_lock_spin(vp
);
1860 vp
->v_flag
|= VFASTDEVCANDIDATE
;
1865 vnode_clearfastdevicecandidate(vnode_t vp
)
1867 vnode_lock_spin(vp
);
1868 vp
->v_flag
&= ~VFASTDEVCANDIDATE
;
1873 vnode_isautocandidate(vnode_t vp
)
1875 return ((vp
->v_flag
& VAUTOCANDIDATE
)? 1 : 0);
1879 vnode_setautocandidate(vnode_t vp
)
1881 vnode_lock_spin(vp
);
1882 vp
->v_flag
|= VAUTOCANDIDATE
;
1887 vnode_clearautocandidate(vnode_t vp
)
1889 vnode_lock_spin(vp
);
1890 vp
->v_flag
&= ~VAUTOCANDIDATE
;
1897 /* mark vnode_t to skip vflush() is SKIPSYSTEM */
1899 vnode_setnoflush(vnode_t vp
)
1901 vnode_lock_spin(vp
);
1902 vp
->v_flag
|= VNOFLUSH
;
1907 vnode_clearnoflush(vnode_t vp
)
1909 vnode_lock_spin(vp
);
1910 vp
->v_flag
&= ~VNOFLUSH
;
1915 /* is vnode_t a blkdevice and has a FS mounted on it */
1917 vnode_ismountedon(vnode_t vp
)
1919 return ((vp
->v_specflags
& SI_MOUNTEDON
)? 1 : 0);
1923 vnode_setmountedon(vnode_t vp
)
1925 vnode_lock_spin(vp
);
1926 vp
->v_specflags
|= SI_MOUNTEDON
;
1931 vnode_clearmountedon(vnode_t vp
)
1933 vnode_lock_spin(vp
);
1934 vp
->v_specflags
&= ~SI_MOUNTEDON
;
1940 vnode_settag(vnode_t vp
, int tag
)
1947 vnode_tag(vnode_t vp
)
1953 vnode_parent(vnode_t vp
)
1956 return(vp
->v_parent
);
1960 vnode_setparent(vnode_t vp
, vnode_t dvp
)
1966 vnode_setname(vnode_t vp
, char * name
)
1971 /* return the registered FS name when adding the FS to kernel */
1973 vnode_vfsname(vnode_t vp
, char * buf
)
1975 strlcpy(buf
, vp
->v_mount
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
1978 /* return the FS type number */
1980 vnode_vfstypenum(vnode_t vp
)
1982 return(vp
->v_mount
->mnt_vtable
->vfc_typenum
);
1986 vnode_vfs64bitready(vnode_t vp
)
1990 * Checking for dead_mountp is a bit of a hack for SnowLeopard: <rdar://problem/6269051>
1992 if ((vp
->v_mount
!= dead_mountp
) && (vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
))
2000 /* return the visible flags on associated mount point of vnode_t */
2002 vnode_vfsvisflags(vnode_t vp
)
2004 return(vp
->v_mount
->mnt_flag
& MNT_VISFLAGMASK
);
2007 /* return the command modifier flags on associated mount point of vnode_t */
2009 vnode_vfscmdflags(vnode_t vp
)
2011 return(vp
->v_mount
->mnt_flag
& MNT_CMDFLAGS
);
2014 /* return the max symlink of short links of vnode_t */
2016 vnode_vfsmaxsymlen(vnode_t vp
)
2018 return(vp
->v_mount
->mnt_maxsymlinklen
);
2021 /* return a pointer to the RO vfs_statfs associated with vnode_t's mount point */
2023 vnode_vfsstatfs(vnode_t vp
)
2025 return(&vp
->v_mount
->mnt_vfsstat
);
2028 /* return a handle to the FSs specific private handle associated with vnode_t's mount point */
2030 vnode_vfsfsprivate(vnode_t vp
)
2032 return(vp
->v_mount
->mnt_data
);
2035 /* is vnode_t in a rdonly mounted FS */
2037 vnode_vfsisrdonly(vnode_t vp
)
2039 return ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
)? 1 : 0);
2043 vnode_compound_rename_available(vnode_t vp
)
2045 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RENAME
);
2048 vnode_compound_rmdir_available(vnode_t vp
)
2050 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RMDIR
);
2053 vnode_compound_mkdir_available(vnode_t vp
)
2055 return vnode_compound_op_available(vp
, COMPOUND_VNOP_MKDIR
);
2058 vnode_compound_remove_available(vnode_t vp
)
2060 return vnode_compound_op_available(vp
, COMPOUND_VNOP_REMOVE
);
2063 vnode_compound_open_available(vnode_t vp
)
2065 return vnode_compound_op_available(vp
, COMPOUND_VNOP_OPEN
);
2069 vnode_compound_op_available(vnode_t vp
, compound_vnop_id_t opid
)
2071 return ((vp
->v_mount
->mnt_compound_ops
& opid
) != 0);
2075 * Returns vnode ref to current working directory; if a per-thread current
2076 * working directory is in effect, return that instead of the per process one.
2078 * XXX Published, but not used.
2081 current_workingdir(void)
2083 return vfs_context_cwd(vfs_context_current());
2086 /* returns vnode ref to current root(chroot) directory */
2088 current_rootdir(void)
2090 proc_t proc
= current_proc();
2093 if ( (vp
= proc
->p_fd
->fd_rdir
) ) {
2094 if ( (vnode_getwithref(vp
)) )
2101 * Get a filesec and optional acl contents from an extended attribute.
2102 * Function will attempt to retrive ACL, UUID, and GUID information using a
2103 * read of a named extended attribute (KAUTH_FILESEC_XATTR).
2105 * Parameters: vp The vnode on which to operate.
2106 * fsecp The filesec (and ACL, if any) being
2108 * ctx The vnode context in which the
2109 * operation is to be attempted.
2111 * Returns: 0 Success
2114 * Notes: The kauth_filesec_t in '*fsecp', if retrieved, will be in
2115 * host byte order, as will be the ACL contents, if any.
2116 * Internally, we will cannonize these values from network (PPC)
2117 * byte order after we retrieve them so that the on-disk contents
2118 * of the extended attribute are identical for both PPC and Intel
2119 * (if we were not being required to provide this service via
2120 * fallback, this would be the job of the filesystem
2121 * 'VNOP_GETATTR' call).
2123 * We use ntohl() because it has a transitive property on Intel
2124 * machines and no effect on PPC mancines. This guarantees us
2126 * XXX: Deleting rather than ignoreing a corrupt security structure is
2127 * probably the only way to reset it without assistance from an
2128 * file system integrity checking tool. Right now we ignore it.
2130 * XXX: We should enummerate the possible errno values here, and where
2131 * in the code they originated.
2134 vnode_get_filesec(vnode_t vp
, kauth_filesec_t
*fsecp
, vfs_context_t ctx
)
2136 kauth_filesec_t fsec
;
2139 size_t xsize
, rsize
;
2141 uint32_t host_fsec_magic
;
2142 uint32_t host_acl_entrycount
;
2147 /* find out how big the EA is */
2148 error
= vn_getxattr(vp
, KAUTH_FILESEC_XATTR
, NULL
, &xsize
, XATTR_NOSECURITY
, ctx
);
2150 /* no EA, no filesec */
2151 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
))
2153 /* either way, we are done */
2158 * To be valid, a kauth_filesec_t must be large enough to hold a zero
2159 * ACE entrly ACL, and if it's larger than that, it must have the right
2160 * number of bytes such that it contains an atomic number of ACEs,
2161 * rather than partial entries. Otherwise, we ignore it.
2163 if (!KAUTH_FILESEC_VALID(xsize
)) {
2164 KAUTH_DEBUG(" ERROR - Bogus kauth_fiilesec_t: %ld bytes", xsize
);
2169 /* how many entries would fit? */
2170 fsec_size
= KAUTH_FILESEC_COUNT(xsize
);
2172 /* get buffer and uio */
2173 if (((fsec
= kauth_filesec_alloc(fsec_size
)) == NULL
) ||
2174 ((fsec_uio
= uio_create(1, 0, UIO_SYSSPACE
, UIO_READ
)) == NULL
) ||
2175 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), xsize
)) {
2176 KAUTH_DEBUG(" ERROR - could not allocate iov to read ACL");
2181 /* read security attribute */
2183 if ((error
= vn_getxattr(vp
,
2184 KAUTH_FILESEC_XATTR
,
2190 /* no attribute - no security data */
2191 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
))
2193 /* either way, we are done */
2198 * Validate security structure; the validation must take place in host
2199 * byte order. If it's corrupt, we will just ignore it.
2202 /* Validate the size before trying to convert it */
2203 if (rsize
< KAUTH_FILESEC_SIZE(0)) {
2204 KAUTH_DEBUG("ACL - DATA TOO SMALL (%d)", rsize
);
2208 /* Validate the magic number before trying to convert it */
2209 host_fsec_magic
= ntohl(KAUTH_FILESEC_MAGIC
);
2210 if (fsec
->fsec_magic
!= host_fsec_magic
) {
2211 KAUTH_DEBUG("ACL - BAD MAGIC %x", host_fsec_magic
);
2215 /* Validate the entry count before trying to convert it. */
2216 host_acl_entrycount
= ntohl(fsec
->fsec_acl
.acl_entrycount
);
2217 if (host_acl_entrycount
!= KAUTH_FILESEC_NOACL
) {
2218 if (host_acl_entrycount
> KAUTH_ACL_MAX_ENTRIES
) {
2219 KAUTH_DEBUG("ACL - BAD ENTRYCOUNT %x", host_acl_entrycount
);
2222 if (KAUTH_FILESEC_SIZE(host_acl_entrycount
) > rsize
) {
2223 KAUTH_DEBUG("ACL - BUFFER OVERFLOW (%d entries too big for %d)", host_acl_entrycount
, rsize
);
2228 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, NULL
);
2235 kauth_filesec_free(fsec
);
2236 if (fsec_uio
!= NULL
)
2244 * Set a filesec and optional acl contents into an extended attribute.
2245 * function will attempt to store ACL, UUID, and GUID information using a
2246 * write to a named extended attribute (KAUTH_FILESEC_XATTR). The 'acl'
2247 * may or may not point to the `fsec->fsec_acl`, depending on whether the
2248 * original caller supplied an acl.
2250 * Parameters: vp The vnode on which to operate.
2251 * fsec The filesec being set.
2252 * acl The acl to be associated with 'fsec'.
2253 * ctx The vnode context in which the
2254 * operation is to be attempted.
2256 * Returns: 0 Success
2259 * Notes: Both the fsec and the acl are always valid.
2261 * The kauth_filesec_t in 'fsec', if any, is in host byte order,
2262 * as are the acl contents, if they are used. Internally, we will
2263 * cannonize these values into network (PPC) byte order before we
2264 * attempt to write them so that the on-disk contents of the
2265 * extended attribute are identical for both PPC and Intel (if we
2266 * were not being required to provide this service via fallback,
2267 * this would be the job of the filesystem 'VNOP_SETATTR' call).
2268 * We reverse this process on the way out, so we leave with the
2269 * same byte order we started with.
2271 * XXX: We should enummerate the possible errno values here, and where
2272 * in the code they originated.
2275 vnode_set_filesec(vnode_t vp
, kauth_filesec_t fsec
, kauth_acl_t acl
, vfs_context_t ctx
)
2279 uint32_t saved_acl_copysize
;
2283 if ((fsec_uio
= uio_create(2, 0, UIO_SYSSPACE
, UIO_WRITE
)) == NULL
) {
2284 KAUTH_DEBUG(" ERROR - could not allocate iov to write ACL");
2289 * Save the pre-converted ACL copysize, because it gets swapped too
2290 * if we are running with the wrong endianness.
2292 saved_acl_copysize
= KAUTH_ACL_COPYSIZE(acl
);
2294 kauth_filesec_acl_setendian(KAUTH_ENDIAN_DISK
, fsec
, acl
);
2296 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), KAUTH_FILESEC_SIZE(0) - KAUTH_ACL_SIZE(KAUTH_FILESEC_NOACL
));
2297 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(acl
), saved_acl_copysize
);
2298 error
= vn_setxattr(vp
,
2299 KAUTH_FILESEC_XATTR
,
2301 XATTR_NOSECURITY
, /* we have auth'ed already */
2303 VFS_DEBUG(ctx
, vp
, "SETATTR - set ACL returning %d", error
);
2305 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, acl
);
2308 if (fsec_uio
!= NULL
)
2315 * Returns: 0 Success
2316 * ENOMEM Not enough space [only if has filesec]
2318 * vnode_get_filesec: ???
2319 * kauth_cred_guid2uid: ???
2320 * kauth_cred_guid2gid: ???
2321 * vfs_update_vfsstat: ???
2324 vnode_getattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2326 kauth_filesec_t fsec
;
2332 /* don't ask for extended security data if the filesystem doesn't support it */
2333 if (!vfs_extendedsecurity(vnode_mount(vp
))) {
2334 VATTR_CLEAR_ACTIVE(vap
, va_acl
);
2335 VATTR_CLEAR_ACTIVE(vap
, va_uuuid
);
2336 VATTR_CLEAR_ACTIVE(vap
, va_guuid
);
2340 * If the caller wants size values we might have to synthesise, give the
2341 * filesystem the opportunity to supply better intermediate results.
2343 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2344 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2345 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2346 VATTR_SET_ACTIVE(vap
, va_data_size
);
2347 VATTR_SET_ACTIVE(vap
, va_data_alloc
);
2348 VATTR_SET_ACTIVE(vap
, va_total_size
);
2349 VATTR_SET_ACTIVE(vap
, va_total_alloc
);
2352 error
= VNOP_GETATTR(vp
, vap
, ctx
);
2354 KAUTH_DEBUG("ERROR - returning %d", error
);
2359 * If extended security data was requested but not returned, try the fallback
2362 if (VATTR_NOT_RETURNED(vap
, va_acl
) || VATTR_NOT_RETURNED(vap
, va_uuuid
) || VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2365 if (XATTR_VNODE_SUPPORTED(vp
)) {
2366 /* try to get the filesec */
2367 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0)
2370 /* if no filesec, no attributes */
2372 VATTR_RETURN(vap
, va_acl
, NULL
);
2373 VATTR_RETURN(vap
, va_uuuid
, kauth_null_guid
);
2374 VATTR_RETURN(vap
, va_guuid
, kauth_null_guid
);
2377 /* looks good, try to return what we were asked for */
2378 VATTR_RETURN(vap
, va_uuuid
, fsec
->fsec_owner
);
2379 VATTR_RETURN(vap
, va_guuid
, fsec
->fsec_group
);
2381 /* only return the ACL if we were actually asked for it */
2382 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2383 if (fsec
->fsec_acl
.acl_entrycount
== KAUTH_FILESEC_NOACL
) {
2384 VATTR_RETURN(vap
, va_acl
, NULL
);
2386 facl
= kauth_acl_alloc(fsec
->fsec_acl
.acl_entrycount
);
2388 kauth_filesec_free(fsec
);
2392 bcopy(&fsec
->fsec_acl
, facl
, KAUTH_ACL_COPYSIZE(&fsec
->fsec_acl
));
2393 VATTR_RETURN(vap
, va_acl
, facl
);
2396 kauth_filesec_free(fsec
);
2400 * If someone gave us an unsolicited filesec, toss it. We promise that
2401 * we're OK with a filesystem giving us anything back, but our callers
2402 * only expect what they asked for.
2404 if (VATTR_IS_SUPPORTED(vap
, va_acl
) && !VATTR_IS_ACTIVE(vap
, va_acl
)) {
2405 if (vap
->va_acl
!= NULL
)
2406 kauth_acl_free(vap
->va_acl
);
2407 VATTR_CLEAR_SUPPORTED(vap
, va_acl
);
2410 #if 0 /* enable when we have a filesystem only supporting UUIDs */
2412 * Handle the case where we need a UID/GID, but only have extended
2413 * security information.
2415 if (VATTR_NOT_RETURNED(vap
, va_uid
) &&
2416 VATTR_IS_SUPPORTED(vap
, va_uuuid
) &&
2417 !kauth_guid_equal(&vap
->va_uuuid
, &kauth_null_guid
)) {
2418 if ((error
= kauth_cred_guid2uid(&vap
->va_uuuid
, &nuid
)) == 0)
2419 VATTR_RETURN(vap
, va_uid
, nuid
);
2421 if (VATTR_NOT_RETURNED(vap
, va_gid
) &&
2422 VATTR_IS_SUPPORTED(vap
, va_guuid
) &&
2423 !kauth_guid_equal(&vap
->va_guuid
, &kauth_null_guid
)) {
2424 if ((error
= kauth_cred_guid2gid(&vap
->va_guuid
, &ngid
)) == 0)
2425 VATTR_RETURN(vap
, va_gid
, ngid
);
2430 * Handle uid/gid == 99 and MNT_IGNORE_OWNERSHIP here.
2432 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
2433 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2435 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2436 nuid
= vp
->v_mount
->mnt_fsowner
;
2437 if (nuid
== KAUTH_UID_NONE
)
2439 } else if (VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2442 /* this will always be something sensible */
2443 nuid
= vp
->v_mount
->mnt_fsowner
;
2445 if ((nuid
== 99) && !vfs_context_issuser(ctx
))
2446 nuid
= kauth_cred_getuid(vfs_context_ucred(ctx
));
2447 VATTR_RETURN(vap
, va_uid
, nuid
);
2449 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
2450 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2452 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2453 ngid
= vp
->v_mount
->mnt_fsgroup
;
2454 if (ngid
== KAUTH_GID_NONE
)
2456 } else if (VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2459 /* this will always be something sensible */
2460 ngid
= vp
->v_mount
->mnt_fsgroup
;
2462 if ((ngid
== 99) && !vfs_context_issuser(ctx
))
2463 ngid
= kauth_cred_getgid(vfs_context_ucred(ctx
));
2464 VATTR_RETURN(vap
, va_gid
, ngid
);
2468 * Synthesise some values that can be reasonably guessed.
2470 if (!VATTR_IS_SUPPORTED(vap
, va_iosize
))
2471 VATTR_RETURN(vap
, va_iosize
, vp
->v_mount
->mnt_vfsstat
.f_iosize
);
2473 if (!VATTR_IS_SUPPORTED(vap
, va_flags
))
2474 VATTR_RETURN(vap
, va_flags
, 0);
2476 if (!VATTR_IS_SUPPORTED(vap
, va_filerev
))
2477 VATTR_RETURN(vap
, va_filerev
, 0);
2479 if (!VATTR_IS_SUPPORTED(vap
, va_gen
))
2480 VATTR_RETURN(vap
, va_gen
, 0);
2483 * Default sizes. Ordering here is important, as later defaults build on earlier ones.
2485 if (!VATTR_IS_SUPPORTED(vap
, va_data_size
))
2486 VATTR_RETURN(vap
, va_data_size
, 0);
2488 /* do we want any of the possibly-computed values? */
2489 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2490 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2491 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2492 /* make sure f_bsize is valid */
2493 if (vp
->v_mount
->mnt_vfsstat
.f_bsize
== 0) {
2494 if ((error
= vfs_update_vfsstat(vp
->v_mount
, ctx
, VFS_KERNEL_EVENT
)) != 0)
2498 /* default va_data_alloc from va_data_size */
2499 if (!VATTR_IS_SUPPORTED(vap
, va_data_alloc
))
2500 VATTR_RETURN(vap
, va_data_alloc
, roundup(vap
->va_data_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2502 /* default va_total_size from va_data_size */
2503 if (!VATTR_IS_SUPPORTED(vap
, va_total_size
))
2504 VATTR_RETURN(vap
, va_total_size
, vap
->va_data_size
);
2506 /* default va_total_alloc from va_total_size which is guaranteed at this point */
2507 if (!VATTR_IS_SUPPORTED(vap
, va_total_alloc
))
2508 VATTR_RETURN(vap
, va_total_alloc
, roundup(vap
->va_total_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2512 * If we don't have a change time, pull it from the modtime.
2514 if (!VATTR_IS_SUPPORTED(vap
, va_change_time
) && VATTR_IS_SUPPORTED(vap
, va_modify_time
))
2515 VATTR_RETURN(vap
, va_change_time
, vap
->va_modify_time
);
2518 * This is really only supported for the creation VNOPs, but since the field is there
2519 * we should populate it correctly.
2521 VATTR_RETURN(vap
, va_type
, vp
->v_type
);
2524 * The fsid can be obtained from the mountpoint directly.
2526 VATTR_RETURN(vap
, va_fsid
, vp
->v_mount
->mnt_vfsstat
.f_fsid
.val
[0]);
2534 * Set the attributes on a vnode in a vnode context.
2536 * Parameters: vp The vnode whose attributes to set.
2537 * vap A pointer to the attributes to set.
2538 * ctx The vnode context in which the
2539 * operation is to be attempted.
2541 * Returns: 0 Success
2544 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order.
2546 * The contents of the data area pointed to by 'vap' may be
2547 * modified if the vnode is on a filesystem which has been
2548 * mounted with ingore ownership flags, or by the underlyng
2549 * VFS itself, or by the fallback code, if the underlying VFS
2550 * does not support ACL, UUID, or GUUID attributes directly.
2552 * XXX: We should enummerate the possible errno values here, and where
2553 * in the code they originated.
2556 vnode_setattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2558 int error
, is_perm_change
=0;
2561 * Make sure the filesystem is mounted R/W.
2562 * If not, return an error.
2564 if (vfs_isrdonly(vp
->v_mount
)) {
2569 #if DEVELOPMENT || DEBUG
2571 * XXX VSWAP: Check for entitlements or special flag here
2572 * so we can restrict access appropriately.
2574 #else /* DEVELOPMENT || DEBUG */
2576 if (vnode_isswap(vp
) && (ctx
!= vfs_context_kernel())) {
2580 #endif /* DEVELOPMENT || DEBUG */
2583 /* For streams, va_data_size is the only setable attribute. */
2584 if ((vp
->v_flag
& VISNAMEDSTREAM
) && (vap
->va_active
!= VNODE_ATTR_va_data_size
)) {
2589 /* Check for truncation */
2590 if(VATTR_IS_ACTIVE(vap
, va_data_size
)) {
2591 switch(vp
->v_type
) {
2593 /* For regular files it's ok */
2596 /* Not allowed to truncate directories */
2600 /* For everything else we will clear the bit and let underlying FS decide on the rest */
2601 VATTR_CLEAR_ACTIVE(vap
, va_data_size
);
2604 /* If it was the only bit set, return success, to handle cases like redirect to /dev/null */
2610 * If ownership is being ignored on this volume, we silently discard
2611 * ownership changes.
2613 if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2614 VATTR_CLEAR_ACTIVE(vap
, va_uid
);
2615 VATTR_CLEAR_ACTIVE(vap
, va_gid
);
2618 if ( VATTR_IS_ACTIVE(vap
, va_uid
) || VATTR_IS_ACTIVE(vap
, va_gid
)
2619 || VATTR_IS_ACTIVE(vap
, va_mode
) || VATTR_IS_ACTIVE(vap
, va_acl
)) {
2624 * Make sure that extended security is enabled if we're going to try
2627 if (!vfs_extendedsecurity(vnode_mount(vp
)) &&
2628 (VATTR_IS_ACTIVE(vap
, va_acl
) || VATTR_IS_ACTIVE(vap
, va_uuuid
) || VATTR_IS_ACTIVE(vap
, va_guuid
))) {
2629 KAUTH_DEBUG("SETATTR - returning ENOTSUP to request to set extended security");
2634 /* Never allow the setting of any unsupported superuser flags. */
2635 if (VATTR_IS_ACTIVE(vap
, va_flags
)) {
2636 vap
->va_flags
&= (SF_SUPPORTED
| UF_SETTABLE
);
2639 error
= VNOP_SETATTR(vp
, vap
, ctx
);
2641 if ((error
== 0) && !VATTR_ALL_SUPPORTED(vap
))
2642 error
= vnode_setattr_fallback(vp
, vap
, ctx
);
2645 // only send a stat_changed event if this is more than
2646 // just an access or backup time update
2647 if (error
== 0 && (vap
->va_active
!= VNODE_ATTR_BIT(va_access_time
)) && (vap
->va_active
!= VNODE_ATTR_BIT(va_backup_time
))) {
2648 if (is_perm_change
) {
2649 if (need_fsevent(FSE_CHOWN
, vp
)) {
2650 add_fsevent(FSE_CHOWN
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2652 } else if(need_fsevent(FSE_STAT_CHANGED
, vp
)) {
2653 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2663 * Fallback for setting the attributes on a vnode in a vnode context. This
2664 * Function will attempt to store ACL, UUID, and GUID information utilizing
2665 * a read/modify/write operation against an EA used as a backing store for
2668 * Parameters: vp The vnode whose attributes to set.
2669 * vap A pointer to the attributes to set.
2670 * ctx The vnode context in which the
2671 * operation is to be attempted.
2673 * Returns: 0 Success
2676 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order,
2677 * as are the fsec and lfsec, if they are used.
2679 * The contents of the data area pointed to by 'vap' may be
2680 * modified to indicate that the attribute is supported for
2681 * any given requested attribute.
2683 * XXX: We should enummerate the possible errno values here, and where
2684 * in the code they originated.
2687 vnode_setattr_fallback(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2689 kauth_filesec_t fsec
;
2691 struct kauth_filesec lfsec
;
2697 * Extended security fallback via extended attributes.
2699 * Note that we do not free the filesec; the caller is expected to
2702 if (VATTR_NOT_RETURNED(vap
, va_acl
) ||
2703 VATTR_NOT_RETURNED(vap
, va_uuuid
) ||
2704 VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2705 VFS_DEBUG(ctx
, vp
, "SETATTR - doing filesec fallback");
2708 * Fail for file types that we don't permit extended security
2711 if (!XATTR_VNODE_SUPPORTED(vp
)) {
2712 VFS_DEBUG(ctx
, vp
, "SETATTR - Can't write ACL to file type %d", vnode_vtype(vp
));
2718 * If we don't have all the extended security items, we need
2719 * to fetch the existing data to perform a read-modify-write
2723 if (!VATTR_IS_ACTIVE(vap
, va_acl
) ||
2724 !VATTR_IS_ACTIVE(vap
, va_uuuid
) ||
2725 !VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2726 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0) {
2727 KAUTH_DEBUG("SETATTR - ERROR %d fetching filesec for update", error
);
2731 /* if we didn't get a filesec, use our local one */
2733 KAUTH_DEBUG("SETATTR - using local filesec for new/full update");
2736 KAUTH_DEBUG("SETATTR - updating existing filesec");
2739 facl
= &fsec
->fsec_acl
;
2741 /* if we're using the local filesec, we need to initialise it */
2742 if (fsec
== &lfsec
) {
2743 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
2744 fsec
->fsec_owner
= kauth_null_guid
;
2745 fsec
->fsec_group
= kauth_null_guid
;
2746 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2747 facl
->acl_flags
= 0;
2751 * Update with the supplied attributes.
2753 if (VATTR_IS_ACTIVE(vap
, va_uuuid
)) {
2754 KAUTH_DEBUG("SETATTR - updating owner UUID");
2755 fsec
->fsec_owner
= vap
->va_uuuid
;
2756 VATTR_SET_SUPPORTED(vap
, va_uuuid
);
2758 if (VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2759 KAUTH_DEBUG("SETATTR - updating group UUID");
2760 fsec
->fsec_group
= vap
->va_guuid
;
2761 VATTR_SET_SUPPORTED(vap
, va_guuid
);
2763 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2764 if (vap
->va_acl
== NULL
) {
2765 KAUTH_DEBUG("SETATTR - removing ACL");
2766 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2768 KAUTH_DEBUG("SETATTR - setting ACL with %d entries", vap
->va_acl
->acl_entrycount
);
2771 VATTR_SET_SUPPORTED(vap
, va_acl
);
2775 * If the filesec data is all invalid, we can just remove
2776 * the EA completely.
2778 if ((facl
->acl_entrycount
== KAUTH_FILESEC_NOACL
) &&
2779 kauth_guid_equal(&fsec
->fsec_owner
, &kauth_null_guid
) &&
2780 kauth_guid_equal(&fsec
->fsec_group
, &kauth_null_guid
)) {
2781 error
= vn_removexattr(vp
, KAUTH_FILESEC_XATTR
, XATTR_NOSECURITY
, ctx
);
2782 /* no attribute is ok, nothing to delete */
2783 if (error
== ENOATTR
)
2785 VFS_DEBUG(ctx
, vp
, "SETATTR - remove filesec returning %d", error
);
2788 error
= vnode_set_filesec(vp
, fsec
, facl
, ctx
);
2789 VFS_DEBUG(ctx
, vp
, "SETATTR - update filesec returning %d", error
);
2792 /* if we fetched a filesec, dispose of the buffer */
2794 kauth_filesec_free(fsec
);
2802 * Upcall for a filesystem to tell VFS about an EVFILT_VNODE-type
2806 vnode_notify(vnode_t vp
, uint32_t events
, struct vnode_attr
*vap
)
2808 /* These are the same as the corresponding knotes, at least for now. Cheating a little. */
2809 uint32_t knote_mask
= (VNODE_EVENT_WRITE
| VNODE_EVENT_DELETE
| VNODE_EVENT_RENAME
2810 | VNODE_EVENT_LINK
| VNODE_EVENT_EXTEND
| VNODE_EVENT_ATTRIB
);
2811 uint32_t dir_contents_mask
= (VNODE_EVENT_DIR_CREATED
| VNODE_EVENT_FILE_CREATED
2812 | VNODE_EVENT_DIR_REMOVED
| VNODE_EVENT_FILE_REMOVED
);
2813 uint32_t knote_events
= (events
& knote_mask
);
2815 /* Permissions are not explicitly part of the kqueue model */
2816 if (events
& VNODE_EVENT_PERMS
) {
2817 knote_events
|= NOTE_ATTRIB
;
2820 /* Directory contents information just becomes NOTE_WRITE */
2821 if ((vnode_isdir(vp
)) && (events
& dir_contents_mask
)) {
2822 knote_events
|= NOTE_WRITE
;
2826 lock_vnode_and_post(vp
, knote_events
);
2829 create_fsevent_from_kevent(vp
, events
, vap
);
2842 vnode_isdyldsharedcache(vnode_t vp
)
2844 return ((vp
->v_flag
& VSHARED_DYLD
) ? 1 : 0);
2849 * For a filesystem that isn't tracking its own vnode watchers:
2850 * check whether a vnode is being monitored.
2853 vnode_ismonitored(vnode_t vp
) {
2854 return (vp
->v_knotes
.slh_first
!= NULL
);
2858 * Initialize a struct vnode_attr and activate the attributes required
2859 * by the vnode_notify() call.
2862 vfs_get_notify_attributes(struct vnode_attr
*vap
)
2865 vap
->va_active
= VNODE_NOTIFY_ATTRS
;
2871 vfs_settriggercallback(fsid_t
*fsid
, vfs_trigger_callback_t vtc
, void *data
, uint32_t flags __unused
, vfs_context_t ctx
)
2876 mp
= mount_list_lookupby_fsid(fsid
, 0 /* locked */, 1 /* withref */);
2881 error
= vfs_busy(mp
, LK_NOWAIT
);
2889 if (mp
->mnt_triggercallback
!= NULL
) {
2895 mp
->mnt_triggercallback
= vtc
;
2896 mp
->mnt_triggerdata
= data
;
2899 mp
->mnt_triggercallback(mp
, VTC_REPLACE
, data
, ctx
);
2905 #endif /* CONFIG_TRIGGERS */
2908 * Definition of vnode operations.
2914 *#% lookup dvp L ? ?
2915 *#% lookup vpp - L -
2917 struct vnop_lookup_args
{
2918 struct vnodeop_desc
*a_desc
;
2921 struct componentname
*a_cnp
;
2922 vfs_context_t a_context
;
2927 * Returns: 0 Success
2928 * lock_fsnode:ENOENT No such file or directory [only for VFS
2929 * that is not thread safe & vnode is
2930 * currently being/has been terminated]
2931 * <vfs_lookup>:ENAMETOOLONG
2932 * <vfs_lookup>:ENOENT
2933 * <vfs_lookup>:EJUSTRETURN
2934 * <vfs_lookup>:EPERM
2935 * <vfs_lookup>:EISDIR
2936 * <vfs_lookup>:ENOTDIR
2939 * Note: The return codes from the underlying VFS's lookup routine can't
2940 * be fully enumerated here, since third party VFS authors may not
2941 * limit their error returns to the ones documented here, even
2942 * though this may result in some programs functioning incorrectly.
2944 * The return codes documented above are those which may currently
2945 * be returned by HFS from hfs_lookup, not including additional
2946 * error code which may be propagated from underlying routines.
2949 VNOP_LOOKUP(vnode_t dvp
, vnode_t
*vpp
, struct componentname
*cnp
, vfs_context_t ctx
)
2952 struct vnop_lookup_args a
;
2954 a
.a_desc
= &vnop_lookup_desc
;
2960 _err
= (*dvp
->v_op
[vnop_lookup_desc
.vdesc_offset
])(&a
);
2961 if (_err
== 0 && *vpp
) {
2962 DTRACE_FSINFO(lookup
, vnode_t
, *vpp
);
2969 struct vnop_compound_open_args
{
2970 struct vnodeop_desc
*a_desc
;
2973 struct componentname
*a_cnp
;
2976 struct vnode_attr
*a_vap
;
2977 vfs_context_t a_context
;
2983 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
)
2986 struct vnop_compound_open_args a
;
2989 uint32_t tmp_status
= 0;
2990 struct componentname
*cnp
= &ndp
->ni_cnd
;
2992 want_create
= (flags
& O_CREAT
);
2994 a
.a_desc
= &vnop_compound_open_desc
;
2996 a
.a_vpp
= vpp
; /* Could be NULL */
3000 a
.a_status
= (statusp
!= NULL
) ? statusp
: &tmp_status
;
3003 a
.a_open_create_authorizer
= vn_authorize_create
;
3004 a
.a_open_existing_authorizer
= vn_authorize_open_existing
;
3005 a
.a_reserved
= NULL
;
3007 if (dvp
== NULLVP
) {
3010 if (want_create
&& !vap
) {
3011 panic("Want create, but no vap?");
3013 if (!want_create
&& vap
) {
3014 panic("Don't want create, but have a vap?");
3017 _err
= (*dvp
->v_op
[vnop_compound_open_desc
.vdesc_offset
])(&a
);
3019 if (_err
== 0 && *vpp
) {
3020 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
3022 DTRACE_FSINFO(compound_open
, vnode_t
, dvp
);
3025 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
3028 did_create
= (*a
.a_status
& COMPOUND_OPEN_STATUS_DID_CREATE
);
3030 if (did_create
&& !want_create
) {
3031 panic("Filesystem did a create, even though none was requested?");
3035 #if CONFIG_APPLEDOUBLE
3036 if (!NATIVE_XATTR(dvp
)) {
3038 * Remove stale Apple Double file (if any).
3040 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
3042 #endif /* CONFIG_APPLEDOUBLE */
3043 /* On create, provide kqueue notification */
3044 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3047 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, did_create
);
3048 #if 0 /* FSEvents... */
3049 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
3060 struct vnop_create_args
{
3061 struct vnodeop_desc
*a_desc
;
3064 struct componentname
*a_cnp
;
3065 struct vnode_attr
*a_vap
;
3066 vfs_context_t a_context
;
3070 VNOP_CREATE(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3073 struct vnop_create_args a
;
3075 a
.a_desc
= &vnop_create_desc
;
3082 _err
= (*dvp
->v_op
[vnop_create_desc
.vdesc_offset
])(&a
);
3083 if (_err
== 0 && *vpp
) {
3084 DTRACE_FSINFO(create
, vnode_t
, *vpp
);
3087 #if CONFIG_APPLEDOUBLE
3088 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
3090 * Remove stale Apple Double file (if any).
3092 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
3094 #endif /* CONFIG_APPLEDOUBLE */
3096 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3104 *#% whiteout dvp L L L
3105 *#% whiteout cnp - - -
3106 *#% whiteout flag - - -
3109 struct vnop_whiteout_args
{
3110 struct vnodeop_desc
*a_desc
;
3112 struct componentname
*a_cnp
;
3114 vfs_context_t a_context
;
3118 VNOP_WHITEOUT(__unused vnode_t dvp
, __unused
struct componentname
*cnp
,
3119 __unused
int flags
, __unused vfs_context_t ctx
)
3121 return (ENOTSUP
); // XXX OBSOLETE
3131 struct vnop_mknod_args
{
3132 struct vnodeop_desc
*a_desc
;
3135 struct componentname
*a_cnp
;
3136 struct vnode_attr
*a_vap
;
3137 vfs_context_t a_context
;
3141 VNOP_MKNOD(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3145 struct vnop_mknod_args a
;
3147 a
.a_desc
= &vnop_mknod_desc
;
3154 _err
= (*dvp
->v_op
[vnop_mknod_desc
.vdesc_offset
])(&a
);
3155 if (_err
== 0 && *vpp
) {
3156 DTRACE_FSINFO(mknod
, vnode_t
, *vpp
);
3159 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3170 struct vnop_open_args
{
3171 struct vnodeop_desc
*a_desc
;
3174 vfs_context_t a_context
;
3178 VNOP_OPEN(vnode_t vp
, int mode
, vfs_context_t ctx
)
3181 struct vnop_open_args a
;
3184 ctx
= vfs_context_current();
3186 a
.a_desc
= &vnop_open_desc
;
3191 _err
= (*vp
->v_op
[vnop_open_desc
.vdesc_offset
])(&a
);
3192 DTRACE_FSINFO(open
, vnode_t
, vp
);
3203 struct vnop_close_args
{
3204 struct vnodeop_desc
*a_desc
;
3207 vfs_context_t a_context
;
3211 VNOP_CLOSE(vnode_t vp
, int fflag
, vfs_context_t ctx
)
3214 struct vnop_close_args a
;
3217 ctx
= vfs_context_current();
3219 a
.a_desc
= &vnop_close_desc
;
3224 _err
= (*vp
->v_op
[vnop_close_desc
.vdesc_offset
])(&a
);
3225 DTRACE_FSINFO(close
, vnode_t
, vp
);
3236 struct vnop_access_args
{
3237 struct vnodeop_desc
*a_desc
;
3240 vfs_context_t a_context
;
3244 VNOP_ACCESS(vnode_t vp
, int action
, vfs_context_t ctx
)
3247 struct vnop_access_args a
;
3250 ctx
= vfs_context_current();
3252 a
.a_desc
= &vnop_access_desc
;
3254 a
.a_action
= action
;
3257 _err
= (*vp
->v_op
[vnop_access_desc
.vdesc_offset
])(&a
);
3258 DTRACE_FSINFO(access
, vnode_t
, vp
);
3266 *#% getattr vp = = =
3269 struct vnop_getattr_args
{
3270 struct vnodeop_desc
*a_desc
;
3272 struct vnode_attr
*a_vap
;
3273 vfs_context_t a_context
;
3277 VNOP_GETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3280 struct vnop_getattr_args a
;
3282 a
.a_desc
= &vnop_getattr_desc
;
3287 _err
= (*vp
->v_op
[vnop_getattr_desc
.vdesc_offset
])(&a
);
3288 DTRACE_FSINFO(getattr
, vnode_t
, vp
);
3296 *#% setattr vp L L L
3299 struct vnop_setattr_args
{
3300 struct vnodeop_desc
*a_desc
;
3302 struct vnode_attr
*a_vap
;
3303 vfs_context_t a_context
;
3307 VNOP_SETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3310 struct vnop_setattr_args a
;
3312 a
.a_desc
= &vnop_setattr_desc
;
3317 _err
= (*vp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
3318 DTRACE_FSINFO(setattr
, vnode_t
, vp
);
3320 #if CONFIG_APPLEDOUBLE
3322 * Shadow uid/gid/mod change to extended attribute file.
3324 if (_err
== 0 && !NATIVE_XATTR(vp
)) {
3325 struct vnode_attr va
;
3329 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
3330 VATTR_SET(&va
, va_uid
, vap
->va_uid
);
3333 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
3334 VATTR_SET(&va
, va_gid
, vap
->va_gid
);
3337 if (VATTR_IS_ACTIVE(vap
, va_mode
)) {
3338 VATTR_SET(&va
, va_mode
, vap
->va_mode
);
3345 dvp
= vnode_getparent(vp
);
3346 vname
= vnode_getname(vp
);
3348 xattrfile_setattr(dvp
, vname
, &va
, ctx
);
3352 vnode_putname(vname
);
3355 #endif /* CONFIG_APPLEDOUBLE */
3358 * If we have changed any of the things about the file that are likely
3359 * to result in changes to authorization results, blow the vnode auth
3363 VATTR_IS_SUPPORTED(vap
, va_mode
) ||
3364 VATTR_IS_SUPPORTED(vap
, va_uid
) ||
3365 VATTR_IS_SUPPORTED(vap
, va_gid
) ||
3366 VATTR_IS_SUPPORTED(vap
, va_flags
) ||
3367 VATTR_IS_SUPPORTED(vap
, va_acl
) ||
3368 VATTR_IS_SUPPORTED(vap
, va_uuuid
) ||
3369 VATTR_IS_SUPPORTED(vap
, va_guuid
))) {
3370 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3373 if (vfs_authopaque(vp
->v_mount
) && vnode_hasnamedstreams(vp
)) {
3375 if (vnode_getnamedstream(vp
, &svp
, XATTR_RESOURCEFORK_NAME
, NS_OPEN
, 0, ctx
) == 0) {
3376 vnode_uncache_authorized_action(svp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3380 #endif /* NAMEDSTREAMS */
3384 post_event_if_success(vp
, _err
, NOTE_ATTRIB
);
3396 struct vnop_read_args
{
3397 struct vnodeop_desc
*a_desc
;
3401 vfs_context_t a_context
;
3405 VNOP_READ(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3408 struct vnop_read_args a
;
3410 user_ssize_t resid
= uio_resid(uio
);
3417 a
.a_desc
= &vnop_read_desc
;
3420 a
.a_ioflag
= ioflag
;
3423 _err
= (*vp
->v_op
[vnop_read_desc
.vdesc_offset
])(&a
);
3424 DTRACE_FSINFO_IO(read
,
3425 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3437 struct vnop_write_args
{
3438 struct vnodeop_desc
*a_desc
;
3442 vfs_context_t a_context
;
3446 VNOP_WRITE(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3448 struct vnop_write_args a
;
3451 user_ssize_t resid
= uio_resid(uio
);
3458 a
.a_desc
= &vnop_write_desc
;
3461 a
.a_ioflag
= ioflag
;
3464 _err
= (*vp
->v_op
[vnop_write_desc
.vdesc_offset
])(&a
);
3465 DTRACE_FSINFO_IO(write
,
3466 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3468 post_event_if_success(vp
, _err
, NOTE_WRITE
);
3480 struct vnop_ioctl_args
{
3481 struct vnodeop_desc
*a_desc
;
3486 vfs_context_t a_context
;
3490 VNOP_IOCTL(vnode_t vp
, u_long command
, caddr_t data
, int fflag
, vfs_context_t ctx
)
3493 struct vnop_ioctl_args a
;
3496 ctx
= vfs_context_current();
3500 * This check should probably have been put in the TTY code instead...
3502 * We have to be careful about what we assume during startup and shutdown.
3503 * We have to be able to use the root filesystem's device vnode even when
3504 * devfs isn't mounted (yet/anymore), so we can't go looking at its mount
3505 * structure. If there is no data pointer, it doesn't matter whether
3506 * the device is 64-bit ready. Any command (like DKIOCSYNCHRONIZE)
3507 * which passes NULL for its data pointer can therefore be used during
3508 * mount or unmount of the root filesystem.
3510 * Depending on what root filesystems need to do during mount/unmount, we
3511 * may need to loosen this check again in the future.
3513 if (vfs_context_is64bit(ctx
) && !(vnode_ischr(vp
) || vnode_isblk(vp
))) {
3514 if (data
!= NULL
&& !vnode_vfs64bitready(vp
)) {
3519 a
.a_desc
= &vnop_ioctl_desc
;
3521 a
.a_command
= command
;
3526 _err
= (*vp
->v_op
[vnop_ioctl_desc
.vdesc_offset
])(&a
);
3527 DTRACE_FSINFO(ioctl
, vnode_t
, vp
);
3539 struct vnop_select_args
{
3540 struct vnodeop_desc
*a_desc
;
3545 vfs_context_t a_context
;
3549 VNOP_SELECT(vnode_t vp
, int which
, int fflags
, void * wql
, vfs_context_t ctx
)
3552 struct vnop_select_args a
;
3555 ctx
= vfs_context_current();
3557 a
.a_desc
= &vnop_select_desc
;
3560 a
.a_fflags
= fflags
;
3564 _err
= (*vp
->v_op
[vnop_select_desc
.vdesc_offset
])(&a
);
3565 DTRACE_FSINFO(select
, vnode_t
, vp
);
3574 *#% exchange fvp L L L
3575 *#% exchange tvp L L L
3578 struct vnop_exchange_args
{
3579 struct vnodeop_desc
*a_desc
;
3583 vfs_context_t a_context
;
3587 VNOP_EXCHANGE(vnode_t fvp
, vnode_t tvp
, int options
, vfs_context_t ctx
)
3590 struct vnop_exchange_args a
;
3592 a
.a_desc
= &vnop_exchange_desc
;
3595 a
.a_options
= options
;
3598 _err
= (*fvp
->v_op
[vnop_exchange_desc
.vdesc_offset
])(&a
);
3599 DTRACE_FSINFO(exchange
, vnode_t
, fvp
);
3601 /* Don't post NOTE_WRITE because file descriptors follow the data ... */
3602 post_event_if_success(fvp
, _err
, NOTE_ATTRIB
);
3603 post_event_if_success(tvp
, _err
, NOTE_ATTRIB
);
3615 struct vnop_revoke_args
{
3616 struct vnodeop_desc
*a_desc
;
3619 vfs_context_t a_context
;
3623 VNOP_REVOKE(vnode_t vp
, int flags
, vfs_context_t ctx
)
3625 struct vnop_revoke_args a
;
3628 a
.a_desc
= &vnop_revoke_desc
;
3633 _err
= (*vp
->v_op
[vnop_revoke_desc
.vdesc_offset
])(&a
);
3634 DTRACE_FSINFO(revoke
, vnode_t
, vp
);
3646 struct vnop_mmap_args
{
3647 struct vnodeop_desc
*a_desc
;
3650 vfs_context_t a_context
;
3654 VNOP_MMAP(vnode_t vp
, int fflags
, vfs_context_t ctx
)
3657 struct vnop_mmap_args a
;
3659 a
.a_desc
= &vnop_mmap_desc
;
3661 a
.a_fflags
= fflags
;
3664 _err
= (*vp
->v_op
[vnop_mmap_desc
.vdesc_offset
])(&a
);
3665 DTRACE_FSINFO(mmap
, vnode_t
, vp
);
3674 *# mnomap - vp U U U
3677 struct vnop_mnomap_args
{
3678 struct vnodeop_desc
*a_desc
;
3680 vfs_context_t a_context
;
3684 VNOP_MNOMAP(vnode_t vp
, vfs_context_t ctx
)
3687 struct vnop_mnomap_args a
;
3689 a
.a_desc
= &vnop_mnomap_desc
;
3693 _err
= (*vp
->v_op
[vnop_mnomap_desc
.vdesc_offset
])(&a
);
3694 DTRACE_FSINFO(mnomap
, vnode_t
, vp
);
3706 struct vnop_fsync_args
{
3707 struct vnodeop_desc
*a_desc
;
3710 vfs_context_t a_context
;
3714 VNOP_FSYNC(vnode_t vp
, int waitfor
, vfs_context_t ctx
)
3716 struct vnop_fsync_args a
;
3719 a
.a_desc
= &vnop_fsync_desc
;
3721 a
.a_waitfor
= waitfor
;
3724 _err
= (*vp
->v_op
[vnop_fsync_desc
.vdesc_offset
])(&a
);
3725 DTRACE_FSINFO(fsync
, vnode_t
, vp
);
3734 *#% remove dvp L U U
3738 struct vnop_remove_args
{
3739 struct vnodeop_desc
*a_desc
;
3742 struct componentname
*a_cnp
;
3744 vfs_context_t a_context
;
3748 VNOP_REMOVE(vnode_t dvp
, vnode_t vp
, struct componentname
* cnp
, int flags
, vfs_context_t ctx
)
3751 struct vnop_remove_args a
;
3753 a
.a_desc
= &vnop_remove_desc
;
3760 _err
= (*dvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&a
);
3761 DTRACE_FSINFO(remove
, vnode_t
, vp
);
3764 vnode_setneedinactive(vp
);
3765 #if CONFIG_APPLEDOUBLE
3766 if ( !(NATIVE_XATTR(dvp
)) ) {
3768 * Remove any associated extended attribute file (._ AppleDouble file).
3770 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
3772 #endif /* CONFIG_APPLEDOUBLE */
3775 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
3776 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3782 VNOP_COMPOUND_REMOVE(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
3785 struct vnop_compound_remove_args a
;
3786 int no_vp
= (*vpp
== NULLVP
);
3788 a
.a_desc
= &vnop_compound_remove_desc
;
3791 a
.a_cnp
= &ndp
->ni_cnd
;
3795 a
.a_remove_authorizer
= vn_authorize_unlink
;
3797 _err
= (*dvp
->v_op
[vnop_compound_remove_desc
.vdesc_offset
])(&a
);
3798 if (_err
== 0 && *vpp
) {
3799 DTRACE_FSINFO(compound_remove
, vnode_t
, *vpp
);
3801 DTRACE_FSINFO(compound_remove
, vnode_t
, dvp
);
3804 vnode_setneedinactive(*vpp
);
3805 #if CONFIG_APPLEDOUBLE
3806 if ( !(NATIVE_XATTR(dvp
)) ) {
3808 * Remove any associated extended attribute file (._ AppleDouble file).
3810 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 1);
3812 #endif /* CONFIG_APPLEDOUBLE */
3815 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
3816 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3819 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
3820 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
3826 //printf("VNOP_COMPOUND_REMOVE() returning %d\n", _err);
3838 struct vnop_link_args
{
3839 struct vnodeop_desc
*a_desc
;
3842 struct componentname
*a_cnp
;
3843 vfs_context_t a_context
;
3847 VNOP_LINK(vnode_t vp
, vnode_t tdvp
, struct componentname
* cnp
, vfs_context_t ctx
)
3850 struct vnop_link_args a
;
3852 #if CONFIG_APPLEDOUBLE
3854 * For file systems with non-native extended attributes,
3855 * disallow linking to an existing "._" Apple Double file.
3857 if ( !NATIVE_XATTR(tdvp
) && (vp
->v_type
== VREG
)) {
3860 vname
= vnode_getname(vp
);
3861 if (vname
!= NULL
) {
3863 if (vname
[0] == '.' && vname
[1] == '_' && vname
[2] != '\0') {
3866 vnode_putname(vname
);
3871 #endif /* CONFIG_APPLEDOUBLE */
3873 a
.a_desc
= &vnop_link_desc
;
3879 _err
= (*tdvp
->v_op
[vnop_link_desc
.vdesc_offset
])(&a
);
3880 DTRACE_FSINFO(link
, vnode_t
, vp
);
3882 post_event_if_success(vp
, _err
, NOTE_LINK
);
3883 post_event_if_success(tdvp
, _err
, NOTE_WRITE
);
3889 vn_rename(struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
3890 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
3891 vfs_rename_flags_t flags
, vfs_context_t ctx
)
3894 struct nameidata
*fromnd
= NULL
;
3895 struct nameidata
*tond
= NULL
;
3896 #if CONFIG_APPLEDOUBLE
3897 vnode_t src_attr_vp
= NULLVP
;
3898 vnode_t dst_attr_vp
= NULLVP
;
3899 char smallname1
[48];
3900 char smallname2
[48];
3901 char *xfromname
= NULL
;
3902 char *xtoname
= NULL
;
3903 #endif /* CONFIG_APPLEDOUBLE */
3905 uint32_t tdfflags
; // Target directory file flags
3907 batched
= vnode_compound_rename_available(fdvp
);
3910 if (*fvpp
== NULLVP
)
3911 panic("Not batched, and no fvp?");
3914 #if CONFIG_APPLEDOUBLE
3916 * We need to preflight any potential AppleDouble file for the source file
3917 * before doing the rename operation, since we could potentially be doing
3918 * this operation on a network filesystem, and would end up duplicating
3919 * the work. Also, save the source and destination names. Skip it if the
3920 * source has a "._" prefix.
3923 if (!NATIVE_XATTR(fdvp
) &&
3924 !(fcnp
->cn_nameptr
[0] == '.' && fcnp
->cn_nameptr
[1] == '_')) {
3928 /* Get source attribute file name. */
3929 len
= fcnp
->cn_namelen
+ 3;
3930 if (len
> sizeof(smallname1
)) {
3931 MALLOC(xfromname
, char *, len
, M_TEMP
, M_WAITOK
);
3933 xfromname
= &smallname1
[0];
3935 strlcpy(xfromname
, "._", min(sizeof smallname1
, len
));
3936 strncat(xfromname
, fcnp
->cn_nameptr
, fcnp
->cn_namelen
);
3937 xfromname
[len
-1] = '\0';
3939 /* Get destination attribute file name. */
3940 len
= tcnp
->cn_namelen
+ 3;
3941 if (len
> sizeof(smallname2
)) {
3942 MALLOC(xtoname
, char *, len
, M_TEMP
, M_WAITOK
);
3944 xtoname
= &smallname2
[0];
3946 strlcpy(xtoname
, "._", min(sizeof smallname2
, len
));
3947 strncat(xtoname
, tcnp
->cn_nameptr
, tcnp
->cn_namelen
);
3948 xtoname
[len
-1] = '\0';
3951 * Look up source attribute file, keep reference on it if exists.
3952 * Note that we do the namei with the nameiop of RENAME, which is different than
3953 * in the rename syscall. It's OK if the source file does not exist, since this
3954 * is only for AppleDouble files.
3956 if (xfromname
!= NULL
) {
3957 MALLOC(fromnd
, struct nameidata
*, sizeof (struct nameidata
), M_TEMP
, M_WAITOK
);
3958 NDINIT(fromnd
, RENAME
, OP_RENAME
, NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
,
3959 UIO_SYSSPACE
, CAST_USER_ADDR_T(xfromname
), ctx
);
3960 fromnd
->ni_dvp
= fdvp
;
3961 error
= namei(fromnd
);
3964 * If there was an error looking up source attribute file,
3965 * we'll behave as if it didn't exist.
3969 if (fromnd
->ni_vp
) {
3970 /* src_attr_vp indicates need to call vnode_put / nameidone later */
3971 src_attr_vp
= fromnd
->ni_vp
;
3973 if (fromnd
->ni_vp
->v_type
!= VREG
) {
3974 src_attr_vp
= NULLVP
;
3975 vnode_put(fromnd
->ni_vp
);
3979 * Either we got an invalid vnode type (not a regular file) or the namei lookup
3980 * suppressed ENOENT as a valid error since we're renaming. Either way, we don't
3981 * have a vnode here, so we drop our namei buffer for the source attribute file
3983 if (src_attr_vp
== NULLVP
) {
3989 #endif /* CONFIG_APPLEDOUBLE */
3992 _err
= VNOP_COMPOUND_RENAME(fdvp
, fvpp
, fcnp
, fvap
, tdvp
, tvpp
, tcnp
, tvap
, flags
, ctx
);
3994 printf("VNOP_COMPOUND_RENAME() returned %d\n", _err
);
3998 _err
= VNOP_RENAMEX(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, flags
, ctx
);
3999 if (_err
== ENOTSUP
&& flags
== VFS_RENAME_SECLUDE
) {
4001 if ((*fvpp
)->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_SECLUDE_RENAME
) {
4002 fcnp
->cn_flags
|= CN_SECLUDE_RENAME
;
4003 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
4007 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
4011 * If moved to a new directory that is restricted,
4012 * set the restricted flag on the item moved.
4015 _err
= vnode_flags(tdvp
, &tdfflags
, ctx
);
4016 if (_err
== 0 && (tdfflags
& SF_RESTRICTED
)) {
4018 _err
= vnode_flags(*fvpp
, &fflags
, ctx
);
4019 if (_err
== 0 && !(fflags
& SF_RESTRICTED
)) {
4020 struct vnode_attr va
;
4022 VATTR_SET(&va
, va_flags
, fflags
| SF_RESTRICTED
);
4023 _err
= vnode_setattr(*fvpp
, &va
, ctx
);
4030 mac_vnode_notify_rename(ctx
, *fvpp
, tdvp
, tcnp
);
4034 #if CONFIG_APPLEDOUBLE
4036 * Rename any associated extended attribute file (._ AppleDouble file).
4038 if (_err
== 0 && !NATIVE_XATTR(fdvp
) && xfromname
!= NULL
) {
4042 * Get destination attribute file vnode.
4043 * Note that tdvp already has an iocount reference. Make sure to check that we
4044 * get a valid vnode from namei.
4046 MALLOC(tond
, struct nameidata
*, sizeof(struct nameidata
), M_TEMP
, M_WAITOK
);
4047 NDINIT(tond
, RENAME
, OP_RENAME
,
4048 NOCACHE
| NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
, UIO_SYSSPACE
,
4049 CAST_USER_ADDR_T(xtoname
), ctx
);
4050 tond
->ni_dvp
= tdvp
;
4051 error
= namei(tond
);
4057 dst_attr_vp
= tond
->ni_vp
;
4061 const char *old_name
= src_attr_vp
->v_name
;
4062 vnode_t old_parent
= src_attr_vp
->v_parent
;
4065 error
= VNOP_COMPOUND_RENAME(fdvp
, &src_attr_vp
, &fromnd
->ni_cnd
, NULL
,
4066 tdvp
, &dst_attr_vp
, &tond
->ni_cnd
, NULL
,
4069 error
= VNOP_RENAME(fdvp
, src_attr_vp
, &fromnd
->ni_cnd
,
4070 tdvp
, dst_attr_vp
, &tond
->ni_cnd
, ctx
);
4073 if (error
== 0 && old_name
== src_attr_vp
->v_name
&&
4074 old_parent
== src_attr_vp
->v_parent
) {
4075 int update_flags
= VNODE_UPDATE_NAME
;
4078 update_flags
|= VNODE_UPDATE_PARENT
;
4080 if ((src_attr_vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_NOUPDATEID_RENAME
) == 0) {
4081 vnode_update_identity(src_attr_vp
, tdvp
,
4082 tond
->ni_cnd
.cn_nameptr
,
4083 tond
->ni_cnd
.cn_namelen
,
4084 tond
->ni_cnd
.cn_hash
,
4089 /* kevent notifications for moving resource files
4090 * _err is zero if we're here, so no need to notify directories, code
4091 * below will do that. only need to post the rename on the source and
4092 * possibly a delete on the dest
4094 post_event_if_success(src_attr_vp
, error
, NOTE_RENAME
);
4096 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4099 } else if (dst_attr_vp
) {
4101 * Just delete destination attribute file vnode if it exists, since
4102 * we didn't have a source attribute file.
4103 * Note that tdvp already has an iocount reference.
4106 struct vnop_remove_args args
;
4108 args
.a_desc
= &vnop_remove_desc
;
4110 args
.a_vp
= dst_attr_vp
;
4111 args
.a_cnp
= &tond
->ni_cnd
;
4112 args
.a_context
= ctx
;
4115 error
= (*tdvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&args
);
4118 vnode_setneedinactive(dst_attr_vp
);
4121 /* kevent notification for deleting the destination's attribute file
4122 * if it existed. Only need to post the delete on the destination, since
4123 * the code below will handle the directories.
4125 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4130 vnode_put(src_attr_vp
);
4134 vnode_put(dst_attr_vp
);
4137 if (xfromname
&& xfromname
!= &smallname1
[0]) {
4138 FREE(xfromname
, M_TEMP
);
4140 if (xtoname
&& xtoname
!= &smallname2
[0]) {
4141 FREE(xtoname
, M_TEMP
);
4143 #endif /* CONFIG_APPLEDOUBLE */
4145 FREE(fromnd
, M_TEMP
);
4157 *#% rename fdvp U U U
4158 *#% rename fvp U U U
4159 *#% rename tdvp L U U
4160 *#% rename tvp X U U
4163 struct vnop_rename_args
{
4164 struct vnodeop_desc
*a_desc
;
4167 struct componentname
*a_fcnp
;
4170 struct componentname
*a_tcnp
;
4171 vfs_context_t a_context
;
4175 VNOP_RENAME(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4176 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4180 struct vnop_rename_args a
;
4182 a
.a_desc
= &vnop_rename_desc
;
4191 /* do the rename of the main file. */
4192 _err
= (*fdvp
->v_op
[vnop_rename_desc
.vdesc_offset
])(&a
);
4193 DTRACE_FSINFO(rename
, vnode_t
, fdvp
);
4198 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4202 post_rename(vnode_t fdvp
, vnode_t fvp
, vnode_t tdvp
, vnode_t tvp
)
4204 if (tvp
&& tvp
!= fvp
)
4205 vnode_setneedinactive(tvp
);
4207 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4208 int events
= NOTE_WRITE
;
4209 if (vnode_isdir(fvp
)) {
4210 /* Link count on dir changed only if we are moving a dir and...
4211 * --Moved to new dir, not overwriting there
4212 * --Kept in same dir and DID overwrite
4214 if (((fdvp
!= tdvp
) && (!tvp
)) || ((fdvp
== tdvp
) && (tvp
))) {
4215 events
|= NOTE_LINK
;
4219 lock_vnode_and_post(fdvp
, events
);
4221 lock_vnode_and_post(tdvp
, events
);
4224 /* If you're replacing the target, post a deletion for it */
4227 lock_vnode_and_post(tvp
, NOTE_DELETE
);
4230 lock_vnode_and_post(fvp
, NOTE_RENAME
);
4238 *#% renamex fdvp U U U
4239 *#% renamex fvp U U U
4240 *#% renamex tdvp L U U
4241 *#% renamex tvp X U U
4244 struct vnop_renamex_args
{
4245 struct vnodeop_desc
*a_desc
;
4248 struct componentname
*a_fcnp
;
4251 struct componentname
*a_tcnp
;
4252 vfs_rename_flags_t a_flags
;
4253 vfs_context_t a_context
;
4257 VNOP_RENAMEX(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4258 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4259 vfs_rename_flags_t flags
, vfs_context_t ctx
)
4262 struct vnop_renamex_args a
;
4264 a
.a_desc
= &vnop_renamex_desc
;
4274 /* do the rename of the main file. */
4275 _err
= (*fdvp
->v_op
[vnop_renamex_desc
.vdesc_offset
])(&a
);
4276 DTRACE_FSINFO(renamex
, vnode_t
, fdvp
);
4281 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4286 VNOP_COMPOUND_RENAME(
4287 struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
4288 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
4289 uint32_t flags
, vfs_context_t ctx
)
4293 struct vnop_compound_rename_args a
;
4296 no_fvp
= (*fvpp
) == NULLVP
;
4297 no_tvp
= (*tvpp
) == NULLVP
;
4299 a
.a_desc
= &vnop_compound_rename_desc
;
4313 a
.a_rename_authorizer
= vn_authorize_rename
;
4314 a
.a_reserved
= NULL
;
4316 /* do the rename of the main file. */
4317 _err
= (*fdvp
->v_op
[vnop_compound_rename_desc
.vdesc_offset
])(&a
);
4318 DTRACE_FSINFO(compound_rename
, vnode_t
, fdvp
);
4321 if (*tvpp
&& *tvpp
!= *fvpp
)
4322 vnode_setneedinactive(*tvpp
);
4325 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4326 if (_err
== 0 && *fvpp
!= *tvpp
) {
4328 panic("No fvpp after compound rename?");
4331 events
= NOTE_WRITE
;
4332 if (vnode_isdir(*fvpp
)) {
4333 /* Link count on dir changed only if we are moving a dir and...
4334 * --Moved to new dir, not overwriting there
4335 * --Kept in same dir and DID overwrite
4337 if (((fdvp
!= tdvp
) && (!*tvpp
)) || ((fdvp
== tdvp
) && (*tvpp
))) {
4338 events
|= NOTE_LINK
;
4342 lock_vnode_and_post(fdvp
, events
);
4344 lock_vnode_and_post(tdvp
, events
);
4347 /* If you're replacing the target, post a deletion for it */
4350 lock_vnode_and_post(*tvpp
, NOTE_DELETE
);
4353 lock_vnode_and_post(*fvpp
, NOTE_RENAME
);
4357 lookup_compound_vnop_post_hook(_err
, fdvp
, *fvpp
, fcnp
->cn_ndp
, 0);
4359 if (no_tvp
&& *tvpp
!= NULLVP
) {
4360 lookup_compound_vnop_post_hook(_err
, tdvp
, *tvpp
, tcnp
->cn_ndp
, 0);
4363 if (_err
&& _err
!= EKEEPLOOKING
) {
4378 vn_mkdir(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4379 struct vnode_attr
*vap
, vfs_context_t ctx
)
4381 if (ndp
->ni_cnd
.cn_nameiop
!= CREATE
) {
4382 panic("Non-CREATE nameiop in vn_mkdir()?");
4385 if (vnode_compound_mkdir_available(dvp
)) {
4386 return VNOP_COMPOUND_MKDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4388 return VNOP_MKDIR(dvp
, vpp
, &ndp
->ni_cnd
, vap
, ctx
);
4399 struct vnop_mkdir_args
{
4400 struct vnodeop_desc
*a_desc
;
4403 struct componentname
*a_cnp
;
4404 struct vnode_attr
*a_vap
;
4405 vfs_context_t a_context
;
4409 VNOP_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4410 struct vnode_attr
*vap
, vfs_context_t ctx
)
4413 struct vnop_mkdir_args a
;
4415 a
.a_desc
= &vnop_mkdir_desc
;
4422 _err
= (*dvp
->v_op
[vnop_mkdir_desc
.vdesc_offset
])(&a
);
4423 if (_err
== 0 && *vpp
) {
4424 DTRACE_FSINFO(mkdir
, vnode_t
, *vpp
);
4426 #if CONFIG_APPLEDOUBLE
4427 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4429 * Remove stale Apple Double file (if any).
4431 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4433 #endif /* CONFIG_APPLEDOUBLE */
4435 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4441 VNOP_COMPOUND_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4442 struct vnode_attr
*vap
, vfs_context_t ctx
)
4445 struct vnop_compound_mkdir_args a
;
4447 a
.a_desc
= &vnop_compound_mkdir_desc
;
4450 a
.a_cnp
= &ndp
->ni_cnd
;
4455 a
.a_mkdir_authorizer
= vn_authorize_mkdir
;
4457 a
.a_reserved
= NULL
;
4459 _err
= (*dvp
->v_op
[vnop_compound_mkdir_desc
.vdesc_offset
])(&a
);
4460 if (_err
== 0 && *vpp
) {
4461 DTRACE_FSINFO(compound_mkdir
, vnode_t
, *vpp
);
4463 #if CONFIG_APPLEDOUBLE
4464 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4466 * Remove stale Apple Double file (if any).
4468 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4470 #endif /* CONFIG_APPLEDOUBLE */
4472 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4474 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, (_err
== 0));
4475 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4484 vn_rmdir(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4486 if (vnode_compound_rmdir_available(dvp
)) {
4487 return VNOP_COMPOUND_RMDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4489 if (*vpp
== NULLVP
) {
4490 panic("NULL vp, but not a compound VNOP?");
4493 panic("Non-NULL vap, but not a compound VNOP?");
4495 return VNOP_RMDIR(dvp
, *vpp
, &ndp
->ni_cnd
, ctx
);
4506 struct vnop_rmdir_args
{
4507 struct vnodeop_desc
*a_desc
;
4510 struct componentname
*a_cnp
;
4511 vfs_context_t a_context
;
4516 VNOP_RMDIR(struct vnode
*dvp
, struct vnode
*vp
, struct componentname
*cnp
, vfs_context_t ctx
)
4519 struct vnop_rmdir_args a
;
4521 a
.a_desc
= &vnop_rmdir_desc
;
4527 _err
= (*vp
->v_op
[vnop_rmdir_desc
.vdesc_offset
])(&a
);
4528 DTRACE_FSINFO(rmdir
, vnode_t
, vp
);
4531 vnode_setneedinactive(vp
);
4532 #if CONFIG_APPLEDOUBLE
4533 if ( !(NATIVE_XATTR(dvp
)) ) {
4535 * Remove any associated extended attribute file (._ AppleDouble file).
4537 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
4542 /* If you delete a dir, it loses its "." reference --> NOTE_LINK */
4543 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4544 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4550 VNOP_COMPOUND_RMDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4551 struct vnode_attr
*vap
, vfs_context_t ctx
)
4554 struct vnop_compound_rmdir_args a
;
4557 a
.a_desc
= &vnop_mkdir_desc
;
4560 a
.a_cnp
= &ndp
->ni_cnd
;
4564 a
.a_rmdir_authorizer
= vn_authorize_rmdir
;
4565 a
.a_reserved
= NULL
;
4567 no_vp
= (*vpp
== NULLVP
);
4569 _err
= (*dvp
->v_op
[vnop_compound_rmdir_desc
.vdesc_offset
])(&a
);
4570 if (_err
== 0 && *vpp
) {
4571 DTRACE_FSINFO(compound_rmdir
, vnode_t
, *vpp
);
4573 #if CONFIG_APPLEDOUBLE
4574 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4576 * Remove stale Apple Double file (if any).
4578 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4583 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4585 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4588 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
4590 #if 0 /* Removing orphaned ._ files requires a vp.... */
4591 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4601 #if CONFIG_APPLEDOUBLE
4603 * Remove a ._ AppleDouble file
4605 #define AD_STALE_SECS (180)
4607 xattrfile_remove(vnode_t dvp
, const char * basename
, vfs_context_t ctx
, int force
)
4610 struct nameidata nd
;
4612 char *filename
= NULL
;
4615 if ((basename
== NULL
) || (basename
[0] == '\0') ||
4616 (basename
[0] == '.' && basename
[1] == '_')) {
4619 filename
= &smallname
[0];
4620 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4621 if (len
>= sizeof(smallname
)) {
4622 len
++; /* snprintf result doesn't include '\0' */
4623 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4624 len
= snprintf(filename
, len
, "._%s", basename
);
4626 NDINIT(&nd
, DELETE
, OP_UNLINK
, WANTPARENT
| LOCKLEAF
| NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4627 CAST_USER_ADDR_T(filename
), ctx
);
4629 if (namei(&nd
) != 0)
4634 if (xvp
->v_type
!= VREG
)
4638 * When creating a new object and a "._" file already
4639 * exists, check to see if its a stale "._" file.
4643 struct vnode_attr va
;
4646 VATTR_WANTED(&va
, va_data_size
);
4647 VATTR_WANTED(&va
, va_modify_time
);
4648 if (VNOP_GETATTR(xvp
, &va
, ctx
) == 0 &&
4649 VATTR_IS_SUPPORTED(&va
, va_data_size
) &&
4650 VATTR_IS_SUPPORTED(&va
, va_modify_time
) &&
4651 va
.va_data_size
!= 0) {
4655 if ((tv
.tv_sec
> va
.va_modify_time
.tv_sec
) &&
4656 (tv
.tv_sec
- va
.va_modify_time
.tv_sec
) > AD_STALE_SECS
) {
4657 force
= 1; /* must be stale */
4664 error
= VNOP_REMOVE(dvp
, xvp
, &nd
.ni_cnd
, 0, ctx
);
4666 vnode_setneedinactive(xvp
);
4668 post_event_if_success(xvp
, error
, NOTE_DELETE
);
4669 post_event_if_success(dvp
, error
, NOTE_WRITE
);
4676 if (filename
&& filename
!= &smallname
[0]) {
4677 FREE(filename
, M_TEMP
);
4682 * Shadow uid/gid/mod to a ._ AppleDouble file
4685 xattrfile_setattr(vnode_t dvp
, const char * basename
, struct vnode_attr
* vap
,
4689 struct nameidata nd
;
4691 char *filename
= NULL
;
4694 if ((dvp
== NULLVP
) ||
4695 (basename
== NULL
) || (basename
[0] == '\0') ||
4696 (basename
[0] == '.' && basename
[1] == '_')) {
4699 filename
= &smallname
[0];
4700 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4701 if (len
>= sizeof(smallname
)) {
4702 len
++; /* snprintf result doesn't include '\0' */
4703 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4704 len
= snprintf(filename
, len
, "._%s", basename
);
4706 NDINIT(&nd
, LOOKUP
, OP_SETATTR
, NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4707 CAST_USER_ADDR_T(filename
), ctx
);
4709 if (namei(&nd
) != 0)
4715 if (xvp
->v_type
== VREG
) {
4716 struct vnop_setattr_args a
;
4718 a
.a_desc
= &vnop_setattr_desc
;
4723 (void) (*xvp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
4728 if (filename
&& filename
!= &smallname
[0]) {
4729 FREE(filename
, M_TEMP
);
4732 #endif /* CONFIG_APPLEDOUBLE */
4737 *#% symlink dvp L U U
4738 *#% symlink vpp - U -
4741 struct vnop_symlink_args
{
4742 struct vnodeop_desc
*a_desc
;
4745 struct componentname
*a_cnp
;
4746 struct vnode_attr
*a_vap
;
4748 vfs_context_t a_context
;
4753 VNOP_SYMLINK(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4754 struct vnode_attr
*vap
, char *target
, vfs_context_t ctx
)
4757 struct vnop_symlink_args a
;
4759 a
.a_desc
= &vnop_symlink_desc
;
4764 a
.a_target
= target
;
4767 _err
= (*dvp
->v_op
[vnop_symlink_desc
.vdesc_offset
])(&a
);
4768 DTRACE_FSINFO(symlink
, vnode_t
, dvp
);
4769 #if CONFIG_APPLEDOUBLE
4770 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4772 * Remove stale Apple Double file (if any). Posts its own knotes
4774 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4776 #endif /* CONFIG_APPLEDOUBLE */
4778 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
4786 *#% readdir vp L L L
4789 struct vnop_readdir_args
{
4790 struct vnodeop_desc
*a_desc
;
4796 vfs_context_t a_context
;
4801 VNOP_READDIR(struct vnode
*vp
, struct uio
*uio
, int flags
, int *eofflag
,
4802 int *numdirent
, vfs_context_t ctx
)
4805 struct vnop_readdir_args a
;
4807 user_ssize_t resid
= uio_resid(uio
);
4810 a
.a_desc
= &vnop_readdir_desc
;
4814 a
.a_eofflag
= eofflag
;
4815 a
.a_numdirent
= numdirent
;
4818 _err
= (*vp
->v_op
[vnop_readdir_desc
.vdesc_offset
])(&a
);
4819 DTRACE_FSINFO_IO(readdir
,
4820 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4828 *#% readdirattr vp L L L
4831 struct vnop_readdirattr_args
{
4832 struct vnodeop_desc
*a_desc
;
4834 struct attrlist
*a_alist
;
4836 uint32_t a_maxcount
;
4838 uint32_t *a_newstate
;
4840 uint32_t *a_actualcount
;
4841 vfs_context_t a_context
;
4846 VNOP_READDIRATTR(struct vnode
*vp
, struct attrlist
*alist
, struct uio
*uio
, uint32_t maxcount
,
4847 uint32_t options
, uint32_t *newstate
, int *eofflag
, uint32_t *actualcount
, vfs_context_t ctx
)
4850 struct vnop_readdirattr_args a
;
4852 user_ssize_t resid
= uio_resid(uio
);
4855 a
.a_desc
= &vnop_readdirattr_desc
;
4859 a
.a_maxcount
= maxcount
;
4860 a
.a_options
= options
;
4861 a
.a_newstate
= newstate
;
4862 a
.a_eofflag
= eofflag
;
4863 a
.a_actualcount
= actualcount
;
4866 _err
= (*vp
->v_op
[vnop_readdirattr_desc
.vdesc_offset
])(&a
);
4867 DTRACE_FSINFO_IO(readdirattr
,
4868 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4874 struct vnop_getttrlistbulk_args
{
4875 struct vnodeop_desc
*a_desc
;
4877 struct attrlist
*a_alist
;
4878 struct vnode_attr
*a_vap
;
4883 uint32_t *a_actualcount
;
4884 vfs_context_t a_context
;
4888 VNOP_GETATTRLISTBULK(struct vnode
*vp
, struct attrlist
*alist
,
4889 struct vnode_attr
*vap
, struct uio
*uio
, void *private, uint64_t options
,
4890 int32_t *eofflag
, int32_t *actualcount
, vfs_context_t ctx
)
4893 struct vnop_getattrlistbulk_args a
;
4895 user_ssize_t resid
= uio_resid(uio
);
4898 a
.a_desc
= &vnop_getattrlistbulk_desc
;
4903 a
.a_private
= private;
4904 a
.a_options
= options
;
4905 a
.a_eofflag
= eofflag
;
4906 a
.a_actualcount
= actualcount
;
4909 _err
= (*vp
->v_op
[vnop_getattrlistbulk_desc
.vdesc_offset
])(&a
);
4910 DTRACE_FSINFO_IO(getattrlistbulk
,
4911 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4919 *#% readlink vp L L L
4922 struct vnop_readlink_args
{
4923 struct vnodeop_desc
*a_desc
;
4926 vfs_context_t a_context
;
4931 * Returns: 0 Success
4932 * lock_fsnode:ENOENT No such file or directory [only for VFS
4933 * that is not thread safe & vnode is
4934 * currently being/has been terminated]
4935 * <vfs_readlink>:EINVAL
4936 * <vfs_readlink>:???
4938 * Note: The return codes from the underlying VFS's readlink routine
4939 * can't be fully enumerated here, since third party VFS authors
4940 * may not limit their error returns to the ones documented here,
4941 * even though this may result in some programs functioning
4944 * The return codes documented above are those which may currently
4945 * be returned by HFS from hfs_vnop_readlink, not including
4946 * additional error code which may be propagated from underlying
4950 VNOP_READLINK(struct vnode
*vp
, struct uio
*uio
, vfs_context_t ctx
)
4953 struct vnop_readlink_args a
;
4955 user_ssize_t resid
= uio_resid(uio
);
4957 a
.a_desc
= &vnop_readlink_desc
;
4962 _err
= (*vp
->v_op
[vnop_readlink_desc
.vdesc_offset
])(&a
);
4963 DTRACE_FSINFO_IO(readlink
,
4964 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4972 *#% inactive vp L U U
4975 struct vnop_inactive_args
{
4976 struct vnodeop_desc
*a_desc
;
4978 vfs_context_t a_context
;
4982 VNOP_INACTIVE(struct vnode
*vp
, vfs_context_t ctx
)
4985 struct vnop_inactive_args a
;
4987 a
.a_desc
= &vnop_inactive_desc
;
4991 _err
= (*vp
->v_op
[vnop_inactive_desc
.vdesc_offset
])(&a
);
4992 DTRACE_FSINFO(inactive
, vnode_t
, vp
);
4995 /* For file systems that do not support namedstream natively, mark
4996 * the shadow stream file vnode to be recycled as soon as the last
4997 * reference goes away. To avoid re-entering reclaim code, do not
4998 * call recycle on terminating namedstream vnodes.
5000 if (vnode_isnamedstream(vp
) &&
5001 (vp
->v_parent
!= NULLVP
) &&
5002 vnode_isshadow(vp
) &&
5003 ((vp
->v_lflag
& VL_TERMINATE
) == 0)) {
5015 *#% reclaim vp U U U
5018 struct vnop_reclaim_args
{
5019 struct vnodeop_desc
*a_desc
;
5021 vfs_context_t a_context
;
5025 VNOP_RECLAIM(struct vnode
*vp
, vfs_context_t ctx
)
5028 struct vnop_reclaim_args a
;
5030 a
.a_desc
= &vnop_reclaim_desc
;
5034 _err
= (*vp
->v_op
[vnop_reclaim_desc
.vdesc_offset
])(&a
);
5035 DTRACE_FSINFO(reclaim
, vnode_t
, vp
);
5042 * Returns: 0 Success
5043 * lock_fsnode:ENOENT No such file or directory [only for VFS
5044 * that is not thread safe & vnode is
5045 * currently being/has been terminated]
5046 * <vnop_pathconf_desc>:??? [per FS implementation specific]
5051 *#% pathconf vp L L L
5054 struct vnop_pathconf_args
{
5055 struct vnodeop_desc
*a_desc
;
5059 vfs_context_t a_context
;
5063 VNOP_PATHCONF(struct vnode
*vp
, int name
, int32_t *retval
, vfs_context_t ctx
)
5066 struct vnop_pathconf_args a
;
5068 a
.a_desc
= &vnop_pathconf_desc
;
5071 a
.a_retval
= retval
;
5074 _err
= (*vp
->v_op
[vnop_pathconf_desc
.vdesc_offset
])(&a
);
5075 DTRACE_FSINFO(pathconf
, vnode_t
, vp
);
5081 * Returns: 0 Success
5082 * err_advlock:ENOTSUP
5084 * <vnop_advlock_desc>:???
5086 * Notes: VFS implementations of advisory locking using calls through
5087 * <vnop_advlock_desc> because lock enforcement does not occur
5088 * locally should try to limit themselves to the return codes
5089 * documented above for lf_advlock and err_advlock.
5094 *#% advlock vp U U U
5097 struct vnop_advlock_args
{
5098 struct vnodeop_desc
*a_desc
;
5104 vfs_context_t a_context
;
5108 VNOP_ADVLOCK(struct vnode
*vp
, caddr_t id
, int op
, struct flock
*fl
, int flags
, vfs_context_t ctx
, struct timespec
*timeout
)
5111 struct vnop_advlock_args a
;
5113 a
.a_desc
= &vnop_advlock_desc
;
5120 a
.a_timeout
= timeout
;
5122 /* Disallow advisory locking on non-seekable vnodes */
5123 if (vnode_isfifo(vp
)) {
5124 _err
= err_advlock(&a
);
5126 if ((vp
->v_flag
& VLOCKLOCAL
)) {
5127 /* Advisory locking done at this layer */
5128 _err
= lf_advlock(&a
);
5129 } else if (flags
& F_OFD_LOCK
) {
5130 /* Non-local locking doesn't work for OFD locks */
5131 _err
= err_advlock(&a
);
5133 /* Advisory locking done by underlying filesystem */
5134 _err
= (*vp
->v_op
[vnop_advlock_desc
.vdesc_offset
])(&a
);
5136 DTRACE_FSINFO(advlock
, vnode_t
, vp
);
5137 if (op
== F_UNLCK
&& flags
== F_FLOCK
)
5138 post_event_if_success(vp
, _err
, NOTE_FUNLOCK
);
5149 *#% allocate vp L L L
5152 struct vnop_allocate_args
{
5153 struct vnodeop_desc
*a_desc
;
5157 off_t
*a_bytesallocated
;
5159 vfs_context_t a_context
;
5164 VNOP_ALLOCATE(struct vnode
*vp
, off_t length
, u_int32_t flags
, off_t
*bytesallocated
, off_t offset
, vfs_context_t ctx
)
5167 struct vnop_allocate_args a
;
5169 a
.a_desc
= &vnop_allocate_desc
;
5171 a
.a_length
= length
;
5173 a
.a_bytesallocated
= bytesallocated
;
5174 a
.a_offset
= offset
;
5177 _err
= (*vp
->v_op
[vnop_allocate_desc
.vdesc_offset
])(&a
);
5178 DTRACE_FSINFO(allocate
, vnode_t
, vp
);
5181 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
5194 struct vnop_pagein_args
{
5195 struct vnodeop_desc
*a_desc
;
5198 upl_offset_t a_pl_offset
;
5202 vfs_context_t a_context
;
5206 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
)
5209 struct vnop_pagein_args a
;
5211 a
.a_desc
= &vnop_pagein_desc
;
5214 a
.a_pl_offset
= pl_offset
;
5215 a
.a_f_offset
= f_offset
;
5220 _err
= (*vp
->v_op
[vnop_pagein_desc
.vdesc_offset
])(&a
);
5221 DTRACE_FSINFO(pagein
, vnode_t
, vp
);
5229 *#% pageout vp = = =
5232 struct vnop_pageout_args
{
5233 struct vnodeop_desc
*a_desc
;
5236 upl_offset_t a_pl_offset
;
5240 vfs_context_t a_context
;
5245 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
)
5248 struct vnop_pageout_args a
;
5250 a
.a_desc
= &vnop_pageout_desc
;
5253 a
.a_pl_offset
= pl_offset
;
5254 a
.a_f_offset
= f_offset
;
5259 _err
= (*vp
->v_op
[vnop_pageout_desc
.vdesc_offset
])(&a
);
5260 DTRACE_FSINFO(pageout
, vnode_t
, vp
);
5262 post_event_if_success(vp
, _err
, NOTE_WRITE
);
5268 vn_remove(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
5270 if (vnode_compound_remove_available(dvp
)) {
5271 return VNOP_COMPOUND_REMOVE(dvp
, vpp
, ndp
, flags
, vap
, ctx
);
5273 return VNOP_REMOVE(dvp
, *vpp
, &ndp
->ni_cnd
, flags
, ctx
);
5282 *#% searchfs vp L L L
5285 struct vnop_searchfs_args
{
5286 struct vnodeop_desc
*a_desc
;
5288 void *a_searchparams1
;
5289 void *a_searchparams2
;
5290 struct attrlist
*a_searchattrs
;
5291 uint32_t a_maxmatches
;
5292 struct timeval
*a_timelimit
;
5293 struct attrlist
*a_returnattrs
;
5294 uint32_t *a_nummatches
;
5295 uint32_t a_scriptcode
;
5298 struct searchstate
*a_searchstate
;
5299 vfs_context_t a_context
;
5304 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
)
5307 struct vnop_searchfs_args a
;
5309 a
.a_desc
= &vnop_searchfs_desc
;
5311 a
.a_searchparams1
= searchparams1
;
5312 a
.a_searchparams2
= searchparams2
;
5313 a
.a_searchattrs
= searchattrs
;
5314 a
.a_maxmatches
= maxmatches
;
5315 a
.a_timelimit
= timelimit
;
5316 a
.a_returnattrs
= returnattrs
;
5317 a
.a_nummatches
= nummatches
;
5318 a
.a_scriptcode
= scriptcode
;
5319 a
.a_options
= options
;
5321 a
.a_searchstate
= searchstate
;
5324 _err
= (*vp
->v_op
[vnop_searchfs_desc
.vdesc_offset
])(&a
);
5325 DTRACE_FSINFO(searchfs
, vnode_t
, vp
);
5329 #endif /* CONFIG_SEARCHFS */
5334 *#% copyfile fvp U U U
5335 *#% copyfile tdvp L U U
5336 *#% copyfile tvp X U U
5339 struct vnop_copyfile_args
{
5340 struct vnodeop_desc
*a_desc
;
5344 struct componentname
*a_tcnp
;
5347 vfs_context_t a_context
;
5351 VNOP_COPYFILE(struct vnode
*fvp
, struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
5352 int mode
, int flags
, vfs_context_t ctx
)
5355 struct vnop_copyfile_args a
;
5356 a
.a_desc
= &vnop_copyfile_desc
;
5364 _err
= (*fvp
->v_op
[vnop_copyfile_desc
.vdesc_offset
])(&a
);
5365 DTRACE_FSINFO(copyfile
, vnode_t
, fvp
);
5370 struct vnop_clonefile_args
{
5371 struct vnodeop_desc
*a_desc
;
5375 struct componentname
*a_cnp
;
5376 struct vnode_attr
*a_vap
;
5378 vfs_context_t a_context
;
5379 int (*a_dir_clone_authorizer
)( /* Authorization callback */
5380 struct vnode_attr
*vap
, /* attribute to be authorized */
5381 kauth_action_t action
, /* action for which attribute is to be authorized */
5382 struct vnode_attr
*dvap
, /* target directory attributes */
5383 vnode_t sdvp
, /* source directory vnode pointer (optional) */
5384 mount_t mp
, /* mount point of filesystem */
5385 dir_clone_authorizer_op_t vattr_op
, /* specific operation requested : setup, authorization or cleanup */
5386 vfs_context_t ctx
, /* As passed to VNOP */
5387 void *reserved
); /* Always NULL */
5388 void *a_reserved
; /* Currently unused */
5393 VNOP_CLONEFILE(vnode_t fvp
, vnode_t dvp
, vnode_t
*vpp
,
5394 struct componentname
*cnp
, struct vnode_attr
*vap
, uint32_t flags
,
5398 struct vnop_clonefile_args a
;
5399 a
.a_desc
= &vnop_clonefile_desc
;
5408 if (vnode_vtype(fvp
) == VDIR
)
5409 a
.a_dir_clone_authorizer
= vnode_attr_authorize_dir_clone
;
5411 a
.a_dir_clone_authorizer
= NULL
;
5413 _err
= (*dvp
->v_op
[vnop_clonefile_desc
.vdesc_offset
])(&a
);
5415 if (_err
== 0 && *vpp
)
5416 DTRACE_FSINFO(clonefile
, vnode_t
, *vpp
);
5418 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
5424 VNOP_GETXATTR(vnode_t vp
, const char *name
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5426 struct vnop_getxattr_args a
;
5429 a
.a_desc
= &vnop_getxattr_desc
;
5434 a
.a_options
= options
;
5437 error
= (*vp
->v_op
[vnop_getxattr_desc
.vdesc_offset
])(&a
);
5438 DTRACE_FSINFO(getxattr
, vnode_t
, vp
);
5444 VNOP_SETXATTR(vnode_t vp
, const char *name
, uio_t uio
, int options
, vfs_context_t ctx
)
5446 struct vnop_setxattr_args a
;
5449 a
.a_desc
= &vnop_setxattr_desc
;
5453 a
.a_options
= options
;
5456 error
= (*vp
->v_op
[vnop_setxattr_desc
.vdesc_offset
])(&a
);
5457 DTRACE_FSINFO(setxattr
, vnode_t
, vp
);
5460 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
5462 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5468 VNOP_REMOVEXATTR(vnode_t vp
, const char *name
, int options
, vfs_context_t ctx
)
5470 struct vnop_removexattr_args a
;
5473 a
.a_desc
= &vnop_removexattr_desc
;
5476 a
.a_options
= options
;
5479 error
= (*vp
->v_op
[vnop_removexattr_desc
.vdesc_offset
])(&a
);
5480 DTRACE_FSINFO(removexattr
, vnode_t
, vp
);
5482 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5488 VNOP_LISTXATTR(vnode_t vp
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5490 struct vnop_listxattr_args a
;
5493 a
.a_desc
= &vnop_listxattr_desc
;
5497 a
.a_options
= options
;
5500 error
= (*vp
->v_op
[vnop_listxattr_desc
.vdesc_offset
])(&a
);
5501 DTRACE_FSINFO(listxattr
, vnode_t
, vp
);
5510 *#% blktooff vp = = =
5513 struct vnop_blktooff_args
{
5514 struct vnodeop_desc
*a_desc
;
5521 VNOP_BLKTOOFF(struct vnode
*vp
, daddr64_t lblkno
, off_t
*offset
)
5524 struct vnop_blktooff_args a
;
5526 a
.a_desc
= &vnop_blktooff_desc
;
5528 a
.a_lblkno
= lblkno
;
5529 a
.a_offset
= offset
;
5531 _err
= (*vp
->v_op
[vnop_blktooff_desc
.vdesc_offset
])(&a
);
5532 DTRACE_FSINFO(blktooff
, vnode_t
, vp
);
5540 *#% offtoblk vp = = =
5543 struct vnop_offtoblk_args
{
5544 struct vnodeop_desc
*a_desc
;
5547 daddr64_t
*a_lblkno
;
5551 VNOP_OFFTOBLK(struct vnode
*vp
, off_t offset
, daddr64_t
*lblkno
)
5554 struct vnop_offtoblk_args a
;
5556 a
.a_desc
= &vnop_offtoblk_desc
;
5558 a
.a_offset
= offset
;
5559 a
.a_lblkno
= lblkno
;
5561 _err
= (*vp
->v_op
[vnop_offtoblk_desc
.vdesc_offset
])(&a
);
5562 DTRACE_FSINFO(offtoblk
, vnode_t
, vp
);
5570 *#% blockmap vp L L L
5573 struct vnop_blockmap_args
{
5574 struct vnodeop_desc
*a_desc
;
5582 vfs_context_t a_context
;
5586 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
)
5589 struct vnop_blockmap_args a
;
5590 size_t localrun
= 0;
5593 ctx
= vfs_context_current();
5595 a
.a_desc
= &vnop_blockmap_desc
;
5597 a
.a_foffset
= foffset
;
5600 a
.a_run
= &localrun
;
5605 _err
= (*vp
->v_op
[vnop_blockmap_desc
.vdesc_offset
])(&a
);
5606 DTRACE_FSINFO(blockmap
, vnode_t
, vp
);
5609 * We used a local variable to request information from the underlying
5610 * filesystem about the length of the I/O run in question. If
5611 * we get malformed output from the filesystem, we cap it to the length
5612 * requested, at most. Update 'run' on the way out.
5615 if (localrun
> size
) {
5628 struct vnop_strategy_args
{
5629 struct vnodeop_desc
*a_desc
;
5635 VNOP_STRATEGY(struct buf
*bp
)
5638 struct vnop_strategy_args a
;
5639 vnode_t vp
= buf_vnode(bp
);
5640 a
.a_desc
= &vnop_strategy_desc
;
5642 _err
= (*vp
->v_op
[vnop_strategy_desc
.vdesc_offset
])(&a
);
5643 DTRACE_FSINFO(strategy
, vnode_t
, vp
);
5648 struct vnop_bwrite_args
{
5649 struct vnodeop_desc
*a_desc
;
5654 VNOP_BWRITE(struct buf
*bp
)
5657 struct vnop_bwrite_args a
;
5658 vnode_t vp
= buf_vnode(bp
);
5659 a
.a_desc
= &vnop_bwrite_desc
;
5661 _err
= (*vp
->v_op
[vnop_bwrite_desc
.vdesc_offset
])(&a
);
5662 DTRACE_FSINFO(bwrite
, vnode_t
, vp
);
5667 struct vnop_kqfilt_add_args
{
5668 struct vnodeop_desc
*a_desc
;
5671 vfs_context_t a_context
;
5675 VNOP_KQFILT_ADD(struct vnode
*vp
, struct knote
*kn
, vfs_context_t ctx
)
5678 struct vnop_kqfilt_add_args a
;
5680 a
.a_desc
= VDESC(vnop_kqfilt_add
);
5685 _err
= (*vp
->v_op
[vnop_kqfilt_add_desc
.vdesc_offset
])(&a
);
5686 DTRACE_FSINFO(kqfilt_add
, vnode_t
, vp
);
5692 struct vnop_kqfilt_remove_args
{
5693 struct vnodeop_desc
*a_desc
;
5696 vfs_context_t a_context
;
5700 VNOP_KQFILT_REMOVE(struct vnode
*vp
, uintptr_t ident
, vfs_context_t ctx
)
5703 struct vnop_kqfilt_remove_args a
;
5705 a
.a_desc
= VDESC(vnop_kqfilt_remove
);
5710 _err
= (*vp
->v_op
[vnop_kqfilt_remove_desc
.vdesc_offset
])(&a
);
5711 DTRACE_FSINFO(kqfilt_remove
, vnode_t
, vp
);
5717 VNOP_MONITOR(vnode_t vp
, uint32_t events
, uint32_t flags
, void *handle
, vfs_context_t ctx
)
5720 struct vnop_monitor_args a
;
5722 a
.a_desc
= VDESC(vnop_monitor
);
5724 a
.a_events
= events
;
5726 a
.a_handle
= handle
;
5729 _err
= (*vp
->v_op
[vnop_monitor_desc
.vdesc_offset
])(&a
);
5730 DTRACE_FSINFO(monitor
, vnode_t
, vp
);
5736 struct vnop_setlabel_args
{
5737 struct vnodeop_desc
*a_desc
;
5740 vfs_context_t a_context
;
5744 VNOP_SETLABEL(struct vnode
*vp
, struct label
*label
, vfs_context_t ctx
)
5747 struct vnop_setlabel_args a
;
5749 a
.a_desc
= VDESC(vnop_setlabel
);
5754 _err
= (*vp
->v_op
[vnop_setlabel_desc
.vdesc_offset
])(&a
);
5755 DTRACE_FSINFO(setlabel
, vnode_t
, vp
);
5763 * Get a named streamed
5766 VNOP_GETNAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, enum nsoperation operation
, int flags
, vfs_context_t ctx
)
5769 struct vnop_getnamedstream_args a
;
5771 a
.a_desc
= &vnop_getnamedstream_desc
;
5775 a
.a_operation
= operation
;
5779 _err
= (*vp
->v_op
[vnop_getnamedstream_desc
.vdesc_offset
])(&a
);
5780 DTRACE_FSINFO(getnamedstream
, vnode_t
, vp
);
5785 * Create a named streamed
5788 VNOP_MAKENAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, int flags
, vfs_context_t ctx
)
5791 struct vnop_makenamedstream_args a
;
5793 a
.a_desc
= &vnop_makenamedstream_desc
;
5800 _err
= (*vp
->v_op
[vnop_makenamedstream_desc
.vdesc_offset
])(&a
);
5801 DTRACE_FSINFO(makenamedstream
, vnode_t
, vp
);
5807 * Remove a named streamed
5810 VNOP_REMOVENAMEDSTREAM(vnode_t vp
, vnode_t svp
, const char *name
, int flags
, vfs_context_t ctx
)
5813 struct vnop_removenamedstream_args a
;
5815 a
.a_desc
= &vnop_removenamedstream_desc
;
5822 _err
= (*vp
->v_op
[vnop_removenamedstream_desc
.vdesc_offset
])(&a
);
5823 DTRACE_FSINFO(removenamedstream
, vnode_t
, vp
);