Logical Block No. to Cylinder/track/sector for Ultrix [comp.sys.dec]

John T Kohl jtkohl at quicksilver.mit.edu
Sun Dec 17 17:34:17 AEST 1989


Archive-name: lbn-to-cyl
Original-posting-by: jtkohl at quicksilver.mit.edu (John T Kohl)
Original-subject: Re: LBN's versus head numbers,formula wanted
Reposted-by: emv at math.lsa.umich.edu (Edward Vielmetti)

[This is an experimental alt.sources re-posting from the newsgroup(s)
comp.sys.dec. Comments on this service to emv at math.lsa.umich.edu 
(Edward Vielmetti).]


Here's a program which reads LBN's from a Unix/Ultrix message file, and
translates to cylinder, etc.  This one knows about ra80's and ra81's; if
you get an RA90 user's manual, it should have the appropriate geometry
info you need to wire into this program.

I got this from someone else at MIT, who got it from someone else...
insert standard disclaimer.

#include <stdio.h>

#define LINESIZE 132	/* Maximum number of characters on a line */

main(argc,argv)
int argc;
char *argv[];
{
    char line[LINESIZE], *fgets(), *lineptr, *findstring();
    long blocknumber;
    FILE *infile;
    int nscyl, nstrk, nblk = -1;

    if (argc != 4) {
	fprintf(stderr, "Usage: %s drive_type drive_name log_file\n", argv[0]);
	exit(-1);
    }

    if (!strcmp(argv[1], "ra81")) {
	nscyl = 714;
	nstrk = 51;
	nblk = 891072;
    } else if (!strcmp(argv[1], "ra80")) {
	nscyl = 434;
	nstrk = 31;
	nblk = 242606;
    } else if (!strcmp(argv[1], "ra60")) {
	nscyl = 168;
	nstrk = 42;
	nblk = 400176;
    }

    if (nblk == -1) {
	fprintf(stderr, "%s: unknown drive type %s\n", argv[0], argv[1]);
	exit(-1);
    }

    if ((infile = fopen(argv[3], "r")) == NULL) {
	fprintf(stderr, "%s: Can't open %s\n", argv[0], argv[3]);
	exit(-1);
    }
    
    while (fgets(line, LINESIZE, infile) != NULL){
	/* Look for a line with the drive name and "hdr" on it */
	if ((findstring(argv[2], line) == NULL) ||
	    (lineptr = findstring("hdr 0x", line)) == NULL)
	    continue;

	/* Get the block number */
    	sscanf(lineptr, "%X", &blocknumber);
    	hdr(blocknumber, nscyl, nstrk, nblk);
    }
}

char *findstring(substring, string)
register char *substring, *string;
{
    register char *ptr;
    int match;

    for ( ; *string != '\0'; string++) {
	match = 1;
	for (ptr = substring; *ptr != '\0'; ptr++, string++) {
	    if (*ptr != *string){
		match = 0;
		break;
	    }
	}
	if (match)
	    return (string);
    }
    return (NULL);
}

hdr(blocknumber, nscyl, nstrk,nb)
long blocknumber;
int nscyl;
int nstrk;
int nb;
{
    long cyl;
    long trk;
    long sec;

    printf("hdr: %6D", blocknumber);
    if (blocknumber >=0 && blocknumber <=nb) {
	cyl = blocknumber / nscyl;
	trk = (blocknumber - (cyl * nscyl)) / nstrk;
	sec = blocknumber - (cyl * nscyl) - (trk * nstrk);
	
	printf(" cyl: %4D trk: %2D sec: %2D\n", cyl, trk, sec);
    }
    else printf(" Illegal blocknumber\n");
}

--
John Kohl <jtkohl at ATHENA.MIT.EDU> or <jtkohl at Kolvir.Brookline.MA.US>
Digital Equipment Corporation/Project Athena
(The above opinions are MINE.  Don't put my words in somebody else's mouth!)



More information about the Alt.sources mailing list