]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) returns location of the backup header too
authorKarel Zak <kzak@redhat.com>
Fri, 19 Mar 2021 13:54:34 +0000 (14:54 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 19 Mar 2021 13:54:34 +0000 (14:54 +0100)
Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c
libfdisk/src/label.c

index 7a71ab9da61f70a0f9b9337bcdf52e774ebe0e92..6a01b1d61887c163557bb87a01154b585d860c8c 100644 (file)
@@ -1247,6 +1247,18 @@ static int gpt_locate_disklabel(struct fdisk_context *cxt, int n,
                *offset = (uint64_t) le64_to_cpu(gpt->pheader->partition_entry_lba) *
                                     cxt->sector_size;
                return gpt_sizeof_entries(gpt->pheader, size);
+       case 3:
+               *name = _("GPT Backup Entries");
+               gpt = self_label(cxt);
+               *offset = (uint64_t) le64_to_cpu(gpt->bheader->partition_entry_lba) *
+                                    cxt->sector_size;
+               return gpt_sizeof_entries(gpt->bheader, size);
+       case 4:
+               *name = _("GPT Backup Header");
+               gpt = self_label(cxt);
+               *offset = (uint64_t) le64_to_cpu(gpt->pheader->alternative_lba) * cxt->sector_size;
+               *size = sizeof(struct gpt_header);
+               break;
        default:
                return 1;                       /* no more chunks */
        }
index 98ab475bf17c42b73f48566b678c140afbbad4cd..524a2bfb4a297a59542aac837094ddf30ec4497e 100644 (file)
@@ -393,9 +393,19 @@ int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
  * @offset: return offset where is item
  * @size: of the item
  *
- * Locate disklabel and returns info about @n item of the label. For example
- * GPT is composed from two items, PMBR and GPT, n=0 return offset to PMBR and n=1
- * return offset to GPT. For more details see 'D' expert fdisk command.
+ * Locate disklabel and returns info about @n item of the label.
+ *
+ * For example GPT is composed from three items, PMBR and GPT, n=0 return
+ * offset to PMBR and n=1 return offset to GPT Header and n=2 returns offset to
+ * GPT array of partitions, n=3 and n=4 returns location of the backup GPT
+ * label at the end of the disk.
+ *
+ * The function returns the current in-memory situation. It's possible that a
+ * header location is modified by write operation, for example when enabled
+ * minimization (see fdisk_gpt_enable_minimize()). In this case it's better to
+ * call this function after fdisk_write_disklabel().
+ *
+ * For more details see 'D' expert fdisk command.
  *
  * Returns: 0 on success, <0 on error, 1 no more items.
  */