Fix broken GPT structure

This commit is contained in:
Alex 2023-05-13 06:31:56 +03:00
parent 61c53c127c
commit 8c98265e06
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 14 additions and 21 deletions

View File

@ -84,13 +84,15 @@ namespace Disk
for (uint32_t e = 0; e < Entries; e++) for (uint32_t e = 0; e < Entries; e++)
{ {
GUIDPartitionTablePartition GPTPartition = reinterpret_cast<GUIDPartitionTablePartition *>(RWBuffer)[e]; GUIDPartitionTableEntry GPTPartition = reinterpret_cast<GUIDPartitionTableEntry *>(RWBuffer)[e];
if (GPTPartition.TypeLow || GPTPartition.TypeHigh) if (memcmp(GPTPartition.PartitionType, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(GPTPartition.PartitionType)) != 0)
{ {
Partition partition{}; Partition partition{};
memcpy(partition.Label, GPTPartition.Label, sizeof(partition.Label)); for (int i = 0; i < 36; i++)
partition.StartLBA = GPTPartition.StartLBA; memcpy(partition.Label + i * 2, &GPTPartition.PartitionName[i], 2);
partition.EndLBA = GPTPartition.EndLBA; partition.Label[71] = '\0';
partition.StartLBA = GPTPartition.FirstLBA;
partition.EndLBA = GPTPartition.LastLBA;
partition.Sectors = partition.EndLBA - partition.StartLBA; partition.Sectors = partition.EndLBA - partition.StartLBA;
partition.Port = ItrPort; partition.Port = ItrPort;
partition.Flags = Present; partition.Flags = Present;
@ -98,14 +100,7 @@ namespace Disk
if (GPTPartition.Attributes & 1) if (GPTPartition.Attributes & 1)
partition.Flags |= EFISystemPartition; partition.Flags |= EFISystemPartition;
partition.Index = drive.Partitions.size(); partition.Index = drive.Partitions.size();
// why there is NUL (\0) between every char????? trace("GPT partition \"%s\" found with %lld sectors", partition.Label, partition.Sectors);
char PartName[72];
memcpy(PartName, GPTPartition.Label, 72);
for (int i = 0; i < 72; i++)
if (PartName[i] == '\0')
PartName[i] = ' ';
PartName[71] = '\0';
trace("GPT partition \"%s\" found with %lld sectors", PartName, partition.Sectors);
drive.Partitions.push_back(partition); drive.Partitions.push_back(partition);
// char *PartitionName = new char[64]; // char *PartitionName = new char[64];

View File

@ -62,16 +62,14 @@ namespace Disk
uint8_t Signature[2]; uint8_t Signature[2];
} __packed; } __packed;
struct GUIDPartitionTablePartition struct GUIDPartitionTableEntry
{ {
uint64_t TypeLow; uint8_t PartitionType[16];
uint64_t TypeHigh; uint8_t UniquePartitionGUID[16];
uint64_t GUIDLow; uint64_t FirstLBA;
uint64_t GUIDHigh; uint64_t LastLBA;
uint64_t StartLBA;
uint64_t EndLBA;
uint64_t Attributes; uint64_t Attributes;
char Label[72]; uint16_t PartitionName[36];
} __packed; } __packed;
struct GUIDPartitionTable struct GUIDPartitionTable