[U-Boot] [PATCH] part_efi: Fix partition size calculation due to inclusive ending LBA.

Richard Retanubun RichardRetanubun at RuggedCom.com
Mon Jan 5 23:05:17 CET 2009


This patch fixed an off-by-one bug found for GPT. Because the ending LBA is inclusive, 
the partition size should be ((ending_lba + 1) - starting-LBA).

This is confirmed against the results from the parted tool.
(e.g. use parted /dev/sda -s unit S print) and observe the size.

Signed-off-by: Richard Retanubun <RichardRetanubun at RuggedCom.com>
---
Hi Wolfgang,

I sent this patch in december 12 to u-boot at lists.denx.de but I don't see it 
in the mailing list (possibly because I botched the commit message).

 disk/part_efi.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index cc188ee..d8a8111 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -163,7 +163,9 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,

        /* The ulong casting limits the maximum disk size to 2 TB */
        info->start = (ulong) le64_to_int((*pgpt_pte)[part - 1].starting_lba);
-       info->size = (ulong) le64_to_int((*pgpt_pte)[part - 1].ending_lba) - info->start;
+       /* The ending LBA is inclusive, to calculate size, add 1 to it */
+       info->size = ((ulong)le64_to_int((*pgpt_pte)[part - 1].ending_lba) + 1)
+                    - info->start;
        info->blksz = GPT_BLOCK_SIZE;

        sprintf((char *)info->name, "%s%d\n", GPT_ENTRY_NAME, part);
--
1.5.6.5





More information about the U-Boot mailing list