home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / UNNONDOS.ZIP / UNNONDOS.C next >
Encoding:
C/C++ Source or Header  |  1990-01-28  |  2.4 KB  |  111 lines

  1. /*      UnNonDos v 1.0
  2.  
  3.     Program to patch the first byte of the FAT to F8 to get rid of
  4.     "Probable NON-DOS disk" problems with CHKDSK
  5.     01/28/90 by Ward Christensen    CIS # 76703,302
  6.                          The Ward Board BBS # (708) 849-1132
  7.               world's first BBS # (312) 545-8086
  8.  
  9. use:    unnondos drive:
  10. ex:    unnondos c:
  11.  
  12. Compiled with Borland Turbo C 2.0
  13.  
  14. Written as a simple response to the many many recent msgs on Compuserve
  15. from people saying
  16.  
  17.     What do I do now: chkdsk says "probable NON-DOS disk"?
  18.  
  19. */
  20.  
  21. #define vers "1.0"
  22.  
  23. #include <stdio.h>
  24. #include <dos.h>
  25. #include <ctype.h>
  26. #include <errno.h>
  27.  
  28. unsigned char    buffer[512];
  29. int        drive,i,rc;
  30. char        drivechar,answer[80];
  31.  
  32. how()
  33. {    puts("\nSyntax:");
  34.     puts("\tUnNonDOS drive:");
  35.     puts("\n\tEx: unnondos c:");
  36. }
  37.  
  38. dump()
  39. {    putchar('\t');
  40.     for (i=0;i<20;++i)
  41.         printf("%02X ",buffer[i]);
  42.     puts(" ");
  43. }
  44.  
  45.  
  46. int main(int argc, char *argv[])
  47. {
  48.     printf("\nUN-NON-DOS (unnondos) Version %s, by Ward Christensen\n",
  49.         vers);
  50.     puts("\nEnsures that a hard disk has an F8 in byte 0 of the first FAT.");
  51.     puts("\tand that bytes 1-2 are FF.");
  52.     puts("\nUsed when CHKDSK reports ""Probable Non-DOS disk"".");
  53.     if (argc != 2)
  54.     {    how();
  55.         exit(1);
  56.     }
  57.         if (argv[1][1] != ':')
  58.     {    how();
  59.              exit(1);
  60.     }
  61.     drivechar = argv[1][0];
  62.         if (islower(drivechar))
  63.         drivechar = toupper(drivechar);
  64.     if (drivechar >= 'A' && drivechar <= 'B')
  65.      puts("\n*** Not designed to work on diskettes - they don't use F8.");
  66.  
  67.     if (drivechar < 'C')
  68.     {    how();
  69.         exit(1);
  70.     }
  71.     if (drivechar > 'Z')
  72.     {    how();
  73.         exit(1);
  74.     }
  75.     drive = drivechar-'A';
  76.         /* drive, # sectors, start sec */
  77.     rc = absread(drive, 1, 1, buffer);
  78.     if (rc != 0)
  79.     {    perror("*** Unable to read Fat 1 sector");
  80.         exit(1);
  81.  
  82.     }
  83.     puts("\nYour current FAT starts out:");
  84.     dump();
  85.     if ((int) buffer[0] == 0x00F8)
  86.     {    puts("\n*** FAT byte 00 is already an F8.  No action taken.");
  87.         exit(0);
  88.     }
  89.     buffer[0] = '\xF8';    /* Patch in correct values */
  90.     buffer[1] = '\xFF';
  91.     buffer[2] = '\xFF';
  92.  
  93.     puts("\nAfter patching, your buffer looks like this:");
  94.     dump();
  95.  
  96.     printf("\nDo you want to write the patched value back to disk? ");
  97.         gets(answer);
  98.     if (islower(answer[0]))
  99.         answer[0] = toupper(answer[0]);
  100.     if (answer[0] == 'Y')
  101.     {    printf("writing...");
  102.         rc = abswrite(drive, 1, 1, buffer);
  103.         if (rc != 0)
  104.         {    perror("*** Error writing back sector");
  105.             exit(1);
  106.         }
  107.     }
  108.     puts("Done");
  109. }
  110.  
  111.