1

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);
  }
alk
  • 69,737
  • 10
  • 105
  • 255
Daniel Rudy
  • 1,411
  • 12
  • 23

1 Answers1

2

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.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
  • That's a pretty good answer which answers my question. In the case of SizeOfPartitionEntry, I'm just going to use whatever it says as long as the minimum is 128. The specification says that the max is 128, but with a 32-bit unsigned integer, you can have 4 billion. So I will go with the max value being 128 and work with any size up to 128. – Daniel Rudy May 25 '15 at 11:15
  • @DanielRudy Can you point where it says the max is 128? I can't see it. – Ross Ridge May 25 '15 at 15:29
  • I don't see it in the spec either, but I know I read it somewhere. Also, since the minimum reserved size is 16384 bytes and each entry is 128 bytes, 16384 / 128 = 128. – Daniel Rudy May 27 '15 at 18:29
  • Yes, but the minimum reserved size would only place a minimum size on the number entries. So it doesn't prevent it from being larger than 128. It would only prevent it from being smaller than 128, but I don't think that's actually the case. The HP Itanium servers I mentioned have only 12 entries, but still reserve at least 16384 bytes (sometimes more) for the table. – Ross Ridge May 27 '15 at 18:42
  • I saw your blurb about HP Itanium servers having 12 entries. So as I understand it, there really isn't a limit as the only requirement for the table size is minimum 16k. However, I doubt that it would be practical to have 1 billion entries as that would reserve 128GB which would be a pretty good percentage of a HDD. And with an unsigned 32-bit int, you can have 4 billion, which is stupid. I do see the need to have more than 4 partitions, but I can't think of any situation that would require more than...32, even with 2 versions of windows and linux or freebsd installed. – Daniel Rudy May 28 '15 at 05:57