From 4c8e837230bb96dc3c447706d9c3b11e4167ba13 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 22 Oct 2009 21:40:27 +0200 Subject: [PATCH] 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 --- shlibs/blkid/src/partitions/gpt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/shlibs/blkid/src/partitions/gpt.c b/shlibs/blkid/src/partitions/gpt.c index dcadf754..2ec3f739 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, -- 2.39.5