home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
f
/
ftp-102.zip
/
ftape-1.02
/
qic
/
verify.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-12
|
5KB
|
175 lines
/* Scan the media for defects after formatting.
Copyright (C) 1992 David L. Brown, Jr.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/*
* verify.c,v 1.4 1992/10/13 01:55:40 dbrown Exp
*
* verify.c,v
* Revision 1.4 1992/10/13 01:55:40 dbrown
* Added FSF copyright.
*
* Revision 1.3 1992/03/21 17:21:53 dbrown
* Put an intentional error on read_segment in floppy part.
*
* Revision 1.2 92/03/19 23:01:10 dbrown
* Now compiles for tape but doesn't do anything.
*
*/
#include <stdio.h>
#include <assert.h>
#include <sys/file.h>
#include <alloca.h>
#include "qic.h"
#include "header.h"
#ifndef FLOPPY
#else /* FLOPPY */
#undef NUMBER_OF_SEGMENTS
/* #define NUMBER_OF_SEGMENTS 75 /* 1.2 Meg media. */
#define NUMBER_OF_SEGMENTS 90 /* 1.44 Meg media. */
/* Perform a scan of the media. Builds a bad sector bitmap in the
memory pointed to by bad_sectors. This map is packed as in little
endian order, one 32-bit word for each segment. Each one bit
represents a bad sector. Returns 1 if the verify was successful. */
int
media_scan (BAD_SECTOR *bad_sectors)
{
int segment;
struct memory_segment data;
data.data = alloca (BLOCK_SIZE * BLOCKS_PER_SEGMENT);
for (segment = 0; segment < NUMBER_OF_SEGMENTS; segment++)
{
BAD_CLEAR (data.marked_bad);
!!!read_segment (&data, segment);
bad_sectors[segment] = data.read_bad;
printf ("segment %3d, bad = 0x%08x\r", segment, data.read_bad);
fflush (stdout);
if (data.read_bad != 0)
putchar ('\n');
}
}
/* Rescan the data, and if we get more read errors, we have a problem. */
int
rescan_data (BAD_SECTOR *bad_sectors)
{
int segment;
struct memory_segment data;
data.data = alloca (BLOCK_SIZE * BLOCKS_PER_SEGMENT);
for (segment = 0; segment < NUMBER_OF_SEGMENTS; segment++)
{
data.marked_bad = bad_sectors[segment];
!!!read_segment (&data, segment);
printf ("segment %3d, bad = 0x%08x\r", segment, data.read_bad);
fflush (stdout);
if (data.read_bad != 0)
{
fprintf (stderr, "\nError, inconsistency.\n");
exit (1);
}
}
putchar ('\n');
}
void
perform_verify ()
{
int i;
int header_segment;
BAD_SECTOR bad_map[NUMBER_OF_SEGMENTS];
media_scan (bad_map);
#if 0
printf ("Rescanning data, should be no errors.\n");
rescan_data (bad_map);
#endif
/* Construct a header. */
for (header_segment = 0;
(header_segment < NUMBER_OF_SEGMENTS
&& bad_map[header_segment] != 0);
header_segment++)
;
{
struct qic_header_segment *h = ¤t_header;
printf ("Header segment is: %d\n", header_segment);
bzero (h, sizeof (struct qic_header_segment));
h->signature[0] = 0x55;
h->signature[1] = 0xaa;
h->signature[2] = 0x55;
h->signature[3] = 0xaa;
#ifdef FLOPPY
h->format_code = 254; /* My QIC on a floppy format. */
#else
h->format_code = 2; /* QIC-80 Rev B and later. */
#endif
h->header = header_segment;
#ifdef FLOPPY
h->alt_header = -1;
#else
#error hasnt yet been written.
#endif
#ifdef FLOPPY
h->data_first = header_segment+1;
#else
#error not yet
#endif
h->data_last = NUMBER_OF_SEGMENTS - 1;
LLONG_SET (h->format_time, 0); /* Need time routine. */
LLONG_SET (h->write_time, 0);
h->segments_per_track = NUMBER_OF_SEGMENTS;
h->tracks_per_cartridge = 1;
h->maximum_floppy_side = 2;
h->maximum_floppy_track = 80;
h->maximum_floppy_sector = 9;
memcpy (h->tape_name, "Testtape", 8);
LLONG_SET (h->tape_name_time, 0); /* Need time routine. */
h->compression_map = 0;
h->format_error = 0x00;
/* I'm not sure what is meant by this, but here's a good guess. */
LLONG_SET (h->segments_used, 2 * NUMBER_OF_SEGMENTS + 1);
LLONG_SET (h->initial_format_time, 0);
h->format_count = 1;
h->failed_sector_count = 0;
*h->oem_name = 0;
*h->oem_lot = 0;
/* Copy in bad sector table. */
for (i = 0; i < NUMBER_OF_SEGMENTS; i++)
h->bad_sectors[i] = bad_map[i];
write_header ();
create_vt ();
write_vt ();
}
}
#endif /* FLOPPY */