sfdisk: use fdisk_set_partition_type()
This is more simple than the generic fdisk_set_partition() API. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
43a1ccecda
commit
2e73a998f4
|
@ -460,7 +460,6 @@ static int command_parttype(struct sfdisk *sf, int argc, char **argv)
|
||||||
int rc;
|
int rc;
|
||||||
size_t partno, n;
|
size_t partno, n;
|
||||||
struct fdisk_label *lb = NULL;
|
struct fdisk_label *lb = NULL;
|
||||||
struct fdisk_partition *pa = NULL;
|
|
||||||
struct fdisk_parttype *type = NULL;
|
struct fdisk_parttype *type = NULL;
|
||||||
const char *devname = NULL, *typestr = NULL;
|
const char *devname = NULL, *typestr = NULL;
|
||||||
|
|
||||||
|
@ -497,6 +496,7 @@ static int command_parttype(struct sfdisk *sf, int argc, char **argv)
|
||||||
/* print partition type */
|
/* print partition type */
|
||||||
if (!typestr) {
|
if (!typestr) {
|
||||||
const struct fdisk_parttype *t = NULL;
|
const struct fdisk_parttype *t = NULL;
|
||||||
|
struct fdisk_partition *pa = NULL;
|
||||||
|
|
||||||
if (fdisk_get_partition(sf->cxt, partno - 1, &pa) == 0)
|
if (fdisk_get_partition(sf->cxt, partno - 1, &pa) == 0)
|
||||||
t = fdisk_partition_get_type(pa);
|
t = fdisk_partition_get_type(pa);
|
||||||
|
@ -510,36 +510,25 @@ static int command_parttype(struct sfdisk *sf, int argc, char **argv)
|
||||||
printf("%s\n", fdisk_parttype_get_string(t));
|
printf("%s\n", fdisk_parttype_get_string(t));
|
||||||
|
|
||||||
fdisk_unref_partition(pa);
|
fdisk_unref_partition(pa);
|
||||||
fdisk_deassign_device(sf->cxt, 0);
|
fdisk_deassign_device(sf->cxt, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse <type> and apply yo PT */
|
/* parse <type> and apply yo PT */
|
||||||
type = fdisk_label_parse_parttype(lb, typestr);
|
type = fdisk_label_parse_parttype(lb, typestr);
|
||||||
if (!type || fdisk_parttype_is_unknown(type)) {
|
if (!type || fdisk_parttype_is_unknown(type))
|
||||||
rc = -EINVAL;
|
errx(EXIT_FAILURE, _("failed to parse %s partition type '%s'"),
|
||||||
warnx(_("failed to parse %s partition type '%s'"),
|
|
||||||
fdisk_label_get_name(lb), typestr);
|
fdisk_label_get_name(lb), typestr);
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
pa = fdisk_new_partition();
|
else if (fdisk_set_partition_type(sf->cxt, partno - 1, type) != 0)
|
||||||
if (!pa)
|
errx(EXIT_FAILURE, _("%s: partition %zu: failed to set partition type"),
|
||||||
err(EXIT_FAILURE, _("failed to allocate partition"));
|
devname, partno);
|
||||||
rc = fdisk_partition_set_type(pa, type);
|
|
||||||
|
|
||||||
if (!rc) {
|
fdisk_free_parttype(type);
|
||||||
rc = fdisk_set_partition(sf->cxt, partno - 1, pa); /* apply to disklabel */
|
|
||||||
if (rc)
|
|
||||||
warnx(_("%s: partition %zu: failed to appply type to disk label"),
|
|
||||||
devname, partno);
|
|
||||||
}
|
|
||||||
done:
|
|
||||||
fdisk_unref_partition(pa);
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
rc = fdisk_write_disklabel(sf->cxt);
|
rc = fdisk_write_disklabel(sf->cxt);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
rc = fdisk_deassign_device(sf->cxt, 1);
|
rc = fdisk_deassign_device(sf->cxt, 0);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue