cleanup casts, spell DIAGNOSTIC correctly, inode times are now timevals
[unix-history] / usr / src / sys / ufs / ffs / ufs_vnops.c
index 076f951..857c6f2 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ufs_vnops.c 7.79 (Berkeley) %G%
+ *     @(#)ufs_vnops.c 7.86 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -23,6 +23,8 @@
 #include <sys/fifo.h>
 #include <sys/malloc.h>
 
 #include <sys/fifo.h>
 #include <sys/malloc.h>
 
+#include <vm/vm.h>
+
 #include <ufs/ufs/lockf.h>
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
 #include <ufs/ufs/lockf.h>
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
@@ -30,8 +32,9 @@
 #include <ufs/ufs/ufsmount.h>
 #include <ufs/ufs/ufs_extern.h>
 
 #include <ufs/ufs/ufsmount.h>
 #include <ufs/ufs/ufs_extern.h>
 
-int ufs_chmod __P((struct vnode *, int, struct proc *));
-int ufs_chown __P((struct vnode *, u_int, u_int, struct proc *));
+int ufs_chmod __P((struct vnode *, int, struct ucred *, struct proc *));
+int ufs_chown
+       __P((struct vnode *, uid_t, gid_t, struct ucred *, struct proc *));
 
 #ifdef _NOQUAD
 #define        SETHIGH(q, h)   (q).val[_QUAD_HIGHWORD] = (h)
 
 #ifdef _NOQUAD
 #define        SETHIGH(q, h)   (q).val[_QUAD_HIGHWORD] = (h)
@@ -233,12 +236,9 @@ ufs_getattr(vp, vap, cred, p)
 #else
        vap->va_qsize = ip->i_din.di_qsize;
 #endif
 #else
        vap->va_qsize = ip->i_din.di_qsize;
 #endif
-       vap->va_atime.tv_sec = ip->i_atime;
-       vap->va_atime.tv_usec = 0;
-       vap->va_mtime.tv_sec = ip->i_mtime;
-       vap->va_mtime.tv_usec = 0;
-       vap->va_ctime.tv_sec = ip->i_ctime;
-       vap->va_ctime.tv_usec = 0;
+       vap->va_atime = ip->i_atime;
+       vap->va_mtime = ip->i_mtime;
+       vap->va_ctime = ip->i_ctime;
        vap->va_flags = ip->i_flags;
        vap->va_gen = ip->i_gen;
        /* this doesn't belong here */
        vap->va_flags = ip->i_flags;
        vap->va_gen = ip->i_gen;
        /* this doesn't belong here */
@@ -282,13 +282,13 @@ ufs_setattr(vp, vap, cred, p)
        /*
         * Go through the fields and update iff not VNOVAL.
         */
        /*
         * Go through the fields and update iff not VNOVAL.
         */
-       if (vap->va_uid != (u_short)VNOVAL || vap->va_gid != (u_short)VNOVAL)
-               if (error = ufs_chown(vp, vap->va_uid, vap->va_gid, p))
+       if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL)
+               if (error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred, p))
                        return (error);
        if (vap->va_size != VNOVAL) {
                if (vp->v_type == VDIR)
                        return (EISDIR);
                        return (error);
        if (vap->va_size != VNOVAL) {
                if (vp->v_type == VDIR)
                        return (EISDIR);
-               if (error = VOP_TRUNCATE(vp, vap->va_size, 0)) /* IO_SYNC? */
+               if (error = VOP_TRUNCATE(vp, vap->va_size, 0, cred))
                        return (error);
        }
        ip = VTOI(vp);
                        return (error);
        }
        ip = VTOI(vp);
@@ -305,8 +305,8 @@ ufs_setattr(vp, vap, cred, p)
                        return (error);
        }
        error = 0;
                        return (error);
        }
        error = 0;
-       if (vap->va_mode != (u_short)VNOVAL)
-               error = ufs_chmod(vp, (int)vap->va_mode, p);
+       if (vap->va_mode != (mode_t)VNOVAL)
+               error = ufs_chmod(vp, (int)vap->va_mode, cred, p);
        if (vap->va_flags != VNOVAL) {
                if (cred->cr_uid != ip->i_uid &&
                    (error = suser(cred, &p->p_acflag)))
        if (vap->va_flags != VNOVAL) {
                if (cred->cr_uid != ip->i_uid &&
                    (error = suser(cred, &p->p_acflag)))
@@ -327,12 +327,12 @@ ufs_setattr(vp, vap, cred, p)
  * Inode must be locked before calling.
  */
 static int
  * Inode must be locked before calling.
  */
 static int
-ufs_chmod(vp, mode, p)
+ufs_chmod(vp, mode, cred, p)
        register struct vnode *vp;
        register int mode;
        register struct vnode *vp;
        register int mode;
+       register struct ucred *cred;
        struct proc *p;
 {
        struct proc *p;
 {
-       register struct ucred *cred = p->p_ucred;
        register struct inode *ip = VTOI(vp);
        int error;
 
        register struct inode *ip = VTOI(vp);
        int error;
 
@@ -358,14 +358,14 @@ ufs_chmod(vp, mode, p)
  * inode must be locked prior to call.
  */
 static int
  * inode must be locked prior to call.
  */
 static int
-ufs_chown(vp, uid, gid, p)
+ufs_chown(vp, uid, gid, cred, p)
        register struct vnode *vp;
        register struct vnode *vp;
-       u_int uid;
-       u_int gid;
+       uid_t uid;
+       gid_t gid;
+       struct ucred *cred;
        struct proc *p;
 {
        register struct inode *ip = VTOI(vp);
        struct proc *p;
 {
        register struct inode *ip = VTOI(vp);
-       register struct ucred *cred = p->p_ucred;
        uid_t ouid;
        gid_t ogid;
        int error = 0;
        uid_t ouid;
        gid_t ogid;
        int error = 0;
@@ -374,9 +374,9 @@ ufs_chown(vp, uid, gid, p)
        long change;
 #endif
 
        long change;
 #endif
 
-       if (uid == (u_short)VNOVAL)
+       if (uid == (uid_t)VNOVAL)
                uid = ip->i_uid;
                uid = ip->i_uid;
-       if (gid == (u_short)VNOVAL)
+       if (gid == (gid_t)VNOVAL)
                gid = ip->i_gid;
        /*
         * If we don't own the file, are trying to change the owner
                gid = ip->i_gid;
        /*
         * If we don't own the file, are trying to change the owner
@@ -554,20 +554,20 @@ ufs_remove(dvp, vp, cnp)
  * link vnode call
  */
 int
  * link vnode call
  */
 int
-ufs_link(vp, tdvp, cnp)
-       register struct vnode *vp;   /* source vnode */
+ufs_link(tdvp, vp, cnp)
        struct vnode *tdvp;
        struct vnode *tdvp;
+       register struct vnode *vp;   /* source vnode */
        struct componentname *cnp;
 {
        register struct inode *ip;
        int error;
 
        struct componentname *cnp;
 {
        register struct inode *ip;
        int error;
 
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((cnp->cn_flags & HASBUF) == 0)
                panic("ufs_link: no name");
 #endif
        ip = VTOI(vp);
        if ((cnp->cn_flags & HASBUF) == 0)
                panic("ufs_link: no name");
 #endif
        ip = VTOI(vp);
-       if ((unsigned short)ip->i_nlink >= LINK_MAX) {
+       if ((nlink_t)ip->i_nlink >= LINK_MAX) {
                free(cnp->cn_pnbuf, M_NAMEI);
                return (EMLINK);
        }
                free(cnp->cn_pnbuf, M_NAMEI);
                return (EMLINK);
        }
@@ -678,8 +678,7 @@ relookup(dvp, vpp, cnp)
                if (*vpp != NULL)
                        panic("leaf should be empty");
 #endif
                if (*vpp != NULL)
                        panic("leaf should be empty");
 #endif
-               if (cnp->cn_nameiop == LOOKUP || cnp->cn_nameiop == DELETE ||
-                   error != ENOENT)
+               if (error != EJUSTRETURN)
                        goto bad;
                /*
                 * If creating and at end of pathname, then can consider
                        goto bad;
                /*
                 * If creating and at end of pathname, then can consider
@@ -784,7 +783,7 @@ ufs_rename(fdvp, fvp, fcnp,
        int error = 0;
        int fdvpneedsrele = 1, tdvpneedsrele = 1;
 
        int error = 0;
        int fdvpneedsrele = 1, tdvpneedsrele = 1;
 
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((tcnp->cn_flags & HASBUF) == 0 ||
            (fcnp->cn_flags & HASBUF) == 0)
                panic("ufs_rename: no name");
        if ((tcnp->cn_flags & HASBUF) == 0 ||
            (fcnp->cn_flags & HASBUF) == 0)
                panic("ufs_rename: no name");
@@ -896,7 +895,7 @@ ufs_rename(fdvp, fvp, fcnp,
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
                 * parent we don't fool with the link count.
                 */
                if (doingdirectory && newparent) {
-                       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+                       if ((nlink_t)dp->i_nlink >= LINK_MAX) {
                                error = EMLINK;
                                goto bad;
                        }
                                error = EMLINK;
                                goto bad;
                        }
@@ -981,7 +980,8 @@ ufs_rename(fdvp, fvp, fcnp,
                if (doingdirectory) {
                        if (--xp->i_nlink != 0)
                                panic("rename: linked directory");
                if (doingdirectory) {
                        if (--xp->i_nlink != 0)
                                panic("rename: linked directory");
-                       error = VOP_TRUNCATE(ITOV(xp), (u_long)0, IO_SYNC);
+                       error = VOP_TRUNCATE(ITOV(xp), (off_t)0, IO_SYNC,
+                           tcnp->cn_cred);
                }
                xp->i_flag |= ICHG;
                ufs_iput(xp);
                }
                xp->i_flag |= ICHG;
                ufs_iput(xp);
@@ -1041,7 +1041,7 @@ unlinkit:
                                if (dirbuf.dotdot_namlen != 2 ||
                                    dirbuf.dotdot_name[0] != '.' ||
                                    dirbuf.dotdot_name[1] != '.') {
                                if (dirbuf.dotdot_namlen != 2 ||
                                    dirbuf.dotdot_name[0] != '.' ||
                                    dirbuf.dotdot_name[1] != '.') {
-                                       ufs_dirbad(xp, 12,
+                                       ufs_dirbad(xp, (doff_t)12,
                                            "rename: mangled dir");
                                } else {
                                        dirbuf.dotdot_ino = newparent;
                                            "rename: mangled dir");
                                } else {
                                        dirbuf.dotdot_ino = newparent;
@@ -1105,12 +1105,12 @@ ufs_mkdir(dvp, vpp, cnp, vap)
        int error;
        int dmode;
 
        int error;
        int dmode;
 
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((cnp->cn_flags & HASBUF) == 0)
                panic("ufs_mkdir: no name");
 #endif
        dp = VTOI(dvp);
        if ((cnp->cn_flags & HASBUF) == 0)
                panic("ufs_mkdir: no name");
 #endif
        dp = VTOI(dvp);
-       if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+       if ((nlink_t)dp->i_nlink >= LINK_MAX) {
                free(cnp->cn_pnbuf, M_NAMEI);
                ufs_iput(dp);
                return (EMLINK);
                free(cnp->cn_pnbuf, M_NAMEI);
                ufs_iput(dp);
                return (EMLINK);
@@ -1256,7 +1256,7 @@ ufs_rmdir(dvp, vp, cnp)
         * worry about them later.
         */
        ip->i_nlink -= 2;
         * worry about them later.
         */
        ip->i_nlink -= 2;
-       error = VOP_TRUNCATE(vp, (u_long)0, IO_SYNC);
+       error = VOP_TRUNCATE(vp, (off_t)0, IO_SYNC, cnp->cn_cred);
        cache_purge(ITOV(ip));
 out:
        if (dvp)
        cache_purge(ITOV(ip));
 out:
        if (dvp)
@@ -1394,8 +1394,6 @@ ufs_islocked(vp)
  * Calculate the logical to physical mapping if not done already,
  * then call the device strategy routine.
  */
  * Calculate the logical to physical mapping if not done already,
  * then call the device strategy routine.
  */
-int checkoverlap = 0;
-
 int
 ufs_strategy(bp)
        register struct buf *bp;
 int
 ufs_strategy(bp)
        register struct buf *bp;
@@ -1409,8 +1407,12 @@ ufs_strategy(bp)
                panic("ufs_strategy: spec");
        if (bp->b_blkno == bp->b_lblkno) {
                if (error =
                panic("ufs_strategy: spec");
        if (bp->b_blkno == bp->b_lblkno) {
                if (error =
-                   VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno))
+                   VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno)) {
+                       bp->b_error = error;
+                       bp->b_flags |= B_ERROR;
+                       biodone(bp);
                        return (error);
                        return (error);
+               }
                if ((long)bp->b_blkno == -1)
                        clrbuf(bp);
        }
                if ((long)bp->b_blkno == -1)
                        clrbuf(bp);
        }
@@ -1418,11 +1420,6 @@ ufs_strategy(bp)
                biodone(bp);
                return (0);
        }
                biodone(bp);
                return (0);
        }
-#ifdef DIAGNOSTIC
-       if (checkoverlap && bp->b_vp->v_mount->mnt_stat.f_type == MOUNT_UFS)
-               ffs_checkoverlap(bp, ip);
-#endif
-               
        vp = ip->i_devvp;
        bp->b_dev = vp->v_rdev;
        (vp->v_op->vop_strategy)(bp);
        vp = ip->i_devvp;
        bp->b_dev = vp->v_rdev;
        (vp->v_op->vop_strategy)(bp);
@@ -1726,7 +1723,7 @@ ufs_makeinode(mode, dvp, vpp, cnp)
        int error;
 
        pdir = VTOI(dvp);
        int error;
 
        pdir = VTOI(dvp);
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
        if ((cnp->cn_flags & HASBUF) == 0)
                panic("ufs_makeinode: no name");
 #endif
        if ((cnp->cn_flags & HASBUF) == 0)
                panic("ufs_makeinode: no name");
 #endif