1

我正在编写软件来利用和操作 GUID 分区表 (GPT)。我一直在使用许多参考资料,但在查看有关 GUID 分区表的UEFI 标准文档时,出现了许多问题。

  1. 在规范文档的第 121 页上,字段SizeOfPartitionEntry表示它可以取 128 的任何倍数。它给出的公式是 128 * 2^n,其中 n 是等于或大于零的任何整数。问题是,是否有理由使用 128 字节以外的大小,因为那是分区条目的一侧?

  2. 在同一页面上,它列出了分区表中的条目数。我的理解是,这始终是 128。是这种情况还是数字可以改变?由于规范定义的最大值是 128,人们会假设它可以更小吗?

目前,我编写的代码只是将值从磁盘上的打包格式转换为非打包格式,以方便数据访问。此外,我还有一些例程可以对 GPT 的各个方面执行 CRC32 检查。该代码如下。

/* 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);
  }
4

1 回答 1

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.

于 2015-05-24T22:53:07.753 回答