]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix fdisk_label_parse_parttype() for unknown types
authorKarel Zak <kzak@redhat.com>
Wed, 15 Jul 2015 13:42:22 +0000 (15:42 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 15 Jul 2015 13:42:22 +0000 (15:42 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk.c
disk-utils/fdisk.h
libfdisk/src/parttype.c

index a4130afb9e7c56a0ff478c146700430ab9f472b1..2a2ab9adc8b397b9c570a7684773707961f6bd96 100644 (file)
@@ -409,7 +409,7 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
        return rc;
 }
 
-struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt)
+static struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt)
 {
        const char *q;
        struct fdisk_label *lb;
@@ -562,6 +562,7 @@ void change_partition_type(struct fdisk_context *cxt)
                        i + 1, old);
 
        fdisk_unref_partition(pa);
+       fdisk_unref_parttype(t);
 }
 
 int print_partition_info(struct fdisk_context *cxt)
index 6a62c2497478e46ca7439ccef5164415a6599e6c..f66404d04c2fc979b5a39f76b858aebaea4d250a 100644 (file)
@@ -44,7 +44,6 @@ extern void dump_disklabel(struct fdisk_context *cxt);
 
 extern void list_partition_types(struct fdisk_context *cxt);
 extern void change_partition_type(struct fdisk_context *cxt);
-extern struct fdisk_parttype *ask_partition_type(struct fdisk_context *cxt);
 
 extern void toggle_dos_compatibility_flag(struct fdisk_context *cxt);
 
index aedf4e83bb2bc187a5ee26361353ef654c3af1a3..712994efb2b35d73a7b938ca3bb06c7184d03249 100644 (file)
@@ -302,9 +302,8 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
                                const struct fdisk_label *lb,
                                const char *str)
 {
-       struct fdisk_parttype *types, *ret;
-       unsigned int code = 0;
-       char *typestr = NULL, *end = NULL;
+       struct fdisk_parttype *types, *ret = NULL;
+       char *end = NULL;
 
        assert(lb);
 
@@ -316,6 +315,7 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
        types = lb->parttypes;
 
        if (types[0].typestr == NULL && isxdigit(*str)) {
+               unsigned int code = 0;
 
                errno = 0;
                code = strtol(str, &end, 16);
@@ -327,6 +327,8 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
                ret = fdisk_label_get_parttype_from_code(lb, code);
                if (ret)
                        goto done;
+
+               ret = fdisk_new_unknown_parttype(code, NULL);
        } else {
                int i;
 
@@ -343,11 +345,13 @@ struct fdisk_parttype *fdisk_label_parse_parttype(
                        ret = &types[i - 1];
                        goto done;
                }
+
+               ret = fdisk_new_unknown_parttype(0, str);
        }
 
-       ret = fdisk_new_unknown_parttype(code, typestr);
 done:
-       DBG(PARTTYPE, ul_debugobj(ret, "returns parsed '%s' partition type", ret->name));
+       DBG(PARTTYPE, ul_debugobj(ret, "returns parsed '%s' [%s] partition type",
+                               ret->name, ret->typestr ? : ""));
        return ret;
 }