Accepting request 977958 from Base:System

OBS-URL: https://build.opensuse.org/request/show/977958
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/parted?expand=0&rev=137
This commit is contained in:
Dominique Leuenberger 2022-05-20 15:50:08 +00:00 committed by Git OBS Bridge
commit 9ed7575d58
3 changed files with 126 additions and 0 deletions

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed May 18 09:19:29 CEST 2022 - aschnell@suse.com
- add new type command from upstream
added patches:
- type-command.patch
-------------------------------------------------------------------
Wed Apr 20 09:11:11 CEST 2022 - aschnell@suse.com

View File

@ -64,6 +64,7 @@ Patch36: libparted-linux-pmem-path.patch
# bsc#1164260
Patch37: parted-print-max-partitions-for-yast.patch
Patch38: direct-handling-of-partition-type-id-and-uuid.patch
Patch39: type-command.patch
# bsc#1164907
Patch64: parted-type-accept-hex.patch
# Fatresize
@ -162,6 +163,7 @@ to develop applications that require these.
%patch36 -p1
%patch37 -p1
%patch38 -p1
%patch39 -p1
%patch64 -p1
%patch100 -p1
%patch101 -p1

117
type-command.patch Normal file
View File

@ -0,0 +1,117 @@
--- 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 (