2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1982, 1986, 1989, 1993
33 * The Regents of the University of California. All rights reserved.
34 * (c) UNIX System Laboratories, Inc.
35 * All or some portions of this file are derived from material licensed
36 * to the University of California by American Telephone and Telegraph
37 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
38 * the permission of UNIX System Laboratories, Inc.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * @(#)vfs_vnops.c 8.14 (Berkeley) 6/15/95
72 #include <sys/param.h>
73 #include <sys/types.h>
74 #include <sys/systm.h>
75 #include <sys/kernel.h>
76 #include <sys/file_internal.h>
78 #include <sys/proc_internal.h>
79 #include <sys/kauth.h>
80 #include <sys/mount_internal.h>
81 #include <sys/namei.h>
82 #include <sys/vnode_internal.h>
83 #include <sys/ioctl.h>
88 #include <sys/fsevents.h>
89 #include <sys/kdebug.h>
90 #include <sys/xattr.h>
91 #include <sys/ubc_internal.h>
92 #include <sys/uio_internal.h>
94 #include <vm/vm_kern.h>
95 #include <vm/vm_map.h>
97 #include <miscfs/specfs/specdev.h>
101 static int vn_closefile(struct fileglob
*fp
, struct proc
*p
);
102 static int vn_ioctl(struct fileproc
*fp
, u_long com
, caddr_t data
, struct proc
*p
);
103 static int vn_read(struct fileproc
*fp
, struct uio
*uio
,
104 kauth_cred_t cred
, int flags
, struct proc
*p
);
105 static int vn_write(struct fileproc
*fp
, struct uio
*uio
,
106 kauth_cred_t cred
, int flags
, struct proc
*p
);
107 static int vn_select( struct fileproc
*fp
, int which
, void * wql
, struct proc
*p
);
108 static int vn_kqfilt_add(struct fileproc
*fp
, struct knote
*kn
, struct proc
*p
);
110 static int vn_kqfilt_remove(struct vnode
*vp
, uintptr_t ident
, struct proc
*p
);
113 struct fileops vnops
=
114 { vn_read
, vn_write
, vn_ioctl
, vn_select
, vn_closefile
, vn_kqfilt_add
, 0 };
117 * Common code for vnode open operations.
118 * Check permissions, and call the VNOP_OPEN or VNOP_CREATE routine.
120 * XXX the profusion of interfaces here is probably a bad thing.
123 vn_open(struct nameidata
*ndp
, int fmode
, int cmode
)
125 return(vn_open_modflags(ndp
, &fmode
, cmode
));
129 vn_open_modflags(struct nameidata
*ndp
, int *fmodep
, int cmode
)
131 struct vnode_attr va
;
134 VATTR_SET(&va
, va_mode
, cmode
);
136 return(vn_open_auth(ndp
, fmodep
, &va
));
140 vn_open_auth(struct nameidata
*ndp
, int *fmodep
, struct vnode_attr
*vap
)
144 vfs_context_t ctx
= ndp
->ni_cnd
.cn_context
;
147 kauth_action_t action
;
153 if (fmode
& O_CREAT
) {
154 ndp
->ni_cnd
.cn_nameiop
= CREATE
;
155 ndp
->ni_cnd
.cn_flags
= LOCKPARENT
| LOCKLEAF
| AUDITVNPATH1
;
157 if ((fmode
& O_EXCL
) == 0)
158 ndp
->ni_cnd
.cn_flags
|= FOLLOW
;
159 if ( (error
= namei(ndp
)) )
164 /* not found, create */
166 /* must have attributes for a new file */
172 /* authorize before creating */
173 if ((error
= vnode_authorize(dvp
, NULL
, KAUTH_VNODE_ADD_FILE
, ctx
)) != 0)
176 VATTR_SET(vap
, va_type
, VREG
);
178 vap
->va_vaflags
|= VA_EXCLUSIVE
;
180 if ((error
= vn_create(dvp
, &ndp
->ni_vp
, &ndp
->ni_cnd
, vap
, 0, ctx
)) != 0)
186 int update_flags
= 0;
188 // Make sure the name & parent pointers are hooked up
189 if (vp
->v_name
== NULL
)
190 update_flags
|= VNODE_UPDATE_NAME
;
191 if (vp
->v_parent
== NULLVP
)
192 update_flags
|= VNODE_UPDATE_PARENT
;
195 vnode_update_identity(vp
, dvp
, ndp
->ni_cnd
.cn_nameptr
, ndp
->ni_cnd
.cn_namelen
, ndp
->ni_cnd
.cn_hash
, update_flags
);
197 if (need_fsevent(FSE_CREATE_FILE
, vp
)) {
198 add_fsevent(FSE_CREATE_FILE
, ctx
,
204 * nameidone has to happen before we vnode_put(dvp)
205 * and clear the ni_dvp field, since it may need
206 * to release the fs_nodelock on the dvp
215 * Check for a creation race.
217 if ((error
== EEXIST
) && !(fmode
& O_EXCL
)) {
228 if (fmode
& O_EXCL
) {
235 ndp
->ni_cnd
.cn_nameiop
= LOOKUP
;
236 ndp
->ni_cnd
.cn_flags
= FOLLOW
| LOCKLEAF
| AUDITVNPATH1
;
237 if ( (error
= namei(ndp
)) )
243 if (vp
->v_type
== VSOCK
&& vp
->v_tag
!= VT_FDESC
) {
244 error
= EOPNOTSUPP
; /* Operation not supported on socket */
249 if (UBCINFOMISSING(vp
))
250 panic("vn_open: ubc_info_init");
251 #endif /* DIAGNOSTIC */
253 /* authorize open of an existing file */
254 if ((fmode
& O_CREAT
) == 0) {
256 /* disallow write operations on directories */
257 if (vnode_isdir(vp
) && (fmode
& (FWRITE
| O_TRUNC
))) {
262 /* compute action to be authorized */
265 action
|= KAUTH_VNODE_READ_DATA
;
266 if (fmode
& (FWRITE
| O_TRUNC
))
267 action
|= KAUTH_VNODE_WRITE_DATA
;
268 if ((error
= vnode_authorize(vp
, NULL
, action
, ctx
)) != 0)
273 if ( (error
= VNOP_OPEN(vp
, fmode
, ctx
)) ) {
276 if ( (error
= vnode_ref_ext(vp
, fmode
)) )
279 /* call out to allow 3rd party notification of open.
280 * Ignore result of kauth_authorize_fileop call.
282 kauth_authorize_fileop(vfs_context_ucred(ctx
), KAUTH_FILEOP_OPEN
,
292 * Check for a race against unlink. We had a vnode
293 * but according to vnode_authorize or VNOP_OPEN it
296 if ((error
== ENOENT
) && (*fmodep
& O_CREAT
)) {
305 * Authorize an action against a vnode. This has been the canonical way to
306 * ensure that the credential/process/etc. referenced by a vfs_context
307 * is granted the rights called out in 'mode' against the vnode 'vp'.
309 * Unfortunately, the use of VREAD/VWRITE/VEXEC makes it very difficult
310 * to add support for more rights. As such, this interface will be deprecated
311 * and callers will use vnode_authorize instead.
313 #warning vn_access is deprecated
315 vn_access(vnode_t vp
, int mode
, vfs_context_t context
)
317 kauth_action_t action
;
321 action
|= KAUTH_VNODE_READ_DATA
;
323 action
|= KAUTH_VNODE_WRITE_DATA
;
325 action
|= KAUTH_VNODE_EXECUTE
;
327 return(vnode_authorize(vp
, NULL
, action
, context
));
334 vn_close(struct vnode
*vp
, int flags
, kauth_cred_t cred
, struct proc
*p
)
336 struct vfs_context context
;
340 context
.vc_ucred
= cred
;
342 if (flags
& FWASWRITTEN
) {
343 if (need_fsevent(FSE_CONTENT_MODIFIED
, vp
)) {
344 add_fsevent(FSE_CONTENT_MODIFIED
, &context
,
350 error
= VNOP_CLOSE(vp
, flags
, &context
);
351 (void)vnode_rele_ext(vp
, flags
, 0);
361 static char *swap_read_zero_page
= NULL
;
363 off_t swap_count
, this_count
;
364 off_t file_end
, read_end
;
368 * Reading from a swap file will get you all zeroes.
371 swap_count
= uio_resid(uio
);
373 file_end
= ubc_getsize(vp
);
374 read_end
= uio
->uio_offset
+ uio_resid(uio
);
375 if (uio
->uio_offset
>= file_end
) {
376 /* uio starts after end of file: nothing to read */
378 } else if (read_end
> file_end
) {
379 /* uio extends beyond end of file: stop before that */
380 swap_count
-= (read_end
- file_end
);
383 while (swap_count
> 0) {
384 if (swap_read_zero_page
== NULL
) {
389 * Take kernel funnel so that only one thread
390 * sets up "swap_read_zero_page".
392 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
394 if (swap_read_zero_page
== NULL
) {
395 MALLOC(my_zero_page
, char *, PAGE_SIZE
,
397 memset(my_zero_page
, '?', PAGE_SIZE
);
399 * Adding a newline character here
400 * and there prevents "less(1)", for
401 * example, from getting too confused
402 * about a file with one really really
405 my_zero_page
[PAGE_SIZE
-1] = '\n';
406 if (swap_read_zero_page
== NULL
) {
407 swap_read_zero_page
= my_zero_page
;
409 FREE(my_zero_page
, M_TEMP
);
413 * Someone else raced us here and won;
414 * just use their page.
417 thread_funnel_set(kernel_flock
, funnel_state
);
420 this_count
= swap_count
;
421 if (this_count
> PAGE_SIZE
) {
422 this_count
= PAGE_SIZE
;
425 prev_resid
= uio_resid(uio
);
426 error
= uiomove((caddr_t
) swap_read_zero_page
,
432 swap_count
-= (prev_resid
- uio_resid(uio
));
438 * Package up an I/O request on a vnode into a uio and do it.
453 return vn_rdwr_64(rw
,
455 (uint64_t)(uintptr_t)base
,
481 struct vfs_context context
;
483 char uio_buf
[ UIO_SIZEOF(1) ];
486 context
.vc_ucred
= cred
;
488 if (UIO_SEG_IS_USER_SPACE(segflg
)) {
489 spacetype
= proc_is64bit(p
) ? UIO_USERSPACE64
: UIO_USERSPACE32
;
492 spacetype
= UIO_SYSSPACE
;
494 auio
= uio_createwithbuffer(1, offset
, spacetype
, rw
,
495 &uio_buf
[0], sizeof(uio_buf
));
496 uio_addiov(auio
, base
, len
);
498 if (rw
== UIO_READ
) {
499 if (vp
->v_flag
& VSWAP
) {
500 error
= vn_read_swapfile(vp
, auio
);
502 error
= VNOP_READ(vp
, auio
, ioflg
, &context
);
505 error
= VNOP_WRITE(vp
, auio
, ioflg
, &context
);
509 // LP64todo - fix this
510 *aresid
= uio_resid(auio
);
512 if (uio_resid(auio
) && error
== 0)
518 * File table vnode read routine.
521 vn_read(struct fileproc
*fp
, struct uio
*uio
, kauth_cred_t cred
,
522 int flags
, struct proc
*p
)
527 struct vfs_context context
;
530 context
.vc_ucred
= cred
;
532 vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
533 if ( (error
= vnode_getwithref(vp
)) ) {
537 if (fp
->f_fglob
->fg_flag
& FNONBLOCK
)
540 if ((flags
& FOF_OFFSET
) == 0)
541 uio
->uio_offset
= fp
->f_fglob
->fg_offset
;
542 count
= uio_resid(uio
);
544 if (vp
->v_flag
& VSWAP
) {
545 /* special case for swap files */
546 error
= vn_read_swapfile(vp
, uio
);
548 error
= VNOP_READ(vp
, uio
, ioflag
, &context
);
550 if ((flags
& FOF_OFFSET
) == 0)
551 fp
->f_fglob
->fg_offset
+= count
- uio_resid(uio
);
559 * File table vnode write routine.
562 vn_write(struct fileproc
*fp
, struct uio
*uio
, kauth_cred_t cred
,
563 int flags
, struct proc
*p
)
568 struct vfs_context context
;
571 context
.vc_ucred
= cred
;
573 vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
574 if ( (error
= vnode_getwithref(vp
)) ) {
578 if (vp
->v_type
== VREG
&& (fp
->f_fglob
->fg_flag
& O_APPEND
))
580 if (fp
->f_fglob
->fg_flag
& FNONBLOCK
)
582 if ((fp
->f_fglob
->fg_flag
& O_FSYNC
) ||
583 (vp
->v_mount
&& (vp
->v_mount
->mnt_flag
& MNT_SYNCHRONOUS
)))
586 if ((flags
& FOF_OFFSET
) == 0) {
587 uio
->uio_offset
= fp
->f_fglob
->fg_offset
;
588 count
= uio_resid(uio
);
590 if (p
&& (vp
->v_type
== VREG
) &&
591 (((uio
->uio_offset
+ uio_uio_resid(uio
)) > p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
) ||
592 (uio_uio_resid(uio
) > (p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
- uio
->uio_offset
)))) {
598 error
= VNOP_WRITE(vp
, uio
, ioflag
, &context
);
600 if ((flags
& FOF_OFFSET
) == 0) {
601 if (ioflag
& IO_APPEND
)
602 fp
->f_fglob
->fg_offset
= uio
->uio_offset
;
604 fp
->f_fglob
->fg_offset
+= count
- uio_resid(uio
);
608 * Set the credentials on successful writes
610 if ((error
== 0) && (vp
->v_tag
== VT_NFS
) && (UBCINFOEXISTS(vp
))) {
612 * When called from aio subsystem, we only have the proc from
613 * which to get the credential, at this point, so use that
614 * instead. This means aio functions are incompatible with
615 * per-thread credentials (aio operations are proxied). We
616 * can't easily correct the aio vs. settid race in this case
617 * anyway, so we disallow it.
619 if ((flags
& FOF_PCRED
) == 0) {
620 ubc_setthreadcred(vp
, p
, current_thread());
630 * File table vnode stat routine.
633 vn_stat_noauth(struct vnode
*vp
, struct stat
*sb
, kauth_filesec_t
*xsec
, vfs_context_t ctx
)
635 struct vnode_attr va
;
638 kauth_filesec_t fsec
;
641 VATTR_WANTED(&va
, va_fsid
);
642 VATTR_WANTED(&va
, va_fileid
);
643 VATTR_WANTED(&va
, va_mode
);
644 VATTR_WANTED(&va
, va_type
);
645 VATTR_WANTED(&va
, va_nlink
);
646 VATTR_WANTED(&va
, va_uid
);
647 VATTR_WANTED(&va
, va_gid
);
648 VATTR_WANTED(&va
, va_rdev
);
649 VATTR_WANTED(&va
, va_data_size
);
650 VATTR_WANTED(&va
, va_access_time
);
651 VATTR_WANTED(&va
, va_modify_time
);
652 VATTR_WANTED(&va
, va_change_time
);
653 VATTR_WANTED(&va
, va_flags
);
654 VATTR_WANTED(&va
, va_gen
);
655 VATTR_WANTED(&va
, va_iosize
);
656 /* lower layers will synthesise va_total_alloc from va_data_size if required */
657 VATTR_WANTED(&va
, va_total_alloc
);
659 VATTR_WANTED(&va
, va_uuuid
);
660 VATTR_WANTED(&va
, va_guuid
);
661 VATTR_WANTED(&va
, va_acl
);
663 error
= vnode_getattr(vp
, &va
, ctx
);
667 * Copy from vattr table
669 sb
->st_dev
= va
.va_fsid
;
670 sb
->st_ino
= (ino_t
)va
.va_fileid
;
672 switch (vp
->v_type
) {
699 sb
->st_nlink
= VATTR_IS_SUPPORTED(&va
, va_nlink
) ? (u_int16_t
)va
.va_nlink
: 1;
700 sb
->st_uid
= va
.va_uid
;
701 sb
->st_gid
= va
.va_gid
;
702 sb
->st_rdev
= va
.va_rdev
;
703 sb
->st_size
= va
.va_data_size
;
704 sb
->st_atimespec
= va
.va_access_time
;
705 sb
->st_mtimespec
= va
.va_modify_time
;
706 sb
->st_ctimespec
= va
.va_change_time
;
707 sb
->st_blksize
= va
.va_iosize
;
708 sb
->st_flags
= va
.va_flags
;
709 sb
->st_blocks
= roundup(va
.va_total_alloc
, 512) / 512;
711 /* if we're interested in exended security data and we got an ACL */
713 if (!VATTR_IS_SUPPORTED(&va
, va_acl
) &&
714 !VATTR_IS_SUPPORTED(&va
, va_uuuid
) &&
715 !VATTR_IS_SUPPORTED(&va
, va_guuid
)) {
716 *xsec
= KAUTH_FILESEC_NONE
;
719 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && (va
.va_acl
!= NULL
)) {
720 fsec
= kauth_filesec_alloc(va
.va_acl
->acl_entrycount
);
722 fsec
= kauth_filesec_alloc(0);
728 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
729 if (VATTR_IS_SUPPORTED(&va
, va_uuuid
)) {
730 fsec
->fsec_owner
= va
.va_uuuid
;
732 fsec
->fsec_owner
= kauth_null_guid
;
734 if (VATTR_IS_SUPPORTED(&va
, va_guuid
)) {
735 fsec
->fsec_group
= va
.va_guuid
;
737 fsec
->fsec_group
= kauth_null_guid
;
739 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && (va
.va_acl
!= NULL
)) {
740 bcopy(va
.va_acl
, &(fsec
->fsec_acl
), KAUTH_ACL_COPYSIZE(va
.va_acl
));
742 fsec
->fsec_acl
.acl_entrycount
= KAUTH_FILESEC_NOACL
;
748 /* Do not give the generation number out to unpriviledged users */
749 if (va
.va_gen
&& !vfs_context_issuser(ctx
))
752 sb
->st_gen
= va
.va_gen
;
756 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && va
.va_acl
!= NULL
)
757 kauth_acl_free(va
.va_acl
);
762 vn_stat(struct vnode
*vp
, struct stat
*sb
, kauth_filesec_t
*xsec
, vfs_context_t ctx
)
767 if ((error
= vnode_authorize(vp
, NULL
, KAUTH_VNODE_READ_ATTRIBUTES
| KAUTH_VNODE_READ_SECURITY
, ctx
)) != 0)
771 return(vn_stat_noauth(vp
, sb
, xsec
, ctx
));
776 * File table vnode ioctl routine.
779 vn_ioctl(fp
, com
, data
, p
)
785 register struct vnode
*vp
= ((struct vnode
*)fp
->f_fglob
->fg_data
);
786 struct vfs_context context
;
792 if ( (error
= vnode_getwithref(vp
)) ) {
796 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
798 switch (vp
->v_type
) {
802 if (com
== FIONREAD
) {
803 if ((error
= vnode_size(vp
, &file_size
, &context
)) != 0)
805 *(int *)data
= file_size
- fp
->f_fglob
->fg_offset
;
808 if (com
== FIONBIO
|| com
== FIOASYNC
) { /* XXX */
821 /* Should not be able to set block size from user space */
822 if (com
== DKIOCSETBLOCKSIZE
) {
827 if (com
== FIODTYPE
) {
828 if (vp
->v_type
== VBLK
) {
829 if (major(vp
->v_rdev
) >= nblkdev
) {
833 *(int *)data
= bdevsw
[major(vp
->v_rdev
)].d_type
;
835 } else if (vp
->v_type
== VCHR
) {
836 if (major(vp
->v_rdev
) >= nchrdev
) {
840 *(int *)data
= cdevsw
[major(vp
->v_rdev
)].d_type
;
847 error
= VNOP_IOCTL(vp
, com
, data
, fp
->f_fglob
->fg_flag
, &context
);
849 if (error
== 0 && com
== TIOCSCTTY
) {
852 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
853 ttyvp
= p
->p_session
->s_ttyvp
;
854 p
->p_session
->s_ttyvp
= vp
;
855 thread_funnel_set(kernel_flock
, funnel_state
);
867 * File table vnode select routine.
870 vn_select(fp
, which
, wql
, p
)
877 struct vnode
* vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
878 struct vfs_context context
;
880 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
882 context
.vc_ucred
= fp
->f_fglob
->fg_cred
;
884 error
= VNOP_SELECT(vp
, which
, fp
->f_fglob
->fg_flag
, wql
, &context
);
893 * Check that the vnode is still valid, and if so
894 * acquire requested lock.
897 vn_lock(__unused vnode_t vp
, __unused
int flags
, __unused proc_t p
)
903 * File table vnode close routine.
910 struct vnode
*vp
= (struct vnode
*)fg
->fg_data
;
913 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
914 error
= vn_close(vp
, fg
->fg_flag
, fg
->fg_cred
, p
);
922 vn_pathconf(vnode_t vp
, int name
, register_t
*retval
, vfs_context_t ctx
)
927 case _PC_EXTENDED_SECURITY_NP
:
928 *retval
= vfs_extendedsecurity(vnode_mount(vp
));
930 case _PC_AUTH_OPAQUE_NP
:
931 *retval
= vfs_authopaque(vnode_mount(vp
));
934 error
= VNOP_PATHCONF(vp
, name
, retval
, ctx
);
942 vn_kqfilt_add(fp
, kn
, p
)
947 struct vnode
*vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
948 struct vfs_context context
;
952 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
954 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
956 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
957 error
= VNOP_KQFILT_ADD(vp
, kn
, &context
);
958 thread_funnel_set(kernel_flock
, funnel_state
);
966 /* No one calls this yet. */
968 vn_kqfilt_remove(vp
, ident
, p
)
973 struct vfs_context context
;
977 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
979 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
981 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
982 error
= VNOP_KQFILT_REMOVE(vp
, ident
, &context
);
983 thread_funnel_set(kernel_flock
, funnel_state
);