summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2009-10-22 21:40:27 +0200
committerKarel Zak2009-10-22 23:19:25 +0200
commit4c8e837230bb96dc3c447706d9c3b11e4167ba13 (patch)
tree2b7938dab8402b295a03c95297077563b1bbc6b7
parentlibblkid: use BLKSSZGET for GPT sectors (diff)
downloadkernel-qcow2-util-linux-4c8e837230bb96dc3c447706d9c3b11e4167ba13.tar.gz
kernel-qcow2-util-linux-4c8e837230bb96dc3c447706d9c3b11e4167ba13.tar.xz
kernel-qcow2-util-linux-4c8e837230bb96dc3c447706d9c3b11e4167ba13.zip
libblkid: convert GPT partition LBA to 512-byte sectors
The libblkid keeps information about partitions in 512-byte counts. This patch: * convert GPT partition LBA to 512-byte sectors * fix n+1 bug in GPT partition size, because: "The partition is defined as all the logical blocks **inclusive** of the StartingLBA and EndingLBA." (UEFI 2.3) Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--shlibs/blkid/src/partitions/gpt.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/shlibs/blkid/src/partitions/gpt.c b/shlibs/blkid/src/partitions/gpt.c
index dcadf754e..2ec3f7397 100644
--- a/shlibs/blkid/src/partitions/gpt.c
+++ b/shlibs/blkid/src/partitions/gpt.c
@@ -287,6 +287,7 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag)
blkid_partlist ls;
int i;
uint64_t fu, lu;
+ uint32_t ssf;
if (last_lba(pr, &lastlba))
@@ -314,6 +315,8 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag)
if (!tab)
goto err;
+ ssf = blkid_probe_get_sectorsize(pr) / 512;
+
fu = le64_to_cpu(h->first_usable_lba);
lu = le64_to_cpu(h->last_usable_lba);
@@ -322,25 +325,27 @@ static int probe_gpt_pt(blkid_probe pr, const struct blkid_idmag *mag)
blkid_partition par;
uint64_t start = le64_to_cpu(e->starting_lba);
uint64_t size = le64_to_cpu(e->ending_lba) -
- le64_to_cpu(e->starting_lba);
+ le64_to_cpu(e->starting_lba) + 1ULL;
/* 00000000-0000-0000-0000-000000000000 entry */
if (!guidcmp(e->partition_type_guid, GPT_UNUSED_ENTRY_GUID))
continue;
/* the partition has to inside usable range */
- if (start < fu || start + size > lu) {
+ if (start < fu || start + size - 1 > lu) {
DBG(DEBUG_LOWPROBE, printf(
"GPT entry[%d] overflows usable area - ignore\n",
i));
continue;
}
- par = blkid_partlist_add_partition(ls, tab, 0, start, size);
+ par = blkid_partlist_add_partition(ls, tab, 0,
+ start * ssf, size * ssf);
if (!par)
goto err;
- blkid_partition_set_utf8name(par, (unsigned char *) e->partition_name,
+ blkid_partition_set_utf8name(par,
+ (unsigned char *) e->partition_name,
sizeof(e->partition_name), BLKID_ENC_UTF16LE);
blkid_partition_set_uuid(par,