From: Karel Zak Date: Wed, 17 Sep 2014 11:14:01 +0000 (+0200) Subject: libfdisk: use new set_part API in fdisk_set_partition_type() X-Git-Tag: v2.26-rc1~371 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b305ad406555c7b478fb00f5e649dd1b12ba1c1e;p=thirdparty%2Futil-linux.git libfdisk: use new set_part API in fdisk_set_partition_type() Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 07238b4b50..0448cc9404 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -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, diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index 58f27962b3..6720ff0cfe 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -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, diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 8104d5429c..5ae67856bc 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -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; }