From 39e38c0a4c0f3ad0e029792e0ddee9761b956c1e Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 11 Sep 2013 12:24:54 -0700 Subject: [PATCH 71/89] libparted: preserve the uuid on dm partitions (#832145) * libparted/arch/linux.c (_dm_add_partition): Set the uuid if there was one. --- libparted/arch/linux.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index 452ea7f..4376d17 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -2710,9 +2710,12 @@ static int _dm_add_partition (PedDisk* disk, const PedPartition* part) { LinuxSpecific* arch_specific = LINUX_SPECIFIC (disk->dev); - char *params = NULL; - char *vol_name = NULL; - uint32_t cookie = 0; + char* params = NULL; + char* vol_name = NULL; + const char* dev_name = NULL; + char* vol_uuid = NULL; + const char* dev_uuid = NULL; + uint32_t cookie = 0; /* Get map name from devicemapper */ struct dm_task *task = dm_task_create (DM_DEVICE_INFO); @@ -2726,7 +2729,7 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part) if (!dm_task_run(task)) goto err; - const char *dev_name = dm_task_get_name (task); + dev_name = dm_task_get_name (task); size_t name_len = strlen (dev_name); vol_name = zasprintf ("%s%s%d", dev_name, @@ -2735,6 +2738,11 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part) if (vol_name == NULL) goto err; + dev_uuid = dm_task_get_uuid (task); + if (dev_uuid && (strlen(dev_uuid) > 0) + && !(vol_uuid = zasprintf ("part%d-%s", part->num, dev_uuid))) + goto err; + /* Caution: dm_task_destroy frees dev_name. */ dm_task_destroy (task); task = NULL; @@ -2747,6 +2755,8 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part) goto err; dm_task_set_name (task, vol_name); + if (vol_uuid) + dm_task_set_uuid (task, vol_uuid); dm_task_add_target (task, 0, part->geom.length, "linear", params); if (!dm_task_set_cookie (task, &cookie, 0)) @@ -2755,6 +2765,7 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part) dm_task_update_nodes (); dm_task_destroy (task); free (params); + free (vol_uuid); free (vol_name); return 1; } else { @@ -2765,6 +2776,7 @@ err: if (task) dm_task_destroy (task); free (params); + free (vol_uuid); free (vol_name); return 0; } -- 1.8.5.3