]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: cleanup fdisk_is_label stuff
authorKarel Zak <kzak@redhat.com>
Wed, 13 Aug 2014 21:57:54 +0000 (23:57 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 13 Aug 2014 21:57:54 +0000 (23:57 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/cfdisk.c
disk-utils/fdisk-menu.c
disk-utils/fdisk.c
libfdisk/src/bsd.c
libfdisk/src/context.c
libfdisk/src/dos.c
libfdisk/src/gpt.c
libfdisk/src/label.c
libfdisk/src/libfdisk.h
libfdisk/src/sgi.c
libfdisk/src/sun.c

index 584ea9fdbd9463177ee552fa19eed099614791ec..7f02c0625690895ea0a1a2e140580ebb1f013c2c 100644 (file)
@@ -1714,8 +1714,8 @@ static int main_menu_ignore_keys(struct cfdisk *cf, char *ignore,
                ignore[i++] = 'b';      /* set bootable */
        } else {
                ignore[i++] = 'n';
-               if (!fdisk_is_disklabel(cf->cxt, DOS) &&
-                   !fdisk_is_disklabel(cf->cxt, SGI))
+               if (!fdisk_is_label(cf->cxt, DOS) &&
+                   !fdisk_is_label(cf->cxt, SGI))
                        ignore[i++] = 'b';
        }
 
@@ -1765,8 +1765,8 @@ static int main_menu_action(struct cfdisk *cf, int key)
        switch (key) {
        case 'b': /* Bootable flag */
        {
-               int fl = fdisk_is_disklabel(cf->cxt, DOS) ? DOS_FLAG_ACTIVE :
-                        fdisk_is_disklabel(cf->cxt, SGI) ? SGI_FLAG_BOOT : 0;
+               int fl = fdisk_is_label(cf->cxt, DOS) ? DOS_FLAG_ACTIVE :
+                        fdisk_is_label(cf->cxt, SGI) ? SGI_FLAG_BOOT : 0;
 
                if (fl && fdisk_partition_toggle_flag(cf->cxt, n, fl))
                        warn = _("Could not toggle the flag.");
@@ -1910,7 +1910,7 @@ static int ui_run(struct cfdisk *cf)
 
        DBG(UI, ul_debug("start COLS=%d, LINES=%d", COLS, LINES));
 
-       if (!fdisk_dev_has_disklabel(cf->cxt) || cf->zero_start) {
+       if (!fdisk_has_label(cf->cxt) || cf->zero_start) {
                rc = ui_create_label(cf);
                if (rc < 0)
                        ui_errx(EXIT_FAILURE,
index 72f8bbb080446a463f793a82e33b6f4456548023..29bc0159354560aecfedda12bad3f297c2555360 100644 (file)
@@ -555,7 +555,7 @@ static int gpt_menu_cb(struct fdisk_context **cxt0,
 
        assert(cxt);
        assert(ent);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        DBG(FRONTEND, ul_debug("enter GPT menu"));
 
@@ -633,7 +633,7 @@ static int dos_menu_cb(struct fdisk_context **cxt0,
                                        = fdisk_new_nested_context(cxt, "bsd");
                        if (!bsd)
                                return -ENOMEM;
-                       if (!fdisk_dev_has_disklabel(bsd))
+                       if (!fdisk_has_label(bsd))
                                rc = fdisk_create_disklabel(bsd, "bsd");
                        if (rc)
                                fdisk_free_context(bsd);
@@ -689,7 +689,7 @@ static int sun_menu_cb(struct fdisk_context **cxt0,
 
        assert(cxt);
        assert(ent);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        DBG(FRONTEND, ul_debug("enter SUN menu"));
 
@@ -744,7 +744,7 @@ static int sgi_menu_cb(struct fdisk_context **cxt0,
 
        assert(cxt);
        assert(ent);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        if (ent->expert)
                return rc;
@@ -784,7 +784,7 @@ static int bsd_menu_cb(struct fdisk_context **cxt0,
 
        assert(cxt);
        assert(ent);
-       assert(fdisk_is_disklabel(cxt, BSD));
+       assert(fdisk_is_label(cxt, BSD));
 
        DBG(FRONTEND, ul_debug("enter BSD menu"));
 
index 5f14a74134dcec501df416f6657112c658ec7bc3..9d6230f70ce21798e084c4464e53b16aad5b9404 100644 (file)
@@ -459,7 +459,7 @@ void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
 
        fdisk_dos_enable_compatible(lb, flag);
 
-       if (fdisk_is_disklabel(cxt, DOS))
+       if (fdisk_is_label(cxt, DOS))
                fdisk_reset_alignment(cxt);     /* reset the current label */
 }
 
@@ -529,7 +529,7 @@ void list_disk_geometry(struct fdisk_context *cxt)
        if (cxt->alignment_offset)
                fdisk_info(cxt, _("Alignment offset: %lu bytes"),
                                cxt->alignment_offset);
-       if (fdisk_dev_has_disklabel(cxt))
+       if (fdisk_has_label(cxt))
                fdisk_info(cxt, _("Disklabel type: %s"), cxt->label->name);
 
        if (fdisk_get_disklabel_id(cxt, &id) == 0 && id)
@@ -748,7 +748,7 @@ static void print_device_pt(struct fdisk_context *cxt, char *device, int warnme)
 
        list_disk_geometry(cxt);
 
-       if (fdisk_dev_has_disklabel(cxt))
+       if (fdisk_has_label(cxt))
                list_disklabel(cxt);
 }
 
@@ -1022,11 +1022,11 @@ int main(int argc, char **argv)
 
                fflush(stdout);
 
-               if (!fdisk_dev_has_disklabel(cxt)) {
+               if (!fdisk_has_label(cxt)) {
                        fdisk_info(cxt, _("Device does not contain a recognized partition table."));
                        fdisk_create_disklabel(cxt, NULL);
 
-               } else if (fdisk_is_disklabel(cxt, GPT) && fdisk_gpt_is_hybrid(cxt))
+               } else if (fdisk_is_label(cxt, GPT) && fdisk_gpt_is_hybrid(cxt))
                        fdisk_warnx(cxt, _(
                                  "A hybrid GPT was detected. You have to sync "
                                  "the hybrid MBR manually (expert command 'M')."));
index 8df5707fddede0fe7378adb892fbd8d2a2c616fc..55996cc25a43d1b1359a641b7dea826fdbd02cc0 100644 (file)
@@ -91,7 +91,7 @@ static inline struct fdisk_bsd_label *self_label(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, BSD));
+       assert(fdisk_is_label(cxt, BSD));
 
        return (struct fdisk_bsd_label *) cxt->label;
 }
@@ -100,7 +100,7 @@ static inline struct bsd_disklabel *self_disklabel(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, BSD));
+       assert(fdisk_is_label(cxt, BSD));
 
        return &((struct fdisk_bsd_label *) cxt->label)->bsd;
 }
@@ -363,7 +363,7 @@ static int bsd_list_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, BSD));
+       assert(fdisk_is_label(cxt, BSD));
 
        if (fdisk_is_details(cxt)) {
                fdisk_info(cxt, "# %s:", cxt->dev_path);
@@ -409,7 +409,7 @@ static int bsd_get_partition(struct fdisk_context *cxt, size_t n,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, BSD));
+       assert(fdisk_is_label(cxt, BSD));
 
        if (n >= d->d_npartitions)
                return -EINVAL;
@@ -795,7 +795,7 @@ int fdisk_bsd_link_partition(struct fdisk_context *cxt)
        struct dos_partition *p;
        struct bsd_disklabel *d = self_disklabel(cxt);
 
-       if (!cxt->parent || !fdisk_is_disklabel(cxt->parent, DOS)) {
+       if (!cxt->parent || !fdisk_is_label(cxt->parent, DOS)) {
                fdisk_warnx(cxt, _("BSD label is not nested within a DOS partition."));
                return -EINVAL;
        }
index fec49c7db1d4ef330ebc63f506c2f115dccd8b4a..03f358639e2027c42dc71b7bf3ec55159038ab1c 100644 (file)
@@ -209,6 +209,28 @@ int fdisk_switch_label(struct fdisk_context *cxt, const char *name)
        return __fdisk_switch_label(cxt, fdisk_get_label(cxt, name));
 }
 
+/**
+ * fdisk_has_label:
+ * @cxt: fdisk context
+ *
+ * Returns: return 1 if there is label on the device.
+ */
+int fdisk_has_label(struct fdisk_context *cxt)
+{
+       return cxt && cxt->label;
+}
+
+/**
+ * fdisk_is_labeltype:
+ * @cxt: fdisk context
+ * @l: disklabel type
+ *
+ * Returns: return 1 if there is @l disklabel on the device.
+ */
+int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype l)
+{
+       return cxt && cxt->label && cxt->label->id == l;
+}
 
 static void reset_context(struct fdisk_context *cxt)
 {
@@ -254,7 +276,7 @@ static int warn_wipe(struct fdisk_context *cxt)
 
        assert(cxt);
 
-       if (fdisk_dev_has_disklabel(cxt) || cxt->dev_fd < 0)
+       if (fdisk_has_label(cxt) || cxt->dev_fd < 0)
                return -EINVAL;
 #ifdef HAVE_LIBBLKID
        DBG(CXT, ul_debugobj(cxt, "wipe check: initialize libblkid prober"));
@@ -337,7 +359,7 @@ int fdisk_assign_device(struct fdisk_context *cxt,
 
        /* warn about obsolete stuff on the device if we aren't in
         * list-only mode and there is not PT yet */
-       if (!fdisk_is_listonly(cxt) && !fdisk_dev_has_disklabel(cxt))
+       if (!fdisk_is_listonly(cxt) && !fdisk_has_label(cxt))
                warn_wipe(cxt);
 
        DBG(CXT, ul_debugobj(cxt, "initialized for %s [%s]",
@@ -666,3 +688,6 @@ const char *fdisk_get_devname(struct fdisk_context *cxt)
        assert(cxt);
        return cxt->dev_path;
 }
+
+
+
index d1fd28f600f61319e3a079b0e80d363986be74cd..2533f0c9ba6c3b18eb079813e804b2db3b33a18d 100644 (file)
@@ -79,7 +79,7 @@ static struct fdisk_parttype dos_parttypes[] = {
 #define alignment_required(_x) ((_x)->grain != (_x)->sector_size)
 
 #define is_dos_compatible(_x) \
-                  (fdisk_is_disklabel(_x, DOS) && \
+                  (fdisk_is_label(_x, DOS) && \
                     fdisk_dos_is_compatible(fdisk_get_label(_x, NULL)))
 
 #define cround(c, n)   fdisk_cround(c, n)
@@ -89,7 +89,7 @@ static inline struct fdisk_dos_label *self_label(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        return (struct fdisk_dos_label *) cxt->label;
 }
@@ -118,7 +118,7 @@ struct dos_partition *fdisk_dos_get_partition(
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        return self_partition(cxt, i);
 }
@@ -283,7 +283,7 @@ static void dos_init(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        DBG(LABEL, ul_debug("DOS: initialize, first sector buffer %p", cxt->firstsector));
 
@@ -373,7 +373,7 @@ static int dos_delete_partition(struct fdisk_context *cxt, size_t partnum)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        pe = self_pte(cxt, partnum);
        if (!pe)
@@ -573,7 +573,7 @@ static int dos_get_disklabel_id(struct fdisk_context *cxt, char **id)
        assert(cxt);
        assert(id);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        num = mbr_get_id(cxt->firstsector);
        if (asprintf(id, "0x%08x", num) > 0)
@@ -589,7 +589,7 @@ static int dos_create_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        DBG(LABEL, ul_debug("DOS: creating new disklabel"));
 
@@ -623,7 +623,7 @@ static int dos_set_disklabel_id(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        DBG(LABEL, ul_debug("DOS: setting Id"));
 
@@ -688,7 +688,7 @@ static int dos_reset_alignment(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        /* overwrite necessary stuff by DOS deprecated stuff */
        if (is_dos_compatible(cxt)) {
@@ -713,7 +713,7 @@ static int dos_probe_label(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        /* ignore disks with AIX magic number */
        if (memcmp(cxt->firstsector, AIX_MAGIC_STRING, AIX_MAGIC_STRLEN) == 0)
@@ -940,7 +940,7 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
        }
        fill_bounds(cxt, first, last);
        if (n < 4) {
-               if (cxt->parent && fdisk_is_disklabel(cxt->parent, GPT))
+               if (cxt->parent && fdisk_is_label(cxt->parent, GPT))
                        start = 1;              /* Bad boy modifies hybrid MBR */
                else
                        start = cxt->first_lba;
@@ -1265,7 +1265,7 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
        struct dos_partition *p;
        struct fdisk_dos_label *l = self_label(cxt);
 
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        fill_bounds(cxt, first, last);
        for (i = 0; i < cxt->label->nparts_max; i++) {
@@ -1353,7 +1353,7 @@ static int dos_add_partition(struct fdisk_context *cxt,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        l = self_label(cxt);
        ext_pe = l->ext_offset ? self_pte(cxt, l->ext_index) : NULL;
@@ -1495,7 +1495,7 @@ static int dos_write_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        mbr_changed = l->non_pt_changed;
 
@@ -1585,7 +1585,7 @@ static int dos_set_parttype(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        if (partnum >= cxt->label->nparts_max || !t || t->type > UINT8_MAX)
                return -EINVAL;
@@ -1653,7 +1653,7 @@ static int dos_list_disklabel(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        return 0;
 }
@@ -1668,7 +1668,7 @@ static int dos_get_partition(struct fdisk_context *cxt, size_t n,
        assert(cxt);
        assert(pa);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        lb = self_label(cxt);
        pe = self_pte(cxt, n);
@@ -1870,7 +1870,7 @@ int fdisk_dos_move_begin(struct fdisk_context *cxt, size_t i)
        int rc;
 
        assert(cxt);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        pe = self_pte(cxt, i);
        p = pe->pt_entry;
@@ -1933,7 +1933,7 @@ static int dos_partition_is_used(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        if (i >= cxt->label->nparts_max)
                return 0;
@@ -1952,7 +1952,7 @@ static int dos_toggle_partition_flag(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, DOS));
+       assert(fdisk_is_label(cxt, DOS));
 
        if (i >= cxt->label->nparts_max)
                return -EINVAL;
index 27331ca4e03954f1e166bf92fe4030661360eb21..c1aa1e774b2ab38124eb9663902b9bbb6f31cef7 100644 (file)
@@ -1168,7 +1168,7 @@ static int gpt_probe_label(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
 
@@ -1338,7 +1338,7 @@ static int gpt_get_partition(struct fdisk_context *cxt, size_t n,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
 
@@ -1385,7 +1385,7 @@ static int gpt_list_disklabel(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        if (fdisk_is_details(cxt)) {
                struct gpt_header *h = self_label(cxt)->pheader;
@@ -1499,7 +1499,7 @@ static int gpt_write_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
        mbr_type = valid_pmbr(cxt);
@@ -1570,7 +1570,7 @@ static int gpt_verify_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
 
@@ -1687,7 +1687,7 @@ static int gpt_delete_partition(struct fdisk_context *cxt,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
 
@@ -1730,7 +1730,7 @@ static int gpt_create_new_partition(struct fdisk_context *cxt,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        DBG(LABEL, ul_debug("GPT new partition: partno=%zu, start=%ju, end=%ju",
                                partnum, fsect, lsect));
@@ -1783,7 +1783,7 @@ static int gpt_add_partition(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
        pheader = gpt->pheader;
@@ -1940,7 +1940,7 @@ static int gpt_create_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
 
@@ -2007,7 +2007,7 @@ static int gpt_get_disklabel_id(struct fdisk_context *cxt, char **id)
        assert(cxt);
        assert(id);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
        guid_to_string(&gpt->pheader->disk_guid, str);
@@ -2027,7 +2027,7 @@ static int gpt_set_disklabel_id(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
        if (fdisk_ask_string(cxt,
@@ -2071,7 +2071,7 @@ static int gpt_set_partition_type(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
        if ((uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries)
@@ -2093,7 +2093,7 @@ static int gpt_part_is_used(struct fdisk_context *cxt, size_t i)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
 
@@ -2114,7 +2114,7 @@ int fdisk_gpt_partition_set_uuid(struct fdisk_context *cxt, size_t i)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        DBG(LABEL, ul_debug("UUID change requested partno=%zu", i));
 
@@ -2160,7 +2160,7 @@ int fdisk_gpt_partition_set_name(struct fdisk_context *cxt, size_t i)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        DBG(LABEL, ul_debug("NAME change requested partno=%zu", i));
 
@@ -2218,7 +2218,7 @@ static int gpt_toggle_partition_flag(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        DBG(LABEL, ul_debug("GPT entry attribute change requested partno=%zu", i));
        gpt = self_label(cxt);
@@ -2304,7 +2304,7 @@ static int gpt_reorder(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
        nparts = le32_to_cpu(gpt->pheader->npartition_entries);
@@ -2327,7 +2327,7 @@ static int gpt_reset_alignment(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, GPT));
+       assert(fdisk_is_label(cxt, GPT));
 
        gpt = self_label(cxt);
        h = gpt ? gpt->pheader : NULL;
index 65a5cde25a086089c75c96aae2c68ea6547eee78..36e4688d992d3d18e2d6aaf662d969c3420b2e0d 100644 (file)
@@ -1,6 +1,7 @@
 
 #include "fdiskP.h"
 
+
 /*
  * Don't use this function derectly
  */
@@ -12,7 +13,7 @@ int fdisk_probe_labels(struct fdisk_context *cxt)
 
        for (i = 0; i < cxt->nlabels; i++) {
                struct fdisk_label *lb = cxt->labels[i];
-               struct fdisk_label *org = cxt->label;
+               struct fdisk_label *org = fdisk_get_label(cxt, NULL);
                int rc;
 
                if (!lb->op->probe)
@@ -41,29 +42,17 @@ int fdisk_probe_labels(struct fdisk_context *cxt)
        return 1; /* not found */
 }
 
-
 /**
- * fdisk_dev_has_disklabel:
- * @cxt: fdisk context
+ * fdisk_label_get_name:
+ * @lb: label
  *
- * Returns: return 1 if there is label on the device.
+ * Returns: label name
  */
-int fdisk_dev_has_disklabel(struct fdisk_context *cxt)
+const char *fdisk_label_get_name(struct fdisk_label *lb)
 {
-       return cxt && cxt->label;
+       return lb ? lb->name : NULL;
 }
 
-/**
- * fdisk_dev_is_disklabel:
- * @cxt: fdisk context
- * @l: disklabel type
- *
- * Returns: return 1 if there is @l disklabel on the device.
- */
-int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l)
-{
-       return cxt && cxt->label && cxt->label->id == l;
-}
 
 /**
  * fdisk_write_disklabel:
index e244e372cf7432d83b701218b7a6fd047eb2be48..8caf60ef7d62bc0c241de980150e254a7f7c7dc2 100644 (file)
@@ -85,6 +85,11 @@ int fdisk_next_label(struct fdisk_context *cxt, struct fdisk_label **lb);
 size_t fdisk_get_nlabels(struct fdisk_context *cxt);
 int fdisk_switch_label(struct fdisk_context *cxt, const char *name);
 
+int fdisk_has_label(struct fdisk_context *cxt);
+int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype l);
+#define fdisk_is_label(c, x) fdisk_is_labeltype(c, FDISK_DISKLABEL_ ## x)
+
+
 int fdisk_assign_device(struct fdisk_context *cxt,
                        const char *fname, int readonly);
 int fdisk_deassign_device(struct fdisk_context *cxt, int nosync);
@@ -154,13 +159,11 @@ enum {
        FDISK_FIELD_UUID,
 };
 
+const char *fdisk_label_get_name(struct fdisk_label *lb);
+
 extern int fdisk_require_geometry(struct fdisk_context *cxt);
 extern int fdisk_missing_geometry(struct fdisk_context *cxt);
 
-extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
-
-extern int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l);
-#define fdisk_is_disklabel(c, x) fdisk_dev_is_disklabel(c, FDISK_DISKLABEL_ ## x)
 
 extern int fdisk_write_disklabel(struct fdisk_context *cxt);
 extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
index 83d25c55891737ed6670ebda7da5fe4cb63ccefa..fef9234cb72a5594a8daa4a87dfdfb8d540fe5a5 100644 (file)
@@ -68,7 +68,7 @@ static inline struct sgi_disklabel *self_disklabel(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        return ((struct fdisk_sgi_label *) cxt->label)->header;
 }
@@ -78,7 +78,7 @@ static inline struct fdisk_sgi_label *self_label(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        return (struct fdisk_sgi_label *) cxt->label;
 }
@@ -222,7 +222,7 @@ static int sgi_probe_label(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
        assert(sizeof(struct sgi_disklabel) <= 512);
 
        /* map first sector to header */
@@ -417,7 +417,7 @@ static int sgi_write_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        sgilabel = self_disklabel(cxt);
        sgilabel->csum = 0;
@@ -533,7 +533,7 @@ static int verify_disklabel(struct fdisk_context *cxt, int verbose)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        clear_freelist(cxt);
        memset(Index, 0, sizeof(Index));
@@ -695,7 +695,7 @@ static int sgi_set_partition(struct fdisk_context *cxt, size_t i,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        sgilabel = self_disklabel(cxt);
        sgilabel->partitions[i].type = cpu_to_be32(sys);
@@ -770,7 +770,7 @@ static int sgi_add_partition(struct fdisk_context *cxt,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        rc = fdisk_partition_next_partno(pa, cxt, &n);
        if (rc)
@@ -911,7 +911,7 @@ static int sgi_create_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
 #ifdef HDIO_GETGEO
        if (cxt->geom.heads && cxt->geom.sectors) {
@@ -1041,7 +1041,7 @@ static int sgi_partition_is_used(
                size_t i)
 {
        assert(cxt);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        if (i >= cxt->label->nparts_max)
                return 0;
@@ -1053,7 +1053,7 @@ static int sgi_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsign
        struct sgi_disklabel *sgilabel;
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SGI));
+       assert(fdisk_is_label(cxt, SGI));
 
        if (i >= cxt->label->nparts_max)
                return -EINVAL;
index 60c4cec6db63aded928375a0ea4caa03601da7c9..7ea399378ca9e62b509a6b77d1903d22ccd786c1 100644 (file)
@@ -53,7 +53,7 @@ static inline struct sun_disklabel *self_disklabel(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        return ((struct fdisk_sun_label *) cxt->label)->header;
 }
@@ -63,7 +63,7 @@ static inline struct fdisk_sun_label *self_label(struct fdisk_context *cxt)
 {
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        return (struct fdisk_sun_label *) cxt->label;
 }
@@ -108,7 +108,7 @@ static int sun_probe_label(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        /* map first sector to header */
        sun = (struct fdisk_sun_label *) cxt->label;
@@ -197,7 +197,7 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        /* map first sector to header */
        rc = fdisk_init_firstsector_buffer(cxt);
@@ -294,7 +294,7 @@ static int sun_toggle_partition_flag(struct fdisk_context *cxt, size_t i, unsign
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        if (i >= cxt->label->nparts_max)
                return -EINVAL;
@@ -331,7 +331,7 @@ static void fetch_sun(struct fdisk_context *cxt,
        assert(cxt);
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        sunlabel = self_disklabel(cxt);
 
@@ -390,7 +390,7 @@ static int sun_verify_disklabel(struct fdisk_context *cxt)
 #endif
     assert(cxt);
     assert(cxt->label);
-    assert(fdisk_is_disklabel(cxt, SUN));
+    assert(fdisk_is_label(cxt, SUN));
 
     fetch_sun(cxt, starts, lens, &start, &stop);
 
@@ -693,7 +693,7 @@ static int sun_delete_partition(struct fdisk_context *cxt,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        sunlabel = self_disklabel(cxt);
        part = &sunlabel->partitions[partnum];
@@ -722,7 +722,7 @@ static int sun_list_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        sunlabel = self_disklabel(cxt);
 
@@ -768,7 +768,7 @@ static int sun_get_partition(struct fdisk_context *cxt, size_t n,
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        if (n >= cxt->label->nparts_max)
                return -EINVAL;
@@ -889,7 +889,7 @@ static int sun_write_disklabel(struct fdisk_context *cxt)
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        sunlabel = self_disklabel(cxt);
 
@@ -925,7 +925,7 @@ static int sun_set_parttype(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        sunlabel = self_disklabel(cxt);
 
@@ -983,7 +983,7 @@ static int sun_partition_is_used(
 
        assert(cxt);
        assert(cxt->label);
-       assert(fdisk_is_disklabel(cxt, SUN));
+       assert(fdisk_is_label(cxt, SUN));
 
        if (i >= cxt->label->nparts_max)
                return 0;