]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) provide last LBA where is partitions array
authorKarel Zak <kzak@redhat.com>
Fri, 7 Jan 2022 13:05:36 +0000 (14:05 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Jan 2022 13:05:36 +0000 (14:05 +0100)
Addresses: https://github.com/util-linux/util-linux/issues/1554
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c
libfdisk/src/libfdisk.h.in

index 07665a825abeee46409281c3110a14895fc333d5..3d8b264d2ac34881be4a9dd77d2f1d08868b93cf 100644 (file)
@@ -1283,6 +1283,7 @@ static int gpt_get_disklabel_item(struct fdisk_context *cxt, struct fdisk_labeli
 {
        struct gpt_header *h;
        int rc = 0;
+       uint64_t x = 0;
 
        assert(cxt);
        assert(cxt->label);
@@ -1316,10 +1317,18 @@ static int gpt_get_disklabel_item(struct fdisk_context *cxt, struct fdisk_labeli
                break;
        case GPT_LABELITEM_ENTRIESLBA:
                /* TRANSLATORS: The start of the array of partition entries. */
-               item->name = _("Partition entries LBA");
+               item->name = _("Partition entries starting LBA");
                item->type = 'j';
                item->data.num64 = le64_to_cpu(h->partition_entry_lba);
                break;
+       case GPT_LABELITEM_ENTRIESLASTLBA:
+               /* TRANSLATORS: The end of the array of partition entries. */
+               item->name = _("Partition entries ending LBA");
+               item->type = 'j';
+               gpt_calculate_sectorsof_entries(h,
+                               le32_to_cpu(h->npartition_entries), &x, cxt);
+               item->data.num64 = le64_to_cpu(h->partition_entry_lba) + x - 1;
+               break;
        case GPT_LABELITEM_ENTRIESALLOC:
                item->name = _("Allocated partition entries");
                item->type = 'j';
index 6d1262a55b50c5e9949da6b3d22c1024e6858321..1c9714975aafa1a6dad267f95b27ca3752f27943 100644 (file)
@@ -776,10 +776,11 @@ extern void fdisk_gpt_enable_minimize(struct fdisk_label *lb, int enable);
  * fdisk_labelitem_gpt:
  * @GPT_LABELITEM_ID: GPT disklabel UUID (!= partition UUID)
  * @GPT_LABELITEM_FIRSTLBA: First Usable LBA
- * @GPT_LABELITEM_LASTLBA: Usable LBA
+ * @GPT_LABELITEM_LASTLBA: Last Usable LBA
  * @GPT_LABELITEM_ALTLBA: Alternative LBA (backup header LBA)
  * @GPT_LABELITEM_ENTRIESLBA: Partitions entries array LBA
  * @GPT_LABELITEM_ENTRIESALLOC: Number of allocated entries in entries array
+ * @GPT_LABELITEM_ENTRIESLASTLBA: Last LBA where is entries array
  *
  * GPT specific label items.
  */
@@ -791,7 +792,8 @@ enum fdisk_labelitem_gpt {
        GPT_LABELITEM_LASTLBA,
        GPT_LABELITEM_ALTLBA,
        GPT_LABELITEM_ENTRIESLBA,
-       GPT_LABELITEM_ENTRIESALLOC
+       GPT_LABELITEM_ENTRIESALLOC,
+       GPT_LABELITEM_ENTRIESLASTLBA
 };
 
 /* script.c */