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_extendedsecurity(mount_t mp
)
632 return(mp
->mnt_kern_flag
& MNTK_EXTENDED_SECURITY
);
635 /* returns the max size of short symlink in this mount_t */
637 vfs_maxsymlen(mount_t mp
)
639 return(mp
->mnt_maxsymlinklen
);
642 /* set max size of short symlink on mount_t */
644 vfs_setmaxsymlen(mount_t mp
, uint32_t symlen
)
646 mp
->mnt_maxsymlinklen
= symlen
;
649 /* return a pointer to the RO vfs_statfs associated with mount_t */
651 vfs_statfs(mount_t mp
)
653 return(&mp
->mnt_vfsstat
);
657 vfs_getattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
661 if ((error
= VFS_GETATTR(mp
, vfa
, ctx
)) != 0)
665 * If we have a filesystem create time, use it to default some others.
667 if (VFSATTR_IS_SUPPORTED(vfa
, f_create_time
)) {
668 if (VFSATTR_IS_ACTIVE(vfa
, f_modify_time
) && !VFSATTR_IS_SUPPORTED(vfa
, f_modify_time
))
669 VFSATTR_RETURN(vfa
, f_modify_time
, vfa
->f_create_time
);
676 vfs_setattr(mount_t mp
, struct vfs_attr
*vfa
, vfs_context_t ctx
)
680 if (vfs_isrdonly(mp
))
683 error
= VFS_SETATTR(mp
, vfa
, ctx
);
686 * If we had alternate ways of setting vfs attributes, we'd
693 /* return the private data handle stored in mount_t */
695 vfs_fsprivate(mount_t mp
)
697 return(mp
->mnt_data
);
700 /* set the private data handle in mount_t */
702 vfs_setfsprivate(mount_t mp
, void *mntdata
)
705 mp
->mnt_data
= mntdata
;
709 /* query whether the mount point supports native EAs */
711 vfs_nativexattrs(mount_t mp
) {
712 return (mp
->mnt_kern_flag
& MNTK_EXTENDED_ATTRS
);
716 * return the block size of the underlying
717 * device associated with mount_t
720 vfs_devblocksize(mount_t mp
) {
722 return(mp
->mnt_devblocksize
);
726 * Returns vnode with an iocount that must be released with vnode_put()
729 vfs_vnodecovered(mount_t mp
)
731 vnode_t vp
= mp
->mnt_vnodecovered
;
732 if ((vp
== NULL
) || (vnode_getwithref(vp
) != 0)) {
740 * Returns device vnode backing a mountpoint with an iocount (if valid vnode exists).
741 * The iocount must be released with vnode_put(). Note that this KPI is subtle
742 * with respect to the validity of using this device vnode for anything substantial
743 * (which is discouraged). If commands are sent to the device driver without
744 * taking proper steps to ensure that the device is still open, chaos may ensue.
745 * Similarly, this routine should only be called if there is some guarantee that
746 * the mount itself is still valid.
749 vfs_devvp(mount_t mp
)
751 vnode_t vp
= mp
->mnt_devvp
;
753 if ((vp
!= NULLVP
) && (vnode_get(vp
) == 0)) {
761 * return the io attributes associated with mount_t
764 vfs_ioattr(mount_t mp
, struct vfsioattr
*ioattrp
)
766 ioattrp
->io_reserved
[0] = NULL
;
767 ioattrp
->io_reserved
[1] = NULL
;
769 ioattrp
->io_maxreadcnt
= MAXPHYS
;
770 ioattrp
->io_maxwritecnt
= MAXPHYS
;
771 ioattrp
->io_segreadcnt
= 32;
772 ioattrp
->io_segwritecnt
= 32;
773 ioattrp
->io_maxsegreadsize
= MAXPHYS
;
774 ioattrp
->io_maxsegwritesize
= MAXPHYS
;
775 ioattrp
->io_devblocksize
= DEV_BSIZE
;
776 ioattrp
->io_flags
= 0;
777 ioattrp
->io_max_swappin_available
= 0;
779 ioattrp
->io_maxreadcnt
= mp
->mnt_maxreadcnt
;
780 ioattrp
->io_maxwritecnt
= mp
->mnt_maxwritecnt
;
781 ioattrp
->io_segreadcnt
= mp
->mnt_segreadcnt
;
782 ioattrp
->io_segwritecnt
= mp
->mnt_segwritecnt
;
783 ioattrp
->io_maxsegreadsize
= mp
->mnt_maxsegreadsize
;
784 ioattrp
->io_maxsegwritesize
= mp
->mnt_maxsegwritesize
;
785 ioattrp
->io_devblocksize
= mp
->mnt_devblocksize
;
786 ioattrp
->io_flags
= mp
->mnt_ioflags
;
787 ioattrp
->io_max_swappin_available
= mp
->mnt_max_swappin_available
;
793 * set the IO attributes associated with mount_t
796 vfs_setioattr(mount_t mp
, struct vfsioattr
* ioattrp
)
800 mp
->mnt_maxreadcnt
= ioattrp
->io_maxreadcnt
;
801 mp
->mnt_maxwritecnt
= ioattrp
->io_maxwritecnt
;
802 mp
->mnt_segreadcnt
= ioattrp
->io_segreadcnt
;
803 mp
->mnt_segwritecnt
= ioattrp
->io_segwritecnt
;
804 mp
->mnt_maxsegreadsize
= ioattrp
->io_maxsegreadsize
;
805 mp
->mnt_maxsegwritesize
= ioattrp
->io_maxsegwritesize
;
806 mp
->mnt_devblocksize
= ioattrp
->io_devblocksize
;
807 mp
->mnt_ioflags
= ioattrp
->io_flags
;
808 mp
->mnt_max_swappin_available
= ioattrp
->io_max_swappin_available
;
812 * Add a new filesystem into the kernel specified in passed in
813 * vfstable structure. It fills in the vnode
814 * dispatch vector that is to be passed to when vnodes are created.
815 * It returns a handle which is to be used to when the FS is to be removed
817 typedef int (*PFI
)(void *);
818 extern int vfs_opv_numops
;
820 vfs_fsadd(struct vfs_fsentry
*vfe
, vfstable_t
*handle
)
822 struct vfstable
*newvfstbl
= NULL
;
824 int (***opv_desc_vector_p
)(void *);
825 int (**opv_desc_vector
)(void *);
826 struct vnodeopv_entry_desc
*opve_descp
;
832 * This routine is responsible for all the initialization that would
833 * ordinarily be done as part of the system startup;
836 if (vfe
== (struct vfs_fsentry
*)0)
839 desccount
= vfe
->vfe_vopcnt
;
840 if ((desccount
<=0) || ((desccount
> 8)) || (vfe
->vfe_vfsops
== (struct vfsops
*)NULL
)
841 || (vfe
->vfe_opvdescs
== (struct vnodeopv_desc
**)NULL
))
844 /* Non-threadsafe filesystems are not supported */
845 if ((vfe
->vfe_flags
& (VFS_TBLTHREADSAFE
| VFS_TBLFSNODELOCK
)) == 0) {
849 MALLOC(newvfstbl
, void *, sizeof(struct vfstable
), M_TEMP
,
851 bzero(newvfstbl
, sizeof(struct vfstable
));
852 newvfstbl
->vfc_vfsops
= vfe
->vfe_vfsops
;
853 strncpy(&newvfstbl
->vfc_name
[0], vfe
->vfe_fsname
, MFSNAMELEN
);
854 if ((vfe
->vfe_flags
& VFS_TBLNOTYPENUM
))
855 newvfstbl
->vfc_typenum
= maxvfstypenum
++;
857 newvfstbl
->vfc_typenum
= vfe
->vfe_fstypenum
;
859 newvfstbl
->vfc_refcount
= 0;
860 newvfstbl
->vfc_flags
= 0;
861 newvfstbl
->vfc_mountroot
= NULL
;
862 newvfstbl
->vfc_next
= NULL
;
863 newvfstbl
->vfc_vfsflags
= 0;
864 if (vfe
->vfe_flags
& VFS_TBL64BITREADY
)
865 newvfstbl
->vfc_vfsflags
|= VFC_VFS64BITREADY
;
866 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEINV2
)
867 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEINV2
;
868 if (vfe
->vfe_flags
& VFS_TBLVNOP_PAGEOUTV2
)
869 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_PAGEOUTV2
;
870 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) == VFS_TBLLOCALVOL
)
871 newvfstbl
->vfc_flags
|= MNT_LOCAL
;
872 if ((vfe
->vfe_flags
& VFS_TBLLOCALVOL
) && (vfe
->vfe_flags
& VFS_TBLGENERICMNTARGS
) == 0)
873 newvfstbl
->vfc_vfsflags
|= VFC_VFSLOCALARGS
;
875 newvfstbl
->vfc_vfsflags
|= VFC_VFSGENERICARGS
;
877 if (vfe
->vfe_flags
& VFS_TBLNATIVEXATTR
)
878 newvfstbl
->vfc_vfsflags
|= VFC_VFSNATIVEXATTR
;
879 if (vfe
->vfe_flags
& VFS_TBLUNMOUNT_PREFLIGHT
)
880 newvfstbl
->vfc_vfsflags
|= VFC_VFSPREFLIGHT
;
881 if (vfe
->vfe_flags
& VFS_TBLREADDIR_EXTENDED
)
882 newvfstbl
->vfc_vfsflags
|= VFC_VFSREADDIR_EXTENDED
;
883 if (vfe
->vfe_flags
& VFS_TBLNOMACLABEL
)
884 newvfstbl
->vfc_vfsflags
|= VFC_VFSNOMACLABEL
;
885 if (vfe
->vfe_flags
& VFS_TBLVNOP_NOUPDATEID_RENAME
)
886 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_NOUPDATEID_RENAME
;
887 if (vfe
->vfe_flags
& VFS_TBLVNOP_SECLUDE_RENAME
)
888 newvfstbl
->vfc_vfsflags
|= VFC_VFSVNOP_SECLUDE_RENAME
;
889 if (vfe
->vfe_flags
& VFS_TBLCANMOUNTROOT
)
890 newvfstbl
->vfc_vfsflags
|= VFC_VFSCANMOUNTROOT
;
893 * Allocate and init the vectors.
894 * Also handle backwards compatibility.
896 * We allocate one large block to hold all <desccount>
897 * vnode operation vectors stored contiguously.
899 /* XXX - shouldn't be M_TEMP */
901 descsize
= desccount
* vfs_opv_numops
* sizeof(PFI
);
902 MALLOC(descptr
, PFI
*, descsize
,
904 bzero(descptr
, descsize
);
906 newvfstbl
->vfc_descptr
= descptr
;
907 newvfstbl
->vfc_descsize
= descsize
;
909 newvfstbl
->vfc_sysctl
= NULL
;
911 for (i
= 0; i
< desccount
; i
++ ) {
912 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
914 * Fill in the caller's pointer to the start of the i'th vector.
915 * They'll need to supply it when calling vnode_create.
917 opv_desc_vector
= descptr
+ i
* vfs_opv_numops
;
918 *opv_desc_vector_p
= opv_desc_vector
;
920 for (j
= 0; vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
].opve_op
; j
++) {
921 opve_descp
= &(vfe
->vfe_opvdescs
[i
]->opv_desc_ops
[j
]);
924 * Sanity check: is this operation listed
925 * in the list of operations? We check this
926 * by seeing if its offset is zero. Since
927 * the default routine should always be listed
928 * first, it should be the only one with a zero
929 * offset. Any other operation with a zero
930 * offset is probably not listed in
931 * vfs_op_descs, and so is probably an error.
933 * A panic here means the layer programmer
934 * has committed the all-too common bug
935 * of adding a new operation to the layer's
936 * list of vnode operations but
937 * not adding the operation to the system-wide
938 * list of supported operations.
940 if (opve_descp
->opve_op
->vdesc_offset
== 0 &&
941 opve_descp
->opve_op
->vdesc_offset
!= VOFFSET(vnop_default
)) {
942 printf("vfs_fsadd: operation %s not listed in %s.\n",
943 opve_descp
->opve_op
->vdesc_name
,
945 panic("vfs_fsadd: bad operation");
948 * Fill in this entry.
950 opv_desc_vector
[opve_descp
->opve_op
->vdesc_offset
] =
951 opve_descp
->opve_impl
;
956 * Finally, go back and replace unfilled routines
957 * with their default. (Sigh, an O(n^3) algorithm. I
958 * could make it better, but that'd be work, and n is small.)
960 opv_desc_vector_p
= vfe
->vfe_opvdescs
[i
]->opv_desc_vector_p
;
963 * Force every operations vector to have a default routine.
965 opv_desc_vector
= *opv_desc_vector_p
;
966 if (opv_desc_vector
[VOFFSET(vnop_default
)] == NULL
)
967 panic("vfs_fsadd: operation vector without default routine.");
968 for (j
= 0; j
< vfs_opv_numops
; j
++)
969 if (opv_desc_vector
[j
] == NULL
)
971 opv_desc_vector
[VOFFSET(vnop_default
)];
973 } /* end of each vnodeopv_desc parsing */
977 *handle
= vfstable_add(newvfstbl
);
979 if (newvfstbl
->vfc_typenum
<= maxvfstypenum
)
980 maxvfstypenum
= newvfstbl
->vfc_typenum
+ 1;
982 if (newvfstbl
->vfc_vfsops
->vfs_init
) {
984 bzero(&vfsc
, sizeof(struct vfsconf
));
985 vfsc
.vfc_reserved1
= 0;
986 bcopy((*handle
)->vfc_name
, vfsc
.vfc_name
, sizeof(vfsc
.vfc_name
));
987 vfsc
.vfc_typenum
= (*handle
)->vfc_typenum
;
988 vfsc
.vfc_refcount
= (*handle
)->vfc_refcount
;
989 vfsc
.vfc_flags
= (*handle
)->vfc_flags
;
990 vfsc
.vfc_reserved2
= 0;
991 vfsc
.vfc_reserved3
= 0;
993 (*newvfstbl
->vfc_vfsops
->vfs_init
)(&vfsc
);
996 FREE(newvfstbl
, M_TEMP
);
1002 * Removes the filesystem from kernel.
1003 * The argument passed in is the handle that was given when
1004 * file system was added
1007 vfs_fsremove(vfstable_t handle
)
1009 struct vfstable
* vfstbl
= (struct vfstable
*)handle
;
1010 void *old_desc
= NULL
;
1013 /* Preflight check for any mounts */
1015 if ( vfstbl
->vfc_refcount
!= 0 ) {
1016 mount_list_unlock();
1021 * save the old descriptor; the free cannot occur unconditionally,
1022 * since vfstable_del() may fail.
1024 if (vfstbl
->vfc_descptr
&& vfstbl
->vfc_descsize
) {
1025 old_desc
= vfstbl
->vfc_descptr
;
1027 err
= vfstable_del(vfstbl
);
1029 mount_list_unlock();
1031 /* free the descriptor if the delete was successful */
1032 if (err
== 0 && old_desc
) {
1033 FREE(old_desc
, M_TEMP
);
1039 void vfs_setowner(mount_t mp
, uid_t uid
, gid_t gid
)
1041 mp
->mnt_fsowner
= uid
;
1042 mp
->mnt_fsgroup
= gid
;
1046 * Callers should be careful how they use this; accessing
1047 * mnt_last_write_completed_timestamp is not thread-safe. Writing to
1048 * it isn't either. Point is: be prepared to deal with strange values
1051 uint64_t vfs_idle_time(mount_t mp
)
1053 if (mp
->mnt_pending_write_size
)
1061 - mp
->mnt_last_write_completed_timestamp
.tv_sec
) * 1000000
1062 + now
.tv_usec
- mp
->mnt_last_write_completed_timestamp
.tv_usec
);
1066 vfs_context_pid(vfs_context_t ctx
)
1068 return (proc_pid(vfs_context_proc(ctx
)));
1072 vfs_context_suser(vfs_context_t ctx
)
1074 return (suser(ctx
->vc_ucred
, NULL
));
1078 * Return bit field of signals posted to all threads in the context's process.
1080 * XXX Signals should be tied to threads, not processes, for most uses of this
1084 vfs_context_issignal(vfs_context_t ctx
, sigset_t mask
)
1086 proc_t p
= vfs_context_proc(ctx
);
1088 return(proc_pendingsignals(p
, mask
));
1093 vfs_context_is64bit(vfs_context_t ctx
)
1095 proc_t proc
= vfs_context_proc(ctx
);
1098 return(proc_is64bit(proc
));
1106 * Description: Given a vfs_context_t, return the proc_t associated with it.
1108 * Parameters: vfs_context_t The context to use
1110 * Returns: proc_t The process for this context
1112 * Notes: This function will return the current_proc() if any of the
1113 * following conditions are true:
1115 * o The supplied context pointer is NULL
1116 * o There is no Mach thread associated with the context
1117 * o There is no Mach task associated with the Mach thread
1118 * o There is no proc_t associated with the Mach task
1119 * o The proc_t has no per process open file table
1120 * o The proc_t is post-vfork()
1122 * This causes this function to return a value matching as
1123 * closely as possible the previous behaviour, while at the
1124 * same time avoiding the task lending that results from vfork()
1127 vfs_context_proc(vfs_context_t ctx
)
1131 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1132 proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
);
1133 if (proc
!= NULL
&& (proc
->p_fd
== NULL
|| (proc
->p_lflag
& P_LVFORK
)))
1136 return(proc
== NULL
? current_proc() : proc
);
1140 * vfs_context_get_special_port
1142 * Description: Return the requested special port from the task associated
1143 * with the given context.
1145 * Parameters: vfs_context_t The context to use
1146 * int Index of special port
1147 * ipc_port_t * Pointer to returned port
1149 * Returns: kern_return_t see task_get_special_port()
1152 vfs_context_get_special_port(vfs_context_t ctx
, int which
, ipc_port_t
*portp
)
1156 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1157 task
= get_threadtask(ctx
->vc_thread
);
1159 return task_get_special_port(task
, which
, portp
);
1163 * vfs_context_set_special_port
1165 * Description: Set the requested special port in 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 New special port
1172 * Returns: kern_return_t see task_set_special_port()
1175 vfs_context_set_special_port(vfs_context_t ctx
, int which
, ipc_port_t port
)
1179 if (ctx
!= NULL
&& ctx
->vc_thread
!= NULL
)
1180 task
= get_threadtask(ctx
->vc_thread
);
1182 return task_set_special_port(task
, which
, port
);
1186 * vfs_context_thread
1188 * Description: Return the Mach thread associated with a vfs_context_t
1190 * Parameters: vfs_context_t The context to use
1192 * Returns: thread_t The thread for this context, or
1193 * NULL, if there is not one.
1195 * Notes: NULL thread_t's are legal, but discouraged. They occur only
1196 * as a result of a static vfs_context_t declaration in a function
1197 * and will result in this function returning NULL.
1199 * This is intentional; this function should NOT return the
1200 * current_thread() in this case.
1203 vfs_context_thread(vfs_context_t ctx
)
1205 return(ctx
->vc_thread
);
1212 * Description: Returns a reference on the vnode for the current working
1213 * directory for the supplied context
1215 * Parameters: vfs_context_t The context to use
1217 * Returns: vnode_t The current working directory
1220 * Notes: The function first attempts to obtain the current directory
1221 * from the thread, and if it is not present there, falls back
1222 * to obtaining it from the process instead. If it can't be
1223 * obtained from either place, we return NULLVP.
1226 vfs_context_cwd(vfs_context_t ctx
)
1228 vnode_t cwd
= NULLVP
;
1230 if(ctx
!= NULL
&& ctx
->vc_thread
!= NULL
) {
1231 uthread_t uth
= get_bsdthread_info(ctx
->vc_thread
);
1235 * Get the cwd from the thread; if there isn't one, get it
1236 * from the process, instead.
1238 if ((cwd
= uth
->uu_cdir
) == NULLVP
&&
1239 (proc
= (proc_t
)get_bsdthreadtask_info(ctx
->vc_thread
)) != NULL
&&
1241 cwd
= proc
->p_fd
->fd_cdir
;
1248 * vfs_context_create
1250 * Description: Allocate and initialize a new context.
1252 * Parameters: vfs_context_t: Context to copy, or NULL for new
1254 * Returns: Pointer to new context
1256 * Notes: Copy cred and thread from argument, if available; else
1257 * initialize with current thread and new cred. Returns
1258 * with a reference held on the credential.
1261 vfs_context_create(vfs_context_t ctx
)
1263 vfs_context_t newcontext
;
1265 newcontext
= (vfs_context_t
)kalloc(sizeof(struct vfs_context
));
1268 kauth_cred_t safecred
;
1270 newcontext
->vc_thread
= ctx
->vc_thread
;
1271 safecred
= ctx
->vc_ucred
;
1273 newcontext
->vc_thread
= current_thread();
1274 safecred
= kauth_cred_get();
1276 if (IS_VALID_CRED(safecred
))
1277 kauth_cred_ref(safecred
);
1278 newcontext
->vc_ucred
= safecred
;
1286 vfs_context_current(void)
1288 vfs_context_t ctx
= NULL
;
1289 volatile uthread_t ut
= (uthread_t
)get_bsdthread_info(current_thread());
1292 if (ut
->uu_context
.vc_ucred
!= NULL
) {
1293 ctx
= &ut
->uu_context
;
1297 return(ctx
== NULL
? vfs_context_kernel() : ctx
);
1304 * Dangerous hack - adopt the first kernel thread as the current thread, to
1305 * get to the vfs_context_t in the uthread associated with a kernel thread.
1306 * This is used by UDF to make the call into IOCDMediaBSDClient,
1307 * IOBDMediaBSDClient, and IODVDMediaBSDClient to determine whether the
1308 * ioctl() is being called from kernel or user space (and all this because
1309 * we do not pass threads into our ioctl()'s, instead of processes).
1311 * This is also used by imageboot_setup(), called early from bsd_init() after
1312 * kernproc has been given a credential.
1314 * Note: The use of proc_thread() here is a convenience to avoid inclusion
1315 * of many Mach headers to do the reference directly rather than indirectly;
1316 * we will need to forego this convenience when we reture proc_thread().
1318 static struct vfs_context kerncontext
;
1320 vfs_context_kernel(void)
1322 if (kerncontext
.vc_ucred
== NOCRED
)
1323 kerncontext
.vc_ucred
= kernproc
->p_ucred
;
1324 if (kerncontext
.vc_thread
== NULL
)
1325 kerncontext
.vc_thread
= proc_thread(kernproc
);
1327 return(&kerncontext
);
1332 vfs_context_rele(vfs_context_t ctx
)
1335 if (IS_VALID_CRED(ctx
->vc_ucred
))
1336 kauth_cred_unref(&ctx
->vc_ucred
);
1337 kfree(ctx
, sizeof(struct vfs_context
));
1344 vfs_context_ucred(vfs_context_t ctx
)
1346 return (ctx
->vc_ucred
);
1350 * Return true if the context is owned by the superuser.
1353 vfs_context_issuser(vfs_context_t ctx
)
1355 return(kauth_cred_issuser(vfs_context_ucred(ctx
)));
1358 int vfs_context_iskernel(vfs_context_t ctx
)
1360 return ctx
== &kerncontext
;
1364 * Given a context, for all fields of vfs_context_t which
1365 * are not held with a reference, set those fields to the
1366 * values for the current execution context. Currently, this
1367 * just means the vc_thread.
1369 * Returns: 0 for success, nonzero for failure
1371 * The intended use is:
1372 * 1. vfs_context_create() gets the caller a context
1373 * 2. vfs_context_bind() sets the unrefcounted data
1374 * 3. vfs_context_rele() releases the context
1378 vfs_context_bind(vfs_context_t ctx
)
1380 ctx
->vc_thread
= current_thread();
1384 int vfs_isswapmount(mount_t mnt
)
1386 return mnt
&& ISSET(mnt
->mnt_kern_flag
, MNTK_SWAP_MOUNT
) ? 1 : 0;
1389 /* XXXXXXXXXXXXXX VNODE KAPIS XXXXXXXXXXXXXXXXXXXXXXXXX */
1393 * Convert between vnode types and inode formats (since POSIX.1
1394 * defines mode word of stat structure in terms of inode formats).
1397 vnode_iftovt(int mode
)
1399 return(iftovt_tab
[((mode
) & S_IFMT
) >> 12]);
1403 vnode_vttoif(enum vtype indx
)
1405 return(vttoif_tab
[(int)(indx
)]);
1409 vnode_makeimode(int indx
, int mode
)
1411 return (int)(VTTOIF(indx
) | (mode
));
1416 * vnode manipulation functions.
1419 /* returns system root vnode iocount; It should be released using vnode_put() */
1425 error
= vnode_get(rootvnode
);
1427 return ((vnode_t
)0);
1434 vnode_vid(vnode_t vp
)
1436 return ((uint32_t)(vp
->v_id
));
1440 vnode_mount(vnode_t vp
)
1442 return (vp
->v_mount
);
1447 vnode_mountdevvp(vnode_t vp
)
1450 return (vp
->v_mount
->mnt_devvp
);
1452 return ((vnode_t
)0);
1457 vnode_mountedhere(vnode_t vp
)
1461 if ((vp
->v_type
== VDIR
) && ((mp
= vp
->v_mountedhere
) != NULL
) &&
1462 (mp
->mnt_vnodecovered
== vp
))
1465 return (mount_t
)NULL
;
1468 /* returns vnode type of vnode_t */
1470 vnode_vtype(vnode_t vp
)
1472 return (vp
->v_type
);
1475 /* returns FS specific node saved in vnode */
1477 vnode_fsnode(vnode_t vp
)
1479 return (vp
->v_data
);
1483 vnode_clearfsnode(vnode_t vp
)
1489 vnode_specrdev(vnode_t vp
)
1495 /* Accessor functions */
1496 /* is vnode_t a root vnode */
1498 vnode_isvroot(vnode_t vp
)
1500 return ((vp
->v_flag
& VROOT
)? 1 : 0);
1503 /* is vnode_t a system vnode */
1505 vnode_issystem(vnode_t vp
)
1507 return ((vp
->v_flag
& VSYSTEM
)? 1 : 0);
1510 /* is vnode_t a swap file vnode */
1512 vnode_isswap(vnode_t vp
)
1514 return ((vp
->v_flag
& VSWAP
)? 1 : 0);
1517 /* is vnode_t a tty */
1519 vnode_istty(vnode_t vp
)
1521 return ((vp
->v_flag
& VISTTY
) ? 1 : 0);
1524 /* if vnode_t mount operation in progress */
1526 vnode_ismount(vnode_t vp
)
1528 return ((vp
->v_flag
& VMOUNT
)? 1 : 0);
1531 /* is this vnode under recyle now */
1533 vnode_isrecycled(vnode_t vp
)
1537 vnode_lock_spin(vp
);
1538 ret
= (vp
->v_lflag
& (VL_TERMINATE
|VL_DEAD
))? 1 : 0;
1543 /* vnode was created by background task requesting rapid aging
1544 and has not since been referenced by a normal task */
1546 vnode_israge(vnode_t vp
)
1548 return ((vp
->v_flag
& VRAGE
)? 1 : 0);
1552 vnode_needssnapshots(vnode_t vp
)
1554 return ((vp
->v_flag
& VNEEDSSNAPSHOT
)? 1 : 0);
1558 /* Check the process/thread to see if we should skip atime updates */
1560 vfs_ctx_skipatime (vfs_context_t ctx
) {
1565 proc
= vfs_context_proc(ctx
);
1566 thr
= vfs_context_thread (ctx
);
1568 /* Validate pointers in case we were invoked via a kernel context */
1570 ut
= get_bsdthread_info (thr
);
1572 if (proc
->p_lflag
& P_LRAGE_VNODES
) {
1577 if (ut
->uu_flag
& UT_RAGE_VNODES
) {
1585 /* is vnode_t marked to not keep data cached once it's been consumed */
1587 vnode_isnocache(vnode_t vp
)
1589 return ((vp
->v_flag
& VNOCACHE_DATA
)? 1 : 0);
1593 * has sequential readahead been disabled on this vnode
1596 vnode_isnoreadahead(vnode_t vp
)
1598 return ((vp
->v_flag
& VRAOFF
)? 1 : 0);
1602 vnode_is_openevt(vnode_t vp
)
1604 return ((vp
->v_flag
& VOPENEVT
)? 1 : 0);
1607 /* is vnode_t a standard one? */
1609 vnode_isstandard(vnode_t vp
)
1611 return ((vp
->v_flag
& VSTANDARD
)? 1 : 0);
1614 /* don't vflush() if SKIPSYSTEM */
1616 vnode_isnoflush(vnode_t vp
)
1618 return ((vp
->v_flag
& VNOFLUSH
)? 1 : 0);
1621 /* is vnode_t a regular file */
1623 vnode_isreg(vnode_t vp
)
1625 return ((vp
->v_type
== VREG
)? 1 : 0);
1628 /* is vnode_t a directory? */
1630 vnode_isdir(vnode_t vp
)
1632 return ((vp
->v_type
== VDIR
)? 1 : 0);
1635 /* is vnode_t a symbolic link ? */
1637 vnode_islnk(vnode_t vp
)
1639 return ((vp
->v_type
== VLNK
)? 1 : 0);
1643 vnode_lookup_continue_needed(vnode_t vp
, struct componentname
*cnp
)
1645 struct nameidata
*ndp
= cnp
->cn_ndp
;
1648 panic("vnode_lookup_continue_needed(): cnp->cn_ndp is NULL\n");
1651 if (vnode_isdir(vp
)) {
1652 if (vp
->v_mountedhere
!= NULL
) {
1657 if (vp
->v_resolve
) {
1660 #endif /* CONFIG_TRIGGERS */
1665 if (vnode_islnk(vp
)) {
1666 /* From lookup(): || *ndp->ni_next == '/') No need for this, we know we're NULL-terminated here */
1667 if (cnp
->cn_flags
& FOLLOW
) {
1670 if (ndp
->ni_flag
& NAMEI_TRAILINGSLASH
) {
1678 ndp
->ni_flag
|= NAMEI_CONTLOOKUP
;
1679 return EKEEPLOOKING
;
1682 /* is vnode_t a fifo ? */
1684 vnode_isfifo(vnode_t vp
)
1686 return ((vp
->v_type
== VFIFO
)? 1 : 0);
1689 /* is vnode_t a block device? */
1691 vnode_isblk(vnode_t vp
)
1693 return ((vp
->v_type
== VBLK
)? 1 : 0);
1697 vnode_isspec(vnode_t vp
)
1699 return (((vp
->v_type
== VCHR
) || (vp
->v_type
== VBLK
)) ? 1 : 0);
1702 /* is vnode_t a char device? */
1704 vnode_ischr(vnode_t vp
)
1706 return ((vp
->v_type
== VCHR
)? 1 : 0);
1709 /* is vnode_t a socket? */
1711 vnode_issock(vnode_t vp
)
1713 return ((vp
->v_type
== VSOCK
)? 1 : 0);
1716 /* is vnode_t a device with multiple active vnodes referring to it? */
1718 vnode_isaliased(vnode_t vp
)
1720 enum vtype vt
= vp
->v_type
;
1721 if (!((vt
== VCHR
) || (vt
== VBLK
))) {
1724 return (vp
->v_specflags
& SI_ALIASED
);
1728 /* is vnode_t a named stream? */
1730 vnode_isnamedstream(
1739 return ((vp
->v_flag
& VISNAMEDSTREAM
) ? 1 : 0);
1755 return ((vp
->v_flag
& VISSHADOW
) ? 1 : 0);
1761 /* does vnode have associated named stream vnodes ? */
1763 vnode_hasnamedstreams(
1772 return ((vp
->v_lflag
& VL_HASSTREAMS
) ? 1 : 0);
1777 /* TBD: set vnode_t to not cache data after it is consumed once; used for quota */
1779 vnode_setnocache(vnode_t vp
)
1781 vnode_lock_spin(vp
);
1782 vp
->v_flag
|= VNOCACHE_DATA
;
1787 vnode_clearnocache(vnode_t vp
)
1789 vnode_lock_spin(vp
);
1790 vp
->v_flag
&= ~VNOCACHE_DATA
;
1795 vnode_set_openevt(vnode_t vp
)
1797 vnode_lock_spin(vp
);
1798 vp
->v_flag
|= VOPENEVT
;
1803 vnode_clear_openevt(vnode_t vp
)
1805 vnode_lock_spin(vp
);
1806 vp
->v_flag
&= ~VOPENEVT
;
1812 vnode_setnoreadahead(vnode_t vp
)
1814 vnode_lock_spin(vp
);
1815 vp
->v_flag
|= VRAOFF
;
1820 vnode_clearnoreadahead(vnode_t vp
)
1822 vnode_lock_spin(vp
);
1823 vp
->v_flag
&= ~VRAOFF
;
1828 vnode_isfastdevicecandidate(vnode_t vp
)
1830 return ((vp
->v_flag
& VFASTDEVCANDIDATE
)? 1 : 0);
1834 vnode_setfastdevicecandidate(vnode_t vp
)
1836 vnode_lock_spin(vp
);
1837 vp
->v_flag
|= VFASTDEVCANDIDATE
;
1842 vnode_clearfastdevicecandidate(vnode_t vp
)
1844 vnode_lock_spin(vp
);
1845 vp
->v_flag
&= ~VFASTDEVCANDIDATE
;
1850 vnode_isautocandidate(vnode_t vp
)
1852 return ((vp
->v_flag
& VAUTOCANDIDATE
)? 1 : 0);
1856 vnode_setautocandidate(vnode_t vp
)
1858 vnode_lock_spin(vp
);
1859 vp
->v_flag
|= VAUTOCANDIDATE
;
1864 vnode_clearautocandidate(vnode_t vp
)
1866 vnode_lock_spin(vp
);
1867 vp
->v_flag
&= ~VAUTOCANDIDATE
;
1874 /* mark vnode_t to skip vflush() is SKIPSYSTEM */
1876 vnode_setnoflush(vnode_t vp
)
1878 vnode_lock_spin(vp
);
1879 vp
->v_flag
|= VNOFLUSH
;
1884 vnode_clearnoflush(vnode_t vp
)
1886 vnode_lock_spin(vp
);
1887 vp
->v_flag
&= ~VNOFLUSH
;
1892 /* is vnode_t a blkdevice and has a FS mounted on it */
1894 vnode_ismountedon(vnode_t vp
)
1896 return ((vp
->v_specflags
& SI_MOUNTEDON
)? 1 : 0);
1900 vnode_setmountedon(vnode_t vp
)
1902 vnode_lock_spin(vp
);
1903 vp
->v_specflags
|= SI_MOUNTEDON
;
1908 vnode_clearmountedon(vnode_t vp
)
1910 vnode_lock_spin(vp
);
1911 vp
->v_specflags
&= ~SI_MOUNTEDON
;
1917 vnode_settag(vnode_t vp
, int tag
)
1924 vnode_tag(vnode_t vp
)
1930 vnode_parent(vnode_t vp
)
1933 return(vp
->v_parent
);
1937 vnode_setparent(vnode_t vp
, vnode_t dvp
)
1943 vnode_setname(vnode_t vp
, char * name
)
1948 /* return the registered FS name when adding the FS to kernel */
1950 vnode_vfsname(vnode_t vp
, char * buf
)
1952 strlcpy(buf
, vp
->v_mount
->mnt_vtable
->vfc_name
, MFSNAMELEN
);
1955 /* return the FS type number */
1957 vnode_vfstypenum(vnode_t vp
)
1959 return(vp
->v_mount
->mnt_vtable
->vfc_typenum
);
1963 vnode_vfs64bitready(vnode_t vp
)
1967 * Checking for dead_mountp is a bit of a hack for SnowLeopard: <rdar://problem/6269051>
1969 if ((vp
->v_mount
!= dead_mountp
) && (vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFS64BITREADY
))
1977 /* return the visible flags on associated mount point of vnode_t */
1979 vnode_vfsvisflags(vnode_t vp
)
1981 return(vp
->v_mount
->mnt_flag
& MNT_VISFLAGMASK
);
1984 /* return the command modifier flags on associated mount point of vnode_t */
1986 vnode_vfscmdflags(vnode_t vp
)
1988 return(vp
->v_mount
->mnt_flag
& MNT_CMDFLAGS
);
1991 /* return the max symlink of short links of vnode_t */
1993 vnode_vfsmaxsymlen(vnode_t vp
)
1995 return(vp
->v_mount
->mnt_maxsymlinklen
);
1998 /* return a pointer to the RO vfs_statfs associated with vnode_t's mount point */
2000 vnode_vfsstatfs(vnode_t vp
)
2002 return(&vp
->v_mount
->mnt_vfsstat
);
2005 /* return a handle to the FSs specific private handle associated with vnode_t's mount point */
2007 vnode_vfsfsprivate(vnode_t vp
)
2009 return(vp
->v_mount
->mnt_data
);
2012 /* is vnode_t in a rdonly mounted FS */
2014 vnode_vfsisrdonly(vnode_t vp
)
2016 return ((vp
->v_mount
->mnt_flag
& MNT_RDONLY
)? 1 : 0);
2020 vnode_compound_rename_available(vnode_t vp
)
2022 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RENAME
);
2025 vnode_compound_rmdir_available(vnode_t vp
)
2027 return vnode_compound_op_available(vp
, COMPOUND_VNOP_RMDIR
);
2030 vnode_compound_mkdir_available(vnode_t vp
)
2032 return vnode_compound_op_available(vp
, COMPOUND_VNOP_MKDIR
);
2035 vnode_compound_remove_available(vnode_t vp
)
2037 return vnode_compound_op_available(vp
, COMPOUND_VNOP_REMOVE
);
2040 vnode_compound_open_available(vnode_t vp
)
2042 return vnode_compound_op_available(vp
, COMPOUND_VNOP_OPEN
);
2046 vnode_compound_op_available(vnode_t vp
, compound_vnop_id_t opid
)
2048 return ((vp
->v_mount
->mnt_compound_ops
& opid
) != 0);
2052 * Returns vnode ref to current working directory; if a per-thread current
2053 * working directory is in effect, return that instead of the per process one.
2055 * XXX Published, but not used.
2058 current_workingdir(void)
2060 return vfs_context_cwd(vfs_context_current());
2063 /* returns vnode ref to current root(chroot) directory */
2065 current_rootdir(void)
2067 proc_t proc
= current_proc();
2070 if ( (vp
= proc
->p_fd
->fd_rdir
) ) {
2071 if ( (vnode_getwithref(vp
)) )
2078 * Get a filesec and optional acl contents from an extended attribute.
2079 * Function will attempt to retrive ACL, UUID, and GUID information using a
2080 * read of a named extended attribute (KAUTH_FILESEC_XATTR).
2082 * Parameters: vp The vnode on which to operate.
2083 * fsecp The filesec (and ACL, if any) being
2085 * ctx The vnode context in which the
2086 * operation is to be attempted.
2088 * Returns: 0 Success
2091 * Notes: The kauth_filesec_t in '*fsecp', if retrieved, will be in
2092 * host byte order, as will be the ACL contents, if any.
2093 * Internally, we will cannonize these values from network (PPC)
2094 * byte order after we retrieve them so that the on-disk contents
2095 * of the extended attribute are identical for both PPC and Intel
2096 * (if we were not being required to provide this service via
2097 * fallback, this would be the job of the filesystem
2098 * 'VNOP_GETATTR' call).
2100 * We use ntohl() because it has a transitive property on Intel
2101 * machines and no effect on PPC mancines. This guarantees us
2103 * XXX: Deleting rather than ignoreing a corrupt security structure is
2104 * probably the only way to reset it without assistance from an
2105 * file system integrity checking tool. Right now we ignore it.
2107 * XXX: We should enummerate the possible errno values here, and where
2108 * in the code they originated.
2111 vnode_get_filesec(vnode_t vp
, kauth_filesec_t
*fsecp
, vfs_context_t ctx
)
2113 kauth_filesec_t fsec
;
2116 size_t xsize
, rsize
;
2118 uint32_t host_fsec_magic
;
2119 uint32_t host_acl_entrycount
;
2124 /* find out how big the EA is */
2125 error
= vn_getxattr(vp
, KAUTH_FILESEC_XATTR
, NULL
, &xsize
, XATTR_NOSECURITY
, ctx
);
2127 /* no EA, no filesec */
2128 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
))
2130 /* either way, we are done */
2135 * To be valid, a kauth_filesec_t must be large enough to hold a zero
2136 * ACE entrly ACL, and if it's larger than that, it must have the right
2137 * number of bytes such that it contains an atomic number of ACEs,
2138 * rather than partial entries. Otherwise, we ignore it.
2140 if (!KAUTH_FILESEC_VALID(xsize
)) {
2141 KAUTH_DEBUG(" ERROR - Bogus kauth_fiilesec_t: %ld bytes", xsize
);
2146 /* how many entries would fit? */
2147 fsec_size
= KAUTH_FILESEC_COUNT(xsize
);
2149 /* get buffer and uio */
2150 if (((fsec
= kauth_filesec_alloc(fsec_size
)) == NULL
) ||
2151 ((fsec_uio
= uio_create(1, 0, UIO_SYSSPACE
, UIO_READ
)) == NULL
) ||
2152 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), xsize
)) {
2153 KAUTH_DEBUG(" ERROR - could not allocate iov to read ACL");
2158 /* read security attribute */
2160 if ((error
= vn_getxattr(vp
,
2161 KAUTH_FILESEC_XATTR
,
2167 /* no attribute - no security data */
2168 if ((error
== ENOATTR
) || (error
== ENOENT
) || (error
== EJUSTRETURN
))
2170 /* either way, we are done */
2175 * Validate security structure; the validation must take place in host
2176 * byte order. If it's corrupt, we will just ignore it.
2179 /* Validate the size before trying to convert it */
2180 if (rsize
< KAUTH_FILESEC_SIZE(0)) {
2181 KAUTH_DEBUG("ACL - DATA TOO SMALL (%d)", rsize
);
2185 /* Validate the magic number before trying to convert it */
2186 host_fsec_magic
= ntohl(KAUTH_FILESEC_MAGIC
);
2187 if (fsec
->fsec_magic
!= host_fsec_magic
) {
2188 KAUTH_DEBUG("ACL - BAD MAGIC %x", host_fsec_magic
);
2192 /* Validate the entry count before trying to convert it. */
2193 host_acl_entrycount
= ntohl(fsec
->fsec_acl
.acl_entrycount
);
2194 if (host_acl_entrycount
!= KAUTH_FILESEC_NOACL
) {
2195 if (host_acl_entrycount
> KAUTH_ACL_MAX_ENTRIES
) {
2196 KAUTH_DEBUG("ACL - BAD ENTRYCOUNT %x", host_acl_entrycount
);
2199 if (KAUTH_FILESEC_SIZE(host_acl_entrycount
) > rsize
) {
2200 KAUTH_DEBUG("ACL - BUFFER OVERFLOW (%d entries too big for %d)", host_acl_entrycount
, rsize
);
2205 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, NULL
);
2212 kauth_filesec_free(fsec
);
2213 if (fsec_uio
!= NULL
)
2221 * Set a filesec and optional acl contents into an extended attribute.
2222 * function will attempt to store ACL, UUID, and GUID information using a
2223 * write to a named extended attribute (KAUTH_FILESEC_XATTR). The 'acl'
2224 * may or may not point to the `fsec->fsec_acl`, depending on whether the
2225 * original caller supplied an acl.
2227 * Parameters: vp The vnode on which to operate.
2228 * fsec The filesec being set.
2229 * acl The acl to be associated with 'fsec'.
2230 * ctx The vnode context in which the
2231 * operation is to be attempted.
2233 * Returns: 0 Success
2236 * Notes: Both the fsec and the acl are always valid.
2238 * The kauth_filesec_t in 'fsec', if any, is in host byte order,
2239 * as are the acl contents, if they are used. Internally, we will
2240 * cannonize these values into network (PPC) byte order before we
2241 * attempt to write them so that the on-disk contents of the
2242 * extended attribute are identical for both PPC and Intel (if we
2243 * were not being required to provide this service via fallback,
2244 * this would be the job of the filesystem 'VNOP_SETATTR' call).
2245 * We reverse this process on the way out, so we leave with the
2246 * same byte order we started with.
2248 * XXX: We should enummerate the possible errno values here, and where
2249 * in the code they originated.
2252 vnode_set_filesec(vnode_t vp
, kauth_filesec_t fsec
, kauth_acl_t acl
, vfs_context_t ctx
)
2256 uint32_t saved_acl_copysize
;
2260 if ((fsec_uio
= uio_create(2, 0, UIO_SYSSPACE
, UIO_WRITE
)) == NULL
) {
2261 KAUTH_DEBUG(" ERROR - could not allocate iov to write ACL");
2266 * Save the pre-converted ACL copysize, because it gets swapped too
2267 * if we are running with the wrong endianness.
2269 saved_acl_copysize
= KAUTH_ACL_COPYSIZE(acl
);
2271 kauth_filesec_acl_setendian(KAUTH_ENDIAN_DISK
, fsec
, acl
);
2273 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(fsec
), KAUTH_FILESEC_SIZE(0) - KAUTH_ACL_SIZE(KAUTH_FILESEC_NOACL
));
2274 uio_addiov(fsec_uio
, CAST_USER_ADDR_T(acl
), saved_acl_copysize
);
2275 error
= vn_setxattr(vp
,
2276 KAUTH_FILESEC_XATTR
,
2278 XATTR_NOSECURITY
, /* we have auth'ed already */
2280 VFS_DEBUG(ctx
, vp
, "SETATTR - set ACL returning %d", error
);
2282 kauth_filesec_acl_setendian(KAUTH_ENDIAN_HOST
, fsec
, acl
);
2285 if (fsec_uio
!= NULL
)
2292 * Returns: 0 Success
2293 * ENOMEM Not enough space [only if has filesec]
2295 * vnode_get_filesec: ???
2296 * kauth_cred_guid2uid: ???
2297 * kauth_cred_guid2gid: ???
2298 * vfs_update_vfsstat: ???
2301 vnode_getattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2303 kauth_filesec_t fsec
;
2309 /* don't ask for extended security data if the filesystem doesn't support it */
2310 if (!vfs_extendedsecurity(vnode_mount(vp
))) {
2311 VATTR_CLEAR_ACTIVE(vap
, va_acl
);
2312 VATTR_CLEAR_ACTIVE(vap
, va_uuuid
);
2313 VATTR_CLEAR_ACTIVE(vap
, va_guuid
);
2317 * If the caller wants size values we might have to synthesise, give the
2318 * filesystem the opportunity to supply better intermediate results.
2320 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2321 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2322 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2323 VATTR_SET_ACTIVE(vap
, va_data_size
);
2324 VATTR_SET_ACTIVE(vap
, va_data_alloc
);
2325 VATTR_SET_ACTIVE(vap
, va_total_size
);
2326 VATTR_SET_ACTIVE(vap
, va_total_alloc
);
2329 error
= VNOP_GETATTR(vp
, vap
, ctx
);
2331 KAUTH_DEBUG("ERROR - returning %d", error
);
2336 * If extended security data was requested but not returned, try the fallback
2339 if (VATTR_NOT_RETURNED(vap
, va_acl
) || VATTR_NOT_RETURNED(vap
, va_uuuid
) || VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2342 if (XATTR_VNODE_SUPPORTED(vp
)) {
2343 /* try to get the filesec */
2344 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0)
2347 /* if no filesec, no attributes */
2349 VATTR_RETURN(vap
, va_acl
, NULL
);
2350 VATTR_RETURN(vap
, va_uuuid
, kauth_null_guid
);
2351 VATTR_RETURN(vap
, va_guuid
, kauth_null_guid
);
2354 /* looks good, try to return what we were asked for */
2355 VATTR_RETURN(vap
, va_uuuid
, fsec
->fsec_owner
);
2356 VATTR_RETURN(vap
, va_guuid
, fsec
->fsec_group
);
2358 /* only return the ACL if we were actually asked for it */
2359 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2360 if (fsec
->fsec_acl
.acl_entrycount
== KAUTH_FILESEC_NOACL
) {
2361 VATTR_RETURN(vap
, va_acl
, NULL
);
2363 facl
= kauth_acl_alloc(fsec
->fsec_acl
.acl_entrycount
);
2365 kauth_filesec_free(fsec
);
2369 bcopy(&fsec
->fsec_acl
, facl
, KAUTH_ACL_COPYSIZE(&fsec
->fsec_acl
));
2370 VATTR_RETURN(vap
, va_acl
, facl
);
2373 kauth_filesec_free(fsec
);
2377 * If someone gave us an unsolicited filesec, toss it. We promise that
2378 * we're OK with a filesystem giving us anything back, but our callers
2379 * only expect what they asked for.
2381 if (VATTR_IS_SUPPORTED(vap
, va_acl
) && !VATTR_IS_ACTIVE(vap
, va_acl
)) {
2382 if (vap
->va_acl
!= NULL
)
2383 kauth_acl_free(vap
->va_acl
);
2384 VATTR_CLEAR_SUPPORTED(vap
, va_acl
);
2387 #if 0 /* enable when we have a filesystem only supporting UUIDs */
2389 * Handle the case where we need a UID/GID, but only have extended
2390 * security information.
2392 if (VATTR_NOT_RETURNED(vap
, va_uid
) &&
2393 VATTR_IS_SUPPORTED(vap
, va_uuuid
) &&
2394 !kauth_guid_equal(&vap
->va_uuuid
, &kauth_null_guid
)) {
2395 if ((error
= kauth_cred_guid2uid(&vap
->va_uuuid
, &nuid
)) == 0)
2396 VATTR_RETURN(vap
, va_uid
, nuid
);
2398 if (VATTR_NOT_RETURNED(vap
, va_gid
) &&
2399 VATTR_IS_SUPPORTED(vap
, va_guuid
) &&
2400 !kauth_guid_equal(&vap
->va_guuid
, &kauth_null_guid
)) {
2401 if ((error
= kauth_cred_guid2gid(&vap
->va_guuid
, &ngid
)) == 0)
2402 VATTR_RETURN(vap
, va_gid
, ngid
);
2407 * Handle uid/gid == 99 and MNT_IGNORE_OWNERSHIP here.
2409 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
2410 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2412 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2413 nuid
= vp
->v_mount
->mnt_fsowner
;
2414 if (nuid
== KAUTH_UID_NONE
)
2416 } else if (VATTR_IS_SUPPORTED(vap
, va_uid
)) {
2419 /* this will always be something sensible */
2420 nuid
= vp
->v_mount
->mnt_fsowner
;
2422 if ((nuid
== 99) && !vfs_context_issuser(ctx
))
2423 nuid
= kauth_cred_getuid(vfs_context_ucred(ctx
));
2424 VATTR_RETURN(vap
, va_uid
, nuid
);
2426 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
2427 if (vfs_context_issuser(ctx
) && VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2429 } else if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2430 ngid
= vp
->v_mount
->mnt_fsgroup
;
2431 if (ngid
== KAUTH_GID_NONE
)
2433 } else if (VATTR_IS_SUPPORTED(vap
, va_gid
)) {
2436 /* this will always be something sensible */
2437 ngid
= vp
->v_mount
->mnt_fsgroup
;
2439 if ((ngid
== 99) && !vfs_context_issuser(ctx
))
2440 ngid
= kauth_cred_getgid(vfs_context_ucred(ctx
));
2441 VATTR_RETURN(vap
, va_gid
, ngid
);
2445 * Synthesise some values that can be reasonably guessed.
2447 if (!VATTR_IS_SUPPORTED(vap
, va_iosize
))
2448 VATTR_RETURN(vap
, va_iosize
, vp
->v_mount
->mnt_vfsstat
.f_iosize
);
2450 if (!VATTR_IS_SUPPORTED(vap
, va_flags
))
2451 VATTR_RETURN(vap
, va_flags
, 0);
2453 if (!VATTR_IS_SUPPORTED(vap
, va_filerev
))
2454 VATTR_RETURN(vap
, va_filerev
, 0);
2456 if (!VATTR_IS_SUPPORTED(vap
, va_gen
))
2457 VATTR_RETURN(vap
, va_gen
, 0);
2460 * Default sizes. Ordering here is important, as later defaults build on earlier ones.
2462 if (!VATTR_IS_SUPPORTED(vap
, va_data_size
))
2463 VATTR_RETURN(vap
, va_data_size
, 0);
2465 /* do we want any of the possibly-computed values? */
2466 if (VATTR_IS_ACTIVE(vap
, va_data_alloc
) ||
2467 VATTR_IS_ACTIVE(vap
, va_total_size
) ||
2468 VATTR_IS_ACTIVE(vap
, va_total_alloc
)) {
2469 /* make sure f_bsize is valid */
2470 if (vp
->v_mount
->mnt_vfsstat
.f_bsize
== 0) {
2471 if ((error
= vfs_update_vfsstat(vp
->v_mount
, ctx
, VFS_KERNEL_EVENT
)) != 0)
2475 /* default va_data_alloc from va_data_size */
2476 if (!VATTR_IS_SUPPORTED(vap
, va_data_alloc
))
2477 VATTR_RETURN(vap
, va_data_alloc
, roundup(vap
->va_data_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2479 /* default va_total_size from va_data_size */
2480 if (!VATTR_IS_SUPPORTED(vap
, va_total_size
))
2481 VATTR_RETURN(vap
, va_total_size
, vap
->va_data_size
);
2483 /* default va_total_alloc from va_total_size which is guaranteed at this point */
2484 if (!VATTR_IS_SUPPORTED(vap
, va_total_alloc
))
2485 VATTR_RETURN(vap
, va_total_alloc
, roundup(vap
->va_total_size
, vp
->v_mount
->mnt_vfsstat
.f_bsize
));
2489 * If we don't have a change time, pull it from the modtime.
2491 if (!VATTR_IS_SUPPORTED(vap
, va_change_time
) && VATTR_IS_SUPPORTED(vap
, va_modify_time
))
2492 VATTR_RETURN(vap
, va_change_time
, vap
->va_modify_time
);
2495 * This is really only supported for the creation VNOPs, but since the field is there
2496 * we should populate it correctly.
2498 VATTR_RETURN(vap
, va_type
, vp
->v_type
);
2501 * The fsid can be obtained from the mountpoint directly.
2503 VATTR_RETURN(vap
, va_fsid
, vp
->v_mount
->mnt_vfsstat
.f_fsid
.val
[0]);
2511 * Set the attributes on a vnode in a vnode context.
2513 * Parameters: vp The vnode whose attributes to set.
2514 * vap A pointer to the attributes to set.
2515 * ctx The vnode context in which the
2516 * operation is to be attempted.
2518 * Returns: 0 Success
2521 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order.
2523 * The contents of the data area pointed to by 'vap' may be
2524 * modified if the vnode is on a filesystem which has been
2525 * mounted with ingore ownership flags, or by the underlyng
2526 * VFS itself, or by the fallback code, if the underlying VFS
2527 * does not support ACL, UUID, or GUUID attributes directly.
2529 * XXX: We should enummerate the possible errno values here, and where
2530 * in the code they originated.
2533 vnode_setattr(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2535 int error
, is_perm_change
=0;
2538 * Make sure the filesystem is mounted R/W.
2539 * If not, return an error.
2541 if (vfs_isrdonly(vp
->v_mount
)) {
2546 /* For streams, va_data_size is the only setable attribute. */
2547 if ((vp
->v_flag
& VISNAMEDSTREAM
) && (vap
->va_active
!= VNODE_ATTR_va_data_size
)) {
2554 * If ownership is being ignored on this volume, we silently discard
2555 * ownership changes.
2557 if (vp
->v_mount
->mnt_flag
& MNT_IGNORE_OWNERSHIP
) {
2558 VATTR_CLEAR_ACTIVE(vap
, va_uid
);
2559 VATTR_CLEAR_ACTIVE(vap
, va_gid
);
2562 if ( VATTR_IS_ACTIVE(vap
, va_uid
) || VATTR_IS_ACTIVE(vap
, va_gid
)
2563 || VATTR_IS_ACTIVE(vap
, va_mode
) || VATTR_IS_ACTIVE(vap
, va_acl
)) {
2568 * Make sure that extended security is enabled if we're going to try
2571 if (!vfs_extendedsecurity(vnode_mount(vp
)) &&
2572 (VATTR_IS_ACTIVE(vap
, va_acl
) || VATTR_IS_ACTIVE(vap
, va_uuuid
) || VATTR_IS_ACTIVE(vap
, va_guuid
))) {
2573 KAUTH_DEBUG("SETATTR - returning ENOTSUP to request to set extended security");
2578 /* Never allow the setting of any unsupported superuser flags. */
2579 if (VATTR_IS_ACTIVE(vap
, va_flags
)) {
2580 vap
->va_flags
&= (SF_SUPPORTED
| UF_SETTABLE
);
2583 error
= VNOP_SETATTR(vp
, vap
, ctx
);
2585 if ((error
== 0) && !VATTR_ALL_SUPPORTED(vap
))
2586 error
= vnode_setattr_fallback(vp
, vap
, ctx
);
2589 // only send a stat_changed event if this is more than
2590 // just an access or backup time update
2591 if (error
== 0 && (vap
->va_active
!= VNODE_ATTR_BIT(va_access_time
)) && (vap
->va_active
!= VNODE_ATTR_BIT(va_backup_time
))) {
2592 if (is_perm_change
) {
2593 if (need_fsevent(FSE_CHOWN
, vp
)) {
2594 add_fsevent(FSE_CHOWN
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2596 } else if(need_fsevent(FSE_STAT_CHANGED
, vp
)) {
2597 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
2607 * Fallback for setting the attributes on a vnode in a vnode context. This
2608 * Function will attempt to store ACL, UUID, and GUID information utilizing
2609 * a read/modify/write operation against an EA used as a backing store for
2612 * Parameters: vp The vnode whose attributes to set.
2613 * vap A pointer to the attributes to set.
2614 * ctx The vnode context in which the
2615 * operation is to be attempted.
2617 * Returns: 0 Success
2620 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order,
2621 * as are the fsec and lfsec, if they are used.
2623 * The contents of the data area pointed to by 'vap' may be
2624 * modified to indicate that the attribute is supported for
2625 * any given requested attribute.
2627 * XXX: We should enummerate the possible errno values here, and where
2628 * in the code they originated.
2631 vnode_setattr_fallback(vnode_t vp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
2633 kauth_filesec_t fsec
;
2635 struct kauth_filesec lfsec
;
2641 * Extended security fallback via extended attributes.
2643 * Note that we do not free the filesec; the caller is expected to
2646 if (VATTR_NOT_RETURNED(vap
, va_acl
) ||
2647 VATTR_NOT_RETURNED(vap
, va_uuuid
) ||
2648 VATTR_NOT_RETURNED(vap
, va_guuid
)) {
2649 VFS_DEBUG(ctx
, vp
, "SETATTR - doing filesec fallback");
2652 * Fail for file types that we don't permit extended security
2655 if (!XATTR_VNODE_SUPPORTED(vp
)) {
2656 VFS_DEBUG(ctx
, vp
, "SETATTR - Can't write ACL to file type %d", vnode_vtype(vp
));
2662 * If we don't have all the extended security items, we need
2663 * to fetch the existing data to perform a read-modify-write
2667 if (!VATTR_IS_ACTIVE(vap
, va_acl
) ||
2668 !VATTR_IS_ACTIVE(vap
, va_uuuid
) ||
2669 !VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2670 if ((error
= vnode_get_filesec(vp
, &fsec
, ctx
)) != 0) {
2671 KAUTH_DEBUG("SETATTR - ERROR %d fetching filesec for update", error
);
2675 /* if we didn't get a filesec, use our local one */
2677 KAUTH_DEBUG("SETATTR - using local filesec for new/full update");
2680 KAUTH_DEBUG("SETATTR - updating existing filesec");
2683 facl
= &fsec
->fsec_acl
;
2685 /* if we're using the local filesec, we need to initialise it */
2686 if (fsec
== &lfsec
) {
2687 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
2688 fsec
->fsec_owner
= kauth_null_guid
;
2689 fsec
->fsec_group
= kauth_null_guid
;
2690 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2691 facl
->acl_flags
= 0;
2695 * Update with the supplied attributes.
2697 if (VATTR_IS_ACTIVE(vap
, va_uuuid
)) {
2698 KAUTH_DEBUG("SETATTR - updating owner UUID");
2699 fsec
->fsec_owner
= vap
->va_uuuid
;
2700 VATTR_SET_SUPPORTED(vap
, va_uuuid
);
2702 if (VATTR_IS_ACTIVE(vap
, va_guuid
)) {
2703 KAUTH_DEBUG("SETATTR - updating group UUID");
2704 fsec
->fsec_group
= vap
->va_guuid
;
2705 VATTR_SET_SUPPORTED(vap
, va_guuid
);
2707 if (VATTR_IS_ACTIVE(vap
, va_acl
)) {
2708 if (vap
->va_acl
== NULL
) {
2709 KAUTH_DEBUG("SETATTR - removing ACL");
2710 facl
->acl_entrycount
= KAUTH_FILESEC_NOACL
;
2712 KAUTH_DEBUG("SETATTR - setting ACL with %d entries", vap
->va_acl
->acl_entrycount
);
2715 VATTR_SET_SUPPORTED(vap
, va_acl
);
2719 * If the filesec data is all invalid, we can just remove
2720 * the EA completely.
2722 if ((facl
->acl_entrycount
== KAUTH_FILESEC_NOACL
) &&
2723 kauth_guid_equal(&fsec
->fsec_owner
, &kauth_null_guid
) &&
2724 kauth_guid_equal(&fsec
->fsec_group
, &kauth_null_guid
)) {
2725 error
= vn_removexattr(vp
, KAUTH_FILESEC_XATTR
, XATTR_NOSECURITY
, ctx
);
2726 /* no attribute is ok, nothing to delete */
2727 if (error
== ENOATTR
)
2729 VFS_DEBUG(ctx
, vp
, "SETATTR - remove filesec returning %d", error
);
2732 error
= vnode_set_filesec(vp
, fsec
, facl
, ctx
);
2733 VFS_DEBUG(ctx
, vp
, "SETATTR - update filesec returning %d", error
);
2736 /* if we fetched a filesec, dispose of the buffer */
2738 kauth_filesec_free(fsec
);
2746 * Upcall for a filesystem to tell VFS about an EVFILT_VNODE-type
2750 vnode_notify(vnode_t vp
, uint32_t events
, struct vnode_attr
*vap
)
2752 /* These are the same as the corresponding knotes, at least for now. Cheating a little. */
2753 uint32_t knote_mask
= (VNODE_EVENT_WRITE
| VNODE_EVENT_DELETE
| VNODE_EVENT_RENAME
2754 | VNODE_EVENT_LINK
| VNODE_EVENT_EXTEND
| VNODE_EVENT_ATTRIB
);
2755 uint32_t dir_contents_mask
= (VNODE_EVENT_DIR_CREATED
| VNODE_EVENT_FILE_CREATED
2756 | VNODE_EVENT_DIR_REMOVED
| VNODE_EVENT_FILE_REMOVED
);
2757 uint32_t knote_events
= (events
& knote_mask
);
2759 /* Permissions are not explicitly part of the kqueue model */
2760 if (events
& VNODE_EVENT_PERMS
) {
2761 knote_events
|= NOTE_ATTRIB
;
2764 /* Directory contents information just becomes NOTE_WRITE */
2765 if ((vnode_isdir(vp
)) && (events
& dir_contents_mask
)) {
2766 knote_events
|= NOTE_WRITE
;
2770 lock_vnode_and_post(vp
, knote_events
);
2773 create_fsevent_from_kevent(vp
, events
, vap
);
2786 vnode_isdyldsharedcache(vnode_t vp
)
2788 return ((vp
->v_flag
& VSHARED_DYLD
) ? 1 : 0);
2793 * For a filesystem that isn't tracking its own vnode watchers:
2794 * check whether a vnode is being monitored.
2797 vnode_ismonitored(vnode_t vp
) {
2798 return (vp
->v_knotes
.slh_first
!= NULL
);
2802 * Initialize a struct vnode_attr and activate the attributes required
2803 * by the vnode_notify() call.
2806 vfs_get_notify_attributes(struct vnode_attr
*vap
)
2809 vap
->va_active
= VNODE_NOTIFY_ATTRS
;
2815 vfs_settriggercallback(fsid_t
*fsid
, vfs_trigger_callback_t vtc
, void *data
, uint32_t flags __unused
, vfs_context_t ctx
)
2820 mp
= mount_list_lookupby_fsid(fsid
, 0 /* locked */, 1 /* withref */);
2825 error
= vfs_busy(mp
, LK_NOWAIT
);
2833 if (mp
->mnt_triggercallback
!= NULL
) {
2839 mp
->mnt_triggercallback
= vtc
;
2840 mp
->mnt_triggerdata
= data
;
2843 mp
->mnt_triggercallback(mp
, VTC_REPLACE
, data
, ctx
);
2849 #endif /* CONFIG_TRIGGERS */
2852 * Definition of vnode operations.
2858 *#% lookup dvp L ? ?
2859 *#% lookup vpp - L -
2861 struct vnop_lookup_args
{
2862 struct vnodeop_desc
*a_desc
;
2865 struct componentname
*a_cnp
;
2866 vfs_context_t a_context
;
2871 * Returns: 0 Success
2872 * lock_fsnode:ENOENT No such file or directory [only for VFS
2873 * that is not thread safe & vnode is
2874 * currently being/has been terminated]
2875 * <vfs_lookup>:ENAMETOOLONG
2876 * <vfs_lookup>:ENOENT
2877 * <vfs_lookup>:EJUSTRETURN
2878 * <vfs_lookup>:EPERM
2879 * <vfs_lookup>:EISDIR
2880 * <vfs_lookup>:ENOTDIR
2883 * Note: The return codes from the underlying VFS's lookup routine can't
2884 * be fully enumerated here, since third party VFS authors may not
2885 * limit their error returns to the ones documented here, even
2886 * though this may result in some programs functioning incorrectly.
2888 * The return codes documented above are those which may currently
2889 * be returned by HFS from hfs_lookup, not including additional
2890 * error code which may be propagated from underlying routines.
2893 VNOP_LOOKUP(vnode_t dvp
, vnode_t
*vpp
, struct componentname
*cnp
, vfs_context_t ctx
)
2896 struct vnop_lookup_args a
;
2898 a
.a_desc
= &vnop_lookup_desc
;
2904 _err
= (*dvp
->v_op
[vnop_lookup_desc
.vdesc_offset
])(&a
);
2905 if (_err
== 0 && *vpp
) {
2906 DTRACE_FSINFO(lookup
, vnode_t
, *vpp
);
2913 struct vnop_compound_open_args
{
2914 struct vnodeop_desc
*a_desc
;
2917 struct componentname
*a_cnp
;
2920 struct vnode_attr
*a_vap
;
2921 vfs_context_t a_context
;
2927 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
)
2930 struct vnop_compound_open_args a
;
2933 uint32_t tmp_status
= 0;
2934 struct componentname
*cnp
= &ndp
->ni_cnd
;
2936 want_create
= (flags
& O_CREAT
);
2938 a
.a_desc
= &vnop_compound_open_desc
;
2940 a
.a_vpp
= vpp
; /* Could be NULL */
2944 a
.a_status
= (statusp
!= NULL
) ? statusp
: &tmp_status
;
2947 a
.a_open_create_authorizer
= vn_authorize_create
;
2948 a
.a_open_existing_authorizer
= vn_authorize_open_existing
;
2949 a
.a_reserved
= NULL
;
2951 if (dvp
== NULLVP
) {
2954 if (want_create
&& !vap
) {
2955 panic("Want create, but no vap?");
2957 if (!want_create
&& vap
) {
2958 panic("Don't want create, but have a vap?");
2961 _err
= (*dvp
->v_op
[vnop_compound_open_desc
.vdesc_offset
])(&a
);
2963 if (_err
== 0 && *vpp
) {
2964 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
2966 DTRACE_FSINFO(compound_open
, vnode_t
, dvp
);
2969 DTRACE_FSINFO(compound_open
, vnode_t
, *vpp
);
2972 did_create
= (*a
.a_status
& COMPOUND_OPEN_STATUS_DID_CREATE
);
2974 if (did_create
&& !want_create
) {
2975 panic("Filesystem did a create, even though none was requested?");
2979 #if CONFIG_APPLEDOUBLE
2980 if (!NATIVE_XATTR(dvp
)) {
2982 * Remove stale Apple Double file (if any).
2984 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
2986 #endif /* CONFIG_APPLEDOUBLE */
2987 /* On create, provide kqueue notification */
2988 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
2991 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, did_create
);
2992 #if 0 /* FSEvents... */
2993 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
3004 struct vnop_create_args
{
3005 struct vnodeop_desc
*a_desc
;
3008 struct componentname
*a_cnp
;
3009 struct vnode_attr
*a_vap
;
3010 vfs_context_t a_context
;
3014 VNOP_CREATE(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3017 struct vnop_create_args a
;
3019 a
.a_desc
= &vnop_create_desc
;
3026 _err
= (*dvp
->v_op
[vnop_create_desc
.vdesc_offset
])(&a
);
3027 if (_err
== 0 && *vpp
) {
3028 DTRACE_FSINFO(create
, vnode_t
, *vpp
);
3031 #if CONFIG_APPLEDOUBLE
3032 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
3034 * Remove stale Apple Double file (if any).
3036 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
3038 #endif /* CONFIG_APPLEDOUBLE */
3040 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3048 *#% whiteout dvp L L L
3049 *#% whiteout cnp - - -
3050 *#% whiteout flag - - -
3053 struct vnop_whiteout_args
{
3054 struct vnodeop_desc
*a_desc
;
3056 struct componentname
*a_cnp
;
3058 vfs_context_t a_context
;
3062 VNOP_WHITEOUT(__unused vnode_t dvp
, __unused
struct componentname
*cnp
,
3063 __unused
int flags
, __unused vfs_context_t ctx
)
3065 return (ENOTSUP
); // XXX OBSOLETE
3075 struct vnop_mknod_args
{
3076 struct vnodeop_desc
*a_desc
;
3079 struct componentname
*a_cnp
;
3080 struct vnode_attr
*a_vap
;
3081 vfs_context_t a_context
;
3085 VNOP_MKNOD(vnode_t dvp
, vnode_t
* vpp
, struct componentname
* cnp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3089 struct vnop_mknod_args a
;
3091 a
.a_desc
= &vnop_mknod_desc
;
3098 _err
= (*dvp
->v_op
[vnop_mknod_desc
.vdesc_offset
])(&a
);
3099 if (_err
== 0 && *vpp
) {
3100 DTRACE_FSINFO(mknod
, vnode_t
, *vpp
);
3103 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3114 struct vnop_open_args
{
3115 struct vnodeop_desc
*a_desc
;
3118 vfs_context_t a_context
;
3122 VNOP_OPEN(vnode_t vp
, int mode
, vfs_context_t ctx
)
3125 struct vnop_open_args a
;
3128 ctx
= vfs_context_current();
3130 a
.a_desc
= &vnop_open_desc
;
3135 _err
= (*vp
->v_op
[vnop_open_desc
.vdesc_offset
])(&a
);
3136 DTRACE_FSINFO(open
, vnode_t
, vp
);
3147 struct vnop_close_args
{
3148 struct vnodeop_desc
*a_desc
;
3151 vfs_context_t a_context
;
3155 VNOP_CLOSE(vnode_t vp
, int fflag
, vfs_context_t ctx
)
3158 struct vnop_close_args a
;
3161 ctx
= vfs_context_current();
3163 a
.a_desc
= &vnop_close_desc
;
3168 _err
= (*vp
->v_op
[vnop_close_desc
.vdesc_offset
])(&a
);
3169 DTRACE_FSINFO(close
, vnode_t
, vp
);
3180 struct vnop_access_args
{
3181 struct vnodeop_desc
*a_desc
;
3184 vfs_context_t a_context
;
3188 VNOP_ACCESS(vnode_t vp
, int action
, vfs_context_t ctx
)
3191 struct vnop_access_args a
;
3194 ctx
= vfs_context_current();
3196 a
.a_desc
= &vnop_access_desc
;
3198 a
.a_action
= action
;
3201 _err
= (*vp
->v_op
[vnop_access_desc
.vdesc_offset
])(&a
);
3202 DTRACE_FSINFO(access
, vnode_t
, vp
);
3210 *#% getattr vp = = =
3213 struct vnop_getattr_args
{
3214 struct vnodeop_desc
*a_desc
;
3216 struct vnode_attr
*a_vap
;
3217 vfs_context_t a_context
;
3221 VNOP_GETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3224 struct vnop_getattr_args a
;
3226 a
.a_desc
= &vnop_getattr_desc
;
3231 _err
= (*vp
->v_op
[vnop_getattr_desc
.vdesc_offset
])(&a
);
3232 DTRACE_FSINFO(getattr
, vnode_t
, vp
);
3240 *#% setattr vp L L L
3243 struct vnop_setattr_args
{
3244 struct vnodeop_desc
*a_desc
;
3246 struct vnode_attr
*a_vap
;
3247 vfs_context_t a_context
;
3251 VNOP_SETATTR(vnode_t vp
, struct vnode_attr
* vap
, vfs_context_t ctx
)
3254 struct vnop_setattr_args a
;
3256 a
.a_desc
= &vnop_setattr_desc
;
3261 _err
= (*vp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
3262 DTRACE_FSINFO(setattr
, vnode_t
, vp
);
3264 #if CONFIG_APPLEDOUBLE
3266 * Shadow uid/gid/mod change to extended attribute file.
3268 if (_err
== 0 && !NATIVE_XATTR(vp
)) {
3269 struct vnode_attr va
;
3273 if (VATTR_IS_ACTIVE(vap
, va_uid
)) {
3274 VATTR_SET(&va
, va_uid
, vap
->va_uid
);
3277 if (VATTR_IS_ACTIVE(vap
, va_gid
)) {
3278 VATTR_SET(&va
, va_gid
, vap
->va_gid
);
3281 if (VATTR_IS_ACTIVE(vap
, va_mode
)) {
3282 VATTR_SET(&va
, va_mode
, vap
->va_mode
);
3289 dvp
= vnode_getparent(vp
);
3290 vname
= vnode_getname(vp
);
3292 xattrfile_setattr(dvp
, vname
, &va
, ctx
);
3296 vnode_putname(vname
);
3299 #endif /* CONFIG_APPLEDOUBLE */
3302 * If we have changed any of the things about the file that are likely
3303 * to result in changes to authorization results, blow the vnode auth
3307 VATTR_IS_SUPPORTED(vap
, va_mode
) ||
3308 VATTR_IS_SUPPORTED(vap
, va_uid
) ||
3309 VATTR_IS_SUPPORTED(vap
, va_gid
) ||
3310 VATTR_IS_SUPPORTED(vap
, va_flags
) ||
3311 VATTR_IS_SUPPORTED(vap
, va_acl
) ||
3312 VATTR_IS_SUPPORTED(vap
, va_uuuid
) ||
3313 VATTR_IS_SUPPORTED(vap
, va_guuid
))) {
3314 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3317 if (vfs_authopaque(vp
->v_mount
) && vnode_hasnamedstreams(vp
)) {
3319 if (vnode_getnamedstream(vp
, &svp
, XATTR_RESOURCEFORK_NAME
, NS_OPEN
, 0, ctx
) == 0) {
3320 vnode_uncache_authorized_action(svp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
3324 #endif /* NAMEDSTREAMS */
3328 post_event_if_success(vp
, _err
, NOTE_ATTRIB
);
3340 struct vnop_read_args
{
3341 struct vnodeop_desc
*a_desc
;
3345 vfs_context_t a_context
;
3349 VNOP_READ(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3352 struct vnop_read_args a
;
3354 user_ssize_t resid
= uio_resid(uio
);
3361 a
.a_desc
= &vnop_read_desc
;
3364 a
.a_ioflag
= ioflag
;
3367 _err
= (*vp
->v_op
[vnop_read_desc
.vdesc_offset
])(&a
);
3368 DTRACE_FSINFO_IO(read
,
3369 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3381 struct vnop_write_args
{
3382 struct vnodeop_desc
*a_desc
;
3386 vfs_context_t a_context
;
3390 VNOP_WRITE(vnode_t vp
, struct uio
* uio
, int ioflag
, vfs_context_t ctx
)
3392 struct vnop_write_args a
;
3395 user_ssize_t resid
= uio_resid(uio
);
3402 a
.a_desc
= &vnop_write_desc
;
3405 a
.a_ioflag
= ioflag
;
3408 _err
= (*vp
->v_op
[vnop_write_desc
.vdesc_offset
])(&a
);
3409 DTRACE_FSINFO_IO(write
,
3410 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
3412 post_event_if_success(vp
, _err
, NOTE_WRITE
);
3424 struct vnop_ioctl_args
{
3425 struct vnodeop_desc
*a_desc
;
3430 vfs_context_t a_context
;
3434 VNOP_IOCTL(vnode_t vp
, u_long command
, caddr_t data
, int fflag
, vfs_context_t ctx
)
3437 struct vnop_ioctl_args a
;
3440 ctx
= vfs_context_current();
3444 * This check should probably have been put in the TTY code instead...
3446 * We have to be careful about what we assume during startup and shutdown.
3447 * We have to be able to use the root filesystem's device vnode even when
3448 * devfs isn't mounted (yet/anymore), so we can't go looking at its mount
3449 * structure. If there is no data pointer, it doesn't matter whether
3450 * the device is 64-bit ready. Any command (like DKIOCSYNCHRONIZE)
3451 * which passes NULL for its data pointer can therefore be used during
3452 * mount or unmount of the root filesystem.
3454 * Depending on what root filesystems need to do during mount/unmount, we
3455 * may need to loosen this check again in the future.
3457 if (vfs_context_is64bit(ctx
) && !(vnode_ischr(vp
) || vnode_isblk(vp
))) {
3458 if (data
!= NULL
&& !vnode_vfs64bitready(vp
)) {
3463 a
.a_desc
= &vnop_ioctl_desc
;
3465 a
.a_command
= command
;
3470 _err
= (*vp
->v_op
[vnop_ioctl_desc
.vdesc_offset
])(&a
);
3471 DTRACE_FSINFO(ioctl
, vnode_t
, vp
);
3483 struct vnop_select_args
{
3484 struct vnodeop_desc
*a_desc
;
3489 vfs_context_t a_context
;
3493 VNOP_SELECT(vnode_t vp
, int which
, int fflags
, void * wql
, vfs_context_t ctx
)
3496 struct vnop_select_args a
;
3499 ctx
= vfs_context_current();
3501 a
.a_desc
= &vnop_select_desc
;
3504 a
.a_fflags
= fflags
;
3508 _err
= (*vp
->v_op
[vnop_select_desc
.vdesc_offset
])(&a
);
3509 DTRACE_FSINFO(select
, vnode_t
, vp
);
3518 *#% exchange fvp L L L
3519 *#% exchange tvp L L L
3522 struct vnop_exchange_args
{
3523 struct vnodeop_desc
*a_desc
;
3527 vfs_context_t a_context
;
3531 VNOP_EXCHANGE(vnode_t fvp
, vnode_t tvp
, int options
, vfs_context_t ctx
)
3534 struct vnop_exchange_args a
;
3536 a
.a_desc
= &vnop_exchange_desc
;
3539 a
.a_options
= options
;
3542 _err
= (*fvp
->v_op
[vnop_exchange_desc
.vdesc_offset
])(&a
);
3543 DTRACE_FSINFO(exchange
, vnode_t
, fvp
);
3545 /* Don't post NOTE_WRITE because file descriptors follow the data ... */
3546 post_event_if_success(fvp
, _err
, NOTE_ATTRIB
);
3547 post_event_if_success(tvp
, _err
, NOTE_ATTRIB
);
3559 struct vnop_revoke_args
{
3560 struct vnodeop_desc
*a_desc
;
3563 vfs_context_t a_context
;
3567 VNOP_REVOKE(vnode_t vp
, int flags
, vfs_context_t ctx
)
3569 struct vnop_revoke_args a
;
3572 a
.a_desc
= &vnop_revoke_desc
;
3577 _err
= (*vp
->v_op
[vnop_revoke_desc
.vdesc_offset
])(&a
);
3578 DTRACE_FSINFO(revoke
, vnode_t
, vp
);
3590 struct vnop_mmap_args
{
3591 struct vnodeop_desc
*a_desc
;
3594 vfs_context_t a_context
;
3598 VNOP_MMAP(vnode_t vp
, int fflags
, vfs_context_t ctx
)
3601 struct vnop_mmap_args a
;
3603 a
.a_desc
= &vnop_mmap_desc
;
3605 a
.a_fflags
= fflags
;
3608 _err
= (*vp
->v_op
[vnop_mmap_desc
.vdesc_offset
])(&a
);
3609 DTRACE_FSINFO(mmap
, vnode_t
, vp
);
3618 *# mnomap - vp U U U
3621 struct vnop_mnomap_args
{
3622 struct vnodeop_desc
*a_desc
;
3624 vfs_context_t a_context
;
3628 VNOP_MNOMAP(vnode_t vp
, vfs_context_t ctx
)
3631 struct vnop_mnomap_args a
;
3633 a
.a_desc
= &vnop_mnomap_desc
;
3637 _err
= (*vp
->v_op
[vnop_mnomap_desc
.vdesc_offset
])(&a
);
3638 DTRACE_FSINFO(mnomap
, vnode_t
, vp
);
3650 struct vnop_fsync_args
{
3651 struct vnodeop_desc
*a_desc
;
3654 vfs_context_t a_context
;
3658 VNOP_FSYNC(vnode_t vp
, int waitfor
, vfs_context_t ctx
)
3660 struct vnop_fsync_args a
;
3663 a
.a_desc
= &vnop_fsync_desc
;
3665 a
.a_waitfor
= waitfor
;
3668 _err
= (*vp
->v_op
[vnop_fsync_desc
.vdesc_offset
])(&a
);
3669 DTRACE_FSINFO(fsync
, vnode_t
, vp
);
3678 *#% remove dvp L U U
3682 struct vnop_remove_args
{
3683 struct vnodeop_desc
*a_desc
;
3686 struct componentname
*a_cnp
;
3688 vfs_context_t a_context
;
3692 VNOP_REMOVE(vnode_t dvp
, vnode_t vp
, struct componentname
* cnp
, int flags
, vfs_context_t ctx
)
3695 struct vnop_remove_args a
;
3697 a
.a_desc
= &vnop_remove_desc
;
3704 _err
= (*dvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&a
);
3705 DTRACE_FSINFO(remove
, vnode_t
, vp
);
3708 vnode_setneedinactive(vp
);
3709 #if CONFIG_APPLEDOUBLE
3710 if ( !(NATIVE_XATTR(dvp
)) ) {
3712 * Remove any associated extended attribute file (._ AppleDouble file).
3714 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
3716 #endif /* CONFIG_APPLEDOUBLE */
3719 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
3720 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3726 VNOP_COMPOUND_REMOVE(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
3729 struct vnop_compound_remove_args a
;
3730 int no_vp
= (*vpp
== NULLVP
);
3732 a
.a_desc
= &vnop_compound_remove_desc
;
3735 a
.a_cnp
= &ndp
->ni_cnd
;
3739 a
.a_remove_authorizer
= vn_authorize_unlink
;
3741 _err
= (*dvp
->v_op
[vnop_compound_remove_desc
.vdesc_offset
])(&a
);
3742 if (_err
== 0 && *vpp
) {
3743 DTRACE_FSINFO(compound_remove
, vnode_t
, *vpp
);
3745 DTRACE_FSINFO(compound_remove
, vnode_t
, dvp
);
3748 vnode_setneedinactive(*vpp
);
3749 #if CONFIG_APPLEDOUBLE
3750 if ( !(NATIVE_XATTR(dvp
)) ) {
3752 * Remove any associated extended attribute file (._ AppleDouble file).
3754 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 1);
3756 #endif /* CONFIG_APPLEDOUBLE */
3759 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
3760 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
3763 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
3764 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
3770 //printf("VNOP_COMPOUND_REMOVE() returning %d\n", _err);
3782 struct vnop_link_args
{
3783 struct vnodeop_desc
*a_desc
;
3786 struct componentname
*a_cnp
;
3787 vfs_context_t a_context
;
3791 VNOP_LINK(vnode_t vp
, vnode_t tdvp
, struct componentname
* cnp
, vfs_context_t ctx
)
3794 struct vnop_link_args a
;
3796 #if CONFIG_APPLEDOUBLE
3798 * For file systems with non-native extended attributes,
3799 * disallow linking to an existing "._" Apple Double file.
3801 if ( !NATIVE_XATTR(tdvp
) && (vp
->v_type
== VREG
)) {
3804 vname
= vnode_getname(vp
);
3805 if (vname
!= NULL
) {
3807 if (vname
[0] == '.' && vname
[1] == '_' && vname
[2] != '\0') {
3810 vnode_putname(vname
);
3815 #endif /* CONFIG_APPLEDOUBLE */
3817 a
.a_desc
= &vnop_link_desc
;
3823 _err
= (*tdvp
->v_op
[vnop_link_desc
.vdesc_offset
])(&a
);
3824 DTRACE_FSINFO(link
, vnode_t
, vp
);
3826 post_event_if_success(vp
, _err
, NOTE_LINK
);
3827 post_event_if_success(tdvp
, _err
, NOTE_WRITE
);
3833 vn_rename(struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
3834 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
3835 vfs_rename_flags_t flags
, vfs_context_t ctx
)
3838 struct nameidata
*fromnd
= NULL
;
3839 struct nameidata
*tond
= NULL
;
3840 #if CONFIG_APPLEDOUBLE
3841 vnode_t src_attr_vp
= NULLVP
;
3842 vnode_t dst_attr_vp
= NULLVP
;
3843 char smallname1
[48];
3844 char smallname2
[48];
3845 char *xfromname
= NULL
;
3846 char *xtoname
= NULL
;
3847 #endif /* CONFIG_APPLEDOUBLE */
3849 uint32_t tdfflags
; // Target directory file flags
3851 batched
= vnode_compound_rename_available(fdvp
);
3854 if (*fvpp
== NULLVP
)
3855 panic("Not batched, and no fvp?");
3858 #if CONFIG_APPLEDOUBLE
3860 * We need to preflight any potential AppleDouble file for the source file
3861 * before doing the rename operation, since we could potentially be doing
3862 * this operation on a network filesystem, and would end up duplicating
3863 * the work. Also, save the source and destination names. Skip it if the
3864 * source has a "._" prefix.
3867 if (!NATIVE_XATTR(fdvp
) &&
3868 !(fcnp
->cn_nameptr
[0] == '.' && fcnp
->cn_nameptr
[1] == '_')) {
3872 /* Get source attribute file name. */
3873 len
= fcnp
->cn_namelen
+ 3;
3874 if (len
> sizeof(smallname1
)) {
3875 MALLOC(xfromname
, char *, len
, M_TEMP
, M_WAITOK
);
3877 xfromname
= &smallname1
[0];
3879 strlcpy(xfromname
, "._", min(sizeof smallname1
, len
));
3880 strncat(xfromname
, fcnp
->cn_nameptr
, fcnp
->cn_namelen
);
3881 xfromname
[len
-1] = '\0';
3883 /* Get destination attribute file name. */
3884 len
= tcnp
->cn_namelen
+ 3;
3885 if (len
> sizeof(smallname2
)) {
3886 MALLOC(xtoname
, char *, len
, M_TEMP
, M_WAITOK
);
3888 xtoname
= &smallname2
[0];
3890 strlcpy(xtoname
, "._", min(sizeof smallname2
, len
));
3891 strncat(xtoname
, tcnp
->cn_nameptr
, tcnp
->cn_namelen
);
3892 xtoname
[len
-1] = '\0';
3895 * Look up source attribute file, keep reference on it if exists.
3896 * Note that we do the namei with the nameiop of RENAME, which is different than
3897 * in the rename syscall. It's OK if the source file does not exist, since this
3898 * is only for AppleDouble files.
3900 if (xfromname
!= NULL
) {
3901 MALLOC(fromnd
, struct nameidata
*, sizeof (struct nameidata
), M_TEMP
, M_WAITOK
);
3902 NDINIT(fromnd
, RENAME
, OP_RENAME
, NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
,
3903 UIO_SYSSPACE
, CAST_USER_ADDR_T(xfromname
), ctx
);
3904 fromnd
->ni_dvp
= fdvp
;
3905 error
= namei(fromnd
);
3908 * If there was an error looking up source attribute file,
3909 * we'll behave as if it didn't exist.
3913 if (fromnd
->ni_vp
) {
3914 /* src_attr_vp indicates need to call vnode_put / nameidone later */
3915 src_attr_vp
= fromnd
->ni_vp
;
3917 if (fromnd
->ni_vp
->v_type
!= VREG
) {
3918 src_attr_vp
= NULLVP
;
3919 vnode_put(fromnd
->ni_vp
);
3923 * Either we got an invalid vnode type (not a regular file) or the namei lookup
3924 * suppressed ENOENT as a valid error since we're renaming. Either way, we don't
3925 * have a vnode here, so we drop our namei buffer for the source attribute file
3927 if (src_attr_vp
== NULLVP
) {
3933 #endif /* CONFIG_APPLEDOUBLE */
3936 _err
= VNOP_COMPOUND_RENAME(fdvp
, fvpp
, fcnp
, fvap
, tdvp
, tvpp
, tcnp
, tvap
, flags
, ctx
);
3938 printf("VNOP_COMPOUND_RENAME() returned %d\n", _err
);
3942 _err
= VNOP_RENAMEX(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, flags
, ctx
);
3943 if (_err
== ENOTSUP
&& flags
== VFS_RENAME_SECLUDE
) {
3945 if ((*fvpp
)->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_SECLUDE_RENAME
) {
3946 fcnp
->cn_flags
|= CN_SECLUDE_RENAME
;
3947 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
3951 _err
= VNOP_RENAME(fdvp
, *fvpp
, fcnp
, tdvp
, *tvpp
, tcnp
, ctx
);
3955 * If moved to a new directory that is restricted,
3956 * set the restricted flag on the item moved.
3959 _err
= vnode_flags(tdvp
, &tdfflags
, ctx
);
3960 if (_err
== 0 && (tdfflags
& SF_RESTRICTED
)) {
3962 _err
= vnode_flags(*fvpp
, &fflags
, ctx
);
3963 if (_err
== 0 && !(fflags
& SF_RESTRICTED
)) {
3964 struct vnode_attr va
;
3966 VATTR_SET(&va
, va_flags
, fflags
| SF_RESTRICTED
);
3967 _err
= vnode_setattr(*fvpp
, &va
, ctx
);
3974 mac_vnode_notify_rename(ctx
, *fvpp
, tdvp
, tcnp
);
3978 #if CONFIG_APPLEDOUBLE
3980 * Rename any associated extended attribute file (._ AppleDouble file).
3982 if (_err
== 0 && !NATIVE_XATTR(fdvp
) && xfromname
!= NULL
) {
3986 * Get destination attribute file vnode.
3987 * Note that tdvp already has an iocount reference. Make sure to check that we
3988 * get a valid vnode from namei.
3990 MALLOC(tond
, struct nameidata
*, sizeof(struct nameidata
), M_TEMP
, M_WAITOK
);
3991 NDINIT(tond
, RENAME
, OP_RENAME
,
3992 NOCACHE
| NOFOLLOW
| USEDVP
| CN_NBMOUNTLOOK
, UIO_SYSSPACE
,
3993 CAST_USER_ADDR_T(xtoname
), ctx
);
3994 tond
->ni_dvp
= tdvp
;
3995 error
= namei(tond
);
4001 dst_attr_vp
= tond
->ni_vp
;
4005 const char *old_name
= src_attr_vp
->v_name
;
4006 vnode_t old_parent
= src_attr_vp
->v_parent
;
4009 error
= VNOP_COMPOUND_RENAME(fdvp
, &src_attr_vp
, &fromnd
->ni_cnd
, NULL
,
4010 tdvp
, &dst_attr_vp
, &tond
->ni_cnd
, NULL
,
4013 error
= VNOP_RENAME(fdvp
, src_attr_vp
, &fromnd
->ni_cnd
,
4014 tdvp
, dst_attr_vp
, &tond
->ni_cnd
, ctx
);
4017 if (error
== 0 && old_name
== src_attr_vp
->v_name
&&
4018 old_parent
== src_attr_vp
->v_parent
) {
4019 int update_flags
= VNODE_UPDATE_NAME
;
4022 update_flags
|= VNODE_UPDATE_PARENT
;
4024 if ((src_attr_vp
->v_mount
->mnt_vtable
->vfc_vfsflags
& VFC_VFSVNOP_NOUPDATEID_RENAME
) == 0) {
4025 vnode_update_identity(src_attr_vp
, tdvp
,
4026 tond
->ni_cnd
.cn_nameptr
,
4027 tond
->ni_cnd
.cn_namelen
,
4028 tond
->ni_cnd
.cn_hash
,
4033 /* kevent notifications for moving resource files
4034 * _err is zero if we're here, so no need to notify directories, code
4035 * below will do that. only need to post the rename on the source and
4036 * possibly a delete on the dest
4038 post_event_if_success(src_attr_vp
, error
, NOTE_RENAME
);
4040 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4043 } else if (dst_attr_vp
) {
4045 * Just delete destination attribute file vnode if it exists, since
4046 * we didn't have a source attribute file.
4047 * Note that tdvp already has an iocount reference.
4050 struct vnop_remove_args args
;
4052 args
.a_desc
= &vnop_remove_desc
;
4054 args
.a_vp
= dst_attr_vp
;
4055 args
.a_cnp
= &tond
->ni_cnd
;
4056 args
.a_context
= ctx
;
4059 error
= (*tdvp
->v_op
[vnop_remove_desc
.vdesc_offset
])(&args
);
4062 vnode_setneedinactive(dst_attr_vp
);
4065 /* kevent notification for deleting the destination's attribute file
4066 * if it existed. Only need to post the delete on the destination, since
4067 * the code below will handle the directories.
4069 post_event_if_success(dst_attr_vp
, error
, NOTE_DELETE
);
4074 vnode_put(src_attr_vp
);
4078 vnode_put(dst_attr_vp
);
4081 if (xfromname
&& xfromname
!= &smallname1
[0]) {
4082 FREE(xfromname
, M_TEMP
);
4084 if (xtoname
&& xtoname
!= &smallname2
[0]) {
4085 FREE(xtoname
, M_TEMP
);
4087 #endif /* CONFIG_APPLEDOUBLE */
4089 FREE(fromnd
, M_TEMP
);
4101 *#% rename fdvp U U U
4102 *#% rename fvp U U U
4103 *#% rename tdvp L U U
4104 *#% rename tvp X U U
4107 struct vnop_rename_args
{
4108 struct vnodeop_desc
*a_desc
;
4111 struct componentname
*a_fcnp
;
4114 struct componentname
*a_tcnp
;
4115 vfs_context_t a_context
;
4119 VNOP_RENAME(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4120 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4124 struct vnop_rename_args a
;
4126 a
.a_desc
= &vnop_rename_desc
;
4135 /* do the rename of the main file. */
4136 _err
= (*fdvp
->v_op
[vnop_rename_desc
.vdesc_offset
])(&a
);
4137 DTRACE_FSINFO(rename
, vnode_t
, fdvp
);
4142 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4146 post_rename(vnode_t fdvp
, vnode_t fvp
, vnode_t tdvp
, vnode_t tvp
)
4148 if (tvp
&& tvp
!= fvp
)
4149 vnode_setneedinactive(tvp
);
4151 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4152 int events
= NOTE_WRITE
;
4153 if (vnode_isdir(fvp
)) {
4154 /* Link count on dir changed only if we are moving a dir and...
4155 * --Moved to new dir, not overwriting there
4156 * --Kept in same dir and DID overwrite
4158 if (((fdvp
!= tdvp
) && (!tvp
)) || ((fdvp
== tdvp
) && (tvp
))) {
4159 events
|= NOTE_LINK
;
4163 lock_vnode_and_post(fdvp
, events
);
4165 lock_vnode_and_post(tdvp
, events
);
4168 /* If you're replacing the target, post a deletion for it */
4171 lock_vnode_and_post(tvp
, NOTE_DELETE
);
4174 lock_vnode_and_post(fvp
, NOTE_RENAME
);
4182 *#% renamex fdvp U U U
4183 *#% renamex fvp U U U
4184 *#% renamex tdvp L U U
4185 *#% renamex tvp X U U
4188 struct vnop_renamex_args
{
4189 struct vnodeop_desc
*a_desc
;
4192 struct componentname
*a_fcnp
;
4195 struct componentname
*a_tcnp
;
4196 vfs_rename_flags_t a_flags
;
4197 vfs_context_t a_context
;
4201 VNOP_RENAMEX(struct vnode
*fdvp
, struct vnode
*fvp
, struct componentname
*fcnp
,
4202 struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
4203 vfs_rename_flags_t flags
, vfs_context_t ctx
)
4206 struct vnop_renamex_args a
;
4208 a
.a_desc
= &vnop_renamex_desc
;
4218 /* do the rename of the main file. */
4219 _err
= (*fdvp
->v_op
[vnop_renamex_desc
.vdesc_offset
])(&a
);
4220 DTRACE_FSINFO(renamex
, vnode_t
, fdvp
);
4225 return post_rename(fdvp
, fvp
, tdvp
, tvp
);
4230 VNOP_COMPOUND_RENAME(
4231 struct vnode
*fdvp
, struct vnode
**fvpp
, struct componentname
*fcnp
, struct vnode_attr
*fvap
,
4232 struct vnode
*tdvp
, struct vnode
**tvpp
, struct componentname
*tcnp
, struct vnode_attr
*tvap
,
4233 uint32_t flags
, vfs_context_t ctx
)
4237 struct vnop_compound_rename_args a
;
4240 no_fvp
= (*fvpp
) == NULLVP
;
4241 no_tvp
= (*tvpp
) == NULLVP
;
4243 a
.a_desc
= &vnop_compound_rename_desc
;
4257 a
.a_rename_authorizer
= vn_authorize_rename
;
4258 a
.a_reserved
= NULL
;
4260 /* do the rename of the main file. */
4261 _err
= (*fdvp
->v_op
[vnop_compound_rename_desc
.vdesc_offset
])(&a
);
4262 DTRACE_FSINFO(compound_rename
, vnode_t
, fdvp
);
4265 if (*tvpp
&& *tvpp
!= *fvpp
)
4266 vnode_setneedinactive(*tvpp
);
4269 /* Wrote at least one directory. If transplanted a dir, also changed link counts */
4270 if (_err
== 0 && *fvpp
!= *tvpp
) {
4272 panic("No fvpp after compound rename?");
4275 events
= NOTE_WRITE
;
4276 if (vnode_isdir(*fvpp
)) {
4277 /* Link count on dir changed only if we are moving a dir and...
4278 * --Moved to new dir, not overwriting there
4279 * --Kept in same dir and DID overwrite
4281 if (((fdvp
!= tdvp
) && (!*tvpp
)) || ((fdvp
== tdvp
) && (*tvpp
))) {
4282 events
|= NOTE_LINK
;
4286 lock_vnode_and_post(fdvp
, events
);
4288 lock_vnode_and_post(tdvp
, events
);
4291 /* If you're replacing the target, post a deletion for it */
4294 lock_vnode_and_post(*tvpp
, NOTE_DELETE
);
4297 lock_vnode_and_post(*fvpp
, NOTE_RENAME
);
4301 lookup_compound_vnop_post_hook(_err
, fdvp
, *fvpp
, fcnp
->cn_ndp
, 0);
4303 if (no_tvp
&& *tvpp
!= NULLVP
) {
4304 lookup_compound_vnop_post_hook(_err
, tdvp
, *tvpp
, tcnp
->cn_ndp
, 0);
4307 if (_err
&& _err
!= EKEEPLOOKING
) {
4322 vn_mkdir(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4323 struct vnode_attr
*vap
, vfs_context_t ctx
)
4325 if (ndp
->ni_cnd
.cn_nameiop
!= CREATE
) {
4326 panic("Non-CREATE nameiop in vn_mkdir()?");
4329 if (vnode_compound_mkdir_available(dvp
)) {
4330 return VNOP_COMPOUND_MKDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4332 return VNOP_MKDIR(dvp
, vpp
, &ndp
->ni_cnd
, vap
, ctx
);
4343 struct vnop_mkdir_args
{
4344 struct vnodeop_desc
*a_desc
;
4347 struct componentname
*a_cnp
;
4348 struct vnode_attr
*a_vap
;
4349 vfs_context_t a_context
;
4353 VNOP_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4354 struct vnode_attr
*vap
, vfs_context_t ctx
)
4357 struct vnop_mkdir_args a
;
4359 a
.a_desc
= &vnop_mkdir_desc
;
4366 _err
= (*dvp
->v_op
[vnop_mkdir_desc
.vdesc_offset
])(&a
);
4367 if (_err
== 0 && *vpp
) {
4368 DTRACE_FSINFO(mkdir
, vnode_t
, *vpp
);
4370 #if CONFIG_APPLEDOUBLE
4371 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4373 * Remove stale Apple Double file (if any).
4375 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4377 #endif /* CONFIG_APPLEDOUBLE */
4379 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4385 VNOP_COMPOUND_MKDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4386 struct vnode_attr
*vap
, vfs_context_t ctx
)
4389 struct vnop_compound_mkdir_args a
;
4391 a
.a_desc
= &vnop_compound_mkdir_desc
;
4394 a
.a_cnp
= &ndp
->ni_cnd
;
4399 a
.a_mkdir_authorizer
= vn_authorize_mkdir
;
4401 a
.a_reserved
= NULL
;
4403 _err
= (*dvp
->v_op
[vnop_compound_mkdir_desc
.vdesc_offset
])(&a
);
4404 if (_err
== 0 && *vpp
) {
4405 DTRACE_FSINFO(compound_mkdir
, vnode_t
, *vpp
);
4407 #if CONFIG_APPLEDOUBLE
4408 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4410 * Remove stale Apple Double file (if any).
4412 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4414 #endif /* CONFIG_APPLEDOUBLE */
4416 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4418 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, (_err
== 0));
4419 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4428 vn_rmdir(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, struct vnode_attr
*vap
, vfs_context_t ctx
)
4430 if (vnode_compound_rmdir_available(dvp
)) {
4431 return VNOP_COMPOUND_RMDIR(dvp
, vpp
, ndp
, vap
, ctx
);
4433 if (*vpp
== NULLVP
) {
4434 panic("NULL vp, but not a compound VNOP?");
4437 panic("Non-NULL vap, but not a compound VNOP?");
4439 return VNOP_RMDIR(dvp
, *vpp
, &ndp
->ni_cnd
, ctx
);
4450 struct vnop_rmdir_args
{
4451 struct vnodeop_desc
*a_desc
;
4454 struct componentname
*a_cnp
;
4455 vfs_context_t a_context
;
4460 VNOP_RMDIR(struct vnode
*dvp
, struct vnode
*vp
, struct componentname
*cnp
, vfs_context_t ctx
)
4463 struct vnop_rmdir_args a
;
4465 a
.a_desc
= &vnop_rmdir_desc
;
4471 _err
= (*vp
->v_op
[vnop_rmdir_desc
.vdesc_offset
])(&a
);
4472 DTRACE_FSINFO(rmdir
, vnode_t
, vp
);
4475 vnode_setneedinactive(vp
);
4476 #if CONFIG_APPLEDOUBLE
4477 if ( !(NATIVE_XATTR(dvp
)) ) {
4479 * Remove any associated extended attribute file (._ AppleDouble file).
4481 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 1);
4486 /* If you delete a dir, it loses its "." reference --> NOTE_LINK */
4487 post_event_if_success(vp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4488 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4494 VNOP_COMPOUND_RMDIR(struct vnode
*dvp
, struct vnode
**vpp
, struct nameidata
*ndp
,
4495 struct vnode_attr
*vap
, vfs_context_t ctx
)
4498 struct vnop_compound_rmdir_args a
;
4501 a
.a_desc
= &vnop_mkdir_desc
;
4504 a
.a_cnp
= &ndp
->ni_cnd
;
4508 a
.a_rmdir_authorizer
= vn_authorize_rmdir
;
4509 a
.a_reserved
= NULL
;
4511 no_vp
= (*vpp
== NULLVP
);
4513 _err
= (*dvp
->v_op
[vnop_compound_rmdir_desc
.vdesc_offset
])(&a
);
4514 if (_err
== 0 && *vpp
) {
4515 DTRACE_FSINFO(compound_rmdir
, vnode_t
, *vpp
);
4517 #if CONFIG_APPLEDOUBLE
4518 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4520 * Remove stale Apple Double file (if any).
4522 xattrfile_remove(dvp
, ndp
->ni_cnd
.cn_nameptr
, ctx
, 0);
4527 post_event_if_success(*vpp
, _err
, NOTE_DELETE
| NOTE_LINK
);
4529 post_event_if_success(dvp
, _err
, NOTE_LINK
| NOTE_WRITE
);
4532 lookup_compound_vnop_post_hook(_err
, dvp
, *vpp
, ndp
, 0);
4534 #if 0 /* Removing orphaned ._ files requires a vp.... */
4535 if (*vpp
&& _err
&& _err
!= EKEEPLOOKING
) {
4545 #if CONFIG_APPLEDOUBLE
4547 * Remove a ._ AppleDouble file
4549 #define AD_STALE_SECS (180)
4551 xattrfile_remove(vnode_t dvp
, const char * basename
, vfs_context_t ctx
, int force
)
4554 struct nameidata nd
;
4556 char *filename
= NULL
;
4559 if ((basename
== NULL
) || (basename
[0] == '\0') ||
4560 (basename
[0] == '.' && basename
[1] == '_')) {
4563 filename
= &smallname
[0];
4564 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4565 if (len
>= sizeof(smallname
)) {
4566 len
++; /* snprintf result doesn't include '\0' */
4567 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4568 len
= snprintf(filename
, len
, "._%s", basename
);
4570 NDINIT(&nd
, DELETE
, OP_UNLINK
, WANTPARENT
| LOCKLEAF
| NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4571 CAST_USER_ADDR_T(filename
), ctx
);
4573 if (namei(&nd
) != 0)
4578 if (xvp
->v_type
!= VREG
)
4582 * When creating a new object and a "._" file already
4583 * exists, check to see if its a stale "._" file.
4587 struct vnode_attr va
;
4590 VATTR_WANTED(&va
, va_data_size
);
4591 VATTR_WANTED(&va
, va_modify_time
);
4592 if (VNOP_GETATTR(xvp
, &va
, ctx
) == 0 &&
4593 VATTR_IS_SUPPORTED(&va
, va_data_size
) &&
4594 VATTR_IS_SUPPORTED(&va
, va_modify_time
) &&
4595 va
.va_data_size
!= 0) {
4599 if ((tv
.tv_sec
> va
.va_modify_time
.tv_sec
) &&
4600 (tv
.tv_sec
- va
.va_modify_time
.tv_sec
) > AD_STALE_SECS
) {
4601 force
= 1; /* must be stale */
4608 error
= VNOP_REMOVE(dvp
, xvp
, &nd
.ni_cnd
, 0, ctx
);
4610 vnode_setneedinactive(xvp
);
4612 post_event_if_success(xvp
, error
, NOTE_DELETE
);
4613 post_event_if_success(dvp
, error
, NOTE_WRITE
);
4620 if (filename
&& filename
!= &smallname
[0]) {
4621 FREE(filename
, M_TEMP
);
4626 * Shadow uid/gid/mod to a ._ AppleDouble file
4629 xattrfile_setattr(vnode_t dvp
, const char * basename
, struct vnode_attr
* vap
,
4633 struct nameidata nd
;
4635 char *filename
= NULL
;
4638 if ((dvp
== NULLVP
) ||
4639 (basename
== NULL
) || (basename
[0] == '\0') ||
4640 (basename
[0] == '.' && basename
[1] == '_')) {
4643 filename
= &smallname
[0];
4644 len
= snprintf(filename
, sizeof(smallname
), "._%s", basename
);
4645 if (len
>= sizeof(smallname
)) {
4646 len
++; /* snprintf result doesn't include '\0' */
4647 MALLOC(filename
, char *, len
, M_TEMP
, M_WAITOK
);
4648 len
= snprintf(filename
, len
, "._%s", basename
);
4650 NDINIT(&nd
, LOOKUP
, OP_SETATTR
, NOFOLLOW
| USEDVP
, UIO_SYSSPACE
,
4651 CAST_USER_ADDR_T(filename
), ctx
);
4653 if (namei(&nd
) != 0)
4659 if (xvp
->v_type
== VREG
) {
4660 struct vnop_setattr_args a
;
4662 a
.a_desc
= &vnop_setattr_desc
;
4667 (void) (*xvp
->v_op
[vnop_setattr_desc
.vdesc_offset
])(&a
);
4672 if (filename
&& filename
!= &smallname
[0]) {
4673 FREE(filename
, M_TEMP
);
4676 #endif /* CONFIG_APPLEDOUBLE */
4681 *#% symlink dvp L U U
4682 *#% symlink vpp - U -
4685 struct vnop_symlink_args
{
4686 struct vnodeop_desc
*a_desc
;
4689 struct componentname
*a_cnp
;
4690 struct vnode_attr
*a_vap
;
4692 vfs_context_t a_context
;
4697 VNOP_SYMLINK(struct vnode
*dvp
, struct vnode
**vpp
, struct componentname
*cnp
,
4698 struct vnode_attr
*vap
, char *target
, vfs_context_t ctx
)
4701 struct vnop_symlink_args a
;
4703 a
.a_desc
= &vnop_symlink_desc
;
4708 a
.a_target
= target
;
4711 _err
= (*dvp
->v_op
[vnop_symlink_desc
.vdesc_offset
])(&a
);
4712 DTRACE_FSINFO(symlink
, vnode_t
, dvp
);
4713 #if CONFIG_APPLEDOUBLE
4714 if (_err
== 0 && !NATIVE_XATTR(dvp
)) {
4716 * Remove stale Apple Double file (if any). Posts its own knotes
4718 xattrfile_remove(dvp
, cnp
->cn_nameptr
, ctx
, 0);
4720 #endif /* CONFIG_APPLEDOUBLE */
4722 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
4730 *#% readdir vp L L L
4733 struct vnop_readdir_args
{
4734 struct vnodeop_desc
*a_desc
;
4740 vfs_context_t a_context
;
4745 VNOP_READDIR(struct vnode
*vp
, struct uio
*uio
, int flags
, int *eofflag
,
4746 int *numdirent
, vfs_context_t ctx
)
4749 struct vnop_readdir_args a
;
4751 user_ssize_t resid
= uio_resid(uio
);
4754 a
.a_desc
= &vnop_readdir_desc
;
4758 a
.a_eofflag
= eofflag
;
4759 a
.a_numdirent
= numdirent
;
4762 _err
= (*vp
->v_op
[vnop_readdir_desc
.vdesc_offset
])(&a
);
4763 DTRACE_FSINFO_IO(readdir
,
4764 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4772 *#% readdirattr vp L L L
4775 struct vnop_readdirattr_args
{
4776 struct vnodeop_desc
*a_desc
;
4778 struct attrlist
*a_alist
;
4780 uint32_t a_maxcount
;
4782 uint32_t *a_newstate
;
4784 uint32_t *a_actualcount
;
4785 vfs_context_t a_context
;
4790 VNOP_READDIRATTR(struct vnode
*vp
, struct attrlist
*alist
, struct uio
*uio
, uint32_t maxcount
,
4791 uint32_t options
, uint32_t *newstate
, int *eofflag
, uint32_t *actualcount
, vfs_context_t ctx
)
4794 struct vnop_readdirattr_args a
;
4796 user_ssize_t resid
= uio_resid(uio
);
4799 a
.a_desc
= &vnop_readdirattr_desc
;
4803 a
.a_maxcount
= maxcount
;
4804 a
.a_options
= options
;
4805 a
.a_newstate
= newstate
;
4806 a
.a_eofflag
= eofflag
;
4807 a
.a_actualcount
= actualcount
;
4810 _err
= (*vp
->v_op
[vnop_readdirattr_desc
.vdesc_offset
])(&a
);
4811 DTRACE_FSINFO_IO(readdirattr
,
4812 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4818 struct vnop_getttrlistbulk_args
{
4819 struct vnodeop_desc
*a_desc
;
4821 struct attrlist
*a_alist
;
4822 struct vnode_attr
*a_vap
;
4827 uint32_t *a_actualcount
;
4828 vfs_context_t a_context
;
4832 VNOP_GETATTRLISTBULK(struct vnode
*vp
, struct attrlist
*alist
,
4833 struct vnode_attr
*vap
, struct uio
*uio
, void *private, uint64_t options
,
4834 int32_t *eofflag
, int32_t *actualcount
, vfs_context_t ctx
)
4837 struct vnop_getattrlistbulk_args a
;
4839 user_ssize_t resid
= uio_resid(uio
);
4842 a
.a_desc
= &vnop_getattrlistbulk_desc
;
4847 a
.a_private
= private;
4848 a
.a_options
= options
;
4849 a
.a_eofflag
= eofflag
;
4850 a
.a_actualcount
= actualcount
;
4853 _err
= (*vp
->v_op
[vnop_getattrlistbulk_desc
.vdesc_offset
])(&a
);
4854 DTRACE_FSINFO_IO(getattrlistbulk
,
4855 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4863 *#% readlink vp L L L
4866 struct vnop_readlink_args
{
4867 struct vnodeop_desc
*a_desc
;
4870 vfs_context_t a_context
;
4875 * Returns: 0 Success
4876 * lock_fsnode:ENOENT No such file or directory [only for VFS
4877 * that is not thread safe & vnode is
4878 * currently being/has been terminated]
4879 * <vfs_readlink>:EINVAL
4880 * <vfs_readlink>:???
4882 * Note: The return codes from the underlying VFS's readlink routine
4883 * can't be fully enumerated here, since third party VFS authors
4884 * may not limit their error returns to the ones documented here,
4885 * even though this may result in some programs functioning
4888 * The return codes documented above are those which may currently
4889 * be returned by HFS from hfs_vnop_readlink, not including
4890 * additional error code which may be propagated from underlying
4894 VNOP_READLINK(struct vnode
*vp
, struct uio
*uio
, vfs_context_t ctx
)
4897 struct vnop_readlink_args a
;
4899 user_ssize_t resid
= uio_resid(uio
);
4901 a
.a_desc
= &vnop_readlink_desc
;
4906 _err
= (*vp
->v_op
[vnop_readlink_desc
.vdesc_offset
])(&a
);
4907 DTRACE_FSINFO_IO(readlink
,
4908 vnode_t
, vp
, user_ssize_t
, (resid
- uio_resid(uio
)));
4916 *#% inactive vp L U U
4919 struct vnop_inactive_args
{
4920 struct vnodeop_desc
*a_desc
;
4922 vfs_context_t a_context
;
4926 VNOP_INACTIVE(struct vnode
*vp
, vfs_context_t ctx
)
4929 struct vnop_inactive_args a
;
4931 a
.a_desc
= &vnop_inactive_desc
;
4935 _err
= (*vp
->v_op
[vnop_inactive_desc
.vdesc_offset
])(&a
);
4936 DTRACE_FSINFO(inactive
, vnode_t
, vp
);
4939 /* For file systems that do not support namedstream natively, mark
4940 * the shadow stream file vnode to be recycled as soon as the last
4941 * reference goes away. To avoid re-entering reclaim code, do not
4942 * call recycle on terminating namedstream vnodes.
4944 if (vnode_isnamedstream(vp
) &&
4945 (vp
->v_parent
!= NULLVP
) &&
4946 vnode_isshadow(vp
) &&
4947 ((vp
->v_lflag
& VL_TERMINATE
) == 0)) {
4959 *#% reclaim vp U U U
4962 struct vnop_reclaim_args
{
4963 struct vnodeop_desc
*a_desc
;
4965 vfs_context_t a_context
;
4969 VNOP_RECLAIM(struct vnode
*vp
, vfs_context_t ctx
)
4972 struct vnop_reclaim_args a
;
4974 a
.a_desc
= &vnop_reclaim_desc
;
4978 _err
= (*vp
->v_op
[vnop_reclaim_desc
.vdesc_offset
])(&a
);
4979 DTRACE_FSINFO(reclaim
, vnode_t
, vp
);
4986 * Returns: 0 Success
4987 * lock_fsnode:ENOENT No such file or directory [only for VFS
4988 * that is not thread safe & vnode is
4989 * currently being/has been terminated]
4990 * <vnop_pathconf_desc>:??? [per FS implementation specific]
4995 *#% pathconf vp L L L
4998 struct vnop_pathconf_args
{
4999 struct vnodeop_desc
*a_desc
;
5003 vfs_context_t a_context
;
5007 VNOP_PATHCONF(struct vnode
*vp
, int name
, int32_t *retval
, vfs_context_t ctx
)
5010 struct vnop_pathconf_args a
;
5012 a
.a_desc
= &vnop_pathconf_desc
;
5015 a
.a_retval
= retval
;
5018 _err
= (*vp
->v_op
[vnop_pathconf_desc
.vdesc_offset
])(&a
);
5019 DTRACE_FSINFO(pathconf
, vnode_t
, vp
);
5025 * Returns: 0 Success
5026 * err_advlock:ENOTSUP
5028 * <vnop_advlock_desc>:???
5030 * Notes: VFS implementations of advisory locking using calls through
5031 * <vnop_advlock_desc> because lock enforcement does not occur
5032 * locally should try to limit themselves to the return codes
5033 * documented above for lf_advlock and err_advlock.
5038 *#% advlock vp U U U
5041 struct vnop_advlock_args
{
5042 struct vnodeop_desc
*a_desc
;
5048 vfs_context_t a_context
;
5052 VNOP_ADVLOCK(struct vnode
*vp
, caddr_t id
, int op
, struct flock
*fl
, int flags
, vfs_context_t ctx
, struct timespec
*timeout
)
5055 struct vnop_advlock_args a
;
5057 a
.a_desc
= &vnop_advlock_desc
;
5064 a
.a_timeout
= timeout
;
5066 /* Disallow advisory locking on non-seekable vnodes */
5067 if (vnode_isfifo(vp
)) {
5068 _err
= err_advlock(&a
);
5070 if ((vp
->v_flag
& VLOCKLOCAL
)) {
5071 /* Advisory locking done at this layer */
5072 _err
= lf_advlock(&a
);
5073 } else if (flags
& F_OFD_LOCK
) {
5074 /* Non-local locking doesn't work for OFD locks */
5075 _err
= err_advlock(&a
);
5077 /* Advisory locking done by underlying filesystem */
5078 _err
= (*vp
->v_op
[vnop_advlock_desc
.vdesc_offset
])(&a
);
5080 DTRACE_FSINFO(advlock
, vnode_t
, vp
);
5081 if (op
== F_UNLCK
&& flags
== F_FLOCK
)
5082 post_event_if_success(vp
, _err
, NOTE_FUNLOCK
);
5093 *#% allocate vp L L L
5096 struct vnop_allocate_args
{
5097 struct vnodeop_desc
*a_desc
;
5101 off_t
*a_bytesallocated
;
5103 vfs_context_t a_context
;
5108 VNOP_ALLOCATE(struct vnode
*vp
, off_t length
, u_int32_t flags
, off_t
*bytesallocated
, off_t offset
, vfs_context_t ctx
)
5111 struct vnop_allocate_args a
;
5113 a
.a_desc
= &vnop_allocate_desc
;
5115 a
.a_length
= length
;
5117 a
.a_bytesallocated
= bytesallocated
;
5118 a
.a_offset
= offset
;
5121 _err
= (*vp
->v_op
[vnop_allocate_desc
.vdesc_offset
])(&a
);
5122 DTRACE_FSINFO(allocate
, vnode_t
, vp
);
5125 add_fsevent(FSE_STAT_CHANGED
, ctx
, FSE_ARG_VNODE
, vp
, FSE_ARG_DONE
);
5138 struct vnop_pagein_args
{
5139 struct vnodeop_desc
*a_desc
;
5142 upl_offset_t a_pl_offset
;
5146 vfs_context_t a_context
;
5150 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
)
5153 struct vnop_pagein_args a
;
5155 a
.a_desc
= &vnop_pagein_desc
;
5158 a
.a_pl_offset
= pl_offset
;
5159 a
.a_f_offset
= f_offset
;
5164 _err
= (*vp
->v_op
[vnop_pagein_desc
.vdesc_offset
])(&a
);
5165 DTRACE_FSINFO(pagein
, vnode_t
, vp
);
5173 *#% pageout vp = = =
5176 struct vnop_pageout_args
{
5177 struct vnodeop_desc
*a_desc
;
5180 upl_offset_t a_pl_offset
;
5184 vfs_context_t a_context
;
5189 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
)
5192 struct vnop_pageout_args a
;
5194 a
.a_desc
= &vnop_pageout_desc
;
5197 a
.a_pl_offset
= pl_offset
;
5198 a
.a_f_offset
= f_offset
;
5203 _err
= (*vp
->v_op
[vnop_pageout_desc
.vdesc_offset
])(&a
);
5204 DTRACE_FSINFO(pageout
, vnode_t
, vp
);
5206 post_event_if_success(vp
, _err
, NOTE_WRITE
);
5212 vn_remove(vnode_t dvp
, vnode_t
*vpp
, struct nameidata
*ndp
, int32_t flags
, struct vnode_attr
*vap
, vfs_context_t ctx
)
5214 if (vnode_compound_remove_available(dvp
)) {
5215 return VNOP_COMPOUND_REMOVE(dvp
, vpp
, ndp
, flags
, vap
, ctx
);
5217 return VNOP_REMOVE(dvp
, *vpp
, &ndp
->ni_cnd
, flags
, ctx
);
5226 *#% searchfs vp L L L
5229 struct vnop_searchfs_args
{
5230 struct vnodeop_desc
*a_desc
;
5232 void *a_searchparams1
;
5233 void *a_searchparams2
;
5234 struct attrlist
*a_searchattrs
;
5235 uint32_t a_maxmatches
;
5236 struct timeval
*a_timelimit
;
5237 struct attrlist
*a_returnattrs
;
5238 uint32_t *a_nummatches
;
5239 uint32_t a_scriptcode
;
5242 struct searchstate
*a_searchstate
;
5243 vfs_context_t a_context
;
5248 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
)
5251 struct vnop_searchfs_args a
;
5253 a
.a_desc
= &vnop_searchfs_desc
;
5255 a
.a_searchparams1
= searchparams1
;
5256 a
.a_searchparams2
= searchparams2
;
5257 a
.a_searchattrs
= searchattrs
;
5258 a
.a_maxmatches
= maxmatches
;
5259 a
.a_timelimit
= timelimit
;
5260 a
.a_returnattrs
= returnattrs
;
5261 a
.a_nummatches
= nummatches
;
5262 a
.a_scriptcode
= scriptcode
;
5263 a
.a_options
= options
;
5265 a
.a_searchstate
= searchstate
;
5268 _err
= (*vp
->v_op
[vnop_searchfs_desc
.vdesc_offset
])(&a
);
5269 DTRACE_FSINFO(searchfs
, vnode_t
, vp
);
5273 #endif /* CONFIG_SEARCHFS */
5278 *#% copyfile fvp U U U
5279 *#% copyfile tdvp L U U
5280 *#% copyfile tvp X U U
5283 struct vnop_copyfile_args
{
5284 struct vnodeop_desc
*a_desc
;
5288 struct componentname
*a_tcnp
;
5291 vfs_context_t a_context
;
5295 VNOP_COPYFILE(struct vnode
*fvp
, struct vnode
*tdvp
, struct vnode
*tvp
, struct componentname
*tcnp
,
5296 int mode
, int flags
, vfs_context_t ctx
)
5299 struct vnop_copyfile_args a
;
5300 a
.a_desc
= &vnop_copyfile_desc
;
5308 _err
= (*fvp
->v_op
[vnop_copyfile_desc
.vdesc_offset
])(&a
);
5309 DTRACE_FSINFO(copyfile
, vnode_t
, fvp
);
5314 struct vnop_clonefile_args
{
5315 struct vnodeop_desc
*a_desc
;
5319 struct componentname
*a_cnp
;
5320 struct vnode_attr
*a_vap
;
5322 vfs_context_t a_context
;
5327 VNOP_CLONEFILE(vnode_t fvp
, vnode_t dvp
, vnode_t
*vpp
,
5328 struct componentname
*cnp
, struct vnode_attr
*vap
, uint32_t flags
,
5332 struct vnop_clonefile_args a
;
5333 a
.a_desc
= &vnop_clonefile_desc
;
5342 _err
= (*dvp
->v_op
[vnop_clonefile_desc
.vdesc_offset
])(&a
);
5344 if (_err
== 0 && *vpp
)
5345 DTRACE_FSINFO(clonefile
, vnode_t
, *vpp
);
5347 post_event_if_success(dvp
, _err
, NOTE_WRITE
);
5353 VNOP_GETXATTR(vnode_t vp
, const char *name
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5355 struct vnop_getxattr_args a
;
5358 a
.a_desc
= &vnop_getxattr_desc
;
5363 a
.a_options
= options
;
5366 error
= (*vp
->v_op
[vnop_getxattr_desc
.vdesc_offset
])(&a
);
5367 DTRACE_FSINFO(getxattr
, vnode_t
, vp
);
5373 VNOP_SETXATTR(vnode_t vp
, const char *name
, uio_t uio
, int options
, vfs_context_t ctx
)
5375 struct vnop_setxattr_args a
;
5378 a
.a_desc
= &vnop_setxattr_desc
;
5382 a
.a_options
= options
;
5385 error
= (*vp
->v_op
[vnop_setxattr_desc
.vdesc_offset
])(&a
);
5386 DTRACE_FSINFO(setxattr
, vnode_t
, vp
);
5389 vnode_uncache_authorized_action(vp
, KAUTH_INVALIDATE_CACHED_RIGHTS
);
5391 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5397 VNOP_REMOVEXATTR(vnode_t vp
, const char *name
, int options
, vfs_context_t ctx
)
5399 struct vnop_removexattr_args a
;
5402 a
.a_desc
= &vnop_removexattr_desc
;
5405 a
.a_options
= options
;
5408 error
= (*vp
->v_op
[vnop_removexattr_desc
.vdesc_offset
])(&a
);
5409 DTRACE_FSINFO(removexattr
, vnode_t
, vp
);
5411 post_event_if_success(vp
, error
, NOTE_ATTRIB
);
5417 VNOP_LISTXATTR(vnode_t vp
, uio_t uio
, size_t *size
, int options
, vfs_context_t ctx
)
5419 struct vnop_listxattr_args a
;
5422 a
.a_desc
= &vnop_listxattr_desc
;
5426 a
.a_options
= options
;
5429 error
= (*vp
->v_op
[vnop_listxattr_desc
.vdesc_offset
])(&a
);
5430 DTRACE_FSINFO(listxattr
, vnode_t
, vp
);
5439 *#% blktooff vp = = =
5442 struct vnop_blktooff_args
{
5443 struct vnodeop_desc
*a_desc
;
5450 VNOP_BLKTOOFF(struct vnode
*vp
, daddr64_t lblkno
, off_t
*offset
)
5453 struct vnop_blktooff_args a
;
5455 a
.a_desc
= &vnop_blktooff_desc
;
5457 a
.a_lblkno
= lblkno
;
5458 a
.a_offset
= offset
;
5460 _err
= (*vp
->v_op
[vnop_blktooff_desc
.vdesc_offset
])(&a
);
5461 DTRACE_FSINFO(blktooff
, vnode_t
, vp
);
5469 *#% offtoblk vp = = =
5472 struct vnop_offtoblk_args
{
5473 struct vnodeop_desc
*a_desc
;
5476 daddr64_t
*a_lblkno
;
5480 VNOP_OFFTOBLK(struct vnode
*vp
, off_t offset
, daddr64_t
*lblkno
)
5483 struct vnop_offtoblk_args a
;
5485 a
.a_desc
= &vnop_offtoblk_desc
;
5487 a
.a_offset
= offset
;
5488 a
.a_lblkno
= lblkno
;
5490 _err
= (*vp
->v_op
[vnop_offtoblk_desc
.vdesc_offset
])(&a
);
5491 DTRACE_FSINFO(offtoblk
, vnode_t
, vp
);
5499 *#% blockmap vp L L L
5502 struct vnop_blockmap_args
{
5503 struct vnodeop_desc
*a_desc
;
5511 vfs_context_t a_context
;
5515 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
)
5518 struct vnop_blockmap_args a
;
5519 size_t localrun
= 0;
5522 ctx
= vfs_context_current();
5524 a
.a_desc
= &vnop_blockmap_desc
;
5526 a
.a_foffset
= foffset
;
5529 a
.a_run
= &localrun
;
5534 _err
= (*vp
->v_op
[vnop_blockmap_desc
.vdesc_offset
])(&a
);
5535 DTRACE_FSINFO(blockmap
, vnode_t
, vp
);
5538 * We used a local variable to request information from the underlying
5539 * filesystem about the length of the I/O run in question. If
5540 * we get malformed output from the filesystem, we cap it to the length
5541 * requested, at most. Update 'run' on the way out.
5544 if (localrun
> size
) {
5557 struct vnop_strategy_args
{
5558 struct vnodeop_desc
*a_desc
;
5564 VNOP_STRATEGY(struct buf
*bp
)
5567 struct vnop_strategy_args a
;
5568 vnode_t vp
= buf_vnode(bp
);
5569 a
.a_desc
= &vnop_strategy_desc
;
5571 _err
= (*vp
->v_op
[vnop_strategy_desc
.vdesc_offset
])(&a
);
5572 DTRACE_FSINFO(strategy
, vnode_t
, vp
);
5577 struct vnop_bwrite_args
{
5578 struct vnodeop_desc
*a_desc
;
5583 VNOP_BWRITE(struct buf
*bp
)
5586 struct vnop_bwrite_args a
;
5587 vnode_t vp
= buf_vnode(bp
);
5588 a
.a_desc
= &vnop_bwrite_desc
;
5590 _err
= (*vp
->v_op
[vnop_bwrite_desc
.vdesc_offset
])(&a
);
5591 DTRACE_FSINFO(bwrite
, vnode_t
, vp
);
5596 struct vnop_kqfilt_add_args
{
5597 struct vnodeop_desc
*a_desc
;
5600 vfs_context_t a_context
;
5604 VNOP_KQFILT_ADD(struct vnode
*vp
, struct knote
*kn
, vfs_context_t ctx
)
5607 struct vnop_kqfilt_add_args a
;
5609 a
.a_desc
= VDESC(vnop_kqfilt_add
);
5614 _err
= (*vp
->v_op
[vnop_kqfilt_add_desc
.vdesc_offset
])(&a
);
5615 DTRACE_FSINFO(kqfilt_add
, vnode_t
, vp
);
5621 struct vnop_kqfilt_remove_args
{
5622 struct vnodeop_desc
*a_desc
;
5625 vfs_context_t a_context
;
5629 VNOP_KQFILT_REMOVE(struct vnode
*vp
, uintptr_t ident
, vfs_context_t ctx
)
5632 struct vnop_kqfilt_remove_args a
;
5634 a
.a_desc
= VDESC(vnop_kqfilt_remove
);
5639 _err
= (*vp
->v_op
[vnop_kqfilt_remove_desc
.vdesc_offset
])(&a
);
5640 DTRACE_FSINFO(kqfilt_remove
, vnode_t
, vp
);
5646 VNOP_MONITOR(vnode_t vp
, uint32_t events
, uint32_t flags
, void *handle
, vfs_context_t ctx
)
5649 struct vnop_monitor_args a
;
5651 a
.a_desc
= VDESC(vnop_monitor
);
5653 a
.a_events
= events
;
5655 a
.a_handle
= handle
;
5658 _err
= (*vp
->v_op
[vnop_monitor_desc
.vdesc_offset
])(&a
);
5659 DTRACE_FSINFO(monitor
, vnode_t
, vp
);
5665 struct vnop_setlabel_args
{
5666 struct vnodeop_desc
*a_desc
;
5669 vfs_context_t a_context
;
5673 VNOP_SETLABEL(struct vnode
*vp
, struct label
*label
, vfs_context_t ctx
)
5676 struct vnop_setlabel_args a
;
5678 a
.a_desc
= VDESC(vnop_setlabel
);
5683 _err
= (*vp
->v_op
[vnop_setlabel_desc
.vdesc_offset
])(&a
);
5684 DTRACE_FSINFO(setlabel
, vnode_t
, vp
);
5692 * Get a named streamed
5695 VNOP_GETNAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, enum nsoperation operation
, int flags
, vfs_context_t ctx
)
5698 struct vnop_getnamedstream_args a
;
5700 a
.a_desc
= &vnop_getnamedstream_desc
;
5704 a
.a_operation
= operation
;
5708 _err
= (*vp
->v_op
[vnop_getnamedstream_desc
.vdesc_offset
])(&a
);
5709 DTRACE_FSINFO(getnamedstream
, vnode_t
, vp
);
5714 * Create a named streamed
5717 VNOP_MAKENAMEDSTREAM(vnode_t vp
, vnode_t
*svpp
, const char *name
, int flags
, vfs_context_t ctx
)
5720 struct vnop_makenamedstream_args a
;
5722 a
.a_desc
= &vnop_makenamedstream_desc
;
5729 _err
= (*vp
->v_op
[vnop_makenamedstream_desc
.vdesc_offset
])(&a
);
5730 DTRACE_FSINFO(makenamedstream
, vnode_t
, vp
);
5736 * Remove a named streamed
5739 VNOP_REMOVENAMEDSTREAM(vnode_t vp
, vnode_t svp
, const char *name
, int flags
, vfs_context_t ctx
)
5742 struct vnop_removenamedstream_args a
;
5744 a
.a_desc
= &vnop_removenamedstream_desc
;
5751 _err
= (*vp
->v_op
[vnop_removenamedstream_desc
.vdesc_offset
])(&a
);
5752 DTRACE_FSINFO(removenamedstream
, vnode_t
, vp
);