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.

297 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. bootlib.h
  5. Abstract:
  6. This module is the header file for the common boot library
  7. Author:
  8. John Vert (jvert) 5-Oct-1993
  9. Revision History:
  10. --*/
  11. #ifndef _BOOTLIB_
  12. #define _BOOTLIB_
  13. #include "ntos.h"
  14. #include "bldr.h"
  15. #include "fatboot.h"
  16. #include "cdfsboot.h"
  17. #include "ntfsboot.h"
  18. #include "hpfsboot.h"
  19. #include "etfsboot.h"
  20. #include "netboot.h"
  21. #include "udfsboot.h"
  22. //
  23. // Define partition context structure.
  24. //
  25. typedef struct _PARTITION_CONTEXT {
  26. LARGE_INTEGER PartitionLength;
  27. ULONG StartingSector;
  28. ULONG EndingSector;
  29. UCHAR DiskId;
  30. UCHAR DeviceUnit;
  31. UCHAR TargetId;
  32. UCHAR PathId;
  33. ULONG SectorShift;
  34. ULONG Size;
  35. struct _DEVICE_OBJECT *PortDeviceObject;
  36. } PARTITION_CONTEXT, *PPARTITION_CONTEXT;
  37. #ifdef EFI_PARTITION_SUPPORT
  38. #pragma pack (1)
  39. typedef struct _EFI_PARTITION_TABLE {
  40. UCHAR Signature[8];
  41. ULONG Revision;
  42. ULONG HeaderSize;
  43. ULONG HeaderCRC;
  44. ULONG Reserved;
  45. unsigned __int64 MyLBA;
  46. unsigned __int64 AlternateLBA;
  47. unsigned __int64 FirstUsableLBA;
  48. unsigned __int64 LastUsableLBA;
  49. UCHAR DiskGuid[16];
  50. unsigned __int64 PartitionEntryLBA;
  51. ULONG PartitionCount;
  52. ULONG PartitionEntrySize;
  53. ULONG PartitionEntryArrayCRC;
  54. UCHAR ReservedEnd[1]; // will extend till block size
  55. } EFI_PARTITION_TABLE, *PEFI_PARTITION_TABLE;
  56. typedef struct _EFI_PARTITION_ENTRY {
  57. UCHAR Type[16];
  58. UCHAR Id[16];
  59. unsigned __int64 StartingLBA;
  60. unsigned __int64 EndingLBA;
  61. unsigned __int64 Attributes;
  62. UCHAR Name[72];
  63. } EFI_PARTITION_ENTRY, *PEFI_PARTITION_ENTRY;
  64. #pragma pack ()
  65. #define EFI_SIGNATURE "EFI PART"
  66. #endif // EFI_PARTITION_SUPPORT
  67. //
  68. // Define serial port context structure
  69. //
  70. typedef struct _SERIAL_CONTEXT {
  71. ULONG PortBase;
  72. ULONG PortNumber;
  73. } SERIAL_CONTEXT, *PSERIAL_CONTEXT;
  74. //
  75. // Define drive context structure (for x86 BIOS)
  76. //
  77. typedef struct _DRIVE_CONTEXT {
  78. BOOLEAN IsCd;
  79. UCHAR Drive;
  80. UCHAR Sectors; // 1 - 63
  81. USHORT Cylinders; // 1 - 1023
  82. USHORT Heads; // 1 - 256
  83. BOOLEAN xInt13;
  84. #if defined(_IA64_)
  85. ULONGLONG DeviceHandle;
  86. #endif // IA64
  87. } DRIVE_CONTEXT, *PDRIVE_CONTEXT;
  88. //
  89. // Define Floppy context structure
  90. //
  91. typedef struct _FLOPPY_CONTEXT {
  92. ULONG DriveType;
  93. ULONG SectorsPerTrack;
  94. UCHAR DiskId;
  95. } FLOPPY_CONTEXT, *PFLOPPY_CONTEXT;
  96. //
  97. // Define keyboard context structure
  98. //
  99. typedef struct _KEYBOARD_CONTEXT {
  100. BOOLEAN ScanCodes;
  101. } KEYBOARD_CONTEXT, *PKEYBOARD_CONTEXT;
  102. //
  103. // Define Console context
  104. //
  105. typedef struct _CONSOLE_CONTEXT {
  106. ULONG ConsoleNumber;
  107. } CONSOLE_CONTEXT, *PCONSOLE_CONTEXT;
  108. //
  109. // Define EFI open handle context
  110. //
  111. typedef struct _EFI_ARC_OPEN_CONTEXT {
  112. PVOID Handle;
  113. PVOID DeviceEntryProtocol;
  114. } EFI_ARC_OPEN_CONTEXT, *PEFI_ARC_OPEN_CONTEXT;
  115. //
  116. // Define file table structure.
  117. //
  118. typedef struct _BL_FILE_FLAGS {
  119. ULONG Open : 1;
  120. ULONG Read : 1;
  121. ULONG Write : 1;
  122. ULONG Firmware : 1;
  123. } BL_FILE_FLAGS, *PBL_FILE_FLAGS;
  124. #define MAXIMUM_FILE_NAME_LENGTH 32
  125. typedef struct _BL_FILE_TABLE {
  126. BL_FILE_FLAGS Flags;
  127. ULONG DeviceId;
  128. LARGE_INTEGER Position;
  129. PVOID StructureContext;
  130. PBL_DEVICE_ENTRY_TABLE DeviceEntryTable;
  131. UCHAR FileNameLength;
  132. CHAR FileName[MAXIMUM_FILE_NAME_LENGTH];
  133. union {
  134. NTFS_FILE_CONTEXT NtfsFileContext;
  135. FAT_FILE_CONTEXT FatFileContext;
  136. UDFS_FILE_CONTEXT UdfsFileContext;
  137. CDFS_FILE_CONTEXT CdfsFileContext;
  138. ETFS_FILE_CONTEXT EtfsFileContext;
  139. NET_FILE_CONTEXT NetFileContext;
  140. PARTITION_CONTEXT PartitionContext;
  141. SERIAL_CONTEXT SerialContext;
  142. DRIVE_CONTEXT DriveContext;
  143. FLOPPY_CONTEXT FloppyContext;
  144. KEYBOARD_CONTEXT KeyboardContext;
  145. CONSOLE_CONTEXT ConsoleContext;
  146. EFI_ARC_OPEN_CONTEXT EfiContext;
  147. } u;
  148. } BL_FILE_TABLE, *PBL_FILE_TABLE;
  149. extern BL_FILE_TABLE BlFileTable[BL_FILE_TABLE_SIZE];
  150. //
  151. // Context structure for our Decompression pseudo-filesystem
  152. // (filter on top of other FS)
  153. //
  154. typedef struct _DECOMP_STRUCTURE_CONTEXT {
  155. //
  156. // File information from the original file system.
  157. //
  158. FILE_INFORMATION FileInfo;
  159. } DECOMP_STRUCTURE_CONTEXT, *PDECOMP_STRUCTURE_CONTEXT;
  160. //
  161. // Define generic filesystem context area.
  162. //
  163. // N.B. An FS_STRUCTURE_CONTEXT structure is temporarily used when
  164. // determining the file system for a volume. Once the file system
  165. // is recognized, a file system specific structure is allocated from
  166. // the heap to retain the file system structure information.
  167. //
  168. typedef union {
  169. UDFS_STRUCTURE_CONTEXT UdfsStructure;
  170. CDFS_STRUCTURE_CONTEXT CdfsStructure;
  171. FAT_STRUCTURE_CONTEXT FatStructure;
  172. HPFS_STRUCTURE_CONTEXT HpfsStructure;
  173. NTFS_STRUCTURE_CONTEXT NtfsStructure;
  174. #if defined(ELTORITO)
  175. ETFS_STRUCTURE_CONTEXT EtfsStructure;
  176. #endif
  177. NET_STRUCTURE_CONTEXT NetStructure;
  178. DECOMP_STRUCTURE_CONTEXT DecompStructure;
  179. } FS_STRUCTURE_CONTEXT, *PFS_STRUCTURE_CONTEXT;
  180. //
  181. //
  182. // N.B. We can speed up the boot time, by not
  183. // querying the device for all the possible file systems
  184. // for every open call. This saves approximately 30 secs
  185. // on CD-ROM / DVD-ROM boot time. To disable this feature
  186. // just undef CACHE_DEVINFO in bldr.h
  187. //
  188. //
  189. #ifdef CACHE_DEVINFO
  190. //
  191. // Device ID to File System information cache.
  192. //
  193. // N.B. For removable media its assumed that the device will
  194. // be closed using ArcClose(...) before using the new media.
  195. // This close call will invalidate the cached entry as
  196. // ArcClose(...) will be mapped to ArcCacheClose(...)
  197. //
  198. typedef struct _DEVICE_TO_FILESYS {
  199. ULONG DeviceId;
  200. PFS_STRUCTURE_CONTEXT Context;
  201. PBL_DEVICE_ENTRY_TABLE DevMethods;
  202. } DEVICE_TO_FILESYS, * PDEVICE_TO_FILESYS;
  203. extern DEVICE_TO_FILESYS DeviceFSCache[BL_FILE_TABLE_SIZE];
  204. #endif // CACHE_DEVINFO
  205. #ifdef EFI_PARTITION_SUPPORT
  206. typedef
  207. BOOLEAN
  208. (*PGPT_READ_CALLBACK)(
  209. IN ULONGLONG StartingLBA,
  210. IN ULONG BytesToRead,
  211. IN OUT PVOID Context,
  212. OUT PVOID OutputData
  213. );
  214. BOOLEAN
  215. BlIsValidGUIDPartitionTable(
  216. IN UNALIGNED EFI_PARTITION_TABLE *PartitionTableHeader,
  217. IN ULONGLONG LBAOfPartitionTable,
  218. IN PVOID Context,
  219. IN PGPT_READ_CALLBACK DiskReadFunction
  220. );
  221. UNALIGNED EFI_PARTITION_ENTRY *
  222. BlLocateGPTPartition(
  223. IN UCHAR PartitionNumber,
  224. IN UCHAR MaxPartitions,
  225. IN PUCHAR ValidPartitionCount OPTIONAL
  226. );
  227. ARC_STATUS
  228. BlOpenGPTDiskPartition(
  229. IN ULONG FileId,
  230. IN ULONG DiskId,
  231. IN UCHAR PartitionNumber
  232. );
  233. ARC_STATUS
  234. BlGetGPTDiskPartitionEntry(
  235. IN ULONG DiskNumber,
  236. IN UCHAR PartitionNumber,
  237. OUT EFI_PARTITION_ENTRY UNALIGNED **PartitionEntry
  238. );
  239. //
  240. // EFI partition table buffer
  241. //
  242. extern UNALIGNED EFI_PARTITION_ENTRY EfiPartitionBuffer[128];
  243. #endif // EFI_PARTITION_SUPPORT
  244. #endif _BOOTLIB_