[parted-devel] [PATCH] libparted: preserve the uuid on dm partitions (#832145)

Brian C. Lane bcl at redhat.com
Tue Aug 7 19:25:38 UTC 2012


From: Fedora Ninjas <parted-owner at fedoraproject.org>

* libparted/arch/linux.c (_dm_add_partition): Set the uuid if there was
  one.
---
 libparted/arch/linux.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 37ddb5f..9f0434a 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2803,6 +2803,8 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
 {
         char*           vol_name = NULL;
         const char*     dev_name = NULL;
+        char*           vol_uuid = NULL;
+        const char*     dev_uuid = NULL;
         char*           params = NULL;
         LinuxSpecific*  arch_specific = LINUX_SPECIFIC (disk->dev);
         uint32_t        cookie = 0;
@@ -2820,6 +2822,7 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
                 goto err;
 
         dev_name = dm_task_get_name (task);
+        dev_uuid = dm_task_get_uuid (task);
 
         if (isdigit (dev_name[strlen (dev_name) - 1])) {
                 if ( ! (vol_name = zasprintf ("%sp%d", dev_name, part->num)))
@@ -2827,6 +2830,10 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
         } else if ( ! (vol_name = zasprintf ("%s%d", dev_name, part->num)))
                 goto err;
 
+        if ( dev_uuid && (strlen(dev_uuid) > 0) \
+             && ! (vol_uuid = zasprintf ("%sp%d", dev_uuid, part->num)))
+                goto err;
+
         /* Caution: dm_task_destroy frees dev_name.  */
         dm_task_destroy (task);
         task = NULL;
@@ -2840,6 +2847,8 @@ _dm_add_partition (PedDisk* disk, 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))
@@ -2850,6 +2859,7 @@ _dm_add_partition (PedDisk* disk, PedPartition* part)
                 dm_task_update_nodes();
                 dm_task_destroy(task);
                 free(params);
+                free(vol_uuid);
                 free(vol_name);
                 return 1;
         } else {
@@ -2861,6 +2871,7 @@ err:
         if (task)
                 dm_task_destroy (task);
         free (params);
+        free (vol_uuid);
         free (vol_name);
         return 0;
 }
-- 
1.7.7.6




More information about the parted-devel mailing list