diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-08-02 11:00:51 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-08-02 11:00:51 +0000 |
commit | 8372d31f0c5f546a3db20ea42865587966b1ff77 (patch) | |
tree | 41dced76b046aec4630243777456e9992dde9f7b | |
parent | 8d078a2a45ccbb5d319e64579aaad811a15ad2c0 (diff) |
proper column management for superblock backups; from freebsd, joerg/satoshi
-rw-r--r-- | sbin/newfs/mkfs.c | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index e22b9a9d7ac..09ef2fd3567 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkfs.c,v 1.2 1996/06/23 14:31:46 deraadt Exp $ */ +/* $OpenBSD: mkfs.c,v 1.3 1996/08/02 11:00:50 deraadt Exp $ */ /* $NetBSD: mkfs.c,v 1.25 1995/06/18 21:35:38 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)mkfs.c 8.3 (Berkeley) 2/3/94"; #else -static char rcsid[] = "$OpenBSD: mkfs.c,v 1.2 1996/06/23 14:31:46 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mkfs.c,v 1.3 1996/08/02 11:00:50 deraadt Exp $"; #endif #endif /* not lint */ @@ -50,6 +50,7 @@ static char rcsid[] = "$OpenBSD: mkfs.c,v 1.2 1996/06/23 14:31:46 deraadt Exp $" #include <ufs/ufs/dir.h> #include <ufs/ffs/fs.h> #include <sys/disklabel.h> +#include <sys/ioctl.h> #include <string.h> #include <unistd.h> @@ -127,6 +128,7 @@ struct dinode zino[MAXBSIZE / sizeof(struct dinode)]; int fsi, fso; daddr_t alloc(); +static int charsperline(); mkfs(pp, fsys, fi, fo) struct partition *pp; @@ -142,6 +144,8 @@ mkfs(pp, fsys, fi, fo) time_t utime; quad_t sizepb; void started(); + int width; + char tmpbuf[100]; /* XXX this will break in about 2,500 years */ #ifndef STANDALONE time(&utime); @@ -592,14 +596,21 @@ next: * then print out indices of cylinder groups. */ if (!mfs) - printf("super-block backups (for fsck -b #) at:"); + printf("super-block backups (for fsck -b #) at:\n"); + i = 0; + width = charsperline(); for (cylno = 0; cylno < sblock.fs_ncg; cylno++) { initcg(cylno, utime); if (mfs) continue; - if (cylno % 8 == 0) + j = sprintf(tmpbuf, " %d,", + fsbtodb(&sblock, cgsblock(&sblock, cylno))); + if (i+j >= width) { printf("\n"); - printf(" %d,", fsbtodb(&sblock, cgsblock(&sblock, cylno))); + i = 0; + } + i += j; + printf("%s", tmpbuf); fflush(stdout); } if (!mfs) @@ -1243,3 +1254,25 @@ setblock(fs, cp, h) return; } } + +/* + * Determine the number of characters in a + * single line. + */ +static int +charsperline() +{ + int columns; + char *cp; + struct winsize ws; + extern char *getenv(); + + 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 */ + return columns; +} |