summaryrefslogtreecommitdiffstats
path: root/fdisks/fdisk.c
diff options
context:
space:
mode:
authorKarel Zak2013-11-28 12:56:12 +0100
committerKarel Zak2014-03-11 11:35:12 +0100
commit851515216f0a6b2692a3228c59d78a756a72e665 (patch)
tree0c6705ead40d3e5189313a9198989f3815beb499 /fdisks/fdisk.c
parentlibfdisk: (sun) remove get_partition_type() (diff)
downloadkernel-qcow2-util-linux-851515216f0a6b2692a3228c59d78a756a72e665.tar.gz
kernel-qcow2-util-linux-851515216f0a6b2692a3228c59d78a756a72e665.tar.xz
kernel-qcow2-util-linux-851515216f0a6b2692a3228c59d78a756a72e665.zip
libfdisk: remove fdisk_get_partition_type()
Let's use more generic: fdisk_get_partition() fdisk_partition_get_parttype() rather than fdisk_get_partition_type(). The patch also improves fdisk_get_partition() semantic to allocate a new partition struct if the argument is NULL. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/fdisk.c')
-rw-r--r--fdisks/fdisk.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index a5c1fe634..db3b29870 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -160,7 +160,9 @@ void toggle_dos_compatibility_flag(struct fdisk_context *cxt)
void change_partition_type(struct fdisk_context *cxt)
{
size_t i;
- struct fdisk_parttype *t = NULL, *org_t = NULL;
+ struct fdisk_parttype *t = NULL;
+ struct fdisk_partition *pa = NULL;
+ const char *old = NULL;
assert(cxt);
assert(cxt->label);
@@ -168,28 +170,30 @@ void change_partition_type(struct fdisk_context *cxt)
if (fdisk_ask_partnum(cxt, &i, FALSE))
return;
- org_t = t = fdisk_get_partition_type(cxt, i);
- if (!t)
- fdisk_warnx(cxt, _("Partition %zu does not exist yet!"), i + 1);
- else {
- do {
- t = ask_partition_type(cxt);
- } while (!t);
-
- if (fdisk_set_partition_type(cxt, i, t) == 0)
- fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
- _("Changed type of partition '%s' to '%s'."),
- org_t ? org_t->name : _("Unknown"),
- t ? t->name : _("Unknown"));
- else
- fdisk_info(cxt,
- _("Type of partition %zu is unchanged: %s."),
- i + 1,
- org_t ? org_t->name : _("Unknown"));
- }
-
- fdisk_free_parttype(t);
- fdisk_free_parttype(org_t);
+ if (fdisk_get_partition(cxt, i, &pa)) {
+ fdisk_warnx(cxt, _("Partition %zu does not exist yet!"), i + 1);
+ return;
+ }
+
+ t = (struct fdisk_parttype *) fdisk_partition_get_type(pa);
+ old = t ? t->name : _("Unknown");
+
+ do {
+ t = ask_partition_type(cxt);
+ } while (!t);
+
+ fdisk_partition_set_type(pa, t);
+
+ if (fdisk_set_partition_type(cxt, i, t) == 0)
+ fdisk_sinfo(cxt, FDISK_INFO_SUCCESS,
+ _("Changed type of partition '%s' to '%s'."),
+ old, t ? t->name : _("Unknown"));
+ else
+ fdisk_info(cxt,
+ _("Type of partition %zu is unchanged: %s."),
+ i + 1, old);
+
+ fdisk_free_partition(pa);
}
void list_disk_geometry(struct fdisk_context *cxt)