X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/2e3baa4b6975b729fc075fa072898e1dffa0ee3a..2e5be88b389bf38136ff973468fbdc768d385fec:/usr/src/sys/kern/vfs_vnops.c diff --git a/usr/src/sys/kern/vfs_vnops.c b/usr/src/sys/kern/vfs_vnops.c index 1fc024d97a..2662c2eec7 100644 --- a/usr/src/sys/kern/vfs_vnops.c +++ b/usr/src/sys/kern/vfs_vnops.c @@ -14,7 +14,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * @(#)vfs_vnops.c 7.10 (Berkeley) %G% + * @(#)vfs_vnops.c 7.20 (Berkeley) %G% */ #include "param.h" @@ -30,8 +30,6 @@ #include "socketvar.h" #include "mount.h" #include "vnode.h" -#include "../ufs/fs.h" -#include "../ufs/quota.h" #include "ioctl.h" #include "tty.h" @@ -59,7 +57,7 @@ vn_open(ndp, fmode, cmode) if (error = namei(ndp)) return (error); if (ndp->ni_vp == NULL) { - vattr_null(vap); + VATTR_NULL(vap); vap->va_type = VREG; vap->va_mode = cmode; if (error = VOP_CREATE(ndp, vap)) @@ -67,10 +65,12 @@ vn_open(ndp, fmode, cmode) fmode &= ~FTRUNC; vp = ndp->ni_vp; } else { + if (ndp->ni_dvp == ndp->ni_vp) + vrele(ndp->ni_dvp); + else if (ndp->ni_dvp != NULL) + vput(ndp->ni_dvp); + ndp->ni_dvp = NULL; vp = ndp->ni_vp; - ndp->ni_vp = 0; - VOP_ABORTOP(ndp); - ndp->ni_vp = vp; if (fmode & FEXCL) { error = EEXIST; goto bad; @@ -103,17 +103,12 @@ vn_open(ndp, fmode, cmode) } } if (fmode & FTRUNC) { - vattr_null(vap); + VATTR_NULL(vap); vap->va_size = 0; if (error = VOP_SETATTR(vp, vap, ndp->ni_cred)) goto bad; } VOP_UNLOCK(vp); - if (setjmp(&u.u_qsave)) { - if (error == 0) - error = EINTR; - return (error); - } error = VOP_OPEN(vp, fmode, ndp->ni_cred); if (error) vrele(vp); @@ -121,7 +116,7 @@ vn_open(ndp, fmode, cmode) bad: vput(vp); - return(error); + return (error); } /* @@ -138,7 +133,7 @@ vn_writechk(vp) * unless the file is a socket or a block or character * device resident on the file system. */ - if ((vp->v_mount->m_flag & M_RDONLY) && vp->v_type != VCHR && + if ((vp->v_mount->mnt_flag & MNT_RDONLY) && vp->v_type != VCHR && vp->v_type != VBLK && vp->v_type != VSOCK) return (EROFS); /* @@ -171,6 +166,8 @@ vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, cred, aresid) 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; @@ -180,14 +177,16 @@ vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, cred, aresid) auio.uio_segflg = segflg; auio.uio_rw = rw; if (rw == UIO_READ) - error = VOP_READ(vp, &auio, &offset, ioflg, cred); + error = VOP_READ(vp, &auio, ioflg, cred); else - error = VOP_WRITE(vp, &auio, &offset, ioflg, cred); + 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); } @@ -196,9 +195,16 @@ vn_read(fp, uio, cred) struct uio *uio; struct ucred *cred; { + register struct vnode *vp = (struct vnode *)fp->f_data; + int count, error; - return (VOP_READ((struct vnode *)fp->f_data, uio, &(fp->f_offset), - (fp->f_flag & FNDELAY) ? IO_NDELAY : 0, cred)); + 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) @@ -207,13 +213,22 @@ vn_write(fp, uio, cred) struct ucred *cred; { register struct vnode *vp = (struct vnode *)fp->f_data; - int ioflag = 0; + 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; - return (VOP_WRITE(vp, uio, &(fp->f_offset), ioflag, cred)); + 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); } /* @@ -257,6 +272,9 @@ vn_stat(vp, sb) case VSOCK: mode |= S_IFSOCK; break; + case VFIFO: + mode |= S_IFIFO; + break; default: return (EBADF); }; @@ -308,16 +326,16 @@ vn_ioctl(fp, com, data) default: return (ENOTTY); + case VFIFO: case VCHR: case VBLK: u.u_r.r_val1 = 0; - if (setjmp(&u.u_qsave)) { - if ((u.u_sigintr & sigmask(u.u_procp->p_cursig)) != 0) - return(EINTR); - u.u_eosys = RESTARTSYS; - return (0); + error = VOP_IOCTL(vp, com, data, fp->f_flag, u.u_cred); + if (error == 0 && com == TIOCSCTTY) { + u.u_procp->p_session->s_ttyvp = vp; + VREF(vp); } - return (VOP_IOCTL(vp, com, data, fp->f_flag, u.u_cred)); + return (error); } } @@ -328,7 +346,8 @@ vn_select(fp, which) struct file *fp; int which; { - return(VOP_SELECT(((struct vnode *)fp->f_data), which, u.u_cred)); + return (VOP_SELECT(((struct vnode *)fp->f_data), which, fp->f_flag, + u.u_cred)); } /* @@ -363,15 +382,13 @@ vn_lock(fp, cmd) { register int priority = PLOCK; register struct vnode *vp = (struct vnode *)fp->f_data; + int error = 0; + static char lockstr[] = "flock"; if ((cmd & LOCK_EX) == 0) priority += 4; - if (setjmp(&u.u_qsave)) { - if ((u.u_sigintr & sigmask(u.u_procp->p_cursig)) != 0) - return(EINTR); - u.u_eosys = RESTARTSYS; - return (0); - } + priority |= PCATCH; + /* * If there's a exclusive lock currently applied * to the file, then we've gotta wait for the @@ -390,9 +407,11 @@ again: if (cmd & LOCK_NB) return (EWOULDBLOCK); vp->v_flag |= VLWAIT; - sleep((caddr_t)&vp->v_exlockc, priority); + if (error = tsleep((caddr_t)&vp->v_exlockc, priority, + lockstr, 0)) + return (error); } - if ((cmd & LOCK_EX) && (vp->v_flag & VSHLOCK)) { + if (error = 0 && (cmd & LOCK_EX) && (vp->v_flag & VSHLOCK)) { /* * Must wait for any shared locks to finish * before we try to apply a exclusive lock. @@ -407,8 +426,9 @@ again: if (cmd & LOCK_NB) return (EWOULDBLOCK); vp->v_flag |= VLWAIT; - sleep((caddr_t)&vp->v_shlockc, PLOCK); - goto again; + if (error = tsleep((caddr_t)&vp->v_shlockc, PLOCK | PCATCH, + lockstr, 0) == 0) + return (error); } if (fp->f_flag & FEXLOCK) panic("vn_lock"); @@ -484,47 +504,6 @@ vn_fhtovp(fhp, lockflag, vpp) return (0); } -/* - * Revoke access the current tty by all processes. - * Used only by the super-user in init - * to give ``clean'' terminals at login. - */ -vhangup() -{ - - if (u.u_error = suser(u.u_cred, &u.u_acflag)) - return; - if (u.u_ttyp == NULL) - return; - forceclose(u.u_ttyd); - if ((u.u_ttyp->t_state) & TS_ISOPEN) - gsignal(u.u_ttyp->t_pgid, SIGHUP); - u.u_ttyp->t_session = 0; - u.u_ttyp->t_pgid = 0; -} - -forceclose(dev) - dev_t dev; -{ - register struct file *fp; - register struct vnode *vp; - - for (fp = file; fp < fileNFILE; fp++) { - if (fp->f_count == 0) - continue; - if (fp->f_type != DTYPE_VNODE) - continue; - vp = (struct vnode *)fp->f_data; - if (vp == 0) - continue; - if (vp->v_type != VCHR) - continue; - if (vp->v_rdev != dev) - continue; - fp->f_flag &= ~(FREAD|FWRITE); - } -} - /* * Noop */