Confusion about GUID Partition Table specification

484 Views Asked by At

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.

  1. 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?

  2. 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);
  }
1

There are 1 best solutions below

5
On BEST ANSWER

The SizeOfPartitionEntry field actually has to be a power of 2 greater than or equal to 128. So 1024 is valid size, but 640 (5 * 128) isn't. Presumably sizes other than 128 are allowed so that future version of the UEFI specification can expand the size of the partition entry in a compatible manner. Your code should be able to handle any valid entry size. Note that as previous versions of the specification allowed any multiple of 8, a robust implementation should handle that case as well.

While the specification does require that "a minimum of 16,384 bytes of space must be reserved for the GPT Partition Entry Array", I don't know if this or anything else places any limits on the NumberOfPartitionEntries field. I think, for example, a value of 4 would be permitted so long as 16Kb is reserved between MyLBA and FirstUsableLBA (and between LastUsableLBA and AlternateLBA) so that table could be expanded if necessary. Either way I can't see anything that that makes 128 the maximum number of entries. It could also be less than 128 if SizeOfPartitionEntry is bigger than 128.

For what it's worth, a quick Web search reveals HP Itanium servers with NumberOfPartitionEntries set to 12.