]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (script) support shortcuts in the type= field
authorKarel Zak <kzak@redhat.com>
Thu, 8 Aug 2019 08:34:27 +0000 (10:34 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 8 Aug 2019 08:34:27 +0000 (10:34 +0200)
The unnamed-field format supports partition type shortcuts:

",1MiB,L'

but for named-field format it requires full type:

 (mbr) "size=1MiB,type=83"
 (gpt)  "size=1MiB,type=0FC63DAF-8483-4772-8E79-3D69D8477DE4"

This patch implements type shortcuts also for named-field format:

"size=1MiB,type=L"

to make it more user-friendly and unified.

Addresses: https://github.com/karelzak/util-linux/issues/837
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/sfdisk.8
libfdisk/src/script.c

index ff54760ca08e8762d7a5e7ccd3c23ae55fba5ae7..c7630bb376ea2a0ece770256ff868123e863941f 100644 (file)
@@ -462,7 +462,8 @@ GPT partition UUID.
 GPT partition name.
 .TP
 .BI type= code
-A hexadecimal number (without 0x) for an MBR partition, or a GUID for a GPT partition.
+A hexadecimal number (without 0x) for an MBR partition, a GUID for a GPT partition,
+or a shortcut as for unnamed-fields format.
 For backward compatibility the \fBId=\fR field has the same meaning.
 .RE
 .RE
index 3db76c87b3d716b959a46b285ebdce23d34af387..a28983dbad866d438156249509ebec92e28e34a6 100644 (file)
@@ -61,6 +61,8 @@ struct fdisk_script {
                                force_label : 1;        /* label: <name> specified */
 };
 
+static struct fdisk_parttype *translate_type_shortcuts(struct fdisk_script *dp, char *str);
+
 
 static void fdisk_script_free_header(struct fdisk_scriptheader *fi)
 {
@@ -1054,8 +1056,11 @@ static int parse_line_nameval(struct fdisk_script *dp, char *s)
                        rc = next_string(&p, &type);
                        if (rc)
                                break;
-                       pa->type = fdisk_label_parse_parttype(
-                                       script_get_label(dp), type);
+
+                       pa->type = translate_type_shortcuts(dp, type);
+                       if (!pa->type)
+                               pa->type = fdisk_label_parse_parttype(
+                                               script_get_label(dp), type);
                        free(type);
 
                        if (!pa->type) {