2 * Copyright (c) 2000-2004 Apple Computer, 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) 1982, 1986, 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
66 * @(#)vfs_vnops.c 8.14 (Berkeley) 6/15/95
70 #include <sys/param.h>
71 #include <sys/types.h>
72 #include <sys/systm.h>
73 #include <sys/kernel.h>
74 #include <sys/file_internal.h>
76 #include <sys/proc_internal.h>
77 #include <sys/kauth.h>
78 #include <sys/mount_internal.h>
79 #include <sys/namei.h>
80 #include <sys/vnode_internal.h>
81 #include <sys/ioctl.h>
86 #include <sys/fsevents.h>
87 #include <sys/kdebug.h>
88 #include <sys/xattr.h>
89 #include <sys/ubc_internal.h>
90 #include <sys/uio_internal.h>
92 #include <vm/vm_kern.h>
93 #include <vm/vm_map.h>
95 #include <miscfs/specfs/specdev.h>
99 static int vn_closefile(struct fileglob
*fp
, struct proc
*p
);
100 static int vn_ioctl(struct fileproc
*fp
, u_long com
, caddr_t data
, struct proc
*p
);
101 static int vn_read(struct fileproc
*fp
, struct uio
*uio
,
102 kauth_cred_t cred
, int flags
, struct proc
*p
);
103 static int vn_write(struct fileproc
*fp
, struct uio
*uio
,
104 kauth_cred_t cred
, int flags
, struct proc
*p
);
105 static int vn_select( struct fileproc
*fp
, int which
, void * wql
, struct proc
*p
);
106 static int vn_kqfilt_add(struct fileproc
*fp
, struct knote
*kn
, struct proc
*p
);
108 static int vn_kqfilt_remove(struct vnode
*vp
, uintptr_t ident
, struct proc
*p
);
111 struct fileops vnops
=
112 { vn_read
, vn_write
, vn_ioctl
, vn_select
, vn_closefile
, vn_kqfilt_add
, 0 };
115 * Common code for vnode open operations.
116 * Check permissions, and call the VNOP_OPEN or VNOP_CREATE routine.
118 * XXX the profusion of interfaces here is probably a bad thing.
121 vn_open(struct nameidata
*ndp
, int fmode
, int cmode
)
123 return(vn_open_modflags(ndp
, &fmode
, cmode
));
127 vn_open_modflags(struct nameidata
*ndp
, int *fmodep
, int cmode
)
129 struct vnode_attr va
;
132 VATTR_SET(&va
, va_mode
, cmode
);
134 return(vn_open_auth(ndp
, fmodep
, &va
));
138 vn_open_auth(struct nameidata
*ndp
, int *fmodep
, struct vnode_attr
*vap
)
142 vfs_context_t ctx
= ndp
->ni_cnd
.cn_context
;
145 kauth_action_t action
;
151 if (fmode
& O_CREAT
) {
152 ndp
->ni_cnd
.cn_nameiop
= CREATE
;
153 ndp
->ni_cnd
.cn_flags
= LOCKPARENT
| LOCKLEAF
| AUDITVNPATH1
;
155 if ((fmode
& O_EXCL
) == 0)
156 ndp
->ni_cnd
.cn_flags
|= FOLLOW
;
157 if ( (error
= namei(ndp
)) )
162 /* not found, create */
164 /* must have attributes for a new file */
170 /* authorize before creating */
171 if ((error
= vnode_authorize(dvp
, NULL
, KAUTH_VNODE_ADD_FILE
, ctx
)) != 0)
174 VATTR_SET(vap
, va_type
, VREG
);
176 vap
->va_vaflags
|= VA_EXCLUSIVE
;
178 if ((error
= vn_create(dvp
, &ndp
->ni_vp
, &ndp
->ni_cnd
, vap
, 0, ctx
)) != 0)
184 int update_flags
= 0;
186 // Make sure the name & parent pointers are hooked up
187 if (vp
->v_name
== NULL
)
188 update_flags
|= VNODE_UPDATE_NAME
;
189 if (vp
->v_parent
== NULLVP
)
190 update_flags
|= VNODE_UPDATE_PARENT
;
193 vnode_update_identity(vp
, dvp
, ndp
->ni_cnd
.cn_nameptr
, ndp
->ni_cnd
.cn_namelen
, ndp
->ni_cnd
.cn_hash
, update_flags
);
195 if (need_fsevent(FSE_CREATE_FILE
, vp
)) {
196 add_fsevent(FSE_CREATE_FILE
, ctx
,
202 * nameidone has to happen before we vnode_put(dvp)
203 * and clear the ni_dvp field, since it may need
204 * to release the fs_nodelock on the dvp
213 * Check for a creation race.
215 if ((error
== EEXIST
) && !(fmode
& O_EXCL
)) {
226 if (fmode
& O_EXCL
) {
233 ndp
->ni_cnd
.cn_nameiop
= LOOKUP
;
234 ndp
->ni_cnd
.cn_flags
= FOLLOW
| LOCKLEAF
| AUDITVNPATH1
;
235 if ( (error
= namei(ndp
)) )
241 if (vp
->v_type
== VSOCK
&& vp
->v_tag
!= VT_FDESC
) {
242 error
= EOPNOTSUPP
; /* Operation not supported on socket */
247 if (UBCINFOMISSING(vp
))
248 panic("vn_open: ubc_info_init");
249 #endif /* DIAGNOSTIC */
251 /* authorize open of an existing file */
252 if ((fmode
& O_CREAT
) == 0) {
254 /* disallow write operations on directories */
255 if (vnode_isdir(vp
) && (fmode
& (FWRITE
| O_TRUNC
))) {
260 /* compute action to be authorized */
263 action
|= KAUTH_VNODE_READ_DATA
;
264 if (fmode
& (FWRITE
| O_TRUNC
))
265 action
|= KAUTH_VNODE_WRITE_DATA
;
266 if ((error
= vnode_authorize(vp
, NULL
, action
, ctx
)) != 0)
271 if ( (error
= VNOP_OPEN(vp
, fmode
, ctx
)) ) {
274 if ( (error
= vnode_ref_ext(vp
, fmode
)) )
277 /* call out to allow 3rd party notification of open.
278 * Ignore result of kauth_authorize_fileop call.
280 kauth_authorize_fileop(vfs_context_ucred(ctx
), KAUTH_FILEOP_OPEN
,
290 * Check for a race against unlink. We had a vnode
291 * but according to vnode_authorize or VNOP_OPEN it
294 if ((error
== ENOENT
) && (*fmodep
& O_CREAT
)) {
303 * Authorize an action against a vnode. This has been the canonical way to
304 * ensure that the credential/process/etc. referenced by a vfs_context
305 * is granted the rights called out in 'mode' against the vnode 'vp'.
307 * Unfortunately, the use of VREAD/VWRITE/VEXEC makes it very difficult
308 * to add support for more rights. As such, this interface will be deprecated
309 * and callers will use vnode_authorize instead.
311 #warning vn_access is deprecated
313 vn_access(vnode_t vp
, int mode
, vfs_context_t context
)
315 kauth_action_t action
;
319 action
|= KAUTH_VNODE_READ_DATA
;
321 action
|= KAUTH_VNODE_WRITE_DATA
;
323 action
|= KAUTH_VNODE_EXECUTE
;
325 return(vnode_authorize(vp
, NULL
, action
, context
));
332 vn_close(struct vnode
*vp
, int flags
, kauth_cred_t cred
, struct proc
*p
)
334 struct vfs_context context
;
338 context
.vc_ucred
= cred
;
340 if (flags
& FWASWRITTEN
) {
341 if (need_fsevent(FSE_CONTENT_MODIFIED
, vp
)) {
342 add_fsevent(FSE_CONTENT_MODIFIED
, &context
,
348 error
= VNOP_CLOSE(vp
, flags
, &context
);
349 (void)vnode_rele_ext(vp
, flags
, 0);
359 static char *swap_read_zero_page
= NULL
;
361 off_t swap_count
, this_count
;
362 off_t file_end
, read_end
;
366 * Reading from a swap file will get you all zeroes.
369 swap_count
= uio_resid(uio
);
371 file_end
= ubc_getsize(vp
);
372 read_end
= uio
->uio_offset
+ uio_resid(uio
);
373 if (uio
->uio_offset
>= file_end
) {
374 /* uio starts after end of file: nothing to read */
376 } else if (read_end
> file_end
) {
377 /* uio extends beyond end of file: stop before that */
378 swap_count
-= (read_end
- file_end
);
381 while (swap_count
> 0) {
382 if (swap_read_zero_page
== NULL
) {
387 * Take kernel funnel so that only one thread
388 * sets up "swap_read_zero_page".
390 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
392 if (swap_read_zero_page
== NULL
) {
393 MALLOC(my_zero_page
, char *, PAGE_SIZE
,
395 memset(my_zero_page
, '?', PAGE_SIZE
);
397 * Adding a newline character here
398 * and there prevents "less(1)", for
399 * example, from getting too confused
400 * about a file with one really really
403 my_zero_page
[PAGE_SIZE
-1] = '\n';
404 if (swap_read_zero_page
== NULL
) {
405 swap_read_zero_page
= my_zero_page
;
407 FREE(my_zero_page
, M_TEMP
);
411 * Someone else raced us here and won;
412 * just use their page.
415 thread_funnel_set(kernel_flock
, funnel_state
);
418 this_count
= swap_count
;
419 if (this_count
> PAGE_SIZE
) {
420 this_count
= PAGE_SIZE
;
423 prev_resid
= uio_resid(uio
);
424 error
= uiomove((caddr_t
) swap_read_zero_page
,
430 swap_count
-= (prev_resid
- uio_resid(uio
));
436 * Package up an I/O request on a vnode into a uio and do it.
451 return vn_rdwr_64(rw
,
453 (uint64_t)(uintptr_t)base
,
479 struct vfs_context context
;
481 char uio_buf
[ UIO_SIZEOF(1) ];
484 context
.vc_ucred
= cred
;
486 if (UIO_SEG_IS_USER_SPACE(segflg
)) {
487 spacetype
= proc_is64bit(p
) ? UIO_USERSPACE64
: UIO_USERSPACE32
;
490 spacetype
= UIO_SYSSPACE
;
492 auio
= uio_createwithbuffer(1, offset
, spacetype
, rw
,
493 &uio_buf
[0], sizeof(uio_buf
));
494 uio_addiov(auio
, base
, len
);
496 if (rw
== UIO_READ
) {
497 if (vp
->v_flag
& VSWAP
) {
498 error
= vn_read_swapfile(vp
, auio
);
500 error
= VNOP_READ(vp
, auio
, ioflg
, &context
);
503 error
= VNOP_WRITE(vp
, auio
, ioflg
, &context
);
507 // LP64todo - fix this
508 *aresid
= uio_resid(auio
);
510 if (uio_resid(auio
) && error
== 0)
516 * File table vnode read routine.
519 vn_read(struct fileproc
*fp
, struct uio
*uio
, kauth_cred_t cred
,
520 int flags
, struct proc
*p
)
525 struct vfs_context context
;
528 context
.vc_ucred
= cred
;
530 vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
531 if ( (error
= vnode_getwithref(vp
)) ) {
535 if (fp
->f_fglob
->fg_flag
& FNONBLOCK
)
538 if ((flags
& FOF_OFFSET
) == 0)
539 uio
->uio_offset
= fp
->f_fglob
->fg_offset
;
540 count
= uio_resid(uio
);
542 if (vp
->v_flag
& VSWAP
) {
543 /* special case for swap files */
544 error
= vn_read_swapfile(vp
, uio
);
546 error
= VNOP_READ(vp
, uio
, ioflag
, &context
);
548 if ((flags
& FOF_OFFSET
) == 0)
549 fp
->f_fglob
->fg_offset
+= count
- uio_resid(uio
);
557 * File table vnode write routine.
560 vn_write(struct fileproc
*fp
, struct uio
*uio
, kauth_cred_t cred
,
561 int flags
, struct proc
*p
)
566 struct vfs_context context
;
569 context
.vc_ucred
= cred
;
571 vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
572 if ( (error
= vnode_getwithref(vp
)) ) {
576 if (vp
->v_type
== VREG
&& (fp
->f_fglob
->fg_flag
& O_APPEND
))
578 if (fp
->f_fglob
->fg_flag
& FNONBLOCK
)
580 if ((fp
->f_fglob
->fg_flag
& O_FSYNC
) ||
581 (vp
->v_mount
&& (vp
->v_mount
->mnt_flag
& MNT_SYNCHRONOUS
)))
584 if ((flags
& FOF_OFFSET
) == 0) {
585 uio
->uio_offset
= fp
->f_fglob
->fg_offset
;
586 count
= uio_resid(uio
);
588 if (p
&& (vp
->v_type
== VREG
) &&
589 (((uio
->uio_offset
+ uio_uio_resid(uio
)) > p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
) ||
590 (uio_uio_resid(uio
) > (p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
- uio
->uio_offset
)))) {
596 error
= VNOP_WRITE(vp
, uio
, ioflag
, &context
);
598 if ((flags
& FOF_OFFSET
) == 0) {
599 if (ioflag
& IO_APPEND
)
600 fp
->f_fglob
->fg_offset
= uio
->uio_offset
;
602 fp
->f_fglob
->fg_offset
+= count
- uio_resid(uio
);
606 * Set the credentials on successful writes
608 if ((error
== 0) && (vp
->v_tag
== VT_NFS
) && (UBCINFOEXISTS(vp
))) {
610 * When called from aio subsystem, we only have the proc from
611 * which to get the credential, at this point, so use that
612 * instead. This means aio functions are incompatible with
613 * per-thread credentials (aio operations are proxied). We
614 * can't easily correct the aio vs. settid race in this case
615 * anyway, so we disallow it.
617 if ((flags
& FOF_PCRED
) == 0) {
618 ubc_setthreadcred(vp
, p
, current_thread());
628 * File table vnode stat routine.
631 vn_stat_noauth(struct vnode
*vp
, struct stat
*sb
, kauth_filesec_t
*xsec
, vfs_context_t ctx
)
633 struct vnode_attr va
;
636 kauth_filesec_t fsec
;
639 VATTR_WANTED(&va
, va_fsid
);
640 VATTR_WANTED(&va
, va_fileid
);
641 VATTR_WANTED(&va
, va_mode
);
642 VATTR_WANTED(&va
, va_type
);
643 VATTR_WANTED(&va
, va_nlink
);
644 VATTR_WANTED(&va
, va_uid
);
645 VATTR_WANTED(&va
, va_gid
);
646 VATTR_WANTED(&va
, va_rdev
);
647 VATTR_WANTED(&va
, va_data_size
);
648 VATTR_WANTED(&va
, va_access_time
);
649 VATTR_WANTED(&va
, va_modify_time
);
650 VATTR_WANTED(&va
, va_change_time
);
651 VATTR_WANTED(&va
, va_flags
);
652 VATTR_WANTED(&va
, va_gen
);
653 VATTR_WANTED(&va
, va_iosize
);
654 /* lower layers will synthesise va_total_alloc from va_data_size if required */
655 VATTR_WANTED(&va
, va_total_alloc
);
657 VATTR_WANTED(&va
, va_uuuid
);
658 VATTR_WANTED(&va
, va_guuid
);
659 VATTR_WANTED(&va
, va_acl
);
661 error
= vnode_getattr(vp
, &va
, ctx
);
665 * Copy from vattr table
667 sb
->st_dev
= va
.va_fsid
;
668 sb
->st_ino
= (ino_t
)va
.va_fileid
;
670 switch (vp
->v_type
) {
697 sb
->st_nlink
= VATTR_IS_SUPPORTED(&va
, va_nlink
) ? (u_int16_t
)va
.va_nlink
: 1;
698 sb
->st_uid
= va
.va_uid
;
699 sb
->st_gid
= va
.va_gid
;
700 sb
->st_rdev
= va
.va_rdev
;
701 sb
->st_size
= va
.va_data_size
;
702 sb
->st_atimespec
= va
.va_access_time
;
703 sb
->st_mtimespec
= va
.va_modify_time
;
704 sb
->st_ctimespec
= va
.va_change_time
;
705 sb
->st_blksize
= va
.va_iosize
;
706 sb
->st_flags
= va
.va_flags
;
707 sb
->st_blocks
= roundup(va
.va_total_alloc
, 512) / 512;
709 /* if we're interested in exended security data and we got an ACL */
711 if (!VATTR_IS_SUPPORTED(&va
, va_acl
) &&
712 !VATTR_IS_SUPPORTED(&va
, va_uuuid
) &&
713 !VATTR_IS_SUPPORTED(&va
, va_guuid
)) {
714 *xsec
= KAUTH_FILESEC_NONE
;
717 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && (va
.va_acl
!= NULL
)) {
718 fsec
= kauth_filesec_alloc(va
.va_acl
->acl_entrycount
);
720 fsec
= kauth_filesec_alloc(0);
726 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
727 if (VATTR_IS_SUPPORTED(&va
, va_uuuid
)) {
728 fsec
->fsec_owner
= va
.va_uuuid
;
730 fsec
->fsec_owner
= kauth_null_guid
;
732 if (VATTR_IS_SUPPORTED(&va
, va_guuid
)) {
733 fsec
->fsec_group
= va
.va_guuid
;
735 fsec
->fsec_group
= kauth_null_guid
;
737 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && (va
.va_acl
!= NULL
)) {
738 bcopy(va
.va_acl
, &(fsec
->fsec_acl
), KAUTH_ACL_COPYSIZE(va
.va_acl
));
740 fsec
->fsec_acl
.acl_entrycount
= KAUTH_FILESEC_NOACL
;
746 /* Do not give the generation number out to unpriviledged users */
747 if (va
.va_gen
&& !vfs_context_issuser(ctx
))
750 sb
->st_gen
= va
.va_gen
;
754 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && va
.va_acl
!= NULL
)
755 kauth_acl_free(va
.va_acl
);
760 vn_stat(struct vnode
*vp
, struct stat
*sb
, kauth_filesec_t
*xsec
, vfs_context_t ctx
)
765 if ((error
= vnode_authorize(vp
, NULL
, KAUTH_VNODE_READ_ATTRIBUTES
| KAUTH_VNODE_READ_SECURITY
, ctx
)) != 0)
769 return(vn_stat_noauth(vp
, sb
, xsec
, ctx
));
774 * File table vnode ioctl routine.
777 vn_ioctl(fp
, com
, data
, p
)
783 register struct vnode
*vp
= ((struct vnode
*)fp
->f_fglob
->fg_data
);
784 struct vfs_context context
;
790 if ( (error
= vnode_getwithref(vp
)) ) {
794 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
796 switch (vp
->v_type
) {
800 if (com
== FIONREAD
) {
801 if ((error
= vnode_size(vp
, &file_size
, &context
)) != 0)
803 *(int *)data
= file_size
- fp
->f_fglob
->fg_offset
;
806 if (com
== FIONBIO
|| com
== FIOASYNC
) { /* XXX */
819 /* Should not be able to set block size from user space */
820 if (com
== DKIOCSETBLOCKSIZE
) {
825 if (com
== FIODTYPE
) {
826 if (vp
->v_type
== VBLK
) {
827 if (major(vp
->v_rdev
) >= nblkdev
) {
831 *(int *)data
= bdevsw
[major(vp
->v_rdev
)].d_type
;
833 } else if (vp
->v_type
== VCHR
) {
834 if (major(vp
->v_rdev
) >= nchrdev
) {
838 *(int *)data
= cdevsw
[major(vp
->v_rdev
)].d_type
;
845 error
= VNOP_IOCTL(vp
, com
, data
, fp
->f_fglob
->fg_flag
, &context
);
847 if (error
== 0 && com
== TIOCSCTTY
) {
850 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
851 ttyvp
= p
->p_session
->s_ttyvp
;
852 p
->p_session
->s_ttyvp
= vp
;
853 thread_funnel_set(kernel_flock
, funnel_state
);
865 * File table vnode select routine.
868 vn_select(fp
, which
, wql
, p
)
875 struct vnode
* vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
876 struct vfs_context context
;
878 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
880 context
.vc_ucred
= fp
->f_fglob
->fg_cred
;
882 error
= VNOP_SELECT(vp
, which
, fp
->f_fglob
->fg_flag
, wql
, &context
);
891 * Check that the vnode is still valid, and if so
892 * acquire requested lock.
895 vn_lock(__unused vnode_t vp
, __unused
int flags
, __unused proc_t p
)
901 * File table vnode close routine.
908 struct vnode
*vp
= (struct vnode
*)fg
->fg_data
;
911 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
912 error
= vn_close(vp
, fg
->fg_flag
, fg
->fg_cred
, p
);
920 vn_pathconf(vnode_t vp
, int name
, register_t
*retval
, vfs_context_t ctx
)
925 case _PC_EXTENDED_SECURITY_NP
:
926 *retval
= vfs_extendedsecurity(vnode_mount(vp
));
928 case _PC_AUTH_OPAQUE_NP
:
929 *retval
= vfs_authopaque(vnode_mount(vp
));
932 error
= VNOP_PATHCONF(vp
, name
, retval
, ctx
);
940 vn_kqfilt_add(fp
, kn
, p
)
945 struct vnode
*vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
946 struct vfs_context context
;
950 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
952 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
954 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
955 error
= VNOP_KQFILT_ADD(vp
, kn
, &context
);
956 thread_funnel_set(kernel_flock
, funnel_state
);
964 /* No one calls this yet. */
966 vn_kqfilt_remove(vp
, ident
, p
)
971 struct vfs_context context
;
975 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
977 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
979 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
980 error
= VNOP_KQFILT_REMOVE(vp
, ident
, &context
);
981 thread_funnel_set(kernel_flock
, funnel_state
);