Source-Changes-HG archive

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

[src/trunk]: src/sbin/newfs Make newfs's spare superblock output nicer. Figur...



details:   https://anonhg.NetBSD.org/src/rev/6282bf5c4be4
branches:  trunk
changeset: 472976:6282bf5c4be4
user:      wrstuden <wrstuden%NetBSD.org@localhost>
date:      Fri May 14 22:36:50 1999 +0000

description:
Make newfs's spare superblock output nicer. Figure out how wide the
largest block number will be, and make the columns wide enough for it. Then
make enough columns to fit in an 80 character window.

Samples: small end & faked up values:

super-block backups (for fsck -b #) at:
   32,  176,  272,  416,  512,  656,  752,  896,  992, 1136, 1232, 1376, 1472,
 1616, 1712, 1856, 1952, 2096, 2192, 2336, 2432, 2576, 2672, 2816, 2912, 3056,
 3152, 3296, 3392, 3536, 3632, 3776, 3872, 4016, 4112, 4256, 4352, 4496, 4592,

For a 155 GB fs we have:

super-block backups (for fsck -b #) at:
       128,     65792,    131456,    197120,    262784,    328448,    394112,
    459776,    525440,    591104,    656768,    722432,    788096,    853760,
    919424,    985088,   1050752,   1116416,   1182080,   1247744,   1313408,
   1379072,   1444736,   1510400,   1576064,   1641728,   1707392,   1773056,
...
 317462144, 317527808, 317593472, 317659136, 317724800, 317790464, 317856128,
 317921792, 317987456, 318053120, 318118784, 318184448, 318250112, 318315776,
 318381440, 318447104, 318512768, 318578432,

Now it actually looks like someone's thought about making large fs's. :-)

diffstat:

 sbin/newfs/mkfs.c |  31 +++++++++++++++++++++++++++----
 1 files changed, 27 insertions(+), 4 deletions(-)

diffs (78 lines):

diff -r e68ad9083d96 -r 6282bf5c4be4 sbin/newfs/mkfs.c
--- a/sbin/newfs/mkfs.c Fri May 14 21:33:41 1999 +0000
+++ b/sbin/newfs/mkfs.c Fri May 14 22:36:50 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkfs.c,v 1.35 1999/03/16 21:52:34 wrstuden Exp $       */
+/*     $NetBSD: mkfs.c,v 1.36 1999/05/14 22:36:50 wrstuden Exp $       */
 
 /*
  * Copyright (c) 1980, 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)mkfs.c     8.11 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: mkfs.c,v 1.35 1999/03/16 21:52:34 wrstuden Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.36 1999/05/14 22:36:50 wrstuden Exp $");
 #endif
 #endif /* not lint */
 
@@ -77,6 +77,8 @@
 static int32_t calcipg __P((int32_t, int32_t, off_t *));
 static void swap_cg __P((struct cg *, struct cg *));
 
+static int count_digits __P((int));
+
 /*
  * make file system for cylinder-group style file systems
  */
@@ -162,6 +164,7 @@
        time_t utime;
        quad_t sizepb;
        char *writebuf2;                /* dynamic buffer */
+       int nprintcols, printcolwidth;
 
 #ifndef STANDALONE
        time(&utime);
@@ -597,6 +600,13 @@
 #undef B2MBFACTOR
        }
        /*
+        * Now determine how wide each column will be, and calculate how
+        * many columns will fit in an 80 char line.
+        */
+       printcolwidth = count_digits(
+                       fsbtodb(&sblock, cgsblock(&sblock, sblock.fs_ncg -1)));
+       nprintcols = 80 / (printcolwidth + 2);
+       /*
         * Now build the cylinders group blocks and
         * then print out indices of cylinder groups.
         */
@@ -606,9 +616,10 @@
                initcg(cylno, utime);
                if (mfs)
                        continue;
-               if (cylno % 8 == 0)
+               if (cylno % nprintcols == 0)
                        printf("\n");
-               printf(" %d,", fsbtodb(&sblock, cgsblock(&sblock, cylno)));
+               printf(" %*d,", printcolwidth,
+                               fsbtodb(&sblock, cgsblock(&sblock, cylno)));
                fflush(stdout);
        }
        if (!mfs)
@@ -1410,3 +1421,15 @@
                                bswap16(((struct odirect*)dir)->d_namlen);
        }
 }
+
+/* Determine how many digits are needed to print a given integer */
+static int
+count_digits(num)
+       int num;
+{
+       int ndig;
+
+       for(ndig = 1; num > 9; num /=10, ndig++);
+
+       return (ndig);
+}



Home | Main Index | Thread Index | Old Index