Confusion about GUID Partition Table specification

时间:2015-05-24 21:27:45

标签: c guid disk-partitioning guid-partition-table

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 个答案:

答案 0 :(得分:2)

SizeOfPartitionEntry 字段实际上必须是2的幂大于或等于128.所以1024是有效大小,但640(5 * 128)不是。据推测,允许128以外的大小,以便UEFI规范的未来版本可以以兼容的方式扩展分区条目的大小。您的代码应该能够处理任何有效的条目大小。请注意,由于规范的先前版本允许8的任意倍数,因此强大的实现也应该处理该情况。

虽然规范确实要求“至少16,384 必须为GPT分区条目数组保留空格字节“,我不知道这个或其他什么对 NumberOfPartitionEntries 字段有任何限制。我想,例如,值为4会只要在 MyLBA FirstUsableLBA 之间(以及 LastUsableLBA AlternateLBA 之间)保留16Kb,就可以使用该表如果有必要,可以扩展。无论哪种方式,我都看不到任何使得最大条目数为128的内容。如果 SizeOfPartitionEntry 大于128,它也可能小于128.

对于它的价值,快速Web搜索显示 NumberOfPartitionEntries 设置为12的HP Itanium服务器。