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)
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.
.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,
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;
.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,
{
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;
}