]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: API: add to label operations to context
authorDavidlohr Bueso <dave@gnu.org>
Sun, 22 Jul 2012 17:05:01 +0000 (19:05 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 23 Jul 2012 15:31:06 +0000 (17:31 +0200)
The context structure is the fdisk API's main data type as it keeps all data
together. Add the label structure to it, so that the pt-specific operations can
be called from the context.

[kzak@redhat.com: - merge with latest changes
                  - don't allocate the label, use const pointer]

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
fdisks/fdisk.c
fdisks/fdisk.h
fdisks/utils.c

index 010431d2740fbe06ae7cb859d09ea0ada3149d21..0c837a315b372eace190ab8def71fb97a886e180 100644 (file)
@@ -68,7 +68,7 @@ int MBRbuffer_changed;
 struct menulist_descr {
        char command;                           /* command key */
        char *description;                      /* command description */
-       enum labeltype label[2];                /* disklabel types associated with main and expert menu */
+       enum fdisk_labeltype label[2];          /* disklabel types associated with main and expert menu */
 };
 
 static const struct menulist_descr menulist[] = {
@@ -133,7 +133,7 @@ unsigned int        user_cylinders, user_heads, user_sectors;
 sector_t sector_offset = 1;
 unsigned int units_per_sector = 1, display_in_cyl_units = 0;
 unsigned long grain = DEFAULT_SECTOR_SIZE;
-enum labeltype disklabel;      /* Current disklabel */
+enum fdisk_labeltype disklabel;        /* Current disklabel */
 
 static void __attribute__ ((__noreturn__)) usage(FILE *out)
 {
index 713b599bb2d52b4a6747535fa1012fabc211799b..a2a6fb55deb62eb59676f2cef0ac9c0a17512e30 100644 (file)
@@ -124,6 +124,9 @@ struct fdisk_context {
        /* geometry */
        sector_t total_sectors; /* in logical sectors */
        struct fdisk_geometry geom;
+
+       /* label operations and description */
+       const struct fdisk_label *label;
 };
 
 /*
@@ -131,6 +134,8 @@ struct fdisk_context {
  */
 struct fdisk_label {
        const char *name;
+
+       /* probe disk label */
        int (*probe)(struct fdisk_context *cxt);
 };
 
@@ -199,17 +204,20 @@ extern const char * str_units(int);
 
 extern sector_t get_nr_sects(struct partition *p);
 
-enum labeltype {
+/*
+ * Supported partition table types (labels)
+ */
+enum fdisk_labeltype {
+       ANY_LABEL = -1,
        DOS_LABEL = 1,
-       SUN_LABEL = 2,
-       SGI_LABEL = 4,
-       AIX_LABEL = 8,
-       OSF_LABEL = 16,
-       MAC_LABEL = 32,
-       ANY_LABEL = -1
+       SUN_LABEL,
+       SGI_LABEL,
+       AIX_LABEL,
+       OSF_LABEL,
+       MAC_LABEL,
 };
 
-extern enum labeltype disklabel;
+extern enum fdisk_labeltype disklabel;
 extern int MBRbuffer_changed;
 extern unsigned long grain;
 
index 43b813d3f20da247f8f0b271725068adcbab6300..ffb0c25fbc7cc33ae3ed564a4eb04c34eac3d04b 100644 (file)
@@ -39,32 +39,32 @@ int fdisk_debug_mask;
  */
 static const struct fdisk_label *labels[] =
 {
-       &bsd_label,
        &dos_label,
-       &sgi_label,
        &sun_label,
+       &sgi_label,
        &aix_label,
+       &bsd_label,
        &mac_label,
 };
 
 static int __probe_labels(struct fdisk_context *cxt)
 {
-       int i, rc = 0;
+       int i;
 
        disklabel = ANY_LABEL;
        update_units(cxt);
 
        for (i = 0; i < ARRAY_SIZE(labels); i++) {
-               rc = labels[i]->probe(cxt);
-               if (rc) {
-                       DBG(LABEL, dbgprint("detected a %s label\n",
-                                           labels[i]->name));
-                       goto done;
-               }
+               if (labels[i]->probe(cxt) != 1)
+                       continue;
+
+               cxt->label = labels[i];
+
+               DBG(LABEL, dbgprint("detected a %s label\n", cxt->label->name));
+               return 0;
        }
 
-done:
-       return rc;
+       return 1; /* not found */
 }
 
 static int __init_firstsector_buffer(struct fdisk_context *cxt)