/* Program: RWTEST.C Author : Kim Moser Date : 09/11/89 System : IBM PC / Borland Turbo-C 2.0 Descrip: Performs a read/write test on every track and sector of a given drive. Reports any bad sectors. Usage : RWTEST [d] where 'd' is the letter of the drive which contains the disk(ette) to be tested. If 'd' is not specified, then the currently logged drive will be tested. */ #include #include #include #include #include #include #include #include char DRV; /* Determined at runtime; 0=A:, 1=B:, etc. */ int WARNDAMAGE = 0; /* Whether data may have been corrupted */ static void credits(void); static void credits(void) { fprintf( stderr, "RWTEST v1.0 (09/11/89) Copyright (C) 1989 Kim Moser All Rights Reserved\n\n" ); } static void usage(void); static void usage(void) { fprintf( stderr, "Usage: RWTEST d:\n" ); fprintf( stderr, "Tests every byte of every sector of every cluster on drive 'd'\n" ); fprintf( stderr, "and reports any sector which does not reliably hold data.\n" ); } static void dodrive(void); static void dodrive(void) { /* char fi_sclus; /* Sectors per cluster */ char fi_fatid; /* FAT id byte */ int fi_nclus; /* Number of clusters */ int fi_bysec; /* Bytes per sector */ */ struct fatinfo FAT; unsigned char *sect1, *sect2, *hold; /* Will point to space the size of a sector */ int clus, sect, byte; int wasAltered; int done; int out=0; unsigned long p; FAT.fi_bysec=0; getfat(DRV+1, &FAT); /* 0=default, 1=A, 2=B, etc. */ /* 0 bytes per sector indicates an error getting FAT info */ if (!FAT.fi_bysec) { fprintf( stderr, "\nError: either %c: is an invalid drive or it can not be read.\n", DRV+'A' ); exit(-1); } /* Allocate room for 3 sectors: */ byte = ((sect1=malloc((size_t)FAT.fi_bysec))==NULL); byte |= ((sect2=malloc((size_t)FAT.fi_bysec))==NULL); if ( byte|=((hold=malloc((size_t)FAT.fi_bysec))==NULL) ) { fprintf( stderr, "Unable to allocate enough memory.\n" ); exit(-1); } fprintf( stderr, "\nDrive %c: %d clusters, %d sector(s) per cluster, %d bytes per sector\n", DRV+'A', FAT.fi_nclus, (int)FAT.fi_sclus, FAT.fi_bysec ); fprintf( stderr, "Working; please wait (hit any key to abort)...\n" ); for (clus=0; (clus