]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (dos) all disklabel locate function
authorKarel Zak <kzak@redhat.com>
Tue, 15 Oct 2013 10:17:03 +0000 (12:17 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 15 Oct 2013 10:21:28 +0000 (12:21 +0200)
.. to make 'D'ump expert command usable also for MBR.

Yes, we have -rc2 now and this is a new feature, but it's tiny change
without any interaction to the rest of the code and without gettext stuff.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index 3aa40deeae959e84e3ecf008aea16e81f581cdae..0456ba5f2f0dd4f84efae6a989856e81c50c3515 100644 (file)
@@ -1374,6 +1374,39 @@ done:
        return rc;
 }
 
+static int dos_locate_disklabel(struct fdisk_context *cxt, int n,
+               const char **name, off_t *offset, size_t *size)
+{
+       assert(cxt);
+
+       *name = NULL;
+       *offset = 0;
+       *size = 0;
+
+       switch (n) {
+       case 0:
+               *name = "MBR";
+               *offset = 0;
+               *size = 512;
+               break;
+       default:
+               /* extended partitions */
+               if (n - 1 + 4 < cxt->label->nparts_max) {
+                       struct pte *pe = self_pte(cxt, n - 1 + 4);
+
+                       assert(pe->private_sectorbuffer);
+
+                       *name = "EBR";
+                       *offset = pe->offset * cxt->sector_size;
+                       *size = 512;
+               } else
+                       return 1;
+               break;
+       }
+
+       return 0;
+}
+
 static struct fdisk_parttype *dos_get_parttype(
                struct fdisk_context *cxt,
                size_t partnum)
@@ -1911,6 +1944,7 @@ static const struct fdisk_label_operations dos_operations =
        .write          = dos_write_disklabel,
        .verify         = dos_verify_disklabel,
        .create         = dos_create_disklabel,
+       .locate         = dos_locate_disklabel,
        .list           = dos_list_disklabel,
        .get_id         = dos_get_disklabel_id,
        .set_id         = dos_set_disklabel_id,