Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Fix assorted 64 -> 32 truncations in lfs. Also, some minor t...



details:   https://anonhg.NetBSD.org/src/rev/fff3bcb55900
branches:  trunk
changeset: 339658:fff3bcb55900
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Aug 02 18:08:12 2015 +0000

description:
Fix assorted 64 -> 32 truncations in lfs. Also, some minor tidyups and
corrections in passing.

diffstat:

 sbin/fsck_lfs/lfs.c         |   4 +-
 sbin/fsck_lfs/pass5.c       |  18 +++++-----
 sbin/fsck_lfs/pass6.c       |   4 +-
 sbin/newfs_lfs/make_lfs.c   |  15 +++++----
 sbin/scan_ffs/scan_ffs.c    |  12 +++---
 sys/ufs/lfs/lfs.h           |   7 ++-
 sys/ufs/lfs/lfs_accessors.h |  69 +++++++++++++++++++++++++++++++++-----------
 sys/ufs/lfs/lfs_balloc.c    |  10 +++---
 sys/ufs/lfs/lfs_bio.c       |  11 +++---
 sys/ufs/lfs/lfs_debug.c     |  16 +++++-----
 sys/ufs/lfs/lfs_inode.c     |  21 +++++++-----
 sys/ufs/lfs/lfs_vfsops.c    |  13 +++++++-
 usr.sbin/dumplfs/dumplfs.c  |  18 +++++-----
 13 files changed, 133 insertions(+), 85 deletions(-)

diffs (truncated from 632 to 300 lines):

diff -r 8da257a5cdae -r fff3bcb55900 sbin/fsck_lfs/lfs.c
--- a/sbin/fsck_lfs/lfs.c       Sun Aug 02 17:57:27 2015 +0000
+++ b/sbin/fsck_lfs/lfs.c       Sun Aug 02 18:08:12 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.c,v 1.48 2015/07/28 05:09:34 dholland Exp $ */
+/* $NetBSD: lfs.c,v 1.49 2015/08/02 18:08:12 dholland Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -72,8 +72,8 @@
 
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_inode.h>
 #include <ufs/lfs/lfs_accessors.h>
-#include <ufs/lfs/lfs_inode.h>
 #undef vnode
 
 #include <assert.h>
diff -r 8da257a5cdae -r fff3bcb55900 sbin/fsck_lfs/pass5.c
--- a/sbin/fsck_lfs/pass5.c     Sun Aug 02 17:57:27 2015 +0000
+++ b/sbin/fsck_lfs/pass5.c     Sun Aug 02 18:08:12 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pass5.c,v 1.32 2015/07/28 05:09:34 dholland Exp $   */
+/* $NetBSD: pass5.c,v 1.33 2015/08/02 18:08:12 dholland Exp $   */
 
 /*-
  * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
@@ -60,9 +60,9 @@
        SEGUSE *su;
        struct ubuf *bp;
        int i;
-       unsigned long bb;       /* total number of used blocks (lower bound) */
-       unsigned long ubb;      /* upper bound number of used blocks */
-       unsigned long avail;    /* blocks available for writing */
+       daddr_t bb;             /* total number of used blocks (lower bound) */
+       daddr_t ubb;            /* upper bound number of used blocks */
+       daddr_t avail;          /* blocks available for writing */
        unsigned long dmeta;    /* blocks in segsums and inodes */
        int nclean;             /* clean segments */
        size_t labelskew;
@@ -152,8 +152,8 @@
                }
        }
        if (avail != lfs_sb_getavail(fs)) {
-               pwarn("AVAIL GIVEN AS %d, SHOULD BE %ld\n",
-                     lfs_sb_getavail(fs), avail);
+               pwarn("AVAIL GIVEN AS %jd, SHOULD BE %ld\n",
+                     (intmax_t)lfs_sb_getavail(fs), avail);
                if (preen || reply("FIX")) {
                        lfs_sb_setavail(fs, avail);
                        sbdirty();
@@ -174,10 +174,10 @@
                labelskew = lfs_btofsb(fs, LFS_LABELPAD);
        if (lfs_sb_getbfree(fs) > lfs_sb_getdsize(fs) - bb - labelskew ||
            lfs_sb_getbfree(fs) < lfs_sb_getdsize(fs) - ubb - labelskew) {
-               pwarn("BFREE GIVEN AS %jd, SHOULD BE BETWEEN %ld AND %ld\n",
+               pwarn("BFREE GIVEN AS %jd, SHOULD BE BETWEEN %jd AND %jd\n",
                    (intmax_t)lfs_sb_getbfree(fs),
-                   lfs_sb_getdsize(fs) - ubb - labelskew,
-                   lfs_sb_getdsize(fs) - bb - labelskew);
+                   (intmax_t)(lfs_sb_getdsize(fs) - ubb - labelskew),
+                   (intmax_t)(lfs_sb_getdsize(fs) - bb - labelskew));
                if (preen || reply("FIX")) {
                        lfs_sb_setbfree(fs,
                                ((lfs_sb_getdsize(fs) - labelskew - ubb) +
diff -r 8da257a5cdae -r fff3bcb55900 sbin/fsck_lfs/pass6.c
--- a/sbin/fsck_lfs/pass6.c     Sun Aug 02 17:57:27 2015 +0000
+++ b/sbin/fsck_lfs/pass6.c     Sun Aug 02 18:08:12 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pass6.c,v 1.37 2015/07/28 05:09:34 dholland Exp $   */
+/* $NetBSD: pass6.c,v 1.38 2015/08/02 18:08:12 dholland Exp $   */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  * Account for this change in the segment table.
  */
 static void
-rfw_update_single(struct uvnode *vp, daddr_t lbn, ulfs_daddr_t ndaddr, int size)
+rfw_update_single(struct uvnode *vp, daddr_t lbn, ulfs_daddr_t ndaddr, size_t size)
 {
        SEGUSE *sup;
        struct ubuf *bp;
diff -r 8da257a5cdae -r fff3bcb55900 sbin/newfs_lfs/make_lfs.c
--- a/sbin/newfs_lfs/make_lfs.c Sun Aug 02 17:57:27 2015 +0000
+++ b/sbin/newfs_lfs/make_lfs.c Sun Aug 02 18:08:12 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make_lfs.c,v 1.34 2015/07/28 05:09:34 dholland Exp $   */
+/*     $NetBSD: make_lfs.c,v 1.35 2015/08/02 18:08:12 dholland Exp $   */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "@(#)lfs.c      8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: make_lfs.c,v 1.34 2015/07/28 05:09:34 dholland Exp $");
+__RCSID("$NetBSD: make_lfs.c,v 1.35 2015/08/02 18:08:12 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -320,7 +320,8 @@
        char tbuf[BUFSIZ];
        struct ubuf *bp;
        struct uvnode *vp, *save_devvp;
-       int bb, ubb, dmeta, labelskew;
+       daddr_t bb, ubb;
+       int dmeta, labelskew;
        u_int64_t tsepb, tnseg;
        time_t stamp;
 
@@ -543,8 +544,8 @@
         * and segment usage table, and half a block per segment that can't
         * be written due to fragmentation.
         */
-       lfs_sb_setdsize(fs, (lfs_sb_getnseg(fs) - lfs_sb_getminfreeseg(fs)) *
-               lfs_segtod(fs, 1));
+       lfs_sb_setdsize(fs,
+               lfs_segtod(fs, lfs_sb_getnseg(fs) - lfs_sb_getminfreeseg(fs)));
        lfs_sb_setbfree(fs, lfs_sb_getdsize(fs));
        lfs_sb_subbfree(fs, LFS_DBTOFSB(fs, ((lfs_sb_getnseg(fs) / 2) << 
                lfs_sb_getblktodb(fs))));
@@ -582,7 +583,7 @@
                lfs_sb_sets0addr(fs, lfs_sb_getsboff(fs, 0));
        else
                lfs_sb_sets0addr(fs, LFS_DBTOFSB(fs, start));
-        lfs_sb_setdsize(fs, lfs_sb_getdsize(fs) - sb_fsb);
+        lfs_sb_subdsize(fs, sb_fsb);
        for (i = 1; i < LFS_MAXNUMSB; i++) {
                sb_addr = ((i * sb_interval) * lfs_segtod(fs, 1))
                    + lfs_sb_getsboff(fs, 0);
@@ -593,7 +594,7 @@
                    >= LFS_DBTOFSB(fs, dkw->dkw_size))
                        break;
                lfs_sb_setsboff(fs, i, sb_addr);
-               lfs_sb_setdsize(fs, lfs_sb_getdsize(fs) - sb_fsb);
+               lfs_sb_subdsize(fs, sb_fsb);
        }
 
        /* We need >= 2 superblocks */
diff -r 8da257a5cdae -r fff3bcb55900 sbin/scan_ffs/scan_ffs.c
--- a/sbin/scan_ffs/scan_ffs.c  Sun Aug 02 17:57:27 2015 +0000
+++ b/sbin/scan_ffs/scan_ffs.c  Sun Aug 02 18:08:12 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: scan_ffs.c,v 1.28 2015/07/28 05:09:35 dholland Exp $ */
+/* $NetBSD: scan_ffs.c,v 1.29 2015/08/02 18:08:12 dholland Exp $ */
 
 /*
  * Copyright (c) 2005-2007 Juan Romero Pardines
@@ -33,7 +33,7 @@
  
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: scan_ffs.c,v 1.28 2015/07/28 05:09:35 dholland Exp $");
+__RCSID("$NetBSD: scan_ffs.c,v 1.29 2015/08/02 18:08:12 dholland Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -249,14 +249,14 @@
 lfs_printpart(struct sblockinfo *sbi, int flag, int n)
 {
        if (flags & VERBOSE)
-                       (void)printf("offset: %" PRIu64 " size %" PRIu32
+                       (void)printf("offset: %" PRIu64 " size %" PRIu64
                        " fsid %" PRIx32 "\n", sbi->lfs_off,
                        lfs_sb_getsize(sbi->lfs),
                        lfs_sb_getident(sbi->lfs));
        switch (flag) {
        case LABELS:
                (void)printf("X:  %9" PRIu64,
-                               (uint64_t)(lfs_sb_getsize(sbi->lfs) *
+                               (lfs_sb_getsize(sbi->lfs) *
                                lfs_sb_getfsize(sbi->lfs) / 512));
                (void)printf(" %9" PRIu64, sbi->lfs_off); 
                (void)printf(" 4.4LFS %6d %5d %7d # %s [LFSv%d]\n",
@@ -269,14 +269,14 @@
                (void)printf(" sb at %" PRIu64, sbi->lfs_off + btodb(LFS_LABELPAD));
                (void)printf(" fsid %" PRIx32, lfs_sb_getident(sbi->lfs));
                (void)printf(" size %" PRIu64 ", last mounted on %s\n",
-                       (uint64_t)(lfs_sb_getsize(sbi->lfs) *
+                       (lfs_sb_getsize(sbi->lfs) *
                        lfs_sb_getfsize(sbi->lfs) / 512), sbi->lfs_path);
                break;
        default:
                (void)printf("LFSv%d ", sbi->lfs->lfs_version);
                (void)printf("at %" PRIu64, sbi->lfs_off);
                (void)printf(" size %" PRIu64 ", last mounted on %s\n",
-                       (uint64_t)(lfs_sb_getsize(sbi->lfs) *
+                       (lfs_sb_getsize(sbi->lfs) *
                        lfs_sb_getfsize(sbi->lfs) / 512), sbi->lfs_path);
                break;
        }
diff -r 8da257a5cdae -r fff3bcb55900 sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Sun Aug 02 17:57:27 2015 +0000
+++ b/sys/ufs/lfs/lfs.h Sun Aug 02 18:08:12 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs.h,v 1.167 2015/07/28 05:13:14 dholland Exp $       */
+/*     $NetBSD: lfs.h,v 1.168 2015/08/02 18:08:13 dholland Exp $       */
 
 /*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp  */
@@ -516,6 +516,7 @@
 typedef struct _cleanerinfo {
        u_int32_t clean;                /* number of clean segments */
        u_int32_t dirty;                /* number of dirty segments */
+       /* XXX64 bfree and avail must -> 64 */
        int32_t   bfree;                /* disk blocks free */
        int32_t   avail;                /* disk blocks available */
        u_int32_t free_head;            /* head of the inode free list */
@@ -587,7 +588,7 @@
 
 /* Checkpoint region. */
        u_int32_t dlfs_freehd;    /* 32: start of the free list */
-       int32_t   dlfs_bfree;     /* 36: number of free disk blocks */
+       int32_t   dlfs_bfree;     /* 36: number of free frags */
        u_int32_t dlfs_nfiles;    /* 40: number of allocated inodes */
        int32_t   dlfs_avail;     /* 44: blocks available for writing */
        int32_t   dlfs_uinodes;   /* 48: inodes in cache not yet on disk */
@@ -605,7 +606,7 @@
 
 /* These fields can be computed from the others. */
        u_int64_t dlfs_maxfilesize; /* 88: maximum representable file size */
-       u_int32_t dlfs_fsbpseg;     /* 96: fsb per segment */
+       u_int32_t dlfs_fsbpseg;     /* 96: frags (fsb) per segment */
        u_int32_t dlfs_inopb;     /* 100: inodes per block */
        u_int32_t dlfs_ifpb;      /* 104: IFILE entries per block */
        u_int32_t dlfs_sepb;      /* 108: SEGUSE entries per block */
diff -r 8da257a5cdae -r fff3bcb55900 sys/ufs/lfs/lfs_accessors.h
--- a/sys/ufs/lfs/lfs_accessors.h       Sun Aug 02 17:57:27 2015 +0000
+++ b/sys/ufs/lfs/lfs_accessors.h       Sun Aug 02 18:08:12 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_accessors.h,v 1.3 2015/08/02 17:57:27 dholland Exp $       */
+/*     $NetBSD: lfs_accessors.h,v 1.4 2015/08/02 18:08:13 dholland Exp $       */
 
 /*  from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp  */
 /*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
@@ -418,14 +418,14 @@
 #define lfs_version lfs_dlfs.dlfs_version
 LFS_DEF_SB_ACCESSOR_FULL(u_int64_t, u_int32_t, size);
 LFS_DEF_SB_ACCESSOR(u_int32_t, ssize);
-LFS_DEF_SB_ACCESSOR(u_int32_t, dsize);
+LFS_DEF_SB_ACCESSOR_FULL(u_int64_t, u_int32_t, dsize);
 LFS_DEF_SB_ACCESSOR(u_int32_t, bsize);
 LFS_DEF_SB_ACCESSOR(u_int32_t, fsize);
 LFS_DEF_SB_ACCESSOR(u_int32_t, frag);
 LFS_DEF_SB_ACCESSOR(u_int32_t, freehd);
-LFS_DEF_SB_ACCESSOR(int32_t, bfree);
+LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, bfree);
 LFS_DEF_SB_ACCESSOR(u_int32_t, nfiles);
-LFS_DEF_SB_ACCESSOR(int32_t, avail);
+LFS_DEF_SB_ACCESSOR_FULL(int64_t, int32_t, avail);
 LFS_DEF_SB_ACCESSOR(int32_t, uinodes);
 LFS_DEF_SB_ACCESSOR(int32_t, idaddr);
 LFS_DEF_SB_ACCESSOR(u_int32_t, ifile);
@@ -518,27 +518,47 @@
 /* LFS_INOPF is the number of inodes in a fragment. */
 #define LFS_INOPF(fs)  (lfs_sb_getinopf(fs))
 
-#define        lfs_blksize(fs, ip, lbn) \
-       (((lbn) >= ULFS_NDADDR || (ip)->i_ffs1_size >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
-           ? lfs_sb_getbsize(fs) \
-           : (lfs_fragroundup(fs, lfs_blkoff(fs, (ip)->i_ffs1_size))))
 #define        lfs_blkoff(fs, loc)     ((int)((loc) & lfs_sb_getbmask(fs)))
 #define lfs_fragoff(fs, loc)    /* calculates (loc % fs->lfs_fsize) */ \
     ((int)((loc) & lfs_sb_getffmask(fs)))
 
+/* XXX: lowercase these as they're no longer macros */
+/* Frags to diskblocks */
+static __unused inline uint64_t
+LFS_FSBTODB(STRUCT_LFS *fs, uint64_t b)
+{
 #if defined(_KERNEL)
-#define        LFS_FSBTODB(fs, b)      ((b) << (lfs_sb_getffshift(fs) - DEV_BSHIFT))
-#define        LFS_DBTOFSB(fs, b)      ((b) >> (lfs_sb_getffshift(fs) - DEV_BSHIFT))
+       return b << (lfs_sb_getffshift(fs) - DEV_BSHIFT);
 #else
-#define        LFS_FSBTODB(fs, b)      ((b) << lfs_sb_getfsbtodb(fs))
-#define        LFS_DBTOFSB(fs, b)      ((b) >> lfs_sb_getfsbtodb(fs))
+       return b << lfs_sb_getfsbtodb(fs);
 #endif
+}
+/* Diskblocks to frags */
+static __unused inline uint64_t
+LFS_DBTOFSB(STRUCT_LFS *fs, uint64_t b)
+{
+#if defined(_KERNEL)
+       return b >> (lfs_sb_getffshift(fs) - DEV_BSHIFT);
+#else
+       return b >> lfs_sb_getfsbtodb(fs);
+#endif
+}
 
 #define        lfs_lblkno(fs, loc)     ((loc) >> lfs_sb_getbshift(fs))
 #define        lfs_lblktosize(fs, blk) ((blk) << lfs_sb_getbshift(fs))
 
-#define lfs_fsbtob(fs, b)      ((b) << lfs_sb_getffshift(fs))
-#define lfs_btofsb(fs, b)      ((b) >> lfs_sb_getffshift(fs))
+/* Frags to bytes */
+static __unused inline uint64_t



Home | Main Index | Thread Index | Old Index