+ }
+ VOP_UNLOCK(vp);
+ error = VOP_OPEN(vp, fmode, ndp->ni_cred);
+ if (error)
+ vrele(vp);
+ return (error);
+
+bad:
+ vput(vp);
+ return (error);
+}
+
+/*
+ * Check for write permissions on the specified vnode.
+ * The read-only status of the file system is checked.
+ * Also, prototype text segments cannot be written.
+ */
+vn_writechk(vp)
+ register struct vnode *vp;
+{
+
+ /*
+ * Disallow write attempts on read-only file systems;
+ * unless the file is a socket or a block or character
+ * device resident on the file system.
+ */
+ if ((vp->v_mount->mnt_flag & MNT_RDONLY) && vp->v_type != VCHR &&
+ vp->v_type != VBLK && vp->v_type != VSOCK)
+ return (EROFS);
+ /*
+ * If there's shared text associated with
+ * the vnode, try to free it up once. If
+ * we fail, we can't allow writing.
+ */
+ if (vp->v_flag & VTEXT)
+ xrele(vp);
+ if (vp->v_flag & VTEXT)
+ return (ETXTBSY);
+ return (0);
+}
+
+/*
+ * Vnode version of rdwri() for calls on file systems.
+ */
+vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, cred, aresid)
+ enum uio_rw rw;
+ struct vnode *vp;
+ caddr_t base;
+ int len;
+ off_t offset;
+ enum uio_seg segflg;
+ int ioflg;
+ struct ucred *cred;
+ int *aresid;
+{
+ struct uio auio;
+ struct iovec aiov;
+ int error;
+
+ if ((ioflg & IO_NODELOCKED) == 0)
+ VOP_LOCK(vp);
+ auio.uio_iov = &aiov;
+ auio.uio_iovcnt = 1;
+ aiov.iov_base = base;
+ aiov.iov_len = len;
+ auio.uio_resid = len;
+ auio.uio_offset = offset;
+ auio.uio_segflg = segflg;
+ auio.uio_rw = rw;
+ if (rw == UIO_READ)
+ error = VOP_READ(vp, &auio, ioflg, cred);
+ else
+ error = VOP_WRITE(vp, &auio, ioflg, cred);
+ if (aresid)
+ *aresid = auio.uio_resid;
+ else
+ if (auio.uio_resid && error == 0)
+ error = EIO;
+ if ((ioflg & IO_NODELOCKED) == 0)
+ VOP_UNLOCK(vp);
+ return (error);
+}
+
+vn_read(fp, uio, cred)
+ struct file *fp;
+ struct uio *uio;
+ struct ucred *cred;
+{
+ register struct vnode *vp = (struct vnode *)fp->f_data;
+ int count, error;
+
+ VOP_LOCK(vp);
+ uio->uio_offset = fp->f_offset;
+ count = uio->uio_resid;
+ error = VOP_READ(vp, uio, (fp->f_flag & FNDELAY) ? IO_NDELAY : 0, cred);
+ fp->f_offset += count - uio->uio_resid;
+ VOP_UNLOCK(vp);
+ return (error);
+}
+
+vn_write(fp, uio, cred)
+ struct file *fp;
+ struct uio *uio;
+ struct ucred *cred;
+{
+ register struct vnode *vp = (struct vnode *)fp->f_data;
+ int count, error, ioflag = 0;
+
+ if (vp->v_type == VREG && (fp->f_flag & FAPPEND))
+ ioflag |= IO_APPEND;
+ if (fp->f_flag & FNDELAY)
+ ioflag |= IO_NDELAY;
+ VOP_LOCK(vp);
+ uio->uio_offset = fp->f_offset;
+ count = uio->uio_resid;
+ error = VOP_WRITE(vp, uio, ioflag, cred);
+ if (ioflag & IO_APPEND)
+ fp->f_offset = uio->uio_offset;
+ else
+ fp->f_offset += count - uio->uio_resid;
+ VOP_UNLOCK(vp);
+ return (error);
+}
+
+/*
+ * Get stat info for a vnode.
+ */
+vn_stat(vp, sb)
+ struct vnode *vp;
+ register struct stat *sb;
+{
+ struct vattr vattr;
+ register struct vattr *vap;
+ int error;
+ u_short mode;
+
+ vap = &vattr;
+ error = VOP_GETATTR(vp, vap, u.u_cred);
+ if (error)
+ return (error);
+ /*
+ * Copy from vattr table
+ */
+ sb->st_dev = vap->va_fsid;
+ sb->st_ino = vap->va_fileid;
+ mode = vap->va_mode;
+ switch (vp->v_type) {
+ case VREG:
+ mode |= S_IFREG;
+ break;
+ case VDIR:
+ mode |= S_IFDIR;
+ break;
+ case VBLK:
+ mode |= S_IFBLK;
+ break;
+ case VCHR:
+ mode |= S_IFCHR;
+ break;
+ case VLNK:
+ mode |= S_IFLNK;
+ break;
+ case VSOCK:
+ mode |= S_IFSOCK;
+ break;
+ case VFIFO:
+ mode |= S_IFIFO;