Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. bpb.h
  5. Abstract:
  6. This module contains the declarations for packed and
  7. unpacked Bios Parameter Block
  8. Author:
  9. Bill McJohn [BillMc] 24-September-1993
  10. Revision History:
  11. Adapted from utils\ifsutil\inc\bpb.hxx
  12. --*/
  13. #if !defined( _BPB_DEFN_ )
  14. #define _BPB_DEFN_
  15. #define cOEM 8
  16. #define cLABEL 11
  17. #define cSYSID 8
  18. typedef struct _PACKED_BIOS_PARAMETER_BLOCK {
  19. UCHAR BytesPerSector[2]; // offset = 0x000
  20. UCHAR SectorsPerCluster[1]; // offset = 0x002
  21. UCHAR ReservedSectors[2]; // offset = 0x003
  22. UCHAR Fats[1]; // offset = 0x005
  23. UCHAR RootEntries[2]; // offset = 0x006
  24. UCHAR Sectors[2]; // offset = 0x008
  25. UCHAR Media[1]; // offset = 0x00A
  26. UCHAR SectorsPerFat[2]; // offset = 0x00B
  27. UCHAR SectorsPerTrack[2]; // offset = 0x00D
  28. UCHAR Heads[2]; // offset = 0x00F
  29. UCHAR HiddenSectors[4]; // offset = 0x011
  30. UCHAR LargeSectors[4]; // offset = 0x015
  31. } PACKED_BIOS_PARAMETER_BLOCK; // sizeof = 0x019
  32. typedef PACKED_BIOS_PARAMETER_BLOCK *PPACKED_BIOS_PARAMETER_BLOCK;
  33. typedef struct BIOS_PARAMETER_BLOCK {
  34. USHORT BytesPerSector;
  35. UCHAR SectorsPerCluster;
  36. USHORT ReservedSectors;
  37. UCHAR Fats;
  38. USHORT RootEntries;
  39. USHORT Sectors;
  40. UCHAR Media;
  41. USHORT SectorsPerFat;
  42. USHORT SectorsPerTrack;
  43. USHORT Heads;
  44. ULONG HiddenSectors;
  45. ULONG LargeSectors;
  46. } BIOS_PARAMETER_BLOCK;
  47. typedef BIOS_PARAMETER_BLOCK *PBIOS_PARAMETER_BLOCK;
  48. #if !defined( _UCHAR_DEFINED_ )
  49. #define _UCHAR_DEFINED_
  50. //
  51. // The following types and macros are used to help unpack the packed and
  52. // misaligned fields found in the Bios parameter block
  53. //
  54. typedef union _UCHAR1 {
  55. UCHAR Uchar[1];
  56. UCHAR ForceAlignment;
  57. } UCHAR1, *PUCHAR1;
  58. typedef union _UCHAR2 {
  59. UCHAR Uchar[2];
  60. USHORT ForceAlignment;
  61. } UCHAR2, *PUCHAR2;
  62. typedef union _UCHAR4 {
  63. UCHAR Uchar[4];
  64. ULONG ForceAlignment;
  65. } UCHAR4, *PUCHAR4;
  66. #define CopyUchar1(Dst,Src) { \
  67. ((PUCHAR1)(Dst))->Uchar[0] = ((PUCHAR1)(Src))->Uchar[0]; \
  68. }
  69. #define CopyUchar2(Dst,Src) { \
  70. ((PUCHAR2)(Dst))->Uchar[0] = ((PUCHAR2)(Src))->Uchar[0]; \
  71. ((PUCHAR2)(Dst))->Uchar[1] = ((PUCHAR2)(Src))->Uchar[1]; \
  72. }
  73. #define CopyUchar4(Dst,Src) { \
  74. ((PUCHAR4)(Dst))->Uchar[0] = ((PUCHAR4)(Src))->Uchar[0]; \
  75. ((PUCHAR4)(Dst))->Uchar[1] = ((PUCHAR4)(Src))->Uchar[1]; \
  76. ((PUCHAR4)(Dst))->Uchar[2] = ((PUCHAR4)(Src))->Uchar[2]; \
  77. ((PUCHAR4)(Dst))->Uchar[3] = ((PUCHAR4)(Src))->Uchar[3]; \
  78. }
  79. #endif // _UCHAR_DEFINED_
  80. //
  81. // This macro takes a Packed BPB and fills in its Unpacked equivalent
  82. //
  83. #define UnpackBios(Bios,Pbios) { \
  84. CopyUchar2(&((Bios)->BytesPerSector), (Pbios)->BytesPerSector ); \
  85. CopyUchar1(&((Bios)->SectorsPerCluster), (Pbios)->SectorsPerCluster); \
  86. CopyUchar2(&((Bios)->ReservedSectors), (Pbios)->ReservedSectors ); \
  87. CopyUchar1(&((Bios)->Fats), (Pbios)->Fats ); \
  88. CopyUchar2(&((Bios)->RootEntries), (Pbios)->RootEntries ); \
  89. CopyUchar2(&((Bios)->Sectors), (Pbios)->Sectors ); \
  90. CopyUchar1(&((Bios)->Media), (Pbios)->Media ); \
  91. CopyUchar2(&((Bios)->SectorsPerFat), (Pbios)->SectorsPerFat ); \
  92. CopyUchar2(&((Bios)->SectorsPerTrack), (Pbios)->SectorsPerTrack ); \
  93. CopyUchar2(&((Bios)->Heads), (Pbios)->Heads ); \
  94. CopyUchar4(&((Bios)->HiddenSectors), (Pbios)->HiddenSectors ); \
  95. CopyUchar4(&((Bios)->LargeSectors), (Pbios)->LargeSectors ); \
  96. }
  97. //
  98. // This macro takes an Unpacked BPB and fills in its Packed equivalent
  99. //
  100. #define PackBios(Bios,Pbios) { \
  101. CopyUchar2((Pbios)->BytesPerSector, &((Bios)->BytesPerSector) ); \
  102. CopyUchar1((Pbios)->SectorsPerCluster, &((Bios)->SectorsPerCluster)); \
  103. CopyUchar2((Pbios)->ReservedSectors, &((Bios)->ReservedSectors) ); \
  104. CopyUchar1((Pbios)->Fats, &((Bios)->Fats) ); \
  105. CopyUchar2((Pbios)->RootEntries, &((Bios)->RootEntries) ); \
  106. CopyUchar2((Pbios)->Sectors, &((Bios)->Sectors) ); \
  107. CopyUchar1((Pbios)->Media, &((Bios)->Media) ); \
  108. CopyUchar2((Pbios)->SectorsPerFat, &((Bios)->SectorsPerFat) ); \
  109. CopyUchar2((Pbios)->SectorsPerTrack, &((Bios)->SectorsPerTrack) ); \
  110. CopyUchar2((Pbios)->Heads, &((Bios)->Heads) ); \
  111. CopyUchar4((Pbios)->HiddenSectors, &((Bios)->HiddenSectors) ); \
  112. CopyUchar4((Pbios)->LargeSectors, &((Bios)->LargeSectors) ); \
  113. }
  114. //
  115. // And now, an extended BPBP:
  116. //
  117. typedef struct _PACKED_EXTENDED_BIOS_PARAMETER_BLOCK {
  118. UCHAR IntelNearJumpCommand[1];
  119. UCHAR BootStrapJumpOffset[2];
  120. UCHAR OemData[cOEM];
  121. PACKED_BIOS_PARAMETER_BLOCK Bpb;
  122. UCHAR PhysicalDrive[1]; // 0 = removable, 80h = fixed
  123. UCHAR CurrentHead[1]; // not used by fs utils
  124. UCHAR Signature[1]; // boot signature
  125. UCHAR SerialNumber[4]; // volume serial number
  126. UCHAR Label[cLABEL]; // volume label, padded with spaces
  127. UCHAR SystemIdText[cSYSID]; // system ID, (e.g. FAT or HPFS)
  128. UCHAR StartBootCode; // first byte of boot code
  129. } PACKED_EXTENDED_BIOS_PARAMETER_BLOCK, *PPACKED_EXTENDED_BIOS_PARAMETER_BLOCK;
  130. typedef struct _EXTENDED_BIOS_PARAMETER_BLOCK {
  131. UCHAR IntelNearJumpCommand;
  132. USHORT BootStrapJumpOffset;
  133. UCHAR OemData[cOEM];
  134. BIOS_PARAMETER_BLOCK Bpb;
  135. UCHAR PhysicalDrive;
  136. UCHAR CurrentHead;
  137. UCHAR Signature;
  138. ULONG SerialNumber;
  139. UCHAR Label[11];
  140. UCHAR SystemIdText[8];
  141. } EXTENDED_BIOS_PARAMETER_BLOCK, *PEXTENDED_BIOS_PARAMETER_BLOCK;
  142. //
  143. // This macro unpacks a Packed Extended BPB.
  144. //
  145. #define UnpackExtendedBios( Bios, Pbios ) { \
  146. CopyUchar1( &((Bios)->IntelNearJumpCommand), (Pbios)->IntelNearJumpCommand ); \
  147. CopyUchar2( &((Bios)->BootStrapJumpOffset), (Pbios)->BootStrapJumpOffset ); \
  148. memcpy( (Bios)->OemData, (Pbios)->OemData, cOEM ); \
  149. UnpackBios( &((Bios)->Bpb), &((Pbios)->Bpb)); \
  150. CopyUchar1( &((Bios)->PhysicalDrive), (Pbios)->PhysicalDrive ); \
  151. CopyUchar1( &((Bios)->CurrentHead), (Pbios)->CurrentHead ); \
  152. CopyUchar1( &((Bios)->Signature), (Pbios)->Signature ) \
  153. CopyUchar4( &((Bios)->SerialNumber), (Pbios)->SerialNumber ); \
  154. memcpy( (Bios)->Label, (Pbios)->Label, cLABEL ); \
  155. memcpy( (Bios)->SystemIdText, (Pbios)->SystemIdText, cSYSID ); \
  156. }
  157. //
  158. // This macro packs a Packed Extended BPB.
  159. //
  160. #define PackExtendedBios( Bios, Pbios ) { \
  161. PackBios( &((Bios)->Bpb), &((Pbios)->Bpb)); \
  162. CopyUchar1( (Pbios)->IntelNearJumpCommand, &((Bios)->IntelNearJumpCommand) ); \
  163. CopyUchar2( (Pbios)->BootStrapJumpOffset, &((Bios)->BootStrapJumpOffset) ); \
  164. memcpy( (Pbios)->OemData, (Bios)->OemData, cOEM ); \
  165. CopyUchar1( (Pbios)->PhysicalDrive, &((Bios)->PhysicalDrive )); \
  166. CopyUchar1( (Pbios)->CurrentHead, &((Bios)->CurrentHead )); \
  167. CopyUchar1( (Pbios)->Signature, &((Bios)->Signature)); \
  168. CopyUchar4( (Pbios)->SerialNumber, &((Bios)->SerialNumber )); \
  169. memcpy( (Pbios)->Label, (Bios)->Label, cLABEL ); \
  170. memcpy( (Pbios)->SystemIdText, (Bios)->SystemIdText, cSYSID ); \
  171. }
  172. #endif