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 >
C/C++ Source or Header  |  1992-10-12  |  5KB  |  175 lines

  1. /* Scan the media for defects after formatting.
  2.    Copyright (C) 1992 David L. Brown, Jr.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.    
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; see the file COPYING.  If not, write to
  16.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /*
  19.  * verify.c,v 1.4 1992/10/13 01:55:40 dbrown Exp
  20.  *
  21.  * verify.c,v
  22.  * Revision 1.4  1992/10/13  01:55:40  dbrown
  23.  * Added FSF copyright.
  24.  *
  25.  * Revision 1.3  1992/03/21  17:21:53  dbrown
  26.  * Put an intentional error on read_segment in floppy part.
  27.  *
  28.  * Revision 1.2  92/03/19  23:01:10  dbrown
  29.  * Now compiles for tape but doesn't do anything.
  30.  * 
  31.  */
  32.  
  33. #include <stdio.h>
  34. #include <assert.h>
  35. #include <sys/file.h>
  36. #include <alloca.h>
  37.  
  38. #include "qic.h"
  39. #include "header.h"
  40.  
  41. #ifndef FLOPPY
  42. #else /* FLOPPY */
  43.  
  44. #undef NUMBER_OF_SEGMENTS
  45. /* #define NUMBER_OF_SEGMENTS 75 /* 1.2 Meg media. */
  46. #define NUMBER_OF_SEGMENTS 90 /* 1.44 Meg media. */
  47.  
  48. /* Perform a scan of the media.  Builds a bad sector bitmap in the
  49.    memory pointed to by bad_sectors.  This map is packed as in little
  50.    endian order, one 32-bit word for each segment.  Each one bit
  51.    represents a bad sector.  Returns 1 if the verify was successful. */
  52.  
  53. int
  54. media_scan (BAD_SECTOR *bad_sectors)
  55. {
  56.   int segment;
  57.   struct memory_segment data;
  58.   data.data = alloca (BLOCK_SIZE * BLOCKS_PER_SEGMENT);
  59.  
  60.   for (segment = 0; segment < NUMBER_OF_SEGMENTS; segment++)
  61.     {
  62.       BAD_CLEAR (data.marked_bad);
  63.       !!!read_segment (&data, segment);
  64.       bad_sectors[segment] = data.read_bad;
  65.       printf ("segment %3d, bad = 0x%08x\r", segment, data.read_bad);
  66.       fflush (stdout);
  67.       if (data.read_bad != 0)
  68.     putchar ('\n');
  69.     }
  70. }
  71.  
  72. /* Rescan the data, and if we get more read errors, we have a problem. */
  73.  
  74. int
  75. rescan_data (BAD_SECTOR *bad_sectors)
  76. {
  77.   int segment;
  78.   struct memory_segment data;
  79.   data.data = alloca (BLOCK_SIZE * BLOCKS_PER_SEGMENT);
  80.  
  81.   for (segment = 0; segment < NUMBER_OF_SEGMENTS; segment++)
  82.     {
  83.       data.marked_bad = bad_sectors[segment];
  84.       !!!read_segment (&data, segment);
  85.       printf ("segment %3d, bad = 0x%08x\r", segment, data.read_bad);
  86.       fflush (stdout);
  87.       if (data.read_bad != 0)
  88.     {
  89.       fprintf (stderr, "\nError, inconsistency.\n");
  90.       exit (1);
  91.     }
  92.     }
  93.   putchar ('\n');
  94. }
  95.  
  96. void
  97. perform_verify ()
  98. {
  99.   int i;
  100.   int header_segment;
  101.   BAD_SECTOR bad_map[NUMBER_OF_SEGMENTS];
  102.  
  103.   media_scan (bad_map);
  104.  
  105. #if 0
  106.   printf ("Rescanning data, should be no errors.\n");
  107.   rescan_data (bad_map);
  108. #endif
  109.  
  110.   /* Construct a header. */
  111.   for (header_segment = 0;
  112.        (header_segment < NUMBER_OF_SEGMENTS
  113.     && bad_map[header_segment] != 0);
  114.        header_segment++)
  115.     ;
  116.   {
  117.     struct qic_header_segment *h = ¤t_header;
  118.  
  119.     printf ("Header segment is: %d\n", header_segment);
  120.     bzero (h, sizeof (struct qic_header_segment));
  121.  
  122.     h->signature[0] = 0x55;
  123.     h->signature[1] = 0xaa;
  124.     h->signature[2] = 0x55;
  125.     h->signature[3] = 0xaa;
  126.  
  127. #ifdef FLOPPY
  128.     h->format_code = 254;    /* My QIC on a floppy format. */
  129. #else
  130.     h->format_code = 2;        /* QIC-80 Rev B and later. */
  131. #endif
  132.     h->header = header_segment;
  133. #ifdef FLOPPY
  134.     h->alt_header = -1;
  135. #else
  136. #error hasnt yet been written.
  137. #endif
  138. #ifdef FLOPPY
  139.     h->data_first = header_segment+1;
  140. #else
  141. #error not yet
  142. #endif
  143.     h->data_last = NUMBER_OF_SEGMENTS - 1;
  144.     LLONG_SET (h->format_time, 0); /* Need time routine. */
  145.     LLONG_SET (h->write_time, 0);
  146.     h->segments_per_track = NUMBER_OF_SEGMENTS;
  147.     h->tracks_per_cartridge = 1;
  148.     h->maximum_floppy_side = 2;
  149.     h->maximum_floppy_track = 80;
  150.     h->maximum_floppy_sector = 9;
  151.     memcpy (h->tape_name, "Testtape", 8);
  152.     LLONG_SET (h->tape_name_time, 0); /* Need time routine. */
  153.     h->compression_map = 0;
  154.     h->format_error = 0x00;
  155.     /* I'm not sure what is meant by this, but here's a good guess. */ 
  156.     LLONG_SET (h->segments_used, 2 * NUMBER_OF_SEGMENTS + 1);
  157.     LLONG_SET (h->initial_format_time, 0);
  158.     h->format_count = 1;
  159.     h->failed_sector_count = 0;
  160.     *h->oem_name = 0;
  161.     *h->oem_lot = 0;
  162.  
  163.     /* Copy in bad sector table. */
  164.     for (i = 0; i < NUMBER_OF_SEGMENTS; i++)
  165.       h->bad_sectors[i] = bad_map[i];
  166.  
  167.     write_header ();
  168.  
  169.     create_vt ();
  170.     write_vt ();
  171.   }
  172. }
  173.  
  174. #endif /* FLOPPY */
  175.