From bbe2a9958251b6354eb8a29574e5a32ee240e3cf Mon Sep 17 00:00:00 2001 From: joerg Date: Mon, 2 Jul 2001 21:24:03 +0000 Subject: [PATCH] Use the printstatus() function from ${.CURDIR}/../fdread/fdutil.c to give a bit more information about up to 10 errors encountered during formatting (unless -q has been specified, of course). While being here, removed a bitrotten comment in the Makefile, and kill the old Emacs local variable stuff at the end of fdformat.c that's no longer useful anway. --- usr.sbin/fdformat/Makefile | 10 ++++---- usr.sbin/fdformat/fdformat.1 | 6 +++-- usr.sbin/fdformat/fdformat.c | 50 ++++++++++++++++++++++-------------- 3 files changed, 40 insertions(+), 26 deletions(-) diff --git a/usr.sbin/fdformat/Makefile b/usr.sbin/fdformat/Makefile index 3c0d4ec42531..40683ea9bd3d 100644 --- a/usr.sbin/fdformat/Makefile +++ b/usr.sbin/fdformat/Makefile @@ -1,10 +1,10 @@ # $FreeBSD$ -PROG= fdformat +.PATH: ${.CURDIR}/../fdread -# the -I's seem to be confusing, but necessery this way -# (so the right will be found in /usr/include, and the -# "../i386/isa/ic/nec765.h" included from fdreg.h is accessible, too) -CFLAGS+= -Wall +PROG= fdformat +SRCS= fdformat.c fdutil.c + +CFLAGS+= -Wall -I ${.CURDIR}/../fdread .include diff --git a/usr.sbin/fdformat/fdformat.1 b/usr.sbin/fdformat/fdformat.1 index bc46b306b5fd..339f0ea8f313 100644 --- a/usr.sbin/fdformat/fdformat.1 +++ b/usr.sbin/fdformat/fdformat.1 @@ -1,4 +1,4 @@ -.\" Copyright (C) 1993, 1994, 1995 by Joerg Wunsch, Dresden +.\" Copyright (C) 1993, 1994, 1995, 2001 by Joerg Wunsch, Dresden .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 16, 1993 +.Dd July 2, 2001 .Os .Dt FDFORMAT 1 .Sh NAME @@ -141,6 +141,8 @@ is printed when the track(s) is being formatted, then a while it's being verified, and if an error has been detected, it will finally change to .Sq Em E . +Detailed status information (cylinder, head and sector number, and the +exact cause of the error) will then be printed for up to 10 errors. .Pp An exit status of 0 is returned upon successful operation. Exit status diff --git a/usr.sbin/fdformat/fdformat.c b/usr.sbin/fdformat/fdformat.c index 178fd2a1ba08..157cb7d7657a 100644 --- a/usr.sbin/fdformat/fdformat.c +++ b/usr.sbin/fdformat/fdformat.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -51,6 +52,8 @@ #include +#include "fdutil.h" + static void format_track(int fd, int cyl, int secs, int head, int rate, int gaplen, int secsize, int fill,int interleave) @@ -172,10 +175,12 @@ main(int argc, char **argv) int format = -1, cyls = -1, secs = -1, heads = -1, intleave = -1; int rate = -1, gaplen = -1, secsize = -1, steps = -1; int fill = 0xf6, quiet = 0, verify = 1, verify_only = 0, confirm = 0; - int fd, c, track, error, tracks_per_dot, bytes_per_track, errs; + int fd, c, i, track, error, tracks_per_dot, bytes_per_track, errs; int fdopts; const char *devname, *suffix; struct fd_type fdt; +#define MAXPRINTERRS 10 + struct fdc_status fdcs[MAXPRINTERRS]; while((c = getopt(argc, argv, "f:c:s:h:r:g:S:F:t:i:qyvn")) != -1) switch(c) { @@ -336,8 +341,16 @@ main(int argc, char **argv) } } if (verify) { - if (verify_track(fd, track, bytes_per_track) < 0) - error = errs = 1; + if (verify_track(fd, track, bytes_per_track) < 0) { + error = 1; + if (errs < MAXPRINTERRS && errno == EIO) { + if (ioctl(fd, FD_GSTAT, fdcs + errs) == + -1) + errx(1, + "floppy IO error, but no FDC status"); + errs++; + } + } if(!quiet && !((track + 1) % tracks_per_dot)) { if (!verify_only) putchar('\b'); @@ -354,20 +367,19 @@ main(int argc, char **argv) if(!quiet) printf(" done.\n"); - return errs; + if (!quiet && errs) { + fflush(stdout); + fprintf(stderr, "Errors encountered:\nCyl Head Sect Error\n"); + for (i = 0; i < errs && i < MAXPRINTERRS; i++) { + fprintf(stderr, " %2d %2d %2d ", + fdcs[i].status[3], fdcs[i].status[4], + fdcs[i].status[5]); + printstatus(fdcs + i, 1); + putc('\n', stderr); + } + if (errs >= MAXPRINTERRS) + fprintf(stderr, "(Further errors not printed.)\n"); + } + + return errs != 0; } -/* - * Local Variables: - * c-indent-level: 8 - * c-continued-statement-offset: 8 - * c-continued-brace-offset: 0 - * c-brace-offset: -8 - * c-brace-imaginary-offset: 0 - * c-argdecl-indent: 8 - * c-label-offset: -8 - * c++-hanging-braces: 1 - * c++-access-specifier-offset: -8 - * c++-empty-arglist-indent: 8 - * c++-friend-offset: 0 - * End: - */