perl-based UNIXPC disk error message browser

John B. Milton jbm at uncle.UUCP
Tue Jun 27 11:42:57 AEST 1989


In article <19 at taqwa.UUCP> mkp at taqwa.UUCP (Michael K. Peterson) writes:
>
>I suppose others have written awk scripts or whatever to glean clues from
>the unix.log file, but I haven't seen anything posted, so here goes.
>
>I put some of the high points from John Milton's "Hardware Notes #13" 
>into a perl script, and it made deciphering the hard disk error messages
>in my unix.log file much easier. John's discussion of the WD1010 error
>register is included in the comment block at the beginning of the script.
>Also, there are three variables, $HEADS, $BADLIST, and $SWAPSIZE, that you'll 
>want to change for your particular disk.  (No provision as yet for
>more than one drive.)

Ooopss. I guess I should have posted my program when I got it working :)
This program does the same thing. It is C, and check the VHB to get the sizes
of the partitions, and heads. It prints out the offsets of the bad blocks found
into each partition. Use post awk processing if you want to automate it's use,
or just hack the code. I use the output of this with bf and ncheck to track
down the file in which a bad spot appears. I have not yet integrated this into
my nightly unix.log backup routine.

John
---
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  chs2blk.c
# Wrapped by jbm at uncle on Mon Jun 26 21:39:35 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'chs2blk.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'chs2blk.c'\"
else
echo shar: Extracting \"'chs2blk.c'\" \(2355 characters\)
sed "s/^X//" >'chs2blk.c' <<'END_OF_FILE'
X/* vi:set ts=2 sw=2: */
X
X#include <fcntl.h>
X#include <stdio.h>
X#include <string.h>
X#include <sys/gdisk.h>
X
Xextern int errno;
Xextern int optind;
Xextern char *optarg;
X
X#define LINESIZE 200
X#define SCTSPERTRK 4 /* shift factor */
X#define SCTPERBLK 2
X#define BLKPERTRK 8 /* 16 512 bytes sectors is 8 1024 bytes blocks */
X#define PART0 72
X#define PART1 5000
X
Xchar *me,Debug=0;
X
Xstatic void show(dname,f)
Xchar *dname;
XFILE *f;
X{
X	int ST,EF,CL,CH,SN,SC,SDH;
X	int block,cyl,drive,head,i,sector,v;
X	char line[LINESIZE];
X	struct vhbd vhb;
X	struct gdswprt dsk;
X
X	if ((v=open(dname))==-1)
X		qperrorf("%s: open device \"%s\"",me,dname);
X	if ((v=read(v,&vhb,sizeof(struct vhbd))==-1))
X		qperrorf("%s: read VHB from device \"%s\"",me,dname);
X	if (vhb.magic!=VHBMAGIC) {
X		fprintf(stderr,"%s: bad magic in VHB (slice zero!,%x!=%x)\n",
X			me,vhb.magic,VHBMAGIC);
X		exit(1);
X	}
X	while (fgets(line,LINESIZE,f)!=NULL) {
X		if (strncmp(line,"HDERR",5)==0) {
X			sscanf(line,"HDERR ST:%x EF:%x CL:%x CH:%x SN:%x SC:%x SDH:%x",
X				&ST,&EF,&CL,&CH,&SN,&SC,&SDH);
X			/* SDH: ESSDDHHH */
X			drive=(SDH&0x18)>>3;
X			cyl=((CH&0xff)<<8)+(CL&0xff);
X			head=SDH&0x07;
X			sector=SN&0x1f;
X			if (Debug) {
X				*strchr(line,'\n')=='\0';
X				fprintf(stderr,"Found: \"%s\"\n",line);
X				fprintf(stderr,"%x %x %x %x %x %x %x\n",ST,EF,CL,CH,SN,SC,SDH);
X				fprintf(stderr,"Drive: %d, Cylinder: %d, Head: %d, Sector: %d\n",
X					drive,cyl,head,sector);
X			}
X			block=((((cyl*vhb.dsk.heads)+head)<<SCTSPERTRK)+sector)/SCTPERBLK;
X			printf("disk block:%d",block);
X			for (i=1; vhb.partab[i].sz.strk && i<MAXSLICE; i++)
X				printf("; part:%d, block:%d",
X					i,block-vhb.partab[i].sz.strk*BLKPERTRK);
X			putchar('\n');
X			if (Debug)
X				fflush(stdout);
X		}
X	}
X}
X
Xstatic char *usage="Usage: %s drive [errfile]\n";
X
Xint main(argc,argv)
Xint argc;
Xchar *argv[];
X{
X	int opt;
X	FILE *f;
X
X	(me=strrchr(argv[0],'/'))==NULL?me=argv[0]:me++;
X	while ((opt=getopt(argc,argv,"d?"))!=EOF)
X		switch (opt) { /* optarg, optind */
X			case 'd':
X				Debug=1;
X				break;
X			case '?':
X			default:
X				fprintf(stderr,usage,me);
X				exit(1);
X		}
X	if (argc-optind<1 || argc-optind>2) {
X		fprintf(stderr,usage,me);
X		exit(1);
X	}
X	if (argc-optind==1)
X		show(argv[optind],stdin);
X	else
X		if ((f=fopen(argv[optind+1],"r"))==NULL)
X			perrorf("%s: open %s",me,argv[optind+1]);
X		else {
X			show(argv[optind],f);
X			fclose(f);
X		}
X}
END_OF_FILE
if test 2355 -ne `wc -c <'chs2blk.c'`; then
    echo shar: \"'chs2blk.c'\" unpacked with wrong size!
fi
# end of 'chs2blk.c'
fi
echo shar: End of shell archive.
exit 0
-- 
John Bly Milton IV, jbm at uncle.UUCP, n8emr!uncle!jbm at osu-cis.cis.ohio-state.edu
(614) h:294-4823, w:466-9324; N8KSN, AMPR: 44.70.0.52; Don't FLAME, inform!



More information about the Comp.sys.att mailing list