Leaked source code of windows server 2003
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.

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