home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d07xx / d0797.lha / BBBF / Programmers / CheckDrive.c < prev   
C/C++ Source or Header  |  1993-01-10  |  4KB  |  124 lines

  1. /* CheckDrive 1.4 ⌐ Johan Eliasson 1992             *
  2.  * To be compiled with SAS C (any version, I think) *
  3.  * > lc -L CheckDrive.c will do.                    */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <dos.h>
  8. #include <string.h>
  9. #include <exec/memory.h>
  10. #include <exec/types.h>
  11. #include <devices/trackdisk.h>
  12. #include <libraries/dosextens.h>
  13. #include <BBBF.h>
  14. #include <BBBF.pragma.h>
  15.  
  16. #define HELLO "CheckDrive 1.4 ⌐ Johan Eliasson 1992\nReading Bootblock.brainfile..."
  17. #define USAGE "Usage: CheckDrive <drive>\ndrive = number of drive to check"
  18.  
  19. UBYTE *VersionString = "$VER: CheckDrive 1.4 (11.11.92)";
  20.  
  21. struct Library *BootblockBase;
  22.  
  23. struct Bootblock *BB;
  24.  
  25. ULONG chip boot[256];
  26. ULONG      drive;
  27. USHORT     virus;
  28. char       string[80];
  29. char       version[30];
  30. long       retcode;
  31. long       readerror;
  32.  
  33. /* ****************************** main() ****************** */
  34.  
  35. void main(int argc,char *argv[])
  36. {
  37.   void die(),error();
  38.  
  39.   if ((argc == 1) || (argv[1][0] == '?'))
  40.     die(USAGE);
  41.  
  42.   Write(Output(),HELLO,strlen(HELLO));
  43.  
  44. /* ***************** Open Bootblock.library ************* */
  45.  
  46.   if (!(BootblockBase = (struct Library *) OpenLibrary("Bootblock.library",1)))
  47.     die("\nCheckDrive 1.4 needs the bootblock.library v1.0+ !");
  48.  
  49. /* ****************** Read brainfile ******************* */
  50.  
  51.   readerror = ReadBBBF("L:Bootblock.brainfile");
  52.  
  53.   if (readerror == ERROR_OBJECT_NOT_FOUND) readerror = ReadBBBF("Bootblock.brainfile");
  54.  
  55. /* ****************** Check result************************** */
  56.  
  57.   switch(readerror)
  58.   {
  59.     case BBBF_LOADED         : printf("Ok!\n\n"); break;
  60.     case BBBF_NOT_BBBF       : die("\n\nIt is not a Bootblock.brainfile!");
  61.     case BBBF_CHECKSUM_ERROR : die("\n\nThe Bootblock.brainfile is corrupted!");
  62.     case BBBF_ALREADY_LOADED : printf("\n\nThe brainfile is already loaded!\n"); break;
  63.     case BBBF_OUT_OF_MEMORY  : die("\n\nOut of memory!");
  64.     default                  : error(readerror);
  65.   };
  66.  
  67. /* ***************** Get additional info **************** */
  68.  
  69.   if (GetBBBFInfo(&virus,version) == BBBF_NOT_LOADED)
  70.     die("The brainfile is not loaded!");
  71.  
  72. /* ************************ Output info ********************** */
  73.  
  74.   printf("Brainfile version %s.\nKnows %d viruses.\n\n",version,virus);
  75.  
  76. /* ************************ Prepare for boot-read ***************** */
  77.  
  78.   if ((atol(argv[1]) <= 4) && (atol(argv[1]) >= 0))
  79.   {
  80.     drive = (ULONG) atol(argv[1]);
  81.  
  82. /* ********************** Read boot ***************************** */
  83.  
  84.     if (readerror = ReadBoot(drive,boot))
  85.       error(readerror);
  86.  
  87. /* ********************** Check boot ************************** */
  88.  
  89.     BB = (struct Bootblock *) CheckBoot(boot,&retcode);
  90.  
  91.     switch(retcode)
  92.     {
  93.       case BBBF_NOT_LOADED : die("Brainfile is not loaded!");
  94.       case BOOT_VIRUS      : sprintf(string,"WARNING! The disk in DF%d: is infected with the \'%s\' virus!",drive,BB->bootname);
  95.                              die(string);
  96.       case BOOT_UNKNOWN    : sprintf(string,"The disk in DF%d: is not infected with any known bootvirus!",drive);
  97.                              die(string);
  98.       case BOOT_NOT_BOOT   : sprintf(string,"The disk in DF%d: is not bootable!");
  99.                              die(string);
  100.     }
  101.   }
  102.  
  103.   die(USAGE);
  104. }
  105.  
  106. void error(short error)
  107. {
  108.   Fault(error,"Error",string,81);
  109.   die(string);
  110. }
  111.  
  112. void die(char *message)
  113. {
  114.   strcat(message,"\n");    /* Saved some bytes there! Or did I really? 8-) */
  115.   Write(Output(),message,strlen(message));
  116.   if (BootblockBase)
  117.   {
  118.     FreeBBBF();
  119.     CloseLibrary(BootblockBase);
  120.   }
  121.   exit(0);
  122. }
  123.  
  124.