mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
Advanced settings FAT modification: add GPT partition support
This commit is contained in:
parent
05f1c4dbb5
commit
d600f36bc4
2 changed files with 49 additions and 2 deletions
|
@ -161,6 +161,23 @@ DeviceWrapperFatPartition *DeviceWrapper::fatPartition(int nr)
|
||||||
if (nr > 4 || nr < 1)
|
if (nr > 4 || nr < 1)
|
||||||
throw std::runtime_error("Only basic partitions 1-4 supported");
|
throw std::runtime_error("Only basic partitions 1-4 supported");
|
||||||
|
|
||||||
|
/* GPT table handling */
|
||||||
|
struct gpt_header gpt;
|
||||||
|
struct gpt_partition gptpart;
|
||||||
|
pread((char *) &gpt, sizeof(gpt), 512);
|
||||||
|
|
||||||
|
if (!strcmp("EFI PART", gpt.Signature) && gpt.MyLBA == 1)
|
||||||
|
{
|
||||||
|
qDebug() << "Using GPT partition table";
|
||||||
|
if (nr > gpt.NumberOfPartitionEntries)
|
||||||
|
throw std::runtime_error("Partition does not exist");
|
||||||
|
|
||||||
|
pread((char *) &gptpart, sizeof(gptpart), gpt.PartitionEntryLBA*512 + gpt.SizeOfPartitionEntry*(nr-1));
|
||||||
|
|
||||||
|
return new DeviceWrapperFatPartition(this, gptpart.StartingLBA*512, (gptpart.EndingLBA-gptpart.StartingLBA+1)*512, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* MBR table handling */
|
||||||
struct mbr_table mbr;
|
struct mbr_table mbr;
|
||||||
pread((char *) &mbr, sizeof(mbr), 0);
|
pread((char *) &mbr, sizeof(mbr), 0);
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ struct mbr_partition_entry {
|
||||||
char begin_hsc[3];
|
char begin_hsc[3];
|
||||||
unsigned char id;
|
unsigned char id;
|
||||||
char end_hsc[3];
|
char end_hsc[3];
|
||||||
unsigned int starting_sector;
|
uint32_t starting_sector;
|
||||||
unsigned int nr_of_sectors;
|
uint32_t nr_of_sectors;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mbr_table {
|
struct mbr_table {
|
||||||
|
@ -29,6 +29,36 @@ struct mbr_table {
|
||||||
unsigned char signature[2];
|
unsigned char signature[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* GUID on-disk structures
|
||||||
|
* https://www.intel.com/content/dam/www/public/us/en/zip/efi-110.zip (p. 369)
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct gpt_header {
|
||||||
|
char Signature[8];
|
||||||
|
uint32_t Revision;
|
||||||
|
uint32_t HeaderSize;
|
||||||
|
uint32_t HeaderCRC32;
|
||||||
|
uint32_t Reserved;
|
||||||
|
uint64_t MyLBA;
|
||||||
|
uint64_t AlternateLBA;
|
||||||
|
uint64_t FirstUsableLBA;
|
||||||
|
uint64_t LastUsableLBA;
|
||||||
|
unsigned char DiskGUID[16];
|
||||||
|
uint64_t PartitionEntryLBA;
|
||||||
|
uint32_t NumberOfPartitionEntries;
|
||||||
|
uint32_t SizeOfPartitionEntry;
|
||||||
|
uint32_t PartitionEntryArrayCRC32;
|
||||||
|
char Reserved2[420]; /* Assuming 512 byte sectors */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct gpt_partition {
|
||||||
|
unsigned char PartitionTypeGuid[16];
|
||||||
|
unsigned char UniquePartitionGuid[16];
|
||||||
|
uint64_t StartingLBA;
|
||||||
|
uint64_t EndingLBA;
|
||||||
|
uint64_t Attributes;
|
||||||
|
char PartitionName[72];
|
||||||
|
};
|
||||||
|
|
||||||
/* File Allocation Table
|
/* File Allocation Table
|
||||||
* https://academy.cba.mit.edu/classes/networking_communications/SD/FAT.pdf
|
* https://academy.cba.mit.edu/classes/networking_communications/SD/FAT.pdf
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue