Skip to contentSkip to conversation

part_efi: Fix partition size calculation due to inclusive ending LBA.

PATCH New Richard Retanubun 2 participants 4 messages Jan 5, 2009 – Jan 27, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 part_efi: Fix partition size calculation due to inclusive ending LBA.

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.

---
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(-)
disk/part_efi.c +3 -1
index cc188ee..d8a8111 100644
@@ -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

#1 lore raw

PATCH 1/1 part_efi: Fix partition size calculation due to inclusive ending LBA.

Ping. checking for feedback on this patch, thanks.

Quoted 41 lines

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.

---
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(-)
disk/part_efi.c +3 -2
index cc188ee..d8a8111 100644
@@ -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

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#2 lore raw

PATCH 1/1 part_efi: Fix partition size calculation due to inclusive ending LBA.

The ending LBA is inclusive. Hence, the partition size should be ((ending-LBA + 1) - starting-LBA) to get the proper partition size.

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

---
Hi Wolfgang,
Here is the patch rebased against commit 8f86a3636ef88427f880610638e80991adc41896

Thanks for the help
-Richard

  disk/part_efi.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
disk/part_efi.c +0 -0
index cc188ee..d8a8111 100644
@@ -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);

Signature · 1 line
1.5.6.5
#3 lore raw

PATCH 1/1 part_efi: Fix partition size calculation due to inclusive ending LBA.

Dear Richard Retanubun,

Quoted 11 lines · In message <[email protected]> you wrote:

The ending LBA is inclusive. Hence, the partition size should be ((ending-LBA + 1) - starting-LBA) to get the proper partition size.

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

---
Hi Wolfgang,
Here is the patch rebased against commit 8f86a3636ef88427f880610638e80991adc41896

Quoted 5 lines

Thanks for the help
-Richard

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

Applied, thanks, but...

disk/part_efi.c int get_partition_info_efi(block_dev_desc_t * dev_desc, int · line 163

Quoted 6 lines
disk/part_efi.c +0 -0
index cc188ee..d8a8111 100644
@@ -163,7 +163,9 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int 
 part,

^^^^^^^^^^
Line wrapped.

Please fix your mailer!

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Democracy is mob rule, but with income taxes.