Subject: bin/26449: fdformat(1) diagnostic messages
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <mishka@apk.od.ua>
List: netbsd-bugs
Date: 07/27/2004 17:29:33
>Number:         26449
>Category:       bin
>Synopsis:       fdformat(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 27 14:31:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Mike M. Volokhov
>Release:        NetBSD 2.0C
>Organization:
Insakharprom-K, Ltd.
>Environment:
System: NetBSD nostromo.holding.local 2.0C NetBSD 2.0C (NOSTROMO) #4: Tue May 18 11:27:25 EEST 2004 mishka@nostromo.holding.local:/build/netbsd/src-current-20040415/sys/arch/i386/compile/NOSTROMO i386
Architecture: i386
Machine: i386
>Description:

	Greetings!

	[This PR initially planned to be in "sw-bug" class, but accepting
	bin/15897 I assume it as "change-request".]

	The diagnostic messages from fdformat(1) utility was "broken" on
	terminals wich have a width less than <number of tracks> * <number
	of heads>. See bin/15897 for details. At revision 1.12 of fdformat.c
	this behaviour was changed, but I propose a different solution.

	The features of my decision:

		- works in generic way (\n, \r, etc.);
		- more informative than standard fdformat;
		- no need to cross over the terminal line boundary;
		  (not for too narrow terminals);
		- code bit shorten than current implementation.

	Some example output:

		# ./fdformat
		Ready to format /dev/rfd0a with 80 cylinders, 2 tracks, 18 sectors of 512 bytes
		(1440 KB) Yes/no [y]?
		Formatting track 5 / head 0 - VERIFY ERROR
		Formatting track 6 / head 0 - VERIFY ERROR
		Formatting track 20 / head 0 - IO ERROR
		Formatting track 20 / head 1 - IO ERROR
		Formatting track 21 / head 0 - IO ERROR
		Formatting track 79 / head 1 (all done)
		fdformat: 5 track formatting errors
		# 

	The tracks 5 and 6 on head 0 have a real errors, and the rest errors
	was manualy generated by temporary ejecting floppy from FDD.

>How-To-Repeat:

	Try format any floppy disk using fdformat(1).

>Fix:

	Apply the following patch on fdformat.c revision 1.12:

Index: fdformat.c
===================================================================
RCS file: /cvsroot/src/usr.bin/fdformat/fdformat.c,v
retrieving revision 1.12
diff -u -r1.12 fdformat.c
--- fdformat.c	23 Apr 2004 15:04:27 -0000	1.12
+++ fdformat.c	26 Jul 2004 10:56:24 -0000
@@ -76,7 +76,6 @@
 static int	confirm(int);
 static void	usage(void) __attribute__((__noreturn__));
 static int	verify_track(int, int, int, struct fdformat_parms *, char *);
-static int	wincolsize(void);
 
 int	main(int, char **);
 
@@ -111,14 +110,13 @@
 	offset = tracksize * (cyl * parms->ntrk + trk); /* track offset */
 
 	if (lseek(fd, offset, SEEK_SET) == (off_t) -1) {
-		(void)putchar('E');
+		(void)printf("- SEEK ERROR\n");
 		return 1;
 	}
 	if (read(fd, buf, tracksize) != tracksize) {
-		(void)putchar('E');
+		(void)printf("- VERIFY ERROR\n");
 		return 1;
-	} else
-		(void)putchar('V');
+	}
 	return 0;
 }
 
@@ -132,18 +130,6 @@
 	exit(1);
 }
 
-static int
-wincolsize(void)
-{
-	struct winsize win;
-
-	if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1) {
-		warn("TIOCGWINSZ");
-		return 80;
-	}
-	return win.ws_col;
-}
-
 #define numarg(which, maskn, op) 				\
 	do {							\
 		tmplong = strtol(optarg, &tmpcharp, 0); 	\
@@ -190,8 +176,6 @@
 	const char *filename = _PATH_FLOPPY_DEV;
 	int fd;
 	int trk, cyl;
-        int colcnt = 0;
-        int colsize = wincolsize();
 
 	while ((ch = getopt(argc, argv, "f:t:nB:C:S:T:P:G:F:X:I:")) != -1)
 		switch (ch) {
@@ -313,18 +297,9 @@
 		cmd.cylinder = cyl;
 		for (trk = 0; trk < parms.ntrk; trk++) {
 			cmd.head = trk;
+			(void)printf("\rFormatting track %i / head %i ", cyl, trk);
+			(void)fflush(stdout);
 			if (ioctl(fd, FDIOCFORMAT_TRACK, &cmd) == 0) {
-                                if (verify && colsize) {
-                                        colcnt++;
-                                        if (colcnt % colsize == 0) {
-                                                (void)putchar('\n');
-                                                colcnt++;
-                                        }
-                                }
-				(void)putchar('F');
-				if (verify)
-					(void)putchar('\b');
-				(void)fflush(stdout);
 				if (verify)
 					errcnt += verify_track(fd, cyl, trk,
 					    &parms, trackbuf);
@@ -333,13 +308,12 @@
 				errx(1, "Formatting botch at <%d,%d>",
 				     cyl, trk);
 			} else if (errno == EIO) {
-				(void)putchar('E');
-				(void)fflush(stdout);
+				(void)printf("- IO ERROR\n");
 				errcnt++;
 			}
 		}
 	}
-	(void)putchar('\n');
+	(void)printf("(all done)\n");
 	if (errcnt)
 		errx(1, "%d track formatting error%s",
 		    errcnt, errcnt == 1 ? "" : "s");

	--
	Best wishes,
	Mishka.

>Release-Note:
>Audit-Trail:
>Unformatted: