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.

188 lines
5.9 KiB

  1. #include "ulib.hxx"
  2. #include "gptedit.hxx"
  3. extern "C" {
  4. #include <stdio.h>
  5. }
  6. BOOLEAN
  7. GUID_PARTITION_TABLE_EDIT::Initialize(
  8. IN HWND WindowHandle,
  9. IN INT ClientHeight,
  10. IN INT ClientWidth,
  11. IN PLOG_IO_DP_DRIVE Drive
  12. )
  13. {
  14. TEXTMETRIC textmetric;
  15. HDC hdc;
  16. hdc = GetDC(WindowHandle);
  17. if (hdc == NULL)
  18. return FALSE;
  19. GetTextMetrics(hdc, &textmetric);
  20. ReleaseDC(WindowHandle, hdc);
  21. VERTICAL_TEXT_SCROLL::Initialize(
  22. WindowHandle,
  23. 0,
  24. ClientHeight,
  25. ClientWidth,
  26. textmetric.tmExternalLeading + textmetric.tmHeight,
  27. textmetric.tmMaxCharWidth);
  28. return TRUE;
  29. }
  30. VOID
  31. GUID_PARTITION_TABLE_EDIT::SetBuf(
  32. IN HWND WindowHandle,
  33. IN OUT PVOID Buffer,
  34. IN ULONG Size
  35. )
  36. {
  37. _buffer = Buffer;
  38. _size = Size;
  39. SetScrollPos(WindowHandle, SB_VERT, 0, FALSE);
  40. }
  41. VOID
  42. GUID_PARTITION_TABLE_EDIT::Paint(
  43. IN HDC DeviceContext,
  44. IN RECT InvalidRect,
  45. IN HWND WindowHandle
  46. )
  47. {
  48. GPT_HEADER header;
  49. PGPT_HEADER pgpth;
  50. GPT_ENTRY entry;
  51. PGPT_ENTRY pgpte;
  52. TEXTMETRIC textmetric;
  53. INT ch, CurrentLine;
  54. TCHAR buf[1024];
  55. ULONG i, *pul, blockSize, firstEntryOffset;
  56. PUCHAR pch;
  57. SelectObject(DeviceContext, GetStockObject(ANSI_FIXED_FONT));
  58. if (!_buffer || _size < 512) {
  59. return;
  60. }
  61. blockSize = 512;
  62. //
  63. // BUGBUG keithka 4/10/00 -- consider catching folks using either
  64. // sector 0 or an MBR by mistake?
  65. //
  66. pgpth = (PGPT_HEADER)((PBYTE)_buffer);
  67. GetTextMetrics(DeviceContext, &textmetric);
  68. ch = textmetric.tmExternalLeading + textmetric.tmHeight;
  69. CurrentLine = 0;
  70. pch = (PUCHAR) &pgpth->Signature;
  71. swprintf( buf, TEXT("Signature: %c%c%c%c%c%c%c%c"),
  72. pch[0], pch[1], pch[2], pch[3], pch[4], pch[5], pch[6], pch[7] );
  73. WriteLine( DeviceContext, CurrentLine++, buf );
  74. swprintf( buf, TEXT("Revision: 0x%x"), pgpth->Revision );
  75. WriteLine( DeviceContext, CurrentLine++, buf );
  76. swprintf( buf, TEXT("HeaderSize: 0x%x"), pgpth->HeaderSize );
  77. WriteLine( DeviceContext, CurrentLine++, buf );
  78. swprintf( buf, TEXT("HeaderCRC32: 0x%x"), pgpth->HeaderCRC32 );
  79. WriteLine( DeviceContext, CurrentLine++, buf );
  80. swprintf( buf, TEXT("MyLBA: 0x%x"), pgpth->MyLBA );
  81. WriteLine( DeviceContext, CurrentLine++, buf );
  82. swprintf( buf, TEXT("AlternateLBA: 0x%x"), pgpth->AlternateLBA );
  83. WriteLine( DeviceContext, CurrentLine++, buf );
  84. swprintf( buf, TEXT("FirstUsableLBA: 0x%x"), pgpth->FirstUsableLBA );
  85. WriteLine( DeviceContext, CurrentLine++, buf );
  86. swprintf( buf, TEXT("LastUsableLBA: 0x%x"), pgpth->LastUsableLBA );
  87. WriteLine( DeviceContext, CurrentLine++, buf );
  88. // swprintf( buf, TEXT("DiskGUID: 0x%x"), pgpth->DiskGUID );
  89. // WriteLine( DeviceContext, CurrentLine++, buf );
  90. swprintf( buf, TEXT("TableLBA: 0x%x"), pgpth->TableLBA );
  91. WriteLine( DeviceContext, CurrentLine++, buf );
  92. swprintf( buf, TEXT("Entries Allocated: 0x%x"), pgpth->EntriesAllocated );
  93. WriteLine( DeviceContext, CurrentLine++, buf );
  94. swprintf( buf, TEXT("SizeOfGPT_ENTRY: 0x%x"), pgpth->SizeOfGPT_ENTRY );
  95. WriteLine( DeviceContext, CurrentLine++, buf );
  96. swprintf( buf, TEXT("TableCRC32: 0x%x"), pgpth->TableCRC32 );
  97. WriteLine( DeviceContext, CurrentLine++, buf );
  98. // Compute the sector checksum. BUGBUG keithka 4/10/00 -- consider???
  99. //
  100. swprintf( buf, TEXT("") );
  101. WriteLine( DeviceContext, CurrentLine++, buf );
  102. if (pgpth->MyLBA >= pgpth->TableLBA) {
  103. swprintf( buf, TEXT("MyLBA >= TableLBA, corrupt GPT?") );
  104. WriteLine( DeviceContext, CurrentLine++, buf );
  105. } else {
  106. firstEntryOffset = (ULONG) (blockSize * (pgpth->TableLBA - pgpth->MyLBA));
  107. pgpte = (PGPT_ENTRY) ((PBYTE)pgpth + firstEntryOffset);
  108. for( i = 0; i < pgpth->EntriesAllocated; i++ ) {
  109. if( (firstEntryOffset + (i + 1) * sizeof(GPT_ENTRY)) > _size ) {
  110. // About to read beyond our buffer.
  111. //
  112. break;
  113. }
  114. swprintf( buf, TEXT("Entry %d"), i );
  115. WriteLine( DeviceContext, CurrentLine++, buf );
  116. // swprintf( buf, TEXT(" PartitionType: 0x%x"), pgpte->PartitionType );
  117. // WriteLine( DeviceContext, CurrentLine++, buf );
  118. // swprintf( buf, TEXT(" PartitionID: 0x%x"), pgpte->PartitionID );
  119. // WriteLine( DeviceContext, CurrentLine++, buf );
  120. swprintf( buf, TEXT(" Starting LBA: 0x%x"), pgpte->StartingLBA );
  121. WriteLine( DeviceContext, CurrentLine++, buf );
  122. swprintf( buf, TEXT(" Ending LBA: 0x%x"), pgpte->EndingLBA );
  123. WriteLine( DeviceContext, CurrentLine++, buf );
  124. swprintf( buf, TEXT(" Attributes: 0x%x"), pgpte->Attributes );
  125. WriteLine( DeviceContext, CurrentLine++, buf );
  126. swprintf( buf, TEXT(" PartitionName: %s"), pgpte->PartitionName );
  127. WriteLine( DeviceContext, CurrentLine++, buf );
  128. swprintf( buf, TEXT("") );
  129. WriteLine( DeviceContext, CurrentLine++, buf );
  130. pgpte++;
  131. }
  132. if (0 == i) {
  133. swprintf( buf, TEXT("No valid GPT entries in the range read") );
  134. WriteLine( DeviceContext, CurrentLine++, buf );
  135. }
  136. }
  137. SetRange(WindowHandle, CurrentLine - 1);
  138. }