bpb.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* $OpenBSD: bpb.h,v 1.6 2014/12/19 22:44:59 guenther Exp $ */
  2. /* $NetBSD: bpb.h,v 1.6 1997/10/17 11:23:35 ws Exp $ */
  3. /*
  4. * Written by Paul Popelka (paulp@uts.amdahl.com)
  5. *
  6. * You can do anything you want with this software, just don't say you wrote
  7. * it, and don't remove this notice.
  8. *
  9. * This software is provided "as is".
  10. *
  11. * The author supplies this software to be publicly redistributed on the
  12. * understanding that the author is not responsible for the correct
  13. * functioning of this software in any circumstances and is not liable for
  14. * any damages caused by this software.
  15. *
  16. * October 1992
  17. */
  18. /*
  19. * BIOS Parameter Block (BPB) for DOS 3.3
  20. */
  21. struct bpb33 {
  22. u_int16_t bpbBytesPerSec; /* bytes per sector */
  23. u_int8_t bpbSecPerClust; /* sectors per cluster */
  24. u_int16_t bpbResSectors; /* number of reserved sectors */
  25. u_int8_t bpbFATs; /* number of FATs */
  26. u_int16_t bpbRootDirEnts; /* number of root directory entries */
  27. u_int16_t bpbSectors; /* total number of sectors */
  28. u_int8_t bpbMedia; /* media descriptor */
  29. u_int16_t bpbFATsecs; /* number of sectors per FAT */
  30. u_int16_t bpbSecPerTrack; /* sectors per track */
  31. u_int16_t bpbHeads; /* number of heads */
  32. u_int16_t bpbHiddenSecs; /* number of hidden sectors */
  33. };
  34. /*
  35. * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3,
  36. * and bpbHugeSectors is not in the 3.3 bpb.
  37. */
  38. struct bpb50 {
  39. u_int16_t bpbBytesPerSec; /* bytes per sector */
  40. u_int8_t bpbSecPerClust; /* sectors per cluster */
  41. u_int16_t bpbResSectors; /* number of reserved sectors */
  42. u_int8_t bpbFATs; /* number of FATs */
  43. u_int16_t bpbRootDirEnts; /* number of root directory entries */
  44. u_int16_t bpbSectors; /* total number of sectors */
  45. u_int8_t bpbMedia; /* media descriptor */
  46. u_int16_t bpbFATsecs; /* number of sectors per FAT */
  47. u_int16_t bpbSecPerTrack; /* sectors per track */
  48. u_int16_t bpbHeads; /* number of heads */
  49. u_int32_t bpbHiddenSecs; /* # of hidden sectors */
  50. u_int32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */
  51. };
  52. /*
  53. * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50.
  54. */
  55. struct bpb710 {
  56. u_int16_t bpbBytesPerSec; /* bytes per sector */
  57. u_int8_t bpbSecPerClust; /* sectors per cluster */
  58. u_int16_t bpbResSectors; /* number of reserved sectors */
  59. u_int8_t bpbFATs; /* number of FATs */
  60. u_int16_t bpbRootDirEnts; /* number of root directory entries */
  61. u_int16_t bpbSectors; /* total number of sectors */
  62. u_int8_t bpbMedia; /* media descriptor */
  63. u_int16_t bpbFATsecs; /* number of sectors per FAT */
  64. u_int16_t bpbSecPerTrack; /* sectors per track */
  65. u_int16_t bpbHeads; /* number of heads */
  66. u_int32_t bpbHiddenSecs; /* # of hidden sectors */
  67. u_int32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */
  68. u_int32_t bpbBigFATsecs; /* like bpbFATsecs for FAT32 */
  69. u_int16_t bpbExtFlags; /* extended flags: */
  70. #define FATNUM 0xf /* mask for numbering active FAT */
  71. #define FATMIRROR 0x80 /* FAT is mirrored (like it always was) */
  72. u_int16_t bpbFSVers; /* filesystem version */
  73. #define FSVERS 0 /* currently only 0 is understood */
  74. u_int32_t bpbRootClust; /* start cluster for root directory */
  75. u_int16_t bpbFSInfo; /* filesystem info structure sector */
  76. u_int16_t bpbBackup; /* backup boot sector */
  77. /* There is a 12 byte filler here, but we ignore it */
  78. };
  79. /*
  80. * The following structures represent how the bpb's look on disk. shorts
  81. * and longs are just character arrays of the appropriate length. This is
  82. * because the compiler forces shorts and longs to align on word or
  83. * halfword boundaries.
  84. *
  85. * XXX The little-endian code here assumes that the processor can access
  86. * 16-bit and 32-bit quantities on byte boundaries. If this is not true,
  87. * use the macros for the big-endian case.
  88. */
  89. #include <sys/endian.h>
  90. #if (BYTE_ORDER == LITTLE_ENDIAN) && !defined(__STRICT_ALIGNMENT)
  91. #define getushort(x) *((u_int16_t *)(x))
  92. #define getulong(x) *((u_int32_t *)(x))
  93. #define putushort(p, v) (*((u_int16_t *)(p)) = (v))
  94. #define putulong(p, v) (*((u_int32_t *)(p)) = (v))
  95. #else
  96. #define getushort(x) (((u_int8_t *)(x))[0] + (((u_int8_t *)(x))[1] << 8))
  97. #define getulong(x) (((u_int8_t *)(x))[0] + (((u_int8_t *)(x))[1] << 8) \
  98. + (((u_int8_t *)(x))[2] << 16) \
  99. + (((u_int8_t *)(x))[3] << 24))
  100. #define putushort(p, v) (((u_int8_t *)(p))[0] = (v), \
  101. ((u_int8_t *)(p))[1] = (v) >> 8)
  102. #define putulong(p, v) (((u_int8_t *)(p))[0] = (v), \
  103. ((u_int8_t *)(p))[1] = (v) >> 8, \
  104. ((u_int8_t *)(p))[2] = (v) >> 16,\
  105. ((u_int8_t *)(p))[3] = (v) >> 24)
  106. #endif
  107. /*
  108. * BIOS Parameter Block (BPB) for DOS 3.3
  109. */
  110. struct byte_bpb33 {
  111. int8_t bpbBytesPerSec[2]; /* bytes per sector */
  112. int8_t bpbSecPerClust; /* sectors per cluster */
  113. int8_t bpbResSectors[2]; /* number of reserved sectors */
  114. int8_t bpbFATs; /* number of FATs */
  115. int8_t bpbRootDirEnts[2]; /* number of root directory entries */
  116. int8_t bpbSectors[2]; /* total number of sectors */
  117. int8_t bpbMedia; /* media descriptor */
  118. int8_t bpbFATsecs[2]; /* number of sectors per FAT */
  119. int8_t bpbSecPerTrack[2]; /* sectors per track */
  120. int8_t bpbHeads[2]; /* number of heads */
  121. int8_t bpbHiddenSecs[2]; /* number of hidden sectors */
  122. };
  123. /*
  124. * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3,
  125. * and bpbHugeSectors is not in the 3.3 bpb.
  126. */
  127. struct byte_bpb50 {
  128. int8_t bpbBytesPerSec[2]; /* bytes per sector */
  129. int8_t bpbSecPerClust; /* sectors per cluster */
  130. int8_t bpbResSectors[2]; /* number of reserved sectors */
  131. int8_t bpbFATs; /* number of FATs */
  132. int8_t bpbRootDirEnts[2]; /* number of root directory entries */
  133. int8_t bpbSectors[2]; /* total number of sectors */
  134. int8_t bpbMedia; /* media descriptor */
  135. int8_t bpbFATsecs[2]; /* number of sectors per FAT */
  136. int8_t bpbSecPerTrack[2]; /* sectors per track */
  137. int8_t bpbHeads[2]; /* number of heads */
  138. int8_t bpbHiddenSecs[4]; /* number of hidden sectors */
  139. int8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */
  140. };
  141. /*
  142. * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50.
  143. */
  144. struct byte_bpb710 {
  145. u_int8_t bpbBytesPerSec[2]; /* bytes per sector */
  146. u_int8_t bpbSecPerClust; /* sectors per cluster */
  147. u_int8_t bpbResSectors[2]; /* number of reserved sectors */
  148. u_int8_t bpbFATs; /* number of FATs */
  149. u_int8_t bpbRootDirEnts[2]; /* number of root directory entries */
  150. u_int8_t bpbSectors[2]; /* total number of sectors */
  151. u_int8_t bpbMedia; /* media descriptor */
  152. u_int8_t bpbFATsecs[2]; /* number of sectors per FAT */
  153. u_int8_t bpbSecPerTrack[2]; /* sectors per track */
  154. u_int8_t bpbHeads[2]; /* number of heads */
  155. u_int8_t bpbHiddenSecs[4]; /* # of hidden sectors */
  156. u_int8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */
  157. u_int8_t bpbBigFATsecs[4]; /* like bpbFATsecs for FAT32 */
  158. u_int8_t bpbExtFlags[2]; /* extended flags: */
  159. u_int8_t bpbFSVers[2]; /* filesystem version */
  160. u_int8_t bpbRootClust[4]; /* start cluster for root directory */
  161. u_int8_t bpbFSInfo[2]; /* filesystem info structure sector */
  162. u_int8_t bpbBackup[2]; /* backup boot sector */
  163. /* There is a 12 byte filler here, but we ignore it */
  164. };
  165. /*
  166. * FAT32 FSInfo block.
  167. */
  168. struct fsinfo {
  169. u_int8_t fsisig1[4];
  170. u_int8_t fsifill1[480];
  171. u_int8_t fsisig2[4];
  172. u_int8_t fsinfree[4];
  173. u_int8_t fsinxtfree[4];
  174. u_int8_t fsifill2[12];
  175. u_int8_t fsisig3[4];
  176. u_int8_t fsifill3[508];
  177. u_int8_t fsisig4[4];
  178. };