File type-command.patch of Package parted

--- a/parted/parted.c	2022-05-18 09:11:33.731616339 +0200
+++ b/parted/parted.c	2022-05-18 09:16:40.517372633 +0200
@@ -187,6 +187,8 @@
 static const char* name_msg =         N_("NAME is any word you want\n");
 static const char* type_id_msg =      N_("TYPE_ID is a value between 0x01 and 0xff\n");
 static const char* type_uuid_msg =    N_("TYPE_UUID is a non-null uuid\n");
+static const char* type_msg =         N_("TYPE_ID is a value between 0x01 and 0xff, "
+		"TYPE_UUID is a UUID\n");
 
 static const char* copyright_msg = N_(
 "Copyright (C) 1998 - 2006 Free Software Foundation, Inc.\n"
@@ -1090,6 +1092,90 @@
         return 0;
 }
 
+static int
+do_type (PedDevice** dev, PedDisk** diskp)
+{
+        if (!*diskp)
+                *diskp = ped_disk_new (*dev);
+        if (!*diskp)
+                goto error;
+
+        bool has_type_id = ped_disk_type_check_feature ((*diskp)->type,
+                                                        PED_DISK_TYPE_PARTITION_TYPE_ID);
+        bool has_type_uuid = ped_disk_type_check_feature ((*diskp)->type,
+                                                          PED_DISK_TYPE_PARTITION_TYPE_UUID);
+
+        PED_ASSERT (!(has_type_id && has_type_uuid));
+
+        if (!has_type_id && !has_type_uuid) {
+                ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+                                     _("%s disk labels do not support partition type."),
+                                     (*diskp)->type->name);
+                goto error;
+        }
+
+        PedPartition* part = NULL;
+        if (!command_line_get_partition (_("Partition number?"), *diskp, &part))
+                goto error;
+
+        char* input = NULL;
+
+        if (has_type_id) {
+                uint8_t type_id = ped_partition_get_type_id (part);
+                static char buf[8];
+                snprintf(buf, 8, "0x%02x", type_id);
+
+                input = command_line_get_word (_("Partition type-id?"), buf, NULL, 0);
+                if (!input)
+                    goto error;
+
+                unsigned int tmp = strtol (input, (char**) NULL, 16);
+                if (tmp < 0x01 || tmp > 0xff) {
+                        ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+                                             _("Invalid type-id."));
+                        goto error_free_input;
+                }
+
+                if (!ped_partition_set_type_id (part, tmp))
+                        goto error_free_input;
+        }
+
+        if (has_type_uuid) {
+                uint8_t* type_uuid = ped_partition_get_type_uuid (part);
+                static char buf[UUID_STR_LEN];
+                uuid_unparse_lower (type_uuid, buf);
+                free (type_uuid);
+
+                input = command_line_get_word (_("Partition type-uuid?"), buf, NULL, 0);
+                if (!input)
+                        goto error;
+
+                uuid_t tmp;
+                if (uuid_parse (input, tmp) != 0 || uuid_is_null (tmp)) {
+                        ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL,
+                                             _("Invalid type-uuid."));
+                        goto error_free_input;
+                }
+
+                if (!ped_partition_set_type_uuid (part, tmp))
+                        goto error_free_input;
+        }
+
+        free (input);
+
+        // Reset the fs_type based on the filesystem, if it exists
+        part->fs_type = ped_file_system_probe (&part->geom);
+
+        if (!ped_disk_commit (*diskp))
+                goto error;
+        return 1;
+
+error_free_input:
+        free (input);
+error:
+        return 0;
+}
+
 static char*
 partition_print_flags (PedPartition const *part)
 {
@@ -2581,6 +2667,14 @@
         str_list_create (_(number_msg), flag_msg, NULL), 1));
 
 command_register (commands, command_create (
+        str_list_create_unique ("type", _("type"), NULL),
+        do_type,
+        str_list_create (
+_("type NUMBER TYPE-ID or TYPE-UUID         type set TYPE-ID or TYPE-UUID of partition NUMBER"),
+NULL),
+        str_list_create (_(number_msg), _(type_msg), NULL), 1));
+
+command_register (commands, command_create (
         str_list_create_unique ("unit", _("unit"), NULL),
         do_unit,
         str_list_create (
openSUSE Build Service is sponsored by