]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) support for disklabel dump
authorKarel Zak <kzak@redhat.com>
Tue, 3 Sep 2013 15:36:04 +0000 (17:36 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:10 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/gpt.c

index c1c3a852c65632df332b927efed1482f9dcb3a52..d3fed63f6a9cd3a08e1f285d6f8cfbafa333c8dd 100644 (file)
@@ -768,6 +768,45 @@ invalid:
        return NULL;
 }
 
+
+static int gpt_locate_disklabel(struct fdisk_context *cxt, int n,
+               const char **name, off_t *offset, size_t *size)
+{
+       struct fdisk_gpt_label *gpt;
+
+       assert(cxt);
+
+       *name = NULL;
+       *offset = 0;
+       *size = 0;
+
+       switch (n) {
+       case 0:
+               *name = "PMBR";
+               *offset = 0;
+               *size = 512;
+               break;
+       case 1:
+               *name = _("GPT Header");
+               *offset = GPT_PRIMARY_PARTITION_TABLE_LBA * cxt->sector_size;
+               *size = sizeof(struct gpt_header);
+               break;
+       case 2:
+               *name = _("GPT Entries");
+               gpt = self_label(cxt);
+               *offset = le64_to_cpu(gpt->pheader->partition_entry_lba) * cxt->sector_size;
+               *size = le32_to_cpu(gpt->pheader->npartition_entries) *
+                        le32_to_cpu(gpt->pheader->sizeof_partition_entry);
+               break;
+       default:
+               return 1;                       /* no more chunks */
+       }
+
+       return 0;
+}
+
+
+
 /*
  * Returns the number of partitions that are in use.
  */
@@ -2031,6 +2070,7 @@ static const struct fdisk_label_operations gpt_operations =
        .verify         = gpt_verify_disklabel,
        .create         = gpt_create_disklabel,
        .list           = gpt_list_disklabel,
+       .locate         = gpt_locate_disklabel,
        .get_id         = gpt_get_disklabel_id,
        .set_id         = gpt_set_disklabel_id,