| 1 | --- C:/work_x64/VirtualBox-4.3.12/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp Fri May 16 15:25:23 2014
|
|---|
| 2 | +++ C:/work_x64/vbox/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp Mon May 19 06:51:41 2014
|
|---|
| 3 | @@ -769,104 +769,122 @@
|
|---|
| 4 | partitioningType = GPT;
|
|---|
| 5 | pPart->uPartitioningType = GPT;//partitioningType;
|
|---|
| 6 |
|
|---|
| 7 | if (aBuffer[510] != 0x55 || aBuffer[511] != 0xaa)
|
|---|
| 8 | return VERR_INVALID_PARAMETER;
|
|---|
| 9 |
|
|---|
| 10 | rc = RTFileReadAt(File, sector_size, &partitionTableHeader, sector_size, NULL);
|
|---|
| 11 | - if (RT_SUCCESS(rc))
|
|---|
| 12 | +
|
|---|
| 13 | + if (RT_FAILURE(rc))
|
|---|
| 14 | + return rc;
|
|---|
| 15 | +
|
|---|
| 16 | + const char* l_ppth = (char*)partitionTableHeader;
|
|---|
| 17 | + rc = strncmp(l_ppth, "EFI PART", 8);
|
|---|
| 18 | + if (RT_FAILURE(rc))
|
|---|
| 19 | + return VERR_INVALID_PARAMETER;
|
|---|
| 20 | +
|
|---|
| 21 | + /** @todo check GPT Version */
|
|---|
| 22 | +
|
|---|
| 23 | + uint64_t firstUsableLBA = RT_MAKE_U64_FROM_U8(partitionTableHeader[40],
|
|---|
| 24 | + partitionTableHeader[41],
|
|---|
| 25 | + partitionTableHeader[42],
|
|---|
| 26 | + partitionTableHeader[43],
|
|---|
| 27 | + partitionTableHeader[44],
|
|---|
| 28 | + partitionTableHeader[45],
|
|---|
| 29 | + partitionTableHeader[46],
|
|---|
| 30 | + partitionTableHeader[47]
|
|---|
| 31 | + );
|
|---|
| 32 | + lastUsableLBA = RT_MAKE_U64_FROM_U8( partitionTableHeader[48],
|
|---|
| 33 | + partitionTableHeader[49],
|
|---|
| 34 | + partitionTableHeader[50],
|
|---|
| 35 | + partitionTableHeader[51],
|
|---|
| 36 | + partitionTableHeader[52],
|
|---|
| 37 | + partitionTableHeader[53],
|
|---|
| 38 | + partitionTableHeader[54],
|
|---|
| 39 | + partitionTableHeader[55]
|
|---|
| 40 | + );
|
|---|
| 41 | + uint32_t partitionsNumber = RT_MAKE_U32_FROM_U8( partitionTableHeader[80],
|
|---|
| 42 | + partitionTableHeader[81],
|
|---|
| 43 | + partitionTableHeader[82],
|
|---|
| 44 | + partitionTableHeader[83]
|
|---|
| 45 | + );
|
|---|
| 46 | + uint32_t partitionEntrySize = RT_MAKE_U32_FROM_U8( partitionTableHeader[84],
|
|---|
| 47 | + partitionTableHeader[85],
|
|---|
| 48 | + partitionTableHeader[86],
|
|---|
| 49 | + partitionTableHeader[87]
|
|---|
| 50 | + );
|
|---|
| 51 | +
|
|---|
| 52 | + uint32_t currentEntry = 0;
|
|---|
| 53 | + /* We must read multiple of sector size bytes, at sector boundary;
|
|---|
| 54 | + Otherwise, ReadFile() fails with ERROR_INVALID_PARAMETER,
|
|---|
| 55 | + on Windows hosts; maybe we should use aBuffer[] */
|
|---|
| 56 | + uint8_t aBuffer2[512];
|
|---|
| 57 | + /* partition entries begin from LBA2 */
|
|---|
| 58 | + uint64_t disk_offset_last = sector_size;
|
|---|
| 59 | + while (currentEntry < partitionsNumber)
|
|---|
| 60 | {
|
|---|
| 61 | - const char* l_ppth = (char*)partitionTableHeader;
|
|---|
| 62 | - rc = strncmp(l_ppth, "EFI PART", 8);
|
|---|
| 63 | - if (RT_FAILURE(rc))
|
|---|
| 64 | - return VERR_INVALID_PARAMETER;
|
|---|
| 65 | -
|
|---|
| 66 | - /** @todo check GPT Version */
|
|---|
| 67 | -
|
|---|
| 68 | - uint64_t firstUsableLBA = RT_MAKE_U64_FROM_U8(partitionTableHeader[40],
|
|---|
| 69 | - partitionTableHeader[41],
|
|---|
| 70 | - partitionTableHeader[42],
|
|---|
| 71 | - partitionTableHeader[43],
|
|---|
| 72 | - partitionTableHeader[44],
|
|---|
| 73 | - partitionTableHeader[45],
|
|---|
| 74 | - partitionTableHeader[46],
|
|---|
| 75 | - partitionTableHeader[47]
|
|---|
| 76 | - );
|
|---|
| 77 | - lastUsableLBA = RT_MAKE_U64_FROM_U8( partitionTableHeader[48],
|
|---|
| 78 | - partitionTableHeader[49],
|
|---|
| 79 | - partitionTableHeader[50],
|
|---|
| 80 | - partitionTableHeader[51],
|
|---|
| 81 | - partitionTableHeader[52],
|
|---|
| 82 | - partitionTableHeader[53],
|
|---|
| 83 | - partitionTableHeader[54],
|
|---|
| 84 | - partitionTableHeader[55]
|
|---|
| 85 | - );
|
|---|
| 86 | - uint32_t partitionsNumber = RT_MAKE_U32_FROM_U8( partitionTableHeader[80],
|
|---|
| 87 | - partitionTableHeader[81],
|
|---|
| 88 | - partitionTableHeader[82],
|
|---|
| 89 | - partitionTableHeader[83]
|
|---|
| 90 | - );
|
|---|
| 91 | - uint32_t partitionEntrySize = RT_MAKE_U32_FROM_U8( partitionTableHeader[84],
|
|---|
| 92 | - partitionTableHeader[85],
|
|---|
| 93 | - partitionTableHeader[86],
|
|---|
| 94 | - partitionTableHeader[87]
|
|---|
| 95 | - );
|
|---|
| 96 | + uint64_t partitionEntry_offset = 1024 + currentEntry * partitionEntrySize;
|
|---|
| 97 | + uint64_t disk_offset = (partitionEntry_offset / sector_size) * sector_size;
|
|---|
| 98 | + uint64_t buffer_offset = partitionEntry_offset % sector_size;
|
|---|
| 99 |
|
|---|
| 100 | - uint32_t currentEntry = 0;
|
|---|
| 101 | - while(currentEntry<partitionsNumber)
|
|---|
| 102 | + if (disk_offset != disk_offset_last)
|
|---|
| 103 | {
|
|---|
| 104 | - uint8_t partitionEntry[128];
|
|---|
| 105 | + rc = RTFileReadAt(File, disk_offset, &aBuffer2, sector_size, NULL);
|
|---|
| 106 |
|
|---|
| 107 | - /*partition entries begin from LBA2*/
|
|---|
| 108 | - rc = RTFileReadAt(File, 1024 + currentEntry*partitionEntrySize, &partitionEntry, partitionEntrySize, NULL);
|
|---|
| 109 | + if (RT_FAILURE(rc))
|
|---|
| 110 | + return rc;
|
|---|
| 111 |
|
|---|
| 112 | - uint64_t start = RT_MAKE_U64_FROM_U8( partitionEntry[32],
|
|---|
| 113 | - partitionEntry[33],
|
|---|
| 114 | - partitionEntry[34],
|
|---|
| 115 | - partitionEntry[35],
|
|---|
| 116 | - partitionEntry[36],
|
|---|
| 117 | - partitionEntry[37],
|
|---|
| 118 | - partitionEntry[38],
|
|---|
| 119 | - partitionEntry[39]
|
|---|
| 120 | - );
|
|---|
| 121 | - uint64_t end = RT_MAKE_U64_FROM_U8( partitionEntry[40],
|
|---|
| 122 | - partitionEntry[41],
|
|---|
| 123 | - partitionEntry[42],
|
|---|
| 124 | - partitionEntry[43],
|
|---|
| 125 | - partitionEntry[44],
|
|---|
| 126 | - partitionEntry[45],
|
|---|
| 127 | - partitionEntry[46],
|
|---|
| 128 | - partitionEntry[47]
|
|---|
| 129 | - );
|
|---|
| 130 | -
|
|---|
| 131 | - PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
|
|---|
| 132 | - pCP->uIndex = currentEntry + 1;
|
|---|
| 133 | - pCP->uType = 0;
|
|---|
| 134 | - pCP->uStartCylinder = 0;
|
|---|
| 135 | - pCP->uStartHead = 0;
|
|---|
| 136 | - pCP->uStartSector = 0;
|
|---|
| 137 | - pCP->uEndCylinder = 0;
|
|---|
| 138 | - pCP->uEndHead = 0;
|
|---|
| 139 | - pCP->uEndSector = 0;
|
|---|
| 140 | - pCP->uPartDataStart = 0; /* will be filled out later properly. */
|
|---|
| 141 | - pCP->cPartDataSectors = 0;
|
|---|
| 142 | - if (start==0 || end==0)
|
|---|
| 143 | - {
|
|---|
| 144 | - pCP->uIndex = 0;
|
|---|
| 145 | - --pPart->cPartitions;
|
|---|
| 146 | - break;
|
|---|
| 147 | - }
|
|---|
| 148 | - else
|
|---|
| 149 | - {
|
|---|
| 150 | - pCP->uStart = start;
|
|---|
| 151 | - pCP->uSize = (end +1) - start;/*+1 LBA because the last address is included*/
|
|---|
| 152 | - }
|
|---|
| 153 | + disk_offset_last = disk_offset;
|
|---|
| 154 | + }
|
|---|
| 155 | +
|
|---|
| 156 | + uint8_t *pBuffer = aBuffer2 + buffer_offset;
|
|---|
| 157 |
|
|---|
| 158 | - ++currentEntry;
|
|---|
| 159 | + uint64_t start = RT_MAKE_U64_FROM_U8( pBuffer[32],
|
|---|
| 160 | + pBuffer[33],
|
|---|
| 161 | + pBuffer[34],
|
|---|
| 162 | + pBuffer[35],
|
|---|
| 163 | + pBuffer[36],
|
|---|
| 164 | + pBuffer[37],
|
|---|
| 165 | + pBuffer[38],
|
|---|
| 166 | + pBuffer[39]
|
|---|
| 167 | + );
|
|---|
| 168 | + uint64_t end = RT_MAKE_U64_FROM_U8( pBuffer[40],
|
|---|
| 169 | + pBuffer[41],
|
|---|
| 170 | + pBuffer[42],
|
|---|
| 171 | + pBuffer[43],
|
|---|
| 172 | + pBuffer[44],
|
|---|
| 173 | + pBuffer[45],
|
|---|
| 174 | + pBuffer[46],
|
|---|
| 175 | + pBuffer[47]
|
|---|
| 176 | + );
|
|---|
| 177 | +
|
|---|
| 178 | + PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
|
|---|
| 179 | + pCP->uIndex = currentEntry + 1;
|
|---|
| 180 | + pCP->uType = 0;
|
|---|
| 181 | + pCP->uStartCylinder = 0;
|
|---|
| 182 | + pCP->uStartHead = 0;
|
|---|
| 183 | + pCP->uStartSector = 0;
|
|---|
| 184 | + pCP->uEndCylinder = 0;
|
|---|
| 185 | + pCP->uEndHead = 0;
|
|---|
| 186 | + pCP->uEndSector = 0;
|
|---|
| 187 | + pCP->uPartDataStart = 0; /* will be filled out later properly. */
|
|---|
| 188 | + pCP->cPartDataSectors = 0;
|
|---|
| 189 | + if (start==0 || end==0)
|
|---|
| 190 | + {
|
|---|
| 191 | + pCP->uIndex = 0;
|
|---|
| 192 | + --pPart->cPartitions;
|
|---|
| 193 | + break;
|
|---|
| 194 | }
|
|---|
| 195 | + else
|
|---|
| 196 | + {
|
|---|
| 197 | + pCP->uStart = start;
|
|---|
| 198 | + pCP->uSize = (end +1) - start; /* +1 LBA because the last address is included */
|
|---|
| 199 | + }
|
|---|
| 200 | +
|
|---|
| 201 | + ++currentEntry;
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 | else
|
|---|
| 205 | {
|
|---|
| 206 | partitioningType = MBR;
|
|---|
| 207 | pPart->uPartitioningType = MBR;//partitioningType;
|
|---|
| 208 |
|
|---|