2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)vfs_vnops.c 8.14 (Berkeley) 6/15/95
64 #include <sys/param.h>
65 #include <sys/types.h>
66 #include <sys/systm.h>
67 #include <sys/kernel.h>
68 #include <sys/file_internal.h>
70 #include <sys/proc_internal.h>
71 #include <sys/kauth.h>
72 #include <sys/mount_internal.h>
73 #include <sys/namei.h>
74 #include <sys/vnode_internal.h>
75 #include <sys/ioctl.h>
80 #include <sys/fsevents.h>
81 #include <sys/kdebug.h>
82 #include <sys/xattr.h>
83 #include <sys/ubc_internal.h>
84 #include <sys/uio_internal.h>
85 #include <sys/resourcevar.h>
87 #include <vm/vm_kern.h>
88 #include <vm/vm_map.h>
90 #include <miscfs/specfs/specdev.h>
94 static int vn_closefile(struct fileglob
*fp
, struct proc
*p
);
95 static int vn_ioctl(struct fileproc
*fp
, u_long com
, caddr_t data
, struct proc
*p
);
96 static int vn_read(struct fileproc
*fp
, struct uio
*uio
,
97 kauth_cred_t cred
, int flags
, struct proc
*p
);
98 static int vn_write(struct fileproc
*fp
, struct uio
*uio
,
99 kauth_cred_t cred
, int flags
, struct proc
*p
);
100 static int vn_select( struct fileproc
*fp
, int which
, void * wql
, struct proc
*p
);
101 static int vn_kqfilt_add(struct fileproc
*fp
, struct knote
*kn
, struct proc
*p
);
103 static int vn_kqfilt_remove(struct vnode
*vp
, uintptr_t ident
, struct proc
*p
);
106 struct fileops vnops
=
107 { vn_read
, vn_write
, vn_ioctl
, vn_select
, vn_closefile
, vn_kqfilt_add
, 0 };
110 * Common code for vnode open operations.
111 * Check permissions, and call the VNOP_OPEN or VNOP_CREATE routine.
113 * XXX the profusion of interfaces here is probably a bad thing.
116 vn_open(struct nameidata
*ndp
, int fmode
, int cmode
)
118 return(vn_open_modflags(ndp
, &fmode
, cmode
));
122 vn_open_modflags(struct nameidata
*ndp
, int *fmodep
, int cmode
)
124 struct vnode_attr va
;
127 VATTR_SET(&va
, va_mode
, cmode
);
129 return(vn_open_auth(ndp
, fmodep
, &va
));
133 * Open a file with authorization, updating the contents of the structures
134 * pointed to by ndp, fmodep, and vap as necessary to perform the requested
135 * operation. This function is used for both opens of existing files, and
136 * creation of new files.
138 * Parameters: ndp The nami data pointer describing the
140 * fmodep A pointer to an int containg the mode
141 * information to be used for the open
142 * vap A pointer to the vnode attribute
143 * descriptor to be used for the open
145 * Indirect: * Contents of the data structures pointed
146 * to by the parameters are modified as
147 * necessary to the requested operation.
152 * Notes: The kauth_filesec_t in 'vap', if any, is in host byte order.
154 * The contents of '*ndp' will be modified, based on the other
155 * arguments to this function, and to return file and directory
156 * data necessary to satisfy the requested operation.
158 * If the file does not exist and we are creating it, then the
159 * O_TRUNC flag will be cleared in '*fmodep' to indicate to the
160 * caller that the file was not truncated.
162 * If the file exists and the O_EXCL flag was not specified, then
163 * the O_CREAT flag will be cleared in '*fmodep' to indicate to
164 * the caller that the existing file was merely opened rather
167 * The contents of '*vap' will be modified as necessary to
168 * complete the operation, including setting of supported
169 * attribute, clearing of fields containing unsupported attributes
170 * in the request, if the request proceeds without them, etc..
172 * XXX: This function is too complicated in actings on its arguments
174 * XXX: We should enummerate the possible errno values here, and where
175 * in the code they originated.
178 vn_open_auth(struct nameidata
*ndp
, int *fmodep
, struct vnode_attr
*vap
)
182 vfs_context_t ctx
= ndp
->ni_cnd
.cn_context
;
185 kauth_action_t action
;
191 if (fmode
& O_CREAT
) {
192 if ( (fmode
& O_DIRECTORY
) ) {
196 ndp
->ni_cnd
.cn_nameiop
= CREATE
;
197 ndp
->ni_cnd
.cn_flags
= LOCKPARENT
| LOCKLEAF
| AUDITVNPATH1
;
199 if ((fmode
& O_EXCL
) == 0)
200 ndp
->ni_cnd
.cn_flags
|= FOLLOW
;
201 if ( (error
= namei(ndp
)) )
206 /* not found, create */
208 /* must have attributes for a new file */
214 /* authorize before creating */
215 if ((error
= vnode_authorize(dvp
, NULL
, KAUTH_VNODE_ADD_FILE
, ctx
)) != 0)
218 VATTR_SET(vap
, va_type
, VREG
);
220 vap
->va_vaflags
|= VA_EXCLUSIVE
;
222 if ((error
= vn_create(dvp
, &ndp
->ni_vp
, &ndp
->ni_cnd
, vap
, 0, ctx
)) != 0)
228 int update_flags
= 0;
230 // Make sure the name & parent pointers are hooked up
231 if (vp
->v_name
== NULL
)
232 update_flags
|= VNODE_UPDATE_NAME
;
233 if (vp
->v_parent
== NULLVP
)
234 update_flags
|= VNODE_UPDATE_PARENT
;
237 vnode_update_identity(vp
, dvp
, ndp
->ni_cnd
.cn_nameptr
, ndp
->ni_cnd
.cn_namelen
, ndp
->ni_cnd
.cn_hash
, update_flags
);
239 if (need_fsevent(FSE_CREATE_FILE
, vp
)) {
240 add_fsevent(FSE_CREATE_FILE
, ctx
,
246 * nameidone has to happen before we vnode_put(dvp)
247 * and clear the ni_dvp field, since it may need
248 * to release the fs_nodelock on the dvp
257 * Check for a creation race.
259 if ((error
== EEXIST
) && !(fmode
& O_EXCL
)) {
270 if (fmode
& O_EXCL
) {
277 ndp
->ni_cnd
.cn_nameiop
= LOOKUP
;
278 ndp
->ni_cnd
.cn_flags
= FOLLOW
| LOCKLEAF
| AUDITVNPATH1
;
279 if ( (error
= namei(ndp
)) )
285 if ( (fmode
& O_DIRECTORY
) && vp
->v_type
!= VDIR
) {
290 if (vp
->v_type
== VSOCK
&& vp
->v_tag
!= VT_FDESC
) {
291 error
= EOPNOTSUPP
; /* Operation not supported on socket */
296 if (UBCINFOMISSING(vp
))
297 panic("vn_open: ubc_info_init");
298 #endif /* DIAGNOSTIC */
300 /* authorize open of an existing file */
301 if ((fmode
& O_CREAT
) == 0) {
303 /* disallow write operations on directories */
304 if (vnode_isdir(vp
) && (fmode
& (FWRITE
| O_TRUNC
))) {
309 /* compute action to be authorized */
312 action
|= KAUTH_VNODE_READ_DATA
;
313 if (fmode
& (FWRITE
| O_TRUNC
))
314 action
|= KAUTH_VNODE_WRITE_DATA
;
315 if ((error
= vnode_authorize(vp
, NULL
, action
, ctx
)) != 0)
320 if ( (error
= VNOP_OPEN(vp
, fmode
, ctx
)) ) {
323 if ( (error
= vnode_ref_ext(vp
, fmode
)) )
326 /* call out to allow 3rd party notification of open.
327 * Ignore result of kauth_authorize_fileop call.
329 kauth_authorize_fileop(vfs_context_ucred(ctx
), KAUTH_FILEOP_OPEN
,
339 * Check for a race against unlink. We had a vnode
340 * but according to vnode_authorize or VNOP_OPEN it
343 if ((error
== ENOENT
) && (*fmodep
& O_CREAT
)) {
352 * Authorize an action against a vnode. This has been the canonical way to
353 * ensure that the credential/process/etc. referenced by a vfs_context
354 * is granted the rights called out in 'mode' against the vnode 'vp'.
356 * Unfortunately, the use of VREAD/VWRITE/VEXEC makes it very difficult
357 * to add support for more rights. As such, this interface will be deprecated
358 * and callers will use vnode_authorize instead.
360 #warning vn_access is deprecated
362 vn_access(vnode_t vp
, int mode
, vfs_context_t context
)
364 kauth_action_t action
;
368 action
|= KAUTH_VNODE_READ_DATA
;
370 action
|= KAUTH_VNODE_WRITE_DATA
;
372 action
|= KAUTH_VNODE_EXECUTE
;
374 return(vnode_authorize(vp
, NULL
, action
, context
));
381 vn_close(struct vnode
*vp
, int flags
, kauth_cred_t cred
, struct proc
*p
)
383 struct vfs_context context
;
387 context
.vc_ucred
= cred
;
389 if (flags
& FWASWRITTEN
) {
390 if (need_fsevent(FSE_CONTENT_MODIFIED
, vp
)) {
391 add_fsevent(FSE_CONTENT_MODIFIED
, &context
,
397 error
= VNOP_CLOSE(vp
, flags
, &context
);
398 (void)vnode_rele_ext(vp
, flags
, 0);
408 static char *swap_read_zero_page
= NULL
;
410 off_t swap_count
, this_count
;
411 off_t file_end
, read_end
;
415 * Reading from a swap file will get you all zeroes.
418 swap_count
= uio_resid(uio
);
420 file_end
= ubc_getsize(vp
);
421 read_end
= uio
->uio_offset
+ uio_resid(uio
);
422 if (uio
->uio_offset
>= file_end
) {
423 /* uio starts after end of file: nothing to read */
425 } else if (read_end
> file_end
) {
426 /* uio extends beyond end of file: stop before that */
427 swap_count
-= (read_end
- file_end
);
430 while (swap_count
> 0) {
431 if (swap_read_zero_page
== NULL
) {
436 * Take kernel funnel so that only one thread
437 * sets up "swap_read_zero_page".
439 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
441 if (swap_read_zero_page
== NULL
) {
442 MALLOC(my_zero_page
, char *, PAGE_SIZE
,
444 memset(my_zero_page
, '?', PAGE_SIZE
);
446 * Adding a newline character here
447 * and there prevents "less(1)", for
448 * example, from getting too confused
449 * about a file with one really really
452 my_zero_page
[PAGE_SIZE
-1] = '\n';
453 if (swap_read_zero_page
== NULL
) {
454 swap_read_zero_page
= my_zero_page
;
456 FREE(my_zero_page
, M_TEMP
);
460 * Someone else raced us here and won;
461 * just use their page.
464 thread_funnel_set(kernel_flock
, funnel_state
);
467 this_count
= swap_count
;
468 if (this_count
> PAGE_SIZE
) {
469 this_count
= PAGE_SIZE
;
472 prev_resid
= uio_resid(uio
);
473 error
= uiomove((caddr_t
) swap_read_zero_page
,
479 swap_count
-= (prev_resid
- uio_resid(uio
));
485 * Package up an I/O request on a vnode into a uio and do it.
500 return vn_rdwr_64(rw
,
502 (uint64_t)(uintptr_t)base
,
528 struct vfs_context context
;
530 char uio_buf
[ UIO_SIZEOF(1) ];
533 context
.vc_ucred
= cred
;
535 if (UIO_SEG_IS_USER_SPACE(segflg
)) {
536 spacetype
= proc_is64bit(p
) ? UIO_USERSPACE64
: UIO_USERSPACE32
;
539 spacetype
= UIO_SYSSPACE
;
541 auio
= uio_createwithbuffer(1, offset
, spacetype
, rw
,
542 &uio_buf
[0], sizeof(uio_buf
));
543 uio_addiov(auio
, base
, len
);
545 if (rw
== UIO_READ
) {
546 if (vp
->v_flag
& VSWAP
) {
547 error
= vn_read_swapfile(vp
, auio
);
549 error
= VNOP_READ(vp
, auio
, ioflg
, &context
);
552 error
= VNOP_WRITE(vp
, auio
, ioflg
, &context
);
556 // LP64todo - fix this
557 *aresid
= uio_resid(auio
);
559 if (uio_resid(auio
) && error
== 0)
565 * File table vnode read routine.
568 vn_read(struct fileproc
*fp
, struct uio
*uio
, kauth_cred_t cred
,
569 int flags
, struct proc
*p
)
574 struct vfs_context context
;
577 context
.vc_ucred
= cred
;
579 vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
580 if ( (error
= vnode_getwithref(vp
)) ) {
584 if (fp
->f_fglob
->fg_flag
& FNONBLOCK
)
587 if ((flags
& FOF_OFFSET
) == 0)
588 uio
->uio_offset
= fp
->f_fglob
->fg_offset
;
589 count
= uio_resid(uio
);
591 if (vp
->v_flag
& VSWAP
) {
592 /* special case for swap files */
593 error
= vn_read_swapfile(vp
, uio
);
595 error
= VNOP_READ(vp
, uio
, ioflag
, &context
);
597 if ((flags
& FOF_OFFSET
) == 0)
598 fp
->f_fglob
->fg_offset
+= count
- uio_resid(uio
);
606 * File table vnode write routine.
609 vn_write(struct fileproc
*fp
, struct uio
*uio
, kauth_cred_t cred
,
610 int flags
, struct proc
*p
)
615 struct vfs_context context
;
618 context
.vc_ucred
= cred
;
620 vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
621 if ( (error
= vnode_getwithref(vp
)) ) {
625 if (vp
->v_type
== VREG
&& (fp
->f_fglob
->fg_flag
& O_APPEND
))
627 if (fp
->f_fglob
->fg_flag
& FNONBLOCK
)
629 if ((fp
->f_fglob
->fg_flag
& O_FSYNC
) ||
630 (vp
->v_mount
&& (vp
->v_mount
->mnt_flag
& MNT_SYNCHRONOUS
)))
633 if ((flags
& FOF_OFFSET
) == 0) {
634 uio
->uio_offset
= fp
->f_fglob
->fg_offset
;
635 count
= uio_resid(uio
);
637 if (p
&& (vp
->v_type
== VREG
) &&
638 (((uio
->uio_offset
+ uio_uio_resid(uio
)) > p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
) ||
639 (uio_uio_resid(uio
) > (p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
- uio
->uio_offset
)))) {
645 error
= VNOP_WRITE(vp
, uio
, ioflag
, &context
);
647 if ((flags
& FOF_OFFSET
) == 0) {
648 if (ioflag
& IO_APPEND
)
649 fp
->f_fglob
->fg_offset
= uio
->uio_offset
;
651 fp
->f_fglob
->fg_offset
+= count
- uio_resid(uio
);
655 * Set the credentials on successful writes
657 if ((error
== 0) && (vp
->v_tag
== VT_NFS
) && (UBCINFOEXISTS(vp
))) {
659 * When called from aio subsystem, we only have the proc from
660 * which to get the credential, at this point, so use that
661 * instead. This means aio functions are incompatible with
662 * per-thread credentials (aio operations are proxied). We
663 * can't easily correct the aio vs. settid race in this case
664 * anyway, so we disallow it.
666 if ((flags
& FOF_PCRED
) == 0) {
667 ubc_setthreadcred(vp
, p
, current_thread());
677 * File table vnode stat routine.
680 vn_stat_noauth(struct vnode
*vp
, struct stat
*sb
, kauth_filesec_t
*xsec
, vfs_context_t ctx
)
682 struct vnode_attr va
;
685 kauth_filesec_t fsec
;
688 VATTR_WANTED(&va
, va_fsid
);
689 VATTR_WANTED(&va
, va_fileid
);
690 VATTR_WANTED(&va
, va_mode
);
691 VATTR_WANTED(&va
, va_type
);
692 VATTR_WANTED(&va
, va_nlink
);
693 VATTR_WANTED(&va
, va_uid
);
694 VATTR_WANTED(&va
, va_gid
);
695 VATTR_WANTED(&va
, va_rdev
);
696 VATTR_WANTED(&va
, va_data_size
);
697 VATTR_WANTED(&va
, va_access_time
);
698 VATTR_WANTED(&va
, va_modify_time
);
699 VATTR_WANTED(&va
, va_change_time
);
700 VATTR_WANTED(&va
, va_flags
);
701 VATTR_WANTED(&va
, va_gen
);
702 VATTR_WANTED(&va
, va_iosize
);
703 /* lower layers will synthesise va_total_alloc from va_data_size if required */
704 VATTR_WANTED(&va
, va_total_alloc
);
706 VATTR_WANTED(&va
, va_uuuid
);
707 VATTR_WANTED(&va
, va_guuid
);
708 VATTR_WANTED(&va
, va_acl
);
710 error
= vnode_getattr(vp
, &va
, ctx
);
714 * Copy from vattr table
716 sb
->st_dev
= va
.va_fsid
;
717 sb
->st_ino
= (ino_t
)va
.va_fileid
;
719 switch (vp
->v_type
) {
746 sb
->st_nlink
= VATTR_IS_SUPPORTED(&va
, va_nlink
) ? (u_int16_t
)va
.va_nlink
: 1;
747 sb
->st_uid
= va
.va_uid
;
748 sb
->st_gid
= va
.va_gid
;
749 sb
->st_rdev
= va
.va_rdev
;
750 sb
->st_size
= va
.va_data_size
;
751 sb
->st_atimespec
= va
.va_access_time
;
752 sb
->st_mtimespec
= va
.va_modify_time
;
753 sb
->st_ctimespec
= va
.va_change_time
;
754 sb
->st_blksize
= va
.va_iosize
;
755 sb
->st_flags
= va
.va_flags
;
756 sb
->st_blocks
= roundup(va
.va_total_alloc
, 512) / 512;
758 /* if we're interested in exended security data and we got an ACL */
760 if (!VATTR_IS_SUPPORTED(&va
, va_acl
) &&
761 !VATTR_IS_SUPPORTED(&va
, va_uuuid
) &&
762 !VATTR_IS_SUPPORTED(&va
, va_guuid
)) {
763 *xsec
= KAUTH_FILESEC_NONE
;
766 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && (va
.va_acl
!= NULL
)) {
767 fsec
= kauth_filesec_alloc(va
.va_acl
->acl_entrycount
);
769 fsec
= kauth_filesec_alloc(0);
775 fsec
->fsec_magic
= KAUTH_FILESEC_MAGIC
;
776 if (VATTR_IS_SUPPORTED(&va
, va_uuuid
)) {
777 fsec
->fsec_owner
= va
.va_uuuid
;
779 fsec
->fsec_owner
= kauth_null_guid
;
781 if (VATTR_IS_SUPPORTED(&va
, va_guuid
)) {
782 fsec
->fsec_group
= va
.va_guuid
;
784 fsec
->fsec_group
= kauth_null_guid
;
786 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && (va
.va_acl
!= NULL
)) {
787 bcopy(va
.va_acl
, &(fsec
->fsec_acl
), KAUTH_ACL_COPYSIZE(va
.va_acl
));
789 fsec
->fsec_acl
.acl_entrycount
= KAUTH_FILESEC_NOACL
;
795 /* Do not give the generation number out to unpriviledged users */
796 if (va
.va_gen
&& !vfs_context_issuser(ctx
))
799 sb
->st_gen
= va
.va_gen
;
803 if (VATTR_IS_SUPPORTED(&va
, va_acl
) && va
.va_acl
!= NULL
)
804 kauth_acl_free(va
.va_acl
);
809 vn_stat(struct vnode
*vp
, struct stat
*sb
, kauth_filesec_t
*xsec
, vfs_context_t ctx
)
814 if ((error
= vnode_authorize(vp
, NULL
, KAUTH_VNODE_READ_ATTRIBUTES
| KAUTH_VNODE_READ_SECURITY
, ctx
)) != 0)
818 return(vn_stat_noauth(vp
, sb
, xsec
, ctx
));
823 * File table vnode ioctl routine.
826 vn_ioctl(fp
, com
, data
, p
)
832 register struct vnode
*vp
= ((struct vnode
*)fp
->f_fglob
->fg_data
);
833 struct vfs_context context
;
839 if ( (error
= vnode_getwithref(vp
)) ) {
843 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
845 switch (vp
->v_type
) {
849 if (com
== FIONREAD
) {
850 if ((error
= vnode_size(vp
, &file_size
, &context
)) != 0)
852 *(int *)data
= file_size
- fp
->f_fglob
->fg_offset
;
855 if (com
== FIONBIO
|| com
== FIOASYNC
) { /* XXX */
868 /* Should not be able to set block size from user space */
869 if (com
== DKIOCSETBLOCKSIZE
) {
874 if (com
== FIODTYPE
) {
875 if (vp
->v_type
== VBLK
) {
876 if (major(vp
->v_rdev
) >= nblkdev
) {
880 *(int *)data
= bdevsw
[major(vp
->v_rdev
)].d_type
;
882 } else if (vp
->v_type
== VCHR
) {
883 if (major(vp
->v_rdev
) >= nchrdev
) {
887 *(int *)data
= cdevsw
[major(vp
->v_rdev
)].d_type
;
894 error
= VNOP_IOCTL(vp
, com
, data
, fp
->f_fglob
->fg_flag
, &context
);
896 if (error
== 0 && com
== TIOCSCTTY
) {
899 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
900 ttyvp
= p
->p_session
->s_ttyvp
;
901 p
->p_session
->s_ttyvp
= vp
;
902 thread_funnel_set(kernel_flock
, funnel_state
);
914 * File table vnode select routine.
917 vn_select(fp
, which
, wql
, p
)
924 struct vnode
* vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
925 struct vfs_context context
;
927 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
929 context
.vc_ucred
= fp
->f_fglob
->fg_cred
;
931 error
= VNOP_SELECT(vp
, which
, fp
->f_fglob
->fg_flag
, wql
, &context
);
940 * Check that the vnode is still valid, and if so
941 * acquire requested lock.
944 vn_lock(__unused vnode_t vp
, __unused
int flags
, __unused proc_t p
)
950 * File table vnode close routine.
957 struct vnode
*vp
= (struct vnode
*)fg
->fg_data
;
960 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
961 error
= vn_close(vp
, fg
->fg_flag
, fg
->fg_cred
, p
);
969 vn_pathconf(vnode_t vp
, int name
, register_t
*retval
, vfs_context_t ctx
)
974 case _PC_EXTENDED_SECURITY_NP
:
975 *retval
= vfs_extendedsecurity(vnode_mount(vp
));
977 case _PC_AUTH_OPAQUE_NP
:
978 *retval
= vfs_authopaque(vnode_mount(vp
));
981 error
= VNOP_PATHCONF(vp
, name
, retval
, ctx
);
989 vn_kqfilt_add(fp
, kn
, p
)
994 struct vnode
*vp
= (struct vnode
*)fp
->f_fglob
->fg_data
;
995 struct vfs_context context
;
999 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
1000 context
.vc_proc
= p
;
1001 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
1003 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1004 error
= VNOP_KQFILT_ADD(vp
, kn
, &context
);
1005 thread_funnel_set(kernel_flock
, funnel_state
);
1007 (void)vnode_put(vp
);
1013 /* No one calls this yet. */
1015 vn_kqfilt_remove(vp
, ident
, p
)
1020 struct vfs_context context
;
1024 if ( (error
= vnode_getwithref(vp
)) == 0 ) {
1025 context
.vc_proc
= p
;
1026 context
.vc_ucred
= p
->p_ucred
; /* XXX kauth_cred_get() ??? */
1028 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
1029 error
= VNOP_KQFILT_REMOVE(vp
, ident
, &context
);
1030 thread_funnel_set(kernel_flock
, funnel_state
);
1032 (void)vnode_put(vp
);