]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: use new set_part API in fdisk_set_partition_type()
authorKarel Zak <kzak@redhat.com>
Wed, 17 Sep 2014 11:14:01 +0000 (13:14 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 7 Oct 2014 12:55:32 +0000 (14:55 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c
libfdisk/src/gpt.c
libfdisk/src/label.c

index 07238b4b50e51dad8cf5f9d7e78afe2ce654571d..0448cc94048fe9b86c26284f063f37747186e6ef 100644 (file)
@@ -798,21 +798,6 @@ static int dos_probe_label(struct fdisk_context *cxt)
        return 1;
 }
 
-/*
- * Avoid warning about DOS partitions when no DOS partition was changed.
- * Here a heuristic "is probably dos partition".
- * We might also do the opposite and warn in all cases except
- * for "is probably nondos partition".
- */
-static int is_dos_partition(int t)
-{
-       return (t == 1 || t == 4 || t == 6 ||
-               t == 0x0b || t == 0x0c || t == 0x0e ||
-               t == 0x11 || t == 0x12 || t == 0x14 || t == 0x16 ||
-               t == 0x1b || t == 0x1c || t == 0x1e || t == 0x24 ||
-               t == 0xc1 || t == 0xc4 || t == 0xc6);
-}
-
 static void set_partition(struct fdisk_context *cxt,
                          int i, int doext, sector_t start,
                          sector_t stop, int sysid, int boot)
@@ -1680,44 +1665,6 @@ static int dos_locate_disklabel(struct fdisk_context *cxt, int n,
        return 0;
 }
 
-static int dos_set_parttype(
-               struct fdisk_context *cxt,
-               size_t partnum,
-               struct fdisk_parttype *t)
-{
-       struct dos_partition *p;
-
-       assert(cxt);
-       assert(cxt->label);
-       assert(fdisk_is_label(cxt, DOS));
-
-       if (partnum >= cxt->label->nparts_max || !t || t->code > UINT8_MAX)
-               return -EINVAL;
-
-       p = self_partition(cxt, partnum);
-       if (t->code == p->sys_ind)
-               return 0;
-
-       if (IS_EXTENDED(p->sys_ind) || IS_EXTENDED(t->code)) {
-               fdisk_warnx(cxt, _("You cannot change a partition into an "
-                       "extended one or vice versa. Delete it first."));
-               return -EINVAL;
-       }
-
-       if (is_dos_partition(t->code) || is_dos_partition(p->sys_ind))
-           fdisk_info(cxt, _("If you have created or modified any DOS 6.x "
-               "partitions, please see the fdisk documentation for additional "
-               "information."));
-
-       if (!t->code)
-               fdisk_warnx(cxt, _("Type 0 means free space to many systems. "
-                                  "Having partitions of type 0 is probably unwise."));
-       p->sys_ind = t->code;
-
-       partition_set_changed(cxt, partnum, 1);
-       return 0;
-}
-
 /*
  * Check whether partition entries are ordered by their starting positions.
  * Return 0 if OK. Return i if partition i should have been earlier.
@@ -2160,8 +2107,6 @@ static const struct fdisk_label_operations dos_operations =
        .add_part       = dos_add_partition,
        .del_part       = dos_delete_partition,
 
-       .part_set_type  = dos_set_parttype,
-
        .part_toggle_flag = dos_toggle_partition_flag,
        .part_is_used   = dos_partition_is_used,
 
index 58f27962b396bfa0becf08f043de3a8cd1a48b64..6720ff0cfe517ef33b1ebb19ed4d178618052a7a 100644 (file)
@@ -2154,31 +2154,6 @@ static int gpt_set_disklabel_id(struct fdisk_context *cxt)
        return 0;
 }
 
-static int gpt_set_partition_type(
-               struct fdisk_context *cxt,
-               size_t i,
-               struct fdisk_parttype *t)
-{
-       struct gpt_guid uuid;
-       struct fdisk_gpt_label *gpt;
-
-       assert(cxt);
-       assert(cxt->label);
-       assert(fdisk_is_label(cxt, GPT));
-
-       gpt = self_label(cxt);
-       if ((uint32_t) i >= le32_to_cpu(gpt->pheader->npartition_entries)
-            || !t || !t->typestr || string_to_guid(t->typestr, &uuid) != 0)
-               return -EINVAL;
-
-       gpt_entry_set_type(&gpt->ents[i], &uuid);
-       gpt_recompute_crc(gpt->pheader, gpt->ents);
-       gpt_recompute_crc(gpt->bheader, gpt->ents);
-
-       fdisk_label_set_changed(cxt->label, 1);
-       return 0;
-}
-
 static int gpt_part_is_used(struct fdisk_context *cxt, size_t i)
 {
        struct fdisk_gpt_label *gpt;
@@ -2394,7 +2369,6 @@ static const struct fdisk_label_operations gpt_operations =
        .del_part       = gpt_delete_partition,
 
        .part_is_used   = gpt_part_is_used,
-       .part_set_type  = gpt_set_partition_type,
        .part_toggle_flag = gpt_toggle_partition_flag,
 
        .deinit         = gpt_deinit,
index 8104d5429c78720c64c2a58358cdb1fd047a2255..5ae67856bc5e878cc5fe97a1b2c7eeb2ba3133ea 100644 (file)
@@ -406,11 +406,17 @@ int fdisk_set_partition_type(struct fdisk_context *cxt,
 {
        if (!cxt || !cxt->label)
                return -EINVAL;
-       if (!cxt->label->op->part_set_type)
-               return -ENOSYS;
 
        DBG(CXT, ul_debugobj(cxt, "partition: %zd: set type", partnum));
-       return cxt->label->op->part_set_type(cxt, partnum, t);
+
+       if (cxt->label->op->set_part) {
+               struct fdisk_partition pa = { .type = t };
+               return cxt->label->op->set_part(cxt, partnum, &pa);
+
+       } else if (cxt->label->op->part_set_type)
+               return cxt->label->op->part_set_type(cxt, partnum, t);
+
+       return -ENOSYS;
 }