From: Karel Zak Date: Wed, 15 Jul 2015 13:42:22 +0000 (+0200) Subject: libfdisk: fix fdisk_label_parse_parttype() for unknown types X-Git-Tag: v2.27-rc1~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bd02cdfdf3a55ce61e8e56e29e9b149b5feaf1c;p=thirdparty%2Futil-linux.git libfdisk: fix fdisk_label_parse_parttype() for unknown types Signed-off-by: Karel Zak --- diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index a4130afb9e..2a2ab9adc8 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -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) diff --git a/disk-utils/fdisk.h b/disk-utils/fdisk.h index 6a62c24974..f66404d04c 100644 --- a/disk-utils/fdisk.h +++ b/disk-utils/fdisk.h @@ -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); diff --git a/libfdisk/src/parttype.c b/libfdisk/src/parttype.c index aedf4e83bb..712994efb2 100644 --- a/libfdisk/src/parttype.c +++ b/libfdisk/src/parttype.c @@ -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; }