check for negative bytes in seguse update; increment version number
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 30 Jul 1992 08:15:01 +0000 (00:15 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 30 Jul 1992 08:15:01 +0000 (00:15 -0800)
after blocks are free (for the cleaner)

SCCS-vsn: sys/ufs/lfs/lfs_inode.c 7.76

usr/src/sys/ufs/lfs/lfs_inode.c

index 3d8ef70..0cafea6 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_inode.c 7.75 (Berkeley) %G%
+ *     @(#)lfs_inode.c 7.76 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -95,6 +95,9 @@ lfs_update(ap)
 #define UPDATE_SEGUSE \
        if (lastseg != -1) { \
                LFS_SEGENTRY(sup, fs, lastseg, sup_bp); \
 #define UPDATE_SEGUSE \
        if (lastseg != -1) { \
                LFS_SEGENTRY(sup, fs, lastseg, sup_bp); \
+               if ((num << fs->lfs_bshift) > sup->su_nbytes) \
+                       panic("lfs_truncate: negative bytes in segment %d\n", \
+                           lastseg); \
                sup->su_nbytes -= num << fs->lfs_bshift; \
                LFS_UBWRITE(sup_bp); \
                blocksreleased += num; \
                sup->su_nbytes -= num << fs->lfs_bshift; \
                LFS_UBWRITE(sup_bp); \
                blocksreleased += num; \
@@ -161,13 +164,6 @@ lfs_truncate(ap)
 
        fs = ip->i_lfs;
 
 
        fs = ip->i_lfs;
 
-       /* If truncating the file to 0, update the version number. */
-       if (length == 0) {
-               LFS_IENTRY(ifp, fs, ip->i_number, bp);
-               ++ifp->if_version;
-               LFS_UBWRITE(bp);
-       }
-
        /* If length is larger than the file, just update the times. */
        if (ip->i_size <= length) {
                ip->i_flag |= ICHG|IUPD;
        /* If length is larger than the file, just update the times. */
        if (ip->i_size <= length) {
                ip->i_flag |= ICHG|IUPD;
@@ -282,6 +278,14 @@ lfs_truncate(ap)
                }
        }
        UPDATE_SEGUSE;
                }
        }
        UPDATE_SEGUSE;
+
+       /* If truncating the file to 0, update the version number. */
+       if (length == 0) {
+               LFS_IENTRY(ifp, fs, ip->i_number, bp);
+               ++ifp->if_version;
+               LFS_UBWRITE(bp);
+       }
+
        ip->i_blocks -= btodb(blocksreleased << fs->lfs_bshift);
        fs->lfs_bfree +=  btodb(blocksreleased << fs->lfs_bshift);
 #ifdef DIAGNOSTIC
        ip->i_blocks -= btodb(blocksreleased << fs->lfs_bshift);
        fs->lfs_bfree +=  btodb(blocksreleased << fs->lfs_bshift);
 #ifdef DIAGNOSTIC