home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BOOTANY1.ZIP / SHOWBOOT.C < prev    next >
Text File  |  1990-10-29  |  5KB  |  167 lines

  1. #include <stdio.h>
  2. #include "bootany.h"
  3.  
  4. #define DISK_READ 2
  5. #define DISK_WRITE 3
  6.  
  7. extern int bootio(int, char *);
  8.  
  9. #define SWITCH(var) switch (var)
  10. #define CASE(val) break; case val:
  11. #define ORCASE(val) case val:
  12. #define DEFAULT break; default:
  13.  
  14. #define EMPTY  0
  15. #define FAT_12 1
  16. #define XENIX  2
  17. #define FAT_16 4
  18. #define EXTEND 5
  19. #define BIGDOS 6
  20. #define HPFS   7
  21. #define NOVELL 0x64
  22. #define PCIX   0x75
  23. #define CP_M   0xDB
  24. #define BBT    0xFF
  25.  
  26. #define StandardTable 0
  27. #define BootAnyTable 1
  28.  
  29. main()
  30. {
  31.   static char head1[] =
  32.      "┌──────┬────┬────┬────────────────────┬────────────────────┬"
  33.      "─────────┬─────────┐";
  34.   static char head2[] =
  35.      "│ Part │Can │Boot│     Beginning      │       Ending       │"
  36.      "Relative │Number of│";
  37.   static char head3[] =
  38.      "│ Type │Boot│Part│Side Cylinder Sector│Side Cylinder Sector│"
  39.      "Sectors  │ Sectors │";
  40.   static char head4[] =
  41.      "├──────┼────┼────┼────┬────────┬──────┼────┬────────┬──────┼"
  42.      "─────────┼─────────┤";
  43.   static char detail1[] =
  44.      "│%6.6s│%4.4s│%4.4s│%3u │%7u │%5u │%3u │%7u │%5u │%8lu │%8lu │";
  45.   static char detail2[] =
  46.      "├──────┼────┼────┼────┼────────┼──────┼────┼────────┼──────┼"
  47.      "─────────┼─────────┤";
  48.   static char foot[] =
  49.      "└──────┴────┴────┴────┴────────┴──────┴────┴────────┴──────┴"
  50.      "─────────┴─────────┘";
  51.   char bootRecord[512];
  52.   char buffer[80];
  53.   int  rc;
  54.   int tableType = StandardTable;
  55.  
  56.    if ((rc = BOOTIO(DISK_READ, bootRecord)) == 0)
  57.      {
  58.        register BootData *bootInfo =
  59.                 (BootData *)(bootRecord + DataAddr);
  60.        register PartitionEntry *part = bootInfo->partEntry;
  61.        int i;
  62.  
  63.        printf(head1);
  64.        printf(head2);
  65.        printf(head3);
  66.        printf(head4);
  67.  
  68.        for (i = 0; i < 4; ++i)
  69.          {
  70.            int  type;
  71.            char boot;
  72.            char *active;
  73.            char *typeString;
  74.            char *bootString;
  75.            long relSectors;
  76.            long numSectors;
  77.  
  78.            if (part->bootIndicator == 0 ||
  79.                part->bootIndicator == (char)(0x80))
  80.              {
  81.                type = (int)(part->systemId);
  82.                boot = part->bootIndicator;
  83.                active = (boot == (char)0x80) ? "YES" : " NO";
  84.              }
  85.             else
  86.              {
  87.                active = "NO";
  88.                tableType = BootAnyTable;
  89.                type = (int)(part->bootIndicator);
  90.                boot = part->systemId;
  91.              }
  92.  
  93.            SWITCH(type)
  94.              {
  95.                CASE(EMPTY)
  96.                  {
  97.                    typeString = "EMPTY ";
  98.                  }
  99.                CASE(FAT_12)
  100.                  {
  101.                    typeString = "DOS-12";
  102.                  }
  103.                CASE(XENIX)
  104.                  {
  105.                    typeString = "XENIX ";
  106.                  }
  107.                CASE(FAT_16)
  108.                  {
  109.                    typeString = "DOS-16";
  110.                  }
  111.                CASE(EXTEND)
  112.                  {
  113.                    typeString = "EXTEND";
  114.                  }
  115.                CASE(BIGDOS)
  116.                  {
  117.                    typeString = "BIGDOS";
  118.                  }
  119.                CASE(HPFS)
  120.                  {
  121.                    typeString = "HPFS  ";
  122.                  }
  123.                CASE(NOVELL)
  124.                  {
  125.                    typeString = "NOVELL";
  126.                  }
  127.                CASE(PCIX)
  128.                  {
  129.                    typeString = "PCIX  ";
  130.                  }
  131.                CASE(CP_M)
  132.                  {
  133.                    typeString = "CP/M  ";
  134.                  }
  135.                CASE(BBT)
  136.                  {
  137.                    typeString = "BBT   ";
  138.                  }
  139.                DEFAULT
  140.                  {
  141.                    typeString = "??????";
  142.                  }
  143.              }
  144.  
  145.            bootString = (boot == (char)0x80) ? "YES" : " NO";
  146.  
  147.            relSectors = *(long*)(&part->relSectorLow);
  148.            numSectors = *(long*)(&part->numSectorsLow);
  149.  
  150.            printf(detail1, typeString, bootString, active,
  151.                   part->beginHead, part->beginCyl, part->beginSector,
  152.                   part->endHead, part->endCyl, part->endSector,
  153.                   relSectors, numSectors);
  154.            if (i < 3)
  155.              {
  156.                printf(detail2);
  157.              }
  158.            ++part;
  159.          }
  160.        printf(foot);
  161.      }
  162.     else
  163.      {
  164.        printf("Error reading boot record - rc = %d\n",rc);
  165.      }
  166. }
  167.