home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 139 / c / erase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-05-13  |  4.2 KB  |  83 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /* Module:     erase.c - Bulk eraser for floppy disks                       */
  4. /*                                                                          */
  5. /* Programmer: George R. Woodside                                           */
  6. /*                                                                          */
  7. /* Date:       February 7, 1987                                             */
  8. /*                                                                          */
  9. /* Function:   Fast erase of a floppy disk by re-writing FATs               */
  10. /*             and directory.                                               */
  11. /*                                                                          */
  12. /****************************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <osbind.h>
  16.  
  17. long  stuff[128 * 17];                  /* data buffer                      */
  18.  
  19. main(argc,argv)
  20. int   argc;
  21. char  *argv[];
  22. {
  23.   register  int  i = 0;                 /* confirmation flag                */
  24.   register  int  drive;                 /* drive to erase                   */
  25.   register  char *look;                 /* look at command arguments        */
  26.   register  long reply;                 /* O/S response                     */
  27.  
  28.   if(argc < 2)                          /* if no arguments,                 */
  29.     {
  30.       printf("Erase: Complete erasure of a floppy disk.\n");
  31.       printf("Usage: erase [ab] [y]\n");/* print usage                      */
  32.       exit(1);                          /* and exit                         */
  33.     }                                   /* end not enough arguments         */
  34.  
  35.   if( (*argv[1] == 'a') || (*argv[1] == 'A') )
  36.     drive = 0;                          /* remember drive                   */
  37.  
  38.   if( (*argv[1] == 'b') || (*argv[1] == 'B') )
  39.     drive = 1;                          /* remember drive                   */
  40.  
  41.   if(argc > 2)
  42.     {
  43.       if( (*argv[2] == 'y') || (*argv[2] == 'Y') )
  44.         i = 1;                          /* show pre-confirmed               */
  45.     }
  46.  
  47.   if( (argc > 2) && (i == 0) )          /* if not confirmed,                */
  48.     {
  49.       look = argv[2];                   /* get the second argument          */
  50.       if(*look++ == '-' )               /* if a leading hyphen,             */
  51.         {
  52.           if( (*look == 'y') || (*look == 'Y') ) /* then a yes,             */
  53.             i = 1;                      /* show pre-confirmed               */
  54.         }                               /* end hyphenated yes               */
  55.     }                                   /* end not confirmed with 2 args    */
  56.  
  57.   if(i == 0)                            /* if not confirmed yet,            */
  58.     {
  59.       printf("Erase floppy drive %c, confirm with 'y':",drive + 'a');
  60.       i = Cconin();                     /* read a character                 */
  61.       if( (i != 'y') && (i != 'Y') )    /* if not a y,                      */
  62.         exit(1);                        /* punt                             */
  63.     }                                   /* end not confirmed                */
  64.  
  65.   for(i = 0; i < 17 * 128; i++)         /* 17 sectors, longs are quicker    */
  66.     stuff[i] = 0L;                      /* fill the buffer with zeroes      */
  67.  
  68.   stuff[0]   = 0xf7ffff00L;             /* set up first FAT                 */
  69.   stuff[640] = 0xf7ffff00L;             /* set up second FAT                */
  70.  
  71.   Getbpb(drive);                        /* insure the drive is known        */
  72.   reply = Rwabs(1,stuff,17,1,drive);    /* write the buffer                 */
  73.  
  74.   if(reply == 0L)                       /* if no problems on write,         */
  75.     {
  76.       Rwabs(0,0L,2,0,drive);            /* set media has changed            */
  77.       exit(0);                          /* did it OK                        */
  78.     }                                   /* end successful erasure           */
  79.  
  80.   printf("Error code %D\n",reply);      /* log error                        */
  81.   exit(1);                              /* exit as error                    */
  82. }
  83.