home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1035 / mbb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  6.8 KB  |  157 lines

  1. /*
  2. **      mbb.h
  3. **              Master Boot Block for DOS type hard disk
  4. **      The pre-boot code, partition table and signature are found here.
  5. **      Pre version 2.3 V/AT 286 also stored disk geometry here.
  6. **      2.3 and above moved this info to the Partition Boot Block.
  7. **
  8. **      $Header: mbb.h,v 1.1 88/04/07 23:11:40 root Alpha $
  9. */
  10.  
  11. #ifndef MBB_H
  12. #define MBB_H
  13.  
  14. /*
  15. **      Master Boot Block as it appears on physical block 0 of a hard disk.
  16. **      Size of this structure must be exactly 512 bytes.  At offset 0x1a6
  17. **      the drive geometry may be stored (in a checksummed atructure).  The
  18. **      partition table starts at offset 0x01BE.  There are four entries and
  19. **      each entry is 16 bytes.  The block signature is in last two bytes.
  20. */
  21.  
  22. /*
  23. **    The MBB Drive Geometry table
  24. **
  25. **          +--------+-------+
  26. ** 0x1A6    | Cylinders      |
  27. **          +--------+-------+
  28. ** 0x1A8    | Heads          |
  29. **          +--------+-------+
  30. ** 0x1AA    | Precomp        |
  31. **          +--------+-------+
  32. ** 0x1AC    | Landing Zone   |
  33. **          +--------+-------+
  34. ** 0x1AE    |    CHECKSUM    |
  35. **          +--------+-------+
  36. */
  37.  
  38. typedef struct {
  39.         short numcyls,
  40.               numheads,
  41.               precompcyl,
  42.               landingzone,
  43.               checksum;
  44. } dparm_t;
  45.  
  46. /*
  47. **          +--------+-------+
  48. ** 0x1B0    |                |
  49. ** 0x1B2    |                |
  50. ** 0x1B4    |                |
  51. ** 0x1B6    | filler[ 14 ]   |
  52. ** 0x1B8    |                |
  53. ** 0x1BA    |                |
  54. ** 0x1BC    |                |
  55. **          +--------+-------+
  56. */
  57.  
  58. /*
  59. **        DOS assumes a 10 bit cylinder number in its ROM bios tables.
  60. **      this is mapped as follows:
  61. **              lower 8 bits are stored in the CYL field
  62. **              upper 2 bits are stored as 2 high order bits in the SEC field
  63. **        All partitions are allocated in cylinder multiples and begin on
  64. **      sector 1 head 0.  EXCEPTION:  The partition that is located at the
  65. **      beginning of the disk *must* start at sector 2 to leave room for the
  66. **      disk's Master Boot Record.
  67. **        The relative sector field is the count of the number of sectors
  68. **      which preceede this partition on the disk.  The starting sector of
  69. **      this partition is found by using the value CYLINDER as found in the
  70. **      partition table, and the known geometry of the drive:
  71. **              relsec = CYL * (HeadsOnDrive * SecsPerHead) 
  72. **      The field is stored with the least significant word first.
  73. **
  74. **        e.g., For a 4 head drive with 17 sectors per track, assume that
  75. **              the second partition starts on cyl 1 (sector 1 and head 1
  76. **              are implied for all but the first partition)
  77. **                      relsec = 1 * ( 4 * 17 )  (cyl 1, 4 heads, 17 sec/track)
  78. **                      relsec = 68
  79. **              For the first partition, relsec = 1 ('cuz of master boot block)
  80. **
  81. **        The number of sectors allocated in this partition is kept in the
  82. **      next field.  It too is stored with the least significant word first.
  83.  
  84. **                       The partition table:
  85. **      Offset  Description             +--------+--------+--------+--------+
  86. ** P1   0x1BE   beginning of partition  |boot ind|  head  | sector |cylinder|
  87. **      0x1C2   end of partition        |syst ind|  head  | sector |cylinder|
  88. **      0x1C6   reletive sector         |    low word     |    high word    |
  89. **      0x1CA   number of sectors       |    low word     |    high word    |
  90. **                                      +--------+--------+--------+--------+
  91. ** P2   0x1CE   beginning of partition  |boot ind|  head  | sector |cylinder|
  92. **      0x1D2   end of partition        |syst ind|  head  | sector |cylinder|
  93. **      0x1D6   reletive sector         |    low word     |    high word    |
  94. **      0x1DA   number of sectors       |    low word     |    high word    |
  95. **                                      +--------+--------+--------+--------+
  96. ** P3   0x1DE   beginning of partition  |boot ind|  head  | sector |cylinder|
  97. **      0x1E2   end of partition        |syst ind|  head  | sector |cylinder|
  98. **      0x1E6   reletive sector         |    low word     |    high word    |
  99. **      0x1EA   number of sectors       |    low word     |    high word    |
  100. **                                      +--------+--------+--------+--------+
  101. ** P4   0x1EE   beginning of partition  |boot ind|  head  | sector |cylinder|
  102. **      0x1F2   end of partition        |syst ind|  head  | sector |cylinder|
  103. **      0x1F6   reletive sector         |    low word     |    high word    |
  104. **      0x1FA   number of sectors       |    low word     |    high word    |
  105. **                                      +--------+--------+--------+--------+
  106. */
  107.  
  108. #define NPART   4               /* # of partitions in partition table */
  109.  
  110. typedef struct  {
  111.     unsigned char   pt_bootind;         /* boot indicator 0x00 | 0x80 */
  112.     unsigned char   pt_bhead;           /* head, sector, & cyl of     */
  113.     unsigned char   pt_bsector;         /*  the boot sector for this  */
  114.     unsigned char   pt_bcyl;            /*  partition (load at 0:7C00)*/
  115.     unsigned char   pt_sys;             /* partition (system) type    */
  116.     unsigned char   pt_ehead;           /* head, sector and cyl of    */
  117.     unsigned char   pt_esector;         /*  the end of this           */
  118.     unsigned char   pt_ecyl;            /*  partition                 */
  119.     unsigned long   pt_start;           /* starting sector            */
  120.     unsigned long   pt_size;            /* size in sectors            */
  121. } partition_t;
  122.  
  123. /*
  124. **        The Master Boot Block Signature is the last 2 bytes of the boot record
  125. **      which have the values 0x55 and 0xAA.
  126. **
  127. **                                      +--------+--------+
  128. **      0x1FE   Master Boot Signature   |  0x55  |  0xAA  |
  129. **                                      +--------+--------+
  130. */
  131.  
  132. #define PT_INFO         (0x1a6) /* WN.H */              /* start of driveinfo*/
  133.  
  134. typedef struct  {
  135.     char          bootcode[ PT_INFO ];  /* boot code  at start of MBB */
  136.     dparm_t       geometry;             /* cyls, heads, ... */
  137.     char          filler[ 14 ];
  138.     partition_t   partitiontable[ NPART ];
  139.     unsigned int  signature;
  140. } mbb_t;
  141.  
  142. #define PT_SIG          0xaa55                          /* magic constant    */
  143. #define PT_BOOT         0x80                            /* active  partition */
  144. #define PT_NULL         0x00                            /* passive partition */
  145. #define PT_UNUSED       0x00                            /* unused system type*/
  146.  
  147. #define PART(mbb,i)    ((mbb)->partition[ (i) ])
  148. #define CYL_BOOT(ptp)  ((ptp)->pt_bcyl | (((ptp)->pt_bsector & 0x00C0)<<2))
  149. #define HEAD_BOOT(ptp) ((ptp)->pt_bhead)
  150. #define SEC_BOOT(ptp)  ((ptp)->pt_bsector & 0x003F)
  151. #define CYL_END(ptp)   ((ptp)->pt_ecyl | (((ptp)->pt_esector & 0x00C0)<<2))
  152. #define HEAD_END(ptp)  ((ptp)->pt_ehead)
  153. #define SEC_END(ptp)   ((ptp)->pt_esector & 0x003F)
  154.  
  155. #endif /* MBB_H */
  156.  
  157.