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.

285 lines
7.7 KiB

  1. //
  2. // FAT/FAT32 boot sectors.
  3. //
  4. #pragma pack(1)
  5. /*
  6. typedef struct _PACKED_BPB_EX {
  7. UCHAR BytesPerSector[2]; // offset = 0x000 0
  8. UCHAR SectorsPerCluster[1]; // offset = 0x002 2
  9. UCHAR ReservedSectors[2]; // offset = 0x003 3
  10. UCHAR Fats[1]; // offset = 0x005 5
  11. UCHAR RootEntries[2]; // offset = 0x006 6
  12. UCHAR Sectors[2]; // offset = 0x008 8
  13. UCHAR Media[1]; // offset = 0x00A 10
  14. UCHAR SectorsPerFat[2]; // offset = 0x00B 11
  15. UCHAR SectorsPerTrack[2]; // offset = 0x00D 13
  16. UCHAR Heads[2]; // offset = 0x00F 15
  17. UCHAR HiddenSectors[4]; // offset = 0x011 17
  18. UCHAR LargeSectors[4]; // offset = 0x015 21
  19. UCHAR LargeSectorsPerFat[4]; // offset = 0x019 25
  20. UCHAR ExtendedFlags[2]; // offset = 0x01D 29
  21. UCHAR FsVersion[2]; // offset = 0x01F 31
  22. UCHAR RootDirFirstCluster[4]; // offset = 0x021 33
  23. UCHAR FsInfoSector[2]; // offset = 0x025 37
  24. UCHAR BackupBootSector[2]; // offset = 0x027 39
  25. UCHAR Reserved[12]; // offset = 0x029 41
  26. } PACKED_BPB_EX; // sizeof = 0x035 53
  27. */
  28. typedef struct _PACKED_BPB_EX {
  29. USHORT BytesPerSector; // offset = 0x000 0
  30. UCHAR SectorsPerCluster; // offset = 0x002 2
  31. USHORT ReservedSectors; // offset = 0x003 3
  32. UCHAR Fats; // offset = 0x005 5
  33. USHORT RootEntries; // offset = 0x006 6
  34. USHORT Sectors; // offset = 0x008 8
  35. UCHAR Media; // offset = 0x00A 10
  36. USHORT SectorsPerFat; // offset = 0x00B 11
  37. USHORT SectorsPerTrack; // offset = 0x00D 13
  38. USHORT Heads; // offset = 0x00F 15
  39. ULONG HiddenSectors; // offset = 0x011 17
  40. ULONG LargeSectors; // offset = 0x015 21
  41. ULONG LargeSectorsPerFat; // offset = 0x019 25
  42. USHORT ExtendedFlags; // offset = 0x01D 29
  43. USHORT FsVersion; // offset = 0x01F 31
  44. ULONG RootDirFirstCluster; // offset = 0x021 33
  45. USHORT FsInfoSector; // offset = 0x025 37
  46. USHORT BackupBootSector; // offset = 0x027 39
  47. UCHAR Reserved[12]; // offset = 0x029 41
  48. } PACKED_BPB_EX; // sizeof = 0x035 53
  49. typedef PACKED_BPB_EX _far *FPPACKED_BPB_EX;
  50. typedef struct _PACKED_BOOT_SECTOR_EX {
  51. UCHAR Jump[3]; // offset = 0x000 0
  52. UCHAR Oem[8]; // offset = 0x003 3
  53. PACKED_BPB_EX PackedBpb; // offset = 0x00B 11
  54. UCHAR PhysicalDriveNumber; // offset = 0x040 64
  55. UCHAR CurrentHead; // offset = 0x041 65
  56. UCHAR Signature; // offset = 0x042 66
  57. UCHAR Id[4]; // offset = 0x043 67
  58. UCHAR VolumeLabel[11]; // offset = 0x047 71
  59. UCHAR SystemId[8]; // offset = 0x058 88
  60. } FAT32_BOOT_SECTOR; // sizeof = 0x060 96
  61. typedef FAT32_BOOT_SECTOR _far *FPFAT32_BOOT_SECTOR;
  62. //
  63. // Define the FAT32 FsInfo sector.
  64. //
  65. typedef struct _FSINFO_SECTOR {
  66. ULONG SectorBeginSignature; // offset = 0x000 0
  67. UCHAR ExtraBootCode[480]; // offset = 0x004 4
  68. ULONG FsInfoSignature; // offset = 0x1e4 484
  69. ULONG FreeClusterCount; // offset = 0x1e8 488
  70. ULONG NextFreeCluster; // offset = 0x1ec 492
  71. UCHAR Reserved[12]; // offset = 0x1f0 496
  72. ULONG SectorEndSignature; // offset = 0x1fc 508
  73. } FSINFO_SECTOR, _far *FPFSINFO_SECTOR;
  74. #define FSINFO_SECTOR_BEGIN_SIGNATURE 0x41615252
  75. #define FSINFO_SECTOR_END_SIGNATURE 0xAA550000
  76. #define FSINFO_SIGNATURE 0x61417272
  77. #pragma pack()
  78. BOOL
  79. _far
  80. IsFat32(
  81. VOID *buf
  82. );
  83. typedef
  84. BOOL
  85. (*PDISKSEL_VALIDATION_ROUTINE) (
  86. IN USHORT DiskId
  87. );
  88. INT
  89. _far
  90. SelectDisk(
  91. IN UINT DiskCount,
  92. IN FPCHAR Prompt,
  93. IN PDISKSEL_VALIDATION_ROUTINE Validate, OPTIONAL
  94. OUT char *AlternateResponse, OPTIONAL
  95. IN FPCHAR textDisk,
  96. IN FPCHAR textPaddedMbCount,
  97. IN FPCHAR textInvalidSelection,
  98. IN FPCHAR textMasterDisk
  99. );
  100. INT
  101. _far
  102. SelectPartition(
  103. IN UINT PartitionCount,
  104. IN CHAR *Prompt,
  105. OUT CHAR *AlternateResponse, OPTIONAL
  106. IN FPCHAR textDisk,
  107. IN FPCHAR textPaddedMbCount,
  108. IN FPCHAR textInvalidSelection
  109. );
  110. BOOL
  111. _far
  112. ConfirmOperation(
  113. IN FPCHAR ConfirmationText,
  114. IN char textYesChar,
  115. IN char textNoChar
  116. );
  117. BOOL
  118. _far
  119. AllocTrackBuffer(
  120. IN BYTE SectorsPerTrack,
  121. OUT FPVOID _far *AlignedBuffer,
  122. OUT FPVOID _far *Buffer
  123. );
  124. VOID
  125. _far
  126. FlushDisks(
  127. VOID
  128. );
  129. ULONG
  130. _far
  131. DosSeek(
  132. IN unsigned Handle,
  133. IN ULONG Offset,
  134. IN BYTE Origin
  135. );
  136. #define DOSSEEK_START 0
  137. #define DOSSEEK_CURRENT 1
  138. #define DOSSEEK_END 2
  139. //** Must use this as initial value for CRC
  140. #define CRC32_INITIAL_VALUE 0L
  141. /*** CRC32Compute - Compute 32-bit
  142. *
  143. * Entry:
  144. * pb - Pointer to buffer to computer CRC on
  145. * cb - Count of bytes in buffer to CRC
  146. * crc32 - Result from previous CRC32Compute call (on first call
  147. * to CRC32Compute, must be CRC32_INITIAL_VALUE!!!!).
  148. *
  149. * Exit:
  150. * Returns updated CRC value.
  151. */
  152. ULONG
  153. _far
  154. CRC32Compute(
  155. IN FPBYTE pb,
  156. IN ULONG cb,
  157. IN ULONG crc32
  158. );
  159. VOID
  160. _far
  161. RebootSystem(
  162. VOID
  163. );
  164. unsigned
  165. _far
  166. GetGlobalCodepage(
  167. VOID
  168. );
  169. BOOL
  170. _far
  171. SetGlobalCodepage(
  172. IN unsigned Codepage
  173. );
  174. unsigned
  175. _far
  176. GetScreenCodepage(
  177. VOID
  178. );
  179. BOOL
  180. _far
  181. SetScreenCodepage(
  182. IN unsigned Codepage
  183. );
  184. typedef struct _CMD_LINE_ARGS {
  185. UINT LanguageCount;
  186. BOOL Test;
  187. BOOL Quiet;
  188. BOOL Reinit;
  189. BOOL DebugLog;
  190. BYTE MasterDiskInt13Unit;
  191. char _far *FileListFile;
  192. char _far *ImageFile;
  193. } CMD_LINE_ARGS, _far *FPCMD_LINE_ARGS;
  194. BOOL
  195. ParseArgs(
  196. IN int argc,
  197. IN FPCHAR argv[],
  198. IN BOOL Strict,
  199. IN FPCHAR AllowedSwitchChars,
  200. OUT FPCMD_LINE_ARGS CmdLineArgs
  201. );
  202. //
  203. // Compression stuff
  204. //
  205. typedef enum {
  206. CompressNone,
  207. CompressMrci1,
  208. CompressMrci2,
  209. CompressMax
  210. } CompressionType;
  211. BOOL
  212. CompressAndSave(
  213. IN CompressionType Type,
  214. IN FPBYTE Data,
  215. IN unsigned DataSize,
  216. OUT FPBYTE CompressScratchBuffer,
  217. IN unsigned BufferSize,
  218. IN UINT FileHandle
  219. );
  220. //
  221. // Logging stuff
  222. //
  223. VOID
  224. _LogStart(
  225. IN char *FileName
  226. );
  227. VOID
  228. _LogEnd(
  229. VOID
  230. );
  231. VOID
  232. _Log(
  233. IN char *FormatString,
  234. ...
  235. );
  236. VOID
  237. _LogSetFlags(
  238. IN unsigned Flags
  239. );
  240. //
  241. // If this flag is set the log file will be closed
  242. // and reopened after every call to _Log(). Useful
  243. // if a reboot is expected to occur.
  244. //
  245. #define LOGFLAG_CLOSE_REOPEN 0x0001