I am writing software to utilize and manipulate GUID Partition Tables (GPT). I've been using a number of references, but in looking through the UEFI standards document concerning GUID Partition Tables, a number of questions have come up.
On page 121 of the specification document, the field SizeOfPartitionEntry says that it can take on any multiple of 128. The formula it gives is 128 * 2^n where n is any integer equal to or greater than zero. The question is, is there a reason to use a size other than 128 bytes as that is the side of a partition entry?
On the same page, it lists the number of entries in the partition table. My understanding is that this is always 128. Is this the case or can the number change? Since the max value as defined by the spec is 128, one would assume that it can be less?
Currently, the code that I have written is to just convert the values from an on-disk packed format to a non-packed format to facilitate data access. Additionally, I have routines that will perform the CRC32 checks on the aspects of the GPT as well. That code is below.
/* Validates the GPT entries. */
int fs_gptp_gptevalid(fs_gptent_t *list, fs_gpt_t *head)
{
uint32 ls; /* List Size */
uint32 crc; /* List CRC */
ls = head->entry_count * head->entry_size;
crc = fs_gptp_crc32(list, ls);
if (crc != head->p_crc32) return(0);
return(1);
}
/* Validates the GPT header. */
int fs_gptp_gpthvalid(fs_gpt_t *head)
{
uint32 hs; /* Header Size */
uint32 crc1, crc2; /* Header CRCs */
/* According to the specification, the header CRC field
needs to be zero when calculating the CRC. */
hs = head->hsize;
crc1 = head->h_crc32;
head->h_crc32 = 0;
crc2 = fs_gptp_crc32(head, hs);
head->h_crc32 = crc1;
if (crc1 != crc2) return(0);
return(1);
}