2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2000-2004
5 * Poul-Henning Kamp. All rights reserved.
6 * Copyright (c) 1989, 1992-1993, 1995
7 * The Regents of the University of California. All rights reserved.
9 * This code is derived from software donated to Berkeley by
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)kernfs_vnops.c 8.15 (Berkeley) 5/21/95
34 * From: FreeBSD: src/sys/miscfs/kernfs/kernfs_vnops.c 1.43
44 #include <sys/param.h>
45 #include <sys/systm.h>
47 #include <sys/dirent.h>
48 #include <sys/eventhandler.h>
49 #include <sys/fcntl.h>
51 #include <sys/filedesc.h>
52 #include <sys/filio.h>
54 #include <sys/kernel.h>
55 #include <sys/limits.h>
57 #include <sys/malloc.h>
59 #include <sys/mount.h>
60 #include <sys/namei.h>
65 #include <sys/sysctl.h>
67 #include <sys/ttycom.h>
68 #include <sys/unistd.h>
69 #include <sys/vnode.h>
71 static struct vop_vector devfs_vnodeops;
72 static struct vop_vector devfs_specops;
73 static struct fileops devfs_ops_f;
75 #include <fs/devfs/devfs.h>
76 #include <fs/devfs/devfs_int.h>
78 #include <security/mac/mac_framework.h>
81 #include <vm/vm_extern.h>
82 #include <vm/vm_object.h>
84 static MALLOC_DEFINE(M_CDEVPDATA, "DEVFSP", "Metainfo for cdev-fp data");
86 struct mtx devfs_de_interlock;
87 MTX_SYSINIT(devfs_de_interlock, &devfs_de_interlock, "devfs interlock", MTX_DEF);
88 struct sx clone_drain_lock;
89 SX_SYSINIT(clone_drain_lock, &clone_drain_lock, "clone events drain lock");
90 struct mtx cdevpriv_mtx;
91 MTX_SYSINIT(cdevpriv_mtx, &cdevpriv_mtx, "cdevpriv lock", MTX_DEF);
93 SYSCTL_DECL(_vfs_devfs);
95 static int devfs_dotimes;
96 SYSCTL_INT(_vfs_devfs, OID_AUTO, dotimes, CTLFLAG_RW,
97 &devfs_dotimes, 0, "Update timestamps on DEVFS with default precision");
100 * Update devfs node timestamp. Note that updates are unlocked and
101 * stat(2) could see partially updated times.
104 devfs_timestamp(struct timespec *tsp)
112 if (tsp->tv_sec != ts) {
120 devfs_fp_check(struct file *fp, struct cdev **devp, struct cdevsw **dswp,
124 *dswp = devvn_refthread(fp->f_vnode, devp, ref);
125 if (*devp != fp->f_data) {
127 dev_relthread(*devp, *ref);
130 KASSERT((*devp)->si_refcount > 0,
131 ("devfs: un-referenced struct cdev *(%s)", devtoname(*devp)));
134 curthread->td_fpop = fp;
139 devfs_get_cdevpriv(void **datap)
142 struct cdev_privdata *p;
145 fp = curthread->td_fpop;
151 *datap = p->cdpd_data;
158 devfs_set_cdevpriv(void *priv, d_priv_dtor_t *priv_dtr)
161 struct cdev_priv *cdp;
162 struct cdev_privdata *p;
165 fp = curthread->td_fpop;
168 cdp = cdev2priv((struct cdev *)fp->f_data);
169 p = malloc(sizeof(struct cdev_privdata), M_CDEVPDATA, M_WAITOK);
171 p->cdpd_dtr = priv_dtr;
173 mtx_lock(&cdevpriv_mtx);
174 if (fp->f_cdevpriv == NULL) {
175 LIST_INSERT_HEAD(&cdp->cdp_fdpriv, p, cdpd_list);
177 mtx_unlock(&cdevpriv_mtx);
180 mtx_unlock(&cdevpriv_mtx);
181 free(p, M_CDEVPDATA);
188 devfs_destroy_cdevpriv(struct cdev_privdata *p)
191 mtx_assert(&cdevpriv_mtx, MA_OWNED);
192 KASSERT(p->cdpd_fp->f_cdevpriv == p,
193 ("devfs_destoy_cdevpriv %p != %p", p->cdpd_fp->f_cdevpriv, p));
194 p->cdpd_fp->f_cdevpriv = NULL;
195 LIST_REMOVE(p, cdpd_list);
196 mtx_unlock(&cdevpriv_mtx);
197 (p->cdpd_dtr)(p->cdpd_data);
198 free(p, M_CDEVPDATA);
202 devfs_fpdrop(struct file *fp)
204 struct cdev_privdata *p;
206 mtx_lock(&cdevpriv_mtx);
207 if ((p = fp->f_cdevpriv) == NULL) {
208 mtx_unlock(&cdevpriv_mtx);
211 devfs_destroy_cdevpriv(p);
215 devfs_clear_cdevpriv(void)
219 fp = curthread->td_fpop;
226 * On success devfs_populate_vp() returns with dmp->dm_lock held.
229 devfs_populate_vp(struct vnode *vp)
231 struct devfs_dirent *de;
232 struct devfs_mount *dmp;
235 ASSERT_VOP_LOCKED(vp, "devfs_populate_vp");
237 dmp = VFSTODEVFS(vp->v_mount);
238 locked = VOP_ISLOCKED(vp);
240 sx_xlock(&dmp->dm_lock);
243 /* Can't call devfs_populate() with the vnode lock held. */
247 sx_xunlock(&dmp->dm_lock);
248 vn_lock(vp, locked | LK_RETRY);
249 sx_xlock(&dmp->dm_lock);
250 if (DEVFS_DMP_DROP(dmp)) {
251 sx_xunlock(&dmp->dm_lock);
252 devfs_unmount_final(dmp);
255 if ((vp->v_iflag & VI_DOOMED) != 0) {
256 sx_xunlock(&dmp->dm_lock);
261 ("devfs_populate_vp: vp->v_data == NULL but vnode not doomed"));
262 if ((de->de_flags & DE_DOOMED) != 0) {
263 sx_xunlock(&dmp->dm_lock);
271 devfs_vptocnp(struct vop_vptocnp_args *ap)
273 struct vnode *vp = ap->a_vp;
274 struct vnode **dvp = ap->a_vpp;
275 struct devfs_mount *dmp;
276 char *buf = ap->a_buf;
277 int *buflen = ap->a_buflen;
278 struct devfs_dirent *dd, *de;
281 dmp = VFSTODEVFS(vp->v_mount);
283 error = devfs_populate_vp(vp);
290 if (vp->v_type == VCHR) {
291 i -= strlen(dd->de_cdp->cdp_c.si_name);
296 bcopy(dd->de_cdp->cdp_c.si_name, buf + i,
297 strlen(dd->de_cdp->cdp_c.si_name));
299 } else if (vp->v_type == VDIR) {
300 if (dd == dmp->dm_rootdir) {
305 i -= dd->de_dirent->d_namlen;
310 bcopy(dd->de_dirent->d_name, buf + i,
311 dd->de_dirent->d_namlen);
318 de = devfs_parent_dirent(de);
323 mtx_lock(&devfs_de_interlock);
327 mtx_unlock(&devfs_de_interlock);
333 mtx_unlock(&devfs_de_interlock);
337 sx_xunlock(&dmp->dm_lock);
342 * Construct the fully qualified path name relative to the mountpoint.
343 * If a NULL cnp is provided, no '/' is appended to the resulting path.
346 devfs_fqpn(char *buf, struct devfs_mount *dmp, struct devfs_dirent *dd,
347 struct componentname *cnp)
350 struct devfs_dirent *de;
352 sx_assert(&dmp->dm_lock, SA_LOCKED);
357 i -= cnp->cn_namelen;
361 bcopy(cnp->cn_nameptr, buf + i, cnp->cn_namelen);
363 while (de != dmp->dm_rootdir) {
364 if (cnp != NULL || i < SPECNAMELEN) {
370 i -= de->de_dirent->d_namlen;
373 bcopy(de->de_dirent->d_name, buf + i,
374 de->de_dirent->d_namlen);
375 de = devfs_parent_dirent(de);
383 devfs_allocv_drop_refs(int drop_dm_lock, struct devfs_mount *dmp,
384 struct devfs_dirent *de)
389 if (de->de_flags & DE_DOOMED)
391 if (DEVFS_DE_DROP(de)) {
392 KASSERT(not_found == 1, ("DEVFS de dropped but not doomed"));
393 devfs_dirent_free(de);
395 if (DEVFS_DMP_DROP(dmp)) {
396 KASSERT(not_found == 1,
397 ("DEVFS mount struct freed before dirent"));
399 sx_xunlock(&dmp->dm_lock);
400 devfs_unmount_final(dmp);
402 if (not_found == 1 || (drop_dm_lock && not_found != 2))
403 sx_unlock(&dmp->dm_lock);
408 devfs_insmntque_dtr(struct vnode *vp, void *arg)
410 struct devfs_dirent *de;
412 de = (struct devfs_dirent *)arg;
413 mtx_lock(&devfs_de_interlock);
416 mtx_unlock(&devfs_de_interlock);
422 * devfs_allocv shall be entered with dmp->dm_lock held, and it drops
426 devfs_allocv(struct devfs_dirent *de, struct mount *mp, int lockmode,
432 struct devfs_mount *dmp;
435 dmp = VFSTODEVFS(mp);
436 if (de->de_flags & DE_DOOMED) {
437 sx_xunlock(&dmp->dm_lock);
443 mtx_lock(&devfs_de_interlock);
447 mtx_unlock(&devfs_de_interlock);
448 sx_xunlock(&dmp->dm_lock);
449 vget(vp, lockmode | LK_INTERLOCK | LK_RETRY, curthread);
450 sx_xlock(&dmp->dm_lock);
451 if (devfs_allocv_drop_refs(0, dmp, de)) {
455 else if ((vp->v_iflag & VI_DOOMED) != 0) {
456 mtx_lock(&devfs_de_interlock);
457 if (de->de_vnode == vp) {
461 mtx_unlock(&devfs_de_interlock);
465 sx_xunlock(&dmp->dm_lock);
469 mtx_unlock(&devfs_de_interlock);
470 if (de->de_dirent->d_type == DT_CHR) {
471 if (!(de->de_cdp->cdp_flags & CDP_ACTIVE)) {
472 devfs_allocv_drop_refs(1, dmp, de);
475 dev = &de->de_cdp->cdp_c;
479 error = getnewvnode("devfs", mp, &devfs_vnodeops, &vp);
481 devfs_allocv_drop_refs(1, dmp, de);
482 printf("devfs_allocv: failed to allocate new vnode\n");
486 if (de->de_dirent->d_type == DT_CHR) {
491 /* XXX: v_rdev should be protect by vnode lock */
493 KASSERT(vp->v_usecount == 1,
494 ("%s %d (%d)\n", __func__, __LINE__, vp->v_usecount));
495 dev->si_usecount += vp->v_usecount;
496 /* Special casing of ttys for deadfs. Probably redundant. */
498 if (dsw != NULL && (dsw->d_flags & D_TTY) != 0)
499 vp->v_vflag |= VV_ISTTY;
502 if ((dev->si_flags & SI_ETERNAL) != 0)
503 vp->v_vflag |= VV_ETERNALDEV;
504 vp->v_op = &devfs_specops;
505 } else if (de->de_dirent->d_type == DT_DIR) {
507 } else if (de->de_dirent->d_type == DT_LNK) {
512 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY | LK_NOWITNESS);
514 mtx_lock(&devfs_de_interlock);
517 mtx_unlock(&devfs_de_interlock);
518 error = insmntque1(vp, mp, devfs_insmntque_dtr, de);
520 (void) devfs_allocv_drop_refs(1, dmp, de);
523 if (devfs_allocv_drop_refs(0, dmp, de)) {
528 mac_devfs_vnode_associate(mp, de, vp);
530 sx_xunlock(&dmp->dm_lock);
536 devfs_access(struct vop_access_args *ap)
538 struct vnode *vp = ap->a_vp;
539 struct devfs_dirent *de;
544 if (vp->v_type == VDIR)
547 error = vaccess(vp->v_type, de->de_mode, de->de_uid, de->de_gid,
548 ap->a_accmode, ap->a_cred, NULL);
553 p = ap->a_td->td_proc;
554 /* We do, however, allow access to the controlling terminal */
556 if (!(p->p_flag & P_CONTROLT)) {
560 if (p->p_session->s_ttydp == de->de_cdp)
566 _Static_assert(((FMASK | FCNTLFLAGS) & (FLASTCLOSE | FREVOKE)) == 0,
567 "devfs-only flag reuse failed");
570 devfs_close(struct vop_close_args *ap)
572 struct vnode *vp = ap->a_vp, *oldvp;
573 struct thread *td = ap->a_td;
575 struct cdev *dev = vp->v_rdev;
577 int dflags, error, ref, vp_locked;
580 * XXX: Don't call d_close() if we were called because of
581 * XXX: insmntque1() failure.
583 if (vp->v_data == NULL)
587 * Hack: a tty device that is a controlling terminal
588 * has a reference from the session structure.
589 * We cannot easily tell that a character device is
590 * a controlling terminal, unless it is the closing
591 * process' controlling terminal. In that case,
592 * if the reference count is 2 (this last descriptor
593 * plus the session), release the reference from the session.
598 if (vp == p->p_session->s_ttyvp) {
601 sx_xlock(&proctree_lock);
602 if (vp == p->p_session->s_ttyvp) {
603 SESS_LOCK(p->p_session);
605 if (count_dev(dev) == 2 &&
606 (vp->v_iflag & VI_DOOMED) == 0) {
607 p->p_session->s_ttyvp = NULL;
608 p->p_session->s_ttydp = NULL;
612 SESS_UNLOCK(p->p_session);
614 sx_xunlock(&proctree_lock);
621 * We do not want to really close the device if it
622 * is still in use unless we are trying to close it
623 * forcibly. Since every use (buffer, vnode, swap, cmap)
624 * holds a reference to the vnode, and because we mark
625 * any other vnodes that alias this device, when the
626 * sum of the reference counts on all the aliased
627 * vnodes descends to one, we are on last close.
629 dsw = dev_refthread(dev, &ref);
634 if (vp->v_iflag & VI_DOOMED) {
636 dflags |= FREVOKE | FNONBLOCK;
637 } else if (dsw->d_flags & D_TRACKCLOSE) {
638 /* Keep device updated on status. */
639 } else if (count_dev(dev) > 1) {
641 dev_relthread(dev, ref);
644 if (count_dev(dev) == 1)
645 dflags |= FLASTCLOSE;
648 vp_locked = VOP_ISLOCKED(vp);
650 KASSERT(dev->si_refcount > 0,
651 ("devfs_close() on un-referenced struct cdev *(%s)", devtoname(dev)));
652 error = dsw->d_close(dev, ap->a_fflag | dflags, S_IFCHR, td);
653 dev_relthread(dev, ref);
654 vn_lock(vp, vp_locked | LK_RETRY);
660 devfs_close_f(struct file *fp, struct thread *td)
666 * NB: td may be NULL if this descriptor is closed due to
667 * garbage collection from a closed UNIX domain socket.
669 fpop = curthread->td_fpop;
670 curthread->td_fpop = fp;
671 error = vnops.fo_close(fp, td);
672 curthread->td_fpop = fpop;
675 * The f_cdevpriv cannot be assigned non-NULL value while we
676 * are destroying the file.
678 if (fp->f_cdevpriv != NULL)
684 devfs_getattr(struct vop_getattr_args *ap)
686 struct vnode *vp = ap->a_vp;
687 struct vattr *vap = ap->a_vap;
688 struct devfs_dirent *de;
689 struct devfs_mount *dmp;
691 struct timeval boottime;
694 error = devfs_populate_vp(vp);
698 dmp = VFSTODEVFS(vp->v_mount);
699 sx_xunlock(&dmp->dm_lock);
702 KASSERT(de != NULL, ("Null dirent in devfs_getattr vp=%p", vp));
703 if (vp->v_type == VDIR) {
706 ("Null dir dirent in devfs_getattr vp=%p", vp));
708 vap->va_uid = de->de_uid;
709 vap->va_gid = de->de_gid;
710 vap->va_mode = de->de_mode;
711 if (vp->v_type == VLNK)
712 vap->va_size = strlen(de->de_symlink);
713 else if (vp->v_type == VDIR)
714 vap->va_size = vap->va_bytes = DEV_BSIZE;
717 if (vp->v_type != VDIR)
719 vap->va_blocksize = DEV_BSIZE;
720 vap->va_type = vp->v_type;
722 getboottime(&boottime);
725 if ((aa).tv_sec <= 3600) { \
726 (aa).tv_sec = boottime.tv_sec; \
727 (aa).tv_nsec = boottime.tv_usec * 1000; \
731 if (vp->v_type != VCHR) {
733 vap->va_atime = de->de_atime;
735 vap->va_mtime = de->de_mtime;
737 vap->va_ctime = de->de_ctime;
741 vap->va_atime = dev->si_atime;
743 vap->va_mtime = dev->si_mtime;
745 vap->va_ctime = dev->si_ctime;
747 vap->va_rdev = cdev2priv(dev)->cdp_inode;
752 vap->va_nlink = de->de_links;
753 vap->va_fileid = de->de_inode;
760 devfs_ioctl_f(struct file *fp, u_long com, void *data, struct ucred *cred, struct thread *td)
767 error = vnops.fo_ioctl(fp, com, data, cred, td);
773 fiodgname_buf_get_ptr(void *fgnp, u_long com)
776 struct fiodgname_arg fgn;
777 #ifdef COMPAT_FREEBSD32
778 struct fiodgname_arg32 fgn32;
785 return (fgnup->fgn.buf);
786 #ifdef COMPAT_FREEBSD32
788 return ((void *)(uintptr_t)fgnup->fgn32.buf);
791 panic("Unhandled ioctl command %ld", com);
796 devfs_ioctl(struct vop_ioctl_args *ap)
798 struct fiodgname_arg *fgn;
799 struct vnode *vpold, *vp;
811 dsw = devvn_refthread(vp, &dev, &ref);
814 KASSERT(dev->si_refcount > 0,
815 ("devfs: un-referenced struct cdev *(%s)", devtoname(dev)));
819 *(int *)ap->a_data = dsw->d_flags & D_TYPEMASK;
823 #ifdef COMPAT_FREEBSD32
832 error = copyout(p, fiodgname_buf_get_ptr(fgn, com), i);
835 error = dsw->d_ioctl(dev, com, ap->a_data, ap->a_fflag, td);
838 dev_relthread(dev, ref);
839 if (error == ENOIOCTL)
842 if (error == 0 && com == TIOCSCTTY) {
843 /* Do nothing if reassigning same control tty */
844 sx_slock(&proctree_lock);
845 if (td->td_proc->p_session->s_ttyvp == vp) {
846 sx_sunlock(&proctree_lock);
850 vpold = td->td_proc->p_session->s_ttyvp;
852 SESS_LOCK(td->td_proc->p_session);
853 td->td_proc->p_session->s_ttyvp = vp;
854 td->td_proc->p_session->s_ttydp = cdev2priv(dev);
855 SESS_UNLOCK(td->td_proc->p_session);
857 sx_sunlock(&proctree_lock);
859 /* Get rid of reference to old control tty */
868 devfs_kqfilter_f(struct file *fp, struct knote *kn)
878 error = devfs_fp_check(fp, &dev, &dsw, &ref);
881 error = dsw->d_kqfilter(dev, kn);
883 dev_relthread(dev, ref);
888 devfs_prison_check(struct devfs_dirent *de, struct thread *td)
890 struct cdev_priv *cdp;
898 dcr = cdp->cdp_c.si_cred;
902 error = prison_check(td->td_ucred, dcr);
905 /* We do, however, allow access to the controlling terminal */
908 if (!(p->p_flag & P_CONTROLT)) {
912 if (p->p_session->s_ttydp == cdp)
919 devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock)
921 struct componentname *cnp;
922 struct vnode *dvp, **vpp;
924 struct devfs_dirent *de, *dd;
925 struct devfs_dirent **dde;
926 struct devfs_mount *dmp;
929 int error, flags, nameiop, dvplocked;
930 char specname[SPECNAMELEN + 1], *pname;
935 pname = cnp->cn_nameptr;
937 flags = cnp->cn_flags;
938 nameiop = cnp->cn_nameiop;
940 dmp = VFSTODEVFS(mp);
944 if ((flags & ISLASTCN) && nameiop == RENAME)
947 if (dvp->v_type != VDIR)
950 if ((flags & ISDOTDOT) && (dvp->v_vflag & VV_ROOT))
953 error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td);
957 if (cnp->cn_namelen == 1 && *pname == '.') {
958 if ((flags & ISLASTCN) && nameiop != LOOKUP)
965 if (flags & ISDOTDOT) {
966 if ((flags & ISLASTCN) && nameiop != LOOKUP)
968 de = devfs_parent_dirent(dd);
971 dvplocked = VOP_ISLOCKED(dvp);
973 error = devfs_allocv(de, mp, cnp->cn_lkflags & LK_TYPE_MASK,
976 vn_lock(dvp, dvplocked | LK_RETRY);
981 de = devfs_find(dd, cnp->cn_nameptr, cnp->cn_namelen, 0);
982 while (de == NULL) { /* While(...) so we can use break */
984 if (nameiop == DELETE)
988 * OK, we didn't have an entry for the name we were asked for
989 * so we try to see if anybody can create it on demand.
991 pname = devfs_fqpn(specname, dmp, dd, cnp);
997 sx_xunlock(&dmp->dm_lock);
998 sx_slock(&clone_drain_lock);
999 EVENTHANDLER_INVOKE(dev_clone,
1000 td->td_ucred, pname, strlen(pname), &cdev);
1001 sx_sunlock(&clone_drain_lock);
1004 sx_xlock(&dmp->dm_lock);
1005 else if (devfs_populate_vp(dvp) != 0) {
1007 sx_xlock(&dmp->dm_lock);
1008 if (DEVFS_DMP_DROP(dmp)) {
1009 sx_xunlock(&dmp->dm_lock);
1010 devfs_unmount_final(dmp);
1012 sx_xunlock(&dmp->dm_lock);
1016 if (DEVFS_DMP_DROP(dmp)) {
1018 sx_xunlock(&dmp->dm_lock);
1019 devfs_unmount_final(dmp);
1029 dde = &cdev2priv(cdev)->cdp_dirents[dmp->dm_idx];
1030 if (dde != NULL && *dde != NULL)
1037 if (de == NULL || de->de_flags & DE_WHITEOUT) {
1038 if ((nameiop == CREATE || nameiop == RENAME) &&
1039 (flags & (LOCKPARENT | WANTPARENT)) && (flags & ISLASTCN)) {
1040 cnp->cn_flags |= SAVENAME;
1041 return (EJUSTRETURN);
1046 if (devfs_prison_check(de, td))
1049 if ((cnp->cn_nameiop == DELETE) && (flags & ISLASTCN)) {
1050 error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
1059 error = devfs_allocv(de, mp, cnp->cn_lkflags & LK_TYPE_MASK, vpp);
1065 devfs_lookup(struct vop_lookup_args *ap)
1068 struct devfs_mount *dmp;
1071 if (devfs_populate_vp(ap->a_dvp) != 0)
1074 dmp = VFSTODEVFS(ap->a_dvp->v_mount);
1076 j = devfs_lookupx(ap, &dm_unlock);
1078 sx_xunlock(&dmp->dm_lock);
1083 devfs_mknod(struct vop_mknod_args *ap)
1085 struct componentname *cnp;
1086 struct vnode *dvp, **vpp;
1087 struct devfs_dirent *dd, *de;
1088 struct devfs_mount *dmp;
1092 * The only type of node we should be creating here is a
1093 * character device, for anything else return EOPNOTSUPP.
1095 if (ap->a_vap->va_type != VCHR)
1096 return (EOPNOTSUPP);
1098 dmp = VFSTODEVFS(dvp->v_mount);
1105 sx_xlock(&dmp->dm_lock);
1106 TAILQ_FOREACH(de, &dd->de_dlist, de_list) {
1107 if (cnp->cn_namelen != de->de_dirent->d_namlen)
1109 if (de->de_dirent->d_type == DT_CHR &&
1110 (de->de_cdp->cdp_flags & CDP_ACTIVE) == 0)
1112 if (bcmp(cnp->cn_nameptr, de->de_dirent->d_name,
1113 de->de_dirent->d_namlen) != 0)
1115 if (de->de_flags & DE_WHITEOUT)
1121 de->de_flags &= ~DE_WHITEOUT;
1122 error = devfs_allocv(de, dvp->v_mount, LK_EXCLUSIVE, vpp);
1125 sx_xunlock(&dmp->dm_lock);
1131 devfs_open(struct vop_open_args *ap)
1133 struct thread *td = ap->a_td;
1134 struct vnode *vp = ap->a_vp;
1135 struct cdev *dev = vp->v_rdev;
1136 struct file *fp = ap->a_fp;
1137 int error, ref, vlocked;
1142 if (vp->v_type == VBLK)
1148 /* Make this field valid before any I/O in d_open. */
1149 if (dev->si_iosize_max == 0)
1150 dev->si_iosize_max = DFLTPHYS;
1152 dsw = dev_refthread(dev, &ref);
1155 if (fp == NULL && dsw->d_fdopen != NULL) {
1156 dev_relthread(dev, ref);
1160 vlocked = VOP_ISLOCKED(vp);
1169 if (dsw->d_fdopen != NULL)
1170 error = dsw->d_fdopen(dev, ap->a_mode, td, fp);
1172 error = dsw->d_open(dev, ap->a_mode, S_IFCHR, td);
1173 /* Clean up any cdevpriv upon error. */
1175 devfs_clear_cdevpriv();
1178 vn_lock(vp, vlocked | LK_RETRY);
1179 dev_relthread(dev, ref);
1181 if (error == ERESTART)
1186 #if 0 /* /dev/console */
1187 KASSERT(fp != NULL, ("Could not vnode bypass device on NULL fp"));
1192 if (fp->f_ops == &badfileops)
1193 finit(fp, fp->f_flag, DTYPE_VNODE, dev, &devfs_ops_f);
1194 mtxp = mtx_pool_find(mtxpool_sleep, fp);
1197 * Hint to the dofilewrite() to not force the buffer draining
1198 * on the writer to the file. Most likely, the write would
1199 * not need normal buffers.
1202 fp->f_vnread_flags |= FDEVFS_VNODE;
1208 devfs_pathconf(struct vop_pathconf_args *ap)
1211 switch (ap->a_name) {
1212 case _PC_FILESIZEBITS:
1216 *ap->a_retval = NAME_MAX;
1219 *ap->a_retval = INT_MAX;
1221 case _PC_SYMLINK_MAX:
1222 *ap->a_retval = MAXPATHLEN;
1225 if (ap->a_vp->v_vflag & VV_ISTTY) {
1226 *ap->a_retval = MAX_CANON;
1231 if (ap->a_vp->v_vflag & VV_ISTTY) {
1232 *ap->a_retval = MAX_INPUT;
1237 if (ap->a_vp->v_vflag & VV_ISTTY) {
1238 *ap->a_retval = _POSIX_VDISABLE;
1242 case _PC_MAC_PRESENT:
1245 * If MAC is enabled, devfs automatically supports
1246 * trivial non-persistant label storage.
1253 case _PC_CHOWN_RESTRICTED:
1257 return (vop_stdpathconf(ap));
1264 devfs_poll_f(struct file *fp, int events, struct ucred *cred, struct thread *td)
1272 error = devfs_fp_check(fp, &dev, &dsw, &ref);
1274 error = vnops.fo_poll(fp, events, cred, td);
1277 error = dsw->d_poll(dev, events, td);
1279 dev_relthread(dev, ref);
1284 * Print out the contents of a special device vnode.
1287 devfs_print(struct vop_print_args *ap)
1290 printf("\tdev %s\n", devtoname(ap->a_vp->v_rdev));
1295 devfs_read_f(struct file *fp, struct uio *uio, struct ucred *cred,
1296 int flags, struct thread *td)
1299 int ioflag, error, ref;
1304 if (uio->uio_resid > DEVFS_IOSIZE_MAX)
1307 error = devfs_fp_check(fp, &dev, &dsw, &ref);
1309 error = vnops.fo_read(fp, uio, cred, flags, td);
1312 resid = uio->uio_resid;
1313 ioflag = fp->f_flag & (O_NONBLOCK | O_DIRECT);
1314 if (ioflag & O_DIRECT)
1315 ioflag |= IO_DIRECT;
1317 foffset_lock_uio(fp, uio, flags | FOF_NOLOCK);
1318 error = dsw->d_read(dev, uio, ioflag);
1319 if (uio->uio_resid != resid || (error == 0 && resid != 0))
1320 devfs_timestamp(&dev->si_atime);
1322 dev_relthread(dev, ref);
1324 foffset_unlock_uio(fp, uio, flags | FOF_NOLOCK | FOF_NEXTOFF);
1329 devfs_readdir(struct vop_readdir_args *ap)
1334 struct devfs_dirent *dd;
1335 struct devfs_dirent *de;
1336 struct devfs_mount *dmp;
1338 int *tmp_ncookies = NULL;
1340 if (ap->a_vp->v_type != VDIR)
1344 if (uio->uio_offset < 0)
1348 * XXX: This is a temporary hack to get around this filesystem not
1349 * supporting cookies. We store the location of the ncookies pointer
1350 * in a temporary variable before calling vfs_subr.c:vfs_read_dirent()
1351 * and set the number of cookies to 0. We then set the pointer to
1352 * NULL so that vfs_read_dirent doesn't try to call realloc() on
1353 * ap->a_cookies. Later in this function, we restore the ap->a_ncookies
1354 * pointer to its original location before returning to the caller.
1356 if (ap->a_ncookies != NULL) {
1357 tmp_ncookies = ap->a_ncookies;
1358 *ap->a_ncookies = 0;
1359 ap->a_ncookies = NULL;
1362 dmp = VFSTODEVFS(ap->a_vp->v_mount);
1363 if (devfs_populate_vp(ap->a_vp) != 0) {
1364 if (tmp_ncookies != NULL)
1365 ap->a_ncookies = tmp_ncookies;
1369 de = ap->a_vp->v_data;
1371 TAILQ_FOREACH(dd, &de->de_dlist, de_list) {
1372 KASSERT(dd->de_cdp != (void *)0xdeadc0de, ("%s %d\n", __func__, __LINE__));
1373 if (dd->de_flags & (DE_COVERED | DE_WHITEOUT))
1375 if (devfs_prison_check(dd, uio->uio_td))
1377 if (dd->de_dirent->d_type == DT_DIR)
1382 MPASS(dp->d_reclen == GENERIC_DIRSIZ(dp));
1383 if (dp->d_reclen > uio->uio_resid)
1385 dp->d_fileno = de->de_inode;
1386 /* NOTE: d_off is the offset for the *next* entry. */
1387 dp->d_off = off + dp->d_reclen;
1388 if (off >= uio->uio_offset) {
1389 error = vfs_read_dirent(ap, dp, off);
1393 off += dp->d_reclen;
1395 sx_xunlock(&dmp->dm_lock);
1396 uio->uio_offset = off;
1399 * Restore ap->a_ncookies if it wasn't originally NULL in the first
1402 if (tmp_ncookies != NULL)
1403 ap->a_ncookies = tmp_ncookies;
1409 devfs_readlink(struct vop_readlink_args *ap)
1411 struct devfs_dirent *de;
1413 de = ap->a_vp->v_data;
1414 return (uiomove(de->de_symlink, strlen(de->de_symlink), ap->a_uio));
1418 devfs_reclaim(struct vop_reclaim_args *ap)
1421 struct devfs_dirent *de;
1424 mtx_lock(&devfs_de_interlock);
1427 de->de_vnode = NULL;
1430 mtx_unlock(&devfs_de_interlock);
1435 devfs_reclaim_vchr(struct vop_reclaim_args *ap)
1441 MPASS(vp->v_type == VCHR);
1450 dev->si_usecount -= vp->v_usecount;
1459 devfs_remove(struct vop_remove_args *ap)
1461 struct vnode *dvp = ap->a_dvp;
1462 struct vnode *vp = ap->a_vp;
1463 struct devfs_dirent *dd;
1464 struct devfs_dirent *de, *de_covered;
1465 struct devfs_mount *dmp = VFSTODEVFS(vp->v_mount);
1467 ASSERT_VOP_ELOCKED(dvp, "devfs_remove");
1468 ASSERT_VOP_ELOCKED(vp, "devfs_remove");
1470 sx_xlock(&dmp->dm_lock);
1471 dd = ap->a_dvp->v_data;
1473 if (de->de_cdp == NULL) {
1474 TAILQ_REMOVE(&dd->de_dlist, de, de_list);
1475 if (de->de_dirent->d_type == DT_LNK) {
1476 de_covered = devfs_find(dd, de->de_dirent->d_name,
1477 de->de_dirent->d_namlen, 0);
1478 if (de_covered != NULL)
1479 de_covered->de_flags &= ~DE_COVERED;
1481 /* We need to unlock dvp because devfs_delete() may lock it. */
1485 devfs_delete(dmp, de, 0);
1486 sx_xunlock(&dmp->dm_lock);
1488 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
1489 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1491 de->de_flags |= DE_WHITEOUT;
1492 sx_xunlock(&dmp->dm_lock);
1498 * Revoke is called on a tty when a terminal session ends. The vnode
1499 * is orphaned by setting v_op to deadfs so we need to let go of it
1500 * as well so that we create a new one next time around.
1504 devfs_revoke(struct vop_revoke_args *ap)
1506 struct vnode *vp = ap->a_vp, *vp2;
1508 struct cdev_priv *cdp;
1509 struct devfs_dirent *de;
1512 KASSERT((ap->a_flags & REVOKEALL) != 0, ("devfs_revoke !REVOKEALL"));
1515 cdp = cdev2priv(dev);
1528 mtx_lock(&devfs_de_interlock);
1531 for (i = 0; i <= cdp->cdp_maxdirent; i++) {
1532 de = cdp->cdp_dirents[i];
1540 mtx_unlock(&devfs_de_interlock);
1541 if (vget(vp2, LK_EXCLUSIVE | LK_INTERLOCK,
1555 mtx_unlock(&devfs_de_interlock);
1560 if (!(cdp->cdp_flags & CDP_ACTIVE) && cdp->cdp_inuse == 0) {
1561 TAILQ_REMOVE(&cdevp_list, cdp, cdp_list);
1563 dev_rel(&cdp->cdp_c);
1567 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1572 devfs_rioctl(struct vop_ioctl_args *ap)
1575 struct devfs_mount *dmp;
1579 vn_lock(vp, LK_SHARED | LK_RETRY);
1580 if (vp->v_iflag & VI_DOOMED) {
1584 dmp = VFSTODEVFS(vp->v_mount);
1585 sx_xlock(&dmp->dm_lock);
1587 DEVFS_DMP_HOLD(dmp);
1588 devfs_populate(dmp);
1589 if (DEVFS_DMP_DROP(dmp)) {
1590 sx_xunlock(&dmp->dm_lock);
1591 devfs_unmount_final(dmp);
1594 error = devfs_rules_ioctl(dmp, ap->a_command, ap->a_data, ap->a_td);
1595 sx_xunlock(&dmp->dm_lock);
1600 devfs_rread(struct vop_read_args *ap)
1603 if (ap->a_vp->v_type != VDIR)
1605 return (VOP_READDIR(ap->a_vp, ap->a_uio, ap->a_cred, NULL, NULL, NULL));
1609 devfs_setattr(struct vop_setattr_args *ap)
1611 struct devfs_dirent *de;
1622 if ((vap->va_type != VNON) ||
1623 (vap->va_nlink != VNOVAL) ||
1624 (vap->va_fsid != VNOVAL) ||
1625 (vap->va_fileid != VNOVAL) ||
1626 (vap->va_blocksize != VNOVAL) ||
1627 (vap->va_flags != VNOVAL && vap->va_flags != 0) ||
1628 (vap->va_rdev != VNOVAL) ||
1629 ((int)vap->va_bytes != VNOVAL) ||
1630 (vap->va_gen != VNOVAL)) {
1634 error = devfs_populate_vp(vp);
1639 if (vp->v_type == VDIR)
1643 if (vap->va_uid == (uid_t)VNOVAL)
1647 if (vap->va_gid == (gid_t)VNOVAL)
1651 if (uid != de->de_uid || gid != de->de_gid) {
1652 if ((ap->a_cred->cr_uid != de->de_uid) || uid != de->de_uid ||
1653 (gid != de->de_gid && !groupmember(gid, ap->a_cred))) {
1654 error = priv_check(td, PRIV_VFS_CHOWN);
1663 if (vap->va_mode != (mode_t)VNOVAL) {
1664 if (ap->a_cred->cr_uid != de->de_uid) {
1665 error = priv_check(td, PRIV_VFS_ADMIN);
1669 de->de_mode = vap->va_mode;
1673 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
1674 error = vn_utimes_perm(vp, vap, ap->a_cred, td);
1677 if (vap->va_atime.tv_sec != VNOVAL) {
1678 if (vp->v_type == VCHR)
1679 vp->v_rdev->si_atime = vap->va_atime;
1681 de->de_atime = vap->va_atime;
1683 if (vap->va_mtime.tv_sec != VNOVAL) {
1684 if (vp->v_type == VCHR)
1685 vp->v_rdev->si_mtime = vap->va_mtime;
1687 de->de_mtime = vap->va_mtime;
1693 if (vp->v_type == VCHR)
1694 vfs_timestamp(&vp->v_rdev->si_ctime);
1696 vfs_timestamp(&de->de_mtime);
1700 sx_xunlock(&VFSTODEVFS(vp->v_mount)->dm_lock);
1706 devfs_setlabel(struct vop_setlabel_args *ap)
1709 struct devfs_dirent *de;
1714 mac_vnode_relabel(ap->a_cred, vp, ap->a_label);
1715 mac_devfs_update(vp->v_mount, de, vp);
1722 devfs_stat_f(struct file *fp, struct stat *sb, struct ucred *cred, struct thread *td)
1725 return (vnops.fo_stat(fp, sb, cred, td));
1729 devfs_symlink(struct vop_symlink_args *ap)
1732 struct devfs_dirent *dd;
1733 struct devfs_dirent *de, *de_covered, *de_dotdot;
1734 struct devfs_mount *dmp;
1736 error = priv_check(curthread, PRIV_DEVFS_SYMLINK);
1739 dmp = VFSTODEVFS(ap->a_dvp->v_mount);
1740 if (devfs_populate_vp(ap->a_dvp) != 0)
1743 dd = ap->a_dvp->v_data;
1744 de = devfs_newdirent(ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen);
1745 de->de_flags = DE_USER;
1749 de->de_inode = alloc_unr(devfs_inos);
1751 de->de_dirent->d_type = DT_LNK;
1752 i = strlen(ap->a_target) + 1;
1753 de->de_symlink = malloc(i, M_DEVFS, M_WAITOK);
1754 bcopy(ap->a_target, de->de_symlink, i);
1756 mac_devfs_create_symlink(ap->a_cnp->cn_cred, dmp->dm_mount, dd, de);
1758 de_covered = devfs_find(dd, de->de_dirent->d_name,
1759 de->de_dirent->d_namlen, 0);
1760 if (de_covered != NULL) {
1761 if ((de_covered->de_flags & DE_USER) != 0) {
1762 devfs_delete(dmp, de, DEVFS_DEL_NORECURSE);
1763 sx_xunlock(&dmp->dm_lock);
1766 KASSERT((de_covered->de_flags & DE_COVERED) == 0,
1767 ("devfs_symlink: entry %p already covered", de_covered));
1768 de_covered->de_flags |= DE_COVERED;
1771 de_dotdot = TAILQ_FIRST(&dd->de_dlist); /* "." */
1772 de_dotdot = TAILQ_NEXT(de_dotdot, de_list); /* ".." */
1773 TAILQ_INSERT_AFTER(&dd->de_dlist, de_dotdot, de, de_list);
1774 devfs_dir_ref_de(dmp, dd);
1775 devfs_rules_apply(dmp, de);
1777 return (devfs_allocv(de, ap->a_dvp->v_mount, LK_EXCLUSIVE, ap->a_vpp));
1781 devfs_truncate_f(struct file *fp, off_t length, struct ucred *cred, struct thread *td)
1784 return (vnops.fo_truncate(fp, length, cred, td));
1788 devfs_write_f(struct file *fp, struct uio *uio, struct ucred *cred,
1789 int flags, struct thread *td)
1792 int error, ioflag, ref;
1797 if (uio->uio_resid > DEVFS_IOSIZE_MAX)
1800 error = devfs_fp_check(fp, &dev, &dsw, &ref);
1802 error = vnops.fo_write(fp, uio, cred, flags, td);
1805 KASSERT(uio->uio_td == td, ("uio_td %p is not td %p", uio->uio_td, td));
1806 ioflag = fp->f_flag & (O_NONBLOCK | O_DIRECT | O_FSYNC);
1807 if (ioflag & O_DIRECT)
1808 ioflag |= IO_DIRECT;
1809 foffset_lock_uio(fp, uio, flags | FOF_NOLOCK);
1811 resid = uio->uio_resid;
1813 error = dsw->d_write(dev, uio, ioflag);
1814 if (uio->uio_resid != resid || (error == 0 && resid != 0)) {
1815 devfs_timestamp(&dev->si_ctime);
1816 dev->si_mtime = dev->si_ctime;
1819 dev_relthread(dev, ref);
1821 foffset_unlock_uio(fp, uio, flags | FOF_NOLOCK | FOF_NEXTOFF);
1826 devfs_mmap_f(struct file *fp, vm_map_t map, vm_offset_t *addr, vm_size_t size,
1827 vm_prot_t prot, vm_prot_t cap_maxprot, int flags, vm_ooffset_t foff,
1842 * Ensure that file and memory protections are
1846 if (mp != NULL && (mp->mnt_flag & MNT_NOEXEC) != 0) {
1847 maxprot = VM_PROT_NONE;
1848 if ((prot & VM_PROT_EXECUTE) != 0)
1851 maxprot = VM_PROT_EXECUTE;
1852 if ((fp->f_flag & FREAD) != 0)
1853 maxprot |= VM_PROT_READ;
1854 else if ((prot & VM_PROT_READ) != 0)
1858 * If we are sharing potential changes via MAP_SHARED and we
1859 * are trying to get write permission although we opened it
1860 * without asking for it, bail out.
1862 * Note that most character devices always share mappings.
1863 * The one exception is that D_MMAP_ANON devices
1864 * (i.e. /dev/zero) permit private writable mappings.
1866 * Rely on vm_mmap_cdev() to fail invalid MAP_PRIVATE requests
1867 * as well as updating maxprot to permit writing for
1868 * D_MMAP_ANON devices rather than doing that here.
1870 if ((flags & MAP_SHARED) != 0) {
1871 if ((fp->f_flag & FWRITE) != 0)
1872 maxprot |= VM_PROT_WRITE;
1873 else if ((prot & VM_PROT_WRITE) != 0)
1876 maxprot &= cap_maxprot;
1879 error = devfs_fp_check(fp, &dev, &dsw, &ref);
1883 error = vm_mmap_cdev(td, size, prot, &maxprot, &flags, dev, dsw, &foff,
1886 dev_relthread(dev, ref);
1890 error = vm_mmap_object(map, addr, size, prot, maxprot, flags, object,
1893 vm_object_deallocate(object);
1898 dev2udev(struct cdev *x)
1902 return (cdev2priv(x)->cdp_inode);
1905 static struct fileops devfs_ops_f = {
1906 .fo_read = devfs_read_f,
1907 .fo_write = devfs_write_f,
1908 .fo_truncate = devfs_truncate_f,
1909 .fo_ioctl = devfs_ioctl_f,
1910 .fo_poll = devfs_poll_f,
1911 .fo_kqfilter = devfs_kqfilter_f,
1912 .fo_stat = devfs_stat_f,
1913 .fo_close = devfs_close_f,
1914 .fo_chmod = vn_chmod,
1915 .fo_chown = vn_chown,
1916 .fo_sendfile = vn_sendfile,
1918 .fo_fill_kinfo = vn_fill_kinfo,
1919 .fo_mmap = devfs_mmap_f,
1920 .fo_flags = DFLAG_PASSABLE | DFLAG_SEEKABLE
1923 /* Vops for non-CHR vnodes in /dev. */
1924 static struct vop_vector devfs_vnodeops = {
1925 .vop_default = &default_vnodeops,
1927 .vop_access = devfs_access,
1928 .vop_getattr = devfs_getattr,
1929 .vop_ioctl = devfs_rioctl,
1930 .vop_lookup = devfs_lookup,
1931 .vop_mknod = devfs_mknod,
1932 .vop_pathconf = devfs_pathconf,
1933 .vop_read = devfs_rread,
1934 .vop_readdir = devfs_readdir,
1935 .vop_readlink = devfs_readlink,
1936 .vop_reclaim = devfs_reclaim,
1937 .vop_remove = devfs_remove,
1938 .vop_revoke = devfs_revoke,
1939 .vop_setattr = devfs_setattr,
1941 .vop_setlabel = devfs_setlabel,
1943 .vop_symlink = devfs_symlink,
1944 .vop_vptocnp = devfs_vptocnp,
1947 /* Vops for VCHR vnodes in /dev. */
1948 static struct vop_vector devfs_specops = {
1949 .vop_default = &default_vnodeops,
1951 .vop_access = devfs_access,
1952 .vop_bmap = VOP_PANIC,
1953 .vop_close = devfs_close,
1954 .vop_create = VOP_PANIC,
1955 .vop_fsync = vop_stdfsync,
1956 .vop_getattr = devfs_getattr,
1957 .vop_ioctl = devfs_ioctl,
1958 .vop_link = VOP_PANIC,
1959 .vop_mkdir = VOP_PANIC,
1960 .vop_mknod = VOP_PANIC,
1961 .vop_open = devfs_open,
1962 .vop_pathconf = devfs_pathconf,
1963 .vop_poll = dead_poll,
1964 .vop_print = devfs_print,
1965 .vop_read = dead_read,
1966 .vop_readdir = VOP_PANIC,
1967 .vop_readlink = VOP_PANIC,
1968 .vop_reallocblks = VOP_PANIC,
1969 .vop_reclaim = devfs_reclaim_vchr,
1970 .vop_remove = devfs_remove,
1971 .vop_rename = VOP_PANIC,
1972 .vop_revoke = devfs_revoke,
1973 .vop_rmdir = VOP_PANIC,
1974 .vop_setattr = devfs_setattr,
1976 .vop_setlabel = devfs_setlabel,
1978 .vop_strategy = VOP_PANIC,
1979 .vop_symlink = VOP_PANIC,
1980 .vop_vptocnp = devfs_vptocnp,
1981 .vop_write = dead_write,
1985 * Our calling convention to the device drivers used to be that we passed
1986 * vnode.h IO_* flags to read()/write(), but we're moving to fcntl.h O_
1987 * flags instead since that's what open(), close() and ioctl() takes and
1988 * we don't really want vnode.h in device drivers.
1989 * We solved the source compatibility by redefining some vnode flags to
1990 * be the same as the fcntl ones and by sending down the bitwise OR of
1991 * the respective fcntl/vnode flags. These CTASSERTS make sure nobody
1992 * pulls the rug out under this.
1994 CTASSERT(O_NONBLOCK == IO_NDELAY);
1995 CTASSERT(O_FSYNC == IO_SYNC);