From 7f3b8ca95f29cd532085ad5403044ed79a08cf7c Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Thu, 25 Jan 1996 23:44:32 +0000 Subject: [PATCH] Make the numbers for the "superblock backups" fit nicely on the screen, even for larger partitions. Until now, partition sizes > 500 MB messed up the screen. --- sbin/newfs/mkfs.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index fc536f018f4f..2d1f03ca0d46 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -46,6 +46,7 @@ static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94"; #include #include #include +#include #ifndef STANDALONE #include @@ -121,6 +122,7 @@ struct dinode zino[MAXBSIZE / sizeof(struct dinode)]; int fsi, fso; daddr_t alloc(); +static int numbersperline(); mkfs(pp, fsys, fi, fo) struct partition *pp; @@ -620,11 +622,12 @@ mkfs(pp, fsys, fi, fo) */ if (!mfs) printf("super-block backups (for fsck -b #) at:"); + i = numbersperline(sblock.fs_size * NSPF(&sblock)); for (cylno = 0; cylno < sblock.fs_ncg; cylno++) { initcg(cylno, utime); if (mfs) continue; - if (cylno % 9 == 0) + if (cylno % i == 0) printf("\n"); printf(" %d,", fsbtodb(&sblock, cgsblock(&sblock, cylno))); fflush(stdout); @@ -1263,3 +1266,34 @@ setblock(fs, cp, h) return; } } + +/* + * Determine the number of block numbers that will nicely fit into a + * single line. + */ + +static int +numbersperline(seccount) + long seccount; +{ + int i, columns; + char *cp; + struct winsize ws; + extern char *getenv(); + + for (i = 0; seccount; i++, seccount /= 10) + ; + i += 2; /* account for comma+space */ + + columns = 0; + if (ioctl(0, TIOCGWINSZ, &ws) != -1) + columns = ws.ws_col; + if (columns == 0 && (cp = getenv("COLUMNS"))) + columns = atoi(cp); + if (columns == 0) + columns = 80; /* last resort */ + i = columns / i; + if (i < 3) + i = 3; /* don't care */ + return i; +}