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.

229 lines
8.0 KiB

  1. #if !defined( _GUID_PARTITION_TABLE_EDIT_ )
  2. #define _GUID_PARTITION_TABLE_EDIT_
  3. #include "edit.hxx"
  4. #include "vscroll.hxx"
  5. typedef struct _GUID_PARTITION_TABLE_ENTRY {
  6. UCHAR BootIndicator;
  7. UCHAR BeginningHead;
  8. UCHAR BeginningSector;
  9. UCHAR BeginningCylinder;
  10. UCHAR SystemID;
  11. UCHAR EndingHead;
  12. UCHAR EndingSector;
  13. UCHAR EndingCylinder;
  14. ULONG StartingSector;
  15. ULONG Sectors;
  16. } GUID_PARTITION_TABLE_ENTRY, *PGUID_PARTITION_TABLE_ENTRY;
  17. typedef UINT64 EFI_LBA;
  18. typedef WCHAR CHAR16;
  19. //
  20. // A GUID
  21. //
  22. typedef struct {
  23. UINT32 Data1;
  24. UINT16 Data2;
  25. UINT16 Data3;
  26. UINT8 Data4[8];
  27. } EFI_GUID;
  28. //
  29. // Rules:
  30. // None of these structures ever appear at LBA 0, because
  31. // we put a "fake" MBR there (the legacy defense MBR).
  32. // Therefore, LBA of 0 is useable as NULL.
  33. //
  34. // For All Entry's, StartingLBA must be >= FirstUsableLBA.
  35. // For All Entry's, EndingLBA must be <= LastUsableLBA.
  36. //
  37. // 0 is not a valid GUID. Therefore, emtpy GPT_ENTRY's will
  38. // have a PartitionType of 0.
  39. // However, if an entry is otherwise valid, but has a PartitionID
  40. // of 0, this means a GUID needs to be generated and placed there.
  41. //
  42. // LBA = Logical Block Address == Sector Number. Always count from 0.
  43. //
  44. // Block size (sector size) could be any number >= sizeof(GPT_ENTRY)
  45. // AND >= sizeof(GPT_HEADER). In practice, always >= 512 bytes.
  46. //
  47. // A block, B, is free for allocation to a partition if and only if
  48. // it is in the range FirstUsableLBA <= B <= LastUsableLBA AND it
  49. // is not already allocated to some other parition.
  50. //
  51. // GPT partitions are always contiguous arrays of blocks. however,
  52. // they need NOT be packed on the disk, their order in the GPT need
  53. // NOT match their order on the disk, there may be blank entries
  54. // in the GPT table, etc. Building an accurate view of the parititon
  55. // *requires* reading the entire GPT_TABLE into memory. In practice,
  56. // it will always be small enough for this to be easy.
  57. //
  58. #include <pshpack4.h>
  59. //
  60. // Each partition is described by a GPT_ENTRY.
  61. //
  62. #define PART_NAME_LEN 36
  63. typedef struct {
  64. EFI_GUID PartitionType; // declartion of this partition's type
  65. EFI_GUID PartitionID; // Unique ID for this particular partition
  66. // (unique to this instance)
  67. EFI_LBA StartingLBA; // 0 based block (sector) address of the
  68. // first block included in the partition.
  69. EFI_LBA EndingLBA; // 0 based block (sector) address of the
  70. // last block included in the partition.
  71. // If StartingLBA == EndingLBA then the
  72. // partition is 1 block long. this is legal.
  73. UINT64 Attributes; // Always ZERO for now
  74. CHAR16 PartitionName[PART_NAME_LEN]; // 36 unicode characters of name
  75. } GPT_ENTRY, *PGPT_ENTRY;
  76. C_ASSERT (sizeof (GPT_ENTRY) == 128);
  77. //
  78. // All of the GPT_ENTRY's are gathered into a GPT_TABLE, which
  79. // is stored as a linear array of blocks on the disk.
  80. //
  81. typedef struct {
  82. GPT_ENTRY Entry[1]; // Always an integer number of Entry's
  83. // per sector. Always at least 1 sector.
  84. // Can be any number of sectors...
  85. } GPT_TABLE, *PGPT_TABLE;
  86. //
  87. // A main and a backup header each describe the disk, and each points
  88. // to it's own copy of the GPT_TABLE...
  89. //
  90. typedef struct {
  91. UINT64 Signature; // GPT PART
  92. UINT32 Revision;
  93. UINT32 HeaderSize;
  94. UINT32 HeaderCRC32; // computed using 0 for own init value
  95. UINT32 Reserved0;
  96. EFI_LBA MyLBA; // 0 based sector number of the first
  97. // sector of this structure
  98. EFI_LBA AlternateLBA; // 0 based sector (block) number of the
  99. // first sector of the secondary
  100. // GPT_HEADER, or 0 if this is the
  101. // secondary.
  102. EFI_LBA FirstUsableLBA; // 0 based sector number of the first
  103. // sector that may be included in a partition.
  104. EFI_LBA LastUsableLBA; // last legal LBA, inclusive.
  105. EFI_GUID DiskGUID; // The unique ID of this LUN/spindle/disk
  106. EFI_LBA TableLBA; // The start of the table of entries...
  107. UINT32 EntriesAllocated; // Number of entries in the table, this is
  108. // how many allocated, NOT how many used.
  109. UINT32 SizeOfGPT_ENTRY; // sizeof(GPT_ENTRY) always mult. of 8
  110. UINT32 TableCRC32; // CRC32 of the table.
  111. // Reserved and zeros to the end of the block
  112. // Don't declare an array or sizeof() gives a nonsense answer..
  113. } GPT_HEADER, *PGPT_HEADER;
  114. C_ASSERT (sizeof (GPT_HEADER) == 92);
  115. #define GPT_HEADER_SIGNATURE 0x5452415020494645
  116. #define GPT_REVISION_1_0 0x00010000
  117. #define ENTRY_DEFAULT 128
  118. //#define ENTRY_DEFAULT 8 // TESTING ONLY
  119. #define ENTRY_SANITY_LIMIT 1024
  120. //
  121. // GPT Disk Layout
  122. //
  123. /*
  124. +---------------------------------------------------+
  125. LBA=0 | "Fake" MBR to ward off legacy parition apps |
  126. +---------------------------------------------------+
  127. LBA=1 | Primary GPT_HEADER |
  128. +---------------------------------------------------+
  129. LBA=2 | Primary GPT_TABLE starts |
  130. ... ... ...
  131. LBA=n | Primary GPT_TABLE ends |
  132. +---------------------------------------------------+
  133. LBA=n+1 | FirstUsableLBA = this block |
  134. ... ... ...
  135. LBA=x | LastUsableLBA = this block |
  136. +---------------------------------------------------+
  137. LBA=x+1 | Secondary GPT_TABLE starts |
  138. ... ... ...
  139. LBA=z | Secondary GPT_TABLE ends |
  140. +---------------------------------------------------+
  141. LBA=z+n | Secondary GPT_HEADER starts |
  142. ... ... ...
  143. LAST | Secondary GPT_HEADER ends at last sector of disk |
  144. +---------------------------------------------------+
  145. SO:
  146. Primary GPT_HEADER is always at LBA=1
  147. Secondary GPT_HEADER is at LBA=Last so long as GPT_HEADER fits
  148. in 1 sector, which we require.
  149. Primary Table is stacked up after the primary header,
  150. which points to it anyway.
  151. Secondary Table is stacked up before the secondary header,
  152. which points to it anyway.
  153. */
  154. //
  155. // ------------------ Functions To Manipulate GPT ---------------
  156. //
  157. typedef struct _LBA_BLOCK {
  158. EFI_LBA Header1_LBA;
  159. EFI_LBA Table1_LBA;
  160. EFI_LBA Header2_LBA;
  161. EFI_LBA Table2_LBA;
  162. } LBA_BLOCK, *PLBA_BLOCK;
  163. DECLARE_CLASS( GUID_PARTITION_TABLE_EDIT );
  164. class GUID_PARTITION_TABLE_EDIT : public VERTICAL_TEXT_SCROLL {
  165. public:
  166. VIRTUAL
  167. BOOLEAN
  168. Initialize(
  169. IN HWND WindowHandle,
  170. IN INT ClientHeight,
  171. IN INT ClientWidth,
  172. IN PLOG_IO_DP_DRIVE Drive
  173. );
  174. VIRTUAL
  175. VOID
  176. SetBuf(
  177. IN HWND WindowHandle,
  178. IN OUT PVOID Buffer,
  179. IN ULONG Size DEFAULT 0
  180. );
  181. VIRTUAL
  182. VOID
  183. Paint(
  184. IN HDC DeviceContext,
  185. IN RECT InvalidRect,
  186. IN HWND WindowHandle
  187. );
  188. private:
  189. PVOID _buffer;
  190. ULONG _size;
  191. };
  192. #include <poppack.h>
  193. #endif