BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / ufs / lfs / lfs_inode.c
index 2a8f19f..1a06aa2 100644 (file)
@@ -1,10 +1,36 @@
 /*
 /*
- * Copyright (c) 1986, 1989, 1991 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1986, 1989, 1991, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)lfs_inode.c 7.80 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)lfs_inode.c 8.5 (Berkeley) 12/30/93
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -44,7 +70,7 @@ lfs_ifind(fs, ino, dip)
        register struct dinode *ldip;
 
        for (cnt = INOPB(fs), ldip = dip + (cnt - 1); cnt--; --ldip)
        register struct dinode *ldip;
 
        for (cnt = INOPB(fs), ldip = dip + (cnt - 1); cnt--; --ldip)
-               if (ldip->di_inum == ino)
+               if (ldip->di_inumber == ino)
                        return (ldip);
 
        panic("lfs_ifind: dinode %u not found", ino);
                        return (ldip);
 
        panic("lfs_ifind: dinode %u not found", ino);
@@ -55,8 +81,8 @@ int
 lfs_update(ap)
        struct vop_update_args /* {
                struct vnode *a_vp;
 lfs_update(ap)
        struct vop_update_args /* {
                struct vnode *a_vp;
-               struct timeval *a_ta;
-               struct timeval *a_tm;
+               struct timeval *a_access;
+               struct timeval *a_modify;
                int a_waitfor;
        } */ *ap;
 {
                int a_waitfor;
        } */ *ap;
 {
@@ -66,21 +92,22 @@ lfs_update(ap)
        if (vp->v_mount->mnt_flag & MNT_RDONLY)
                return (0);
        ip = VTOI(vp);
        if (vp->v_mount->mnt_flag & MNT_RDONLY)
                return (0);
        ip = VTOI(vp);
-       if ((ip->i_flag & (IUPD | IACC | ICHG | IMOD)) == 0)
+       if ((ip->i_flag &
+           (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0)
                return (0);
                return (0);
-       if (ip->i_flag & IACC)
-               ip->i_atime.ts_sec = ap->a_ta->tv_sec;
-       if (ip->i_flag & IUPD) {
-               ip->i_mtime.ts_sec = ap->a_tm->tv_sec;
+       if (ip->i_flag & IN_ACCESS)
+               ip->i_atime.ts_sec = ap->a_access->tv_sec;
+       if (ip->i_flag & IN_UPDATE) {
+               ip->i_mtime.ts_sec = ap->a_modify->tv_sec;
                (ip)->i_modrev++;
        }
                (ip)->i_modrev++;
        }
-       if (ip->i_flag & ICHG)
+       if (ip->i_flag & IN_CHANGE)
                ip->i_ctime.ts_sec = time.tv_sec;
                ip->i_ctime.ts_sec = time.tv_sec;
-       ip->i_flag &= ~(IUPD|IACC|ICHG);
+       ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_UPDATE);
 
 
-       if (!(ip->i_flag & IMOD))
+       if (!(ip->i_flag & IN_MODIFIED))
                ++(VFSTOUFS(vp->v_mount)->um_lfs->lfs_uinodes);
                ++(VFSTOUFS(vp->v_mount)->um_lfs->lfs_uinodes);
-       ip->i_flag |= IMOD;
+       ip->i_flag |= IN_MODIFIED;
 
        /* If sync, push back the vnode and any dirty blocks it may have. */
        return (ap->a_waitfor & LFS_SYNC ? lfs_vflush(vp) : 0);
 
        /* If sync, push back the vnode and any dirty blocks it may have. */
        return (ap->a_waitfor & LFS_SYNC ? lfs_vflush(vp) : 0);
@@ -124,7 +151,7 @@ lfs_truncate(ap)
                struct proc *a_p;
        } */ *ap;
 {
                struct proc *a_p;
        } */ *ap;
 {
-       register INDIR *inp;
+       register struct indir *inp;
        register int i;
        register daddr_t *daddrp;
        register struct vnode *vp = ap->a_vp;
        register int i;
        register daddr_t *daddrp;
        register struct vnode *vp = ap->a_vp;
@@ -134,7 +161,7 @@ lfs_truncate(ap)
        struct ifile *ifp;
        struct inode *ip;
        struct lfs *fs;
        struct ifile *ifp;
        struct inode *ip;
        struct lfs *fs;
-       INDIR a[NIADDR + 2], a_end[NIADDR + 2];
+       struct indir a[NIADDR + 2], a_end[NIADDR + 2];
        SEGUSE *sup;
        daddr_t daddr, lastblock, lbn, olastblock;
        long off, a_released, blocksreleased, i_released;
        SEGUSE *sup;
        daddr_t daddr, lastblock, lbn, olastblock;
        long off, a_released, blocksreleased, i_released;
@@ -149,7 +176,7 @@ lfs_truncate(ap)
 #endif
                bzero((char *)&ip->i_shortlink, (u_int)ip->i_size);
                ip->i_size = 0;
 #endif
                bzero((char *)&ip->i_shortlink, (u_int)ip->i_size);
                ip->i_size = 0;
-               ip->i_flag |= ICHG|IUPD;
+               ip->i_flag |= IN_CHANGE | IN_UPDATE;
                return (VOP_UPDATE(vp, &tv, &tv, 0));
        }
        vnode_pager_setsize(vp, (u_long)length);
                return (VOP_UPDATE(vp, &tv, &tv, 0));
        }
        vnode_pager_setsize(vp, (u_long)length);
@@ -158,7 +185,7 @@ lfs_truncate(ap)
 
        /* If length is larger than the file, just update the times. */
        if (ip->i_size <= length) {
 
        /* If length is larger than the file, just update the times. */
        if (ip->i_size <= length) {
-               ip->i_flag |= ICHG|IUPD;
+               ip->i_flag |= IN_CHANGE | IN_UPDATE;
                return (VOP_UPDATE(vp, &tv, &tv, 0));
        }
 
                return (VOP_UPDATE(vp, &tv, &tv, 0));
        }
 
@@ -190,7 +217,7 @@ lfs_truncate(ap)
                ip->i_size = length;
                size = blksize(fs);
                (void)vnode_pager_uncache(vp);
                ip->i_size = length;
                size = blksize(fs);
                (void)vnode_pager_uncache(vp);
-               bzero(bp->b_un.b_addr + offset, (unsigned)(size - offset));
+               bzero((char *)bp->b_data + offset, (u_int)(size - offset));
                allocbuf(bp, size);
                if (e1 = VOP_BWRITE(bp))
                        return (e1);
                allocbuf(bp, size);
                if (e1 = VOP_BWRITE(bp))
                        return (e1);
@@ -204,7 +231,8 @@ lfs_truncate(ap)
        lastseg = -1;
 
        for (lbn = olastblock; lbn >= lastblock;) {
        lastseg = -1;
 
        for (lbn = olastblock; lbn >= lastblock;) {
-               lfs_bmaparray(vp, lbn, &daddr, a, &depth);
+               /* XXX use run length from bmap array to make this faster */
+               ufs_bmaparray(vp, lbn, &daddr, a, &depth, NULL);
                if (lbn == olastblock)
                        for (i = NIADDR + 2; i--;)
                                a_end[i] = a[i];
                if (lbn == olastblock)
                        for (i = NIADDR + 2; i--;)
                                a_end[i] = a[i];
@@ -217,7 +245,7 @@ lfs_truncate(ap)
                        break;
 #ifdef DIAGNOSTIC
                case 1:                         /* An indirect block. */
                        break;
 #ifdef DIAGNOSTIC
                case 1:                         /* An indirect block. */
-                       panic("lfs_truncate: lfs_bmaparray returned depth 1");
+                       panic("lfs_truncate: ufs_bmaparray returned depth 1");
                        /* NOTREACHED */
 #endif
                default:                        /* Chain of indirect blocks. */
                        /* NOTREACHED */
 #endif
                default:                        /* Chain of indirect blocks. */
@@ -233,7 +261,7 @@ lfs_truncate(ap)
                                    inp->in_lbn, fs->lfs_bsize, NOCRED, &bp))
                                        panic("lfs_truncate: bread bno %d",
                                            inp->in_lbn);
                                    inp->in_lbn, fs->lfs_bsize, NOCRED, &bp))
                                        panic("lfs_truncate: bread bno %d",
                                            inp->in_lbn);
-                               daddrp = bp->b_un.b_daddr + inp->in_off;
+                               daddrp = (daddr_t *)bp->b_data + inp->in_off;
                                for (i = inp->in_off;
                                    i++ <= a_end[depth].in_off;) {
                                        daddr = *daddrp++;
                                for (i = inp->in_off;
                                    i++ <= a_end[depth].in_off;) {
                                        daddr = *daddrp++;
@@ -243,8 +271,8 @@ lfs_truncate(ap)
                                if (inp->in_off == 0)
                                        brelse (bp);
                                else {
                                if (inp->in_off == 0)
                                        brelse (bp);
                                else {
-                                       bzero(bp->b_un.b_daddr + inp->in_off,
-                                           fs->lfs_bsize - 
+                                       bzero((daddr_t *)bp->b_data +
+                                           inp->in_off, fs->lfs_bsize - 
                                            inp->in_off * sizeof(daddr_t));
                                        if (e1 = VOP_BWRITE(bp)) 
                                                return (e1);
                                            inp->in_off * sizeof(daddr_t));
                                        if (e1 = VOP_BWRITE(bp)) 
                                                return (e1);
@@ -275,12 +303,14 @@ lfs_truncate(ap)
        }
 
 #ifdef DIAGNOSTIC
        }
 
 #ifdef DIAGNOSTIC
-       if (ip->i_blocks < fsbtodb(fs, blocksreleased))
-               panic("lfs_truncate: block count < 0");
+       if (ip->i_blocks < fsbtodb(fs, blocksreleased)) {
+               printf("lfs_truncate: block count < 0\n");
+               blocksreleased = ip->i_blocks;
+       }
 #endif
        ip->i_blocks -= fsbtodb(fs, blocksreleased);
        fs->lfs_bfree +=  fsbtodb(fs, blocksreleased);
 #endif
        ip->i_blocks -= fsbtodb(fs, blocksreleased);
        fs->lfs_bfree +=  fsbtodb(fs, blocksreleased);
-       ip->i_flag |= ICHG|IUPD;
+       ip->i_flag |= IN_CHANGE | IN_UPDATE;
        /*
         * Traverse dirty block list counting number of dirty buffers
         * that are being deleted out of the cache, so that the lfs_avail
        /*
         * Traverse dirty block list counting number of dirty buffers
         * that are being deleted out of the cache, so that the lfs_avail
@@ -288,7 +318,7 @@ lfs_truncate(ap)
         */
        a_released = 0;
        i_released = 0;
         */
        a_released = 0;
        i_released = 0;
-       for (bp = vp->v_dirtyblkhd; bp; bp = bp->b_blockf)
+       for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = bp->b_vnbufs.le_next)
                if (bp->b_flags & B_LOCKED) {
                        ++a_released;
                        /*
                if (bp->b_flags & B_LOCKED) {
                        ++a_released;
                        /*
@@ -321,8 +351,9 @@ lfs_truncate(ap)
                    "Truncation to zero, but ", ip->i_blocks,
                    " blocks left on inode");
 #endif
                    "Truncation to zero, but ", ip->i_blocks,
                    " blocks left on inode");
 #endif
-       fs->lfs_avail -= fsbtodb(fs, a_released);
-       e1 = vinvalbuf(vp, length > 0, ap->a_cred, ap->a_p); 
+       fs->lfs_avail += fsbtodb(fs, a_released);
+       e1 = vinvalbuf(vp, (length > 0) ? V_SAVE : 0, ap->a_cred, ap->a_p,
+           0, 0); 
        e2 = VOP_UPDATE(vp, &tv, &tv, 0);
        return (e1 ? e1 : e2 ? e2 : 0);
 }
        e2 = VOP_UPDATE(vp, &tv, &tv, 0);
        return (e1 ? e1 : e2 ? e2 : 0);
 }