[parted-devel] [PATCH 1/6] libparted: refactor device-mapper partition sync code
Jim Meyering
jim at meyering.net
Wed Oct 17 14:31:32 UTC 2012
Jim Meyering wrote:
> Phillip Susi wrote:
...
> ...
>> +static int
>> +_dm_add_partition (PedDisk* disk, const PedPartition* part)
>> +{
>> + LinuxSpecific* arch_specific = LINUX_SPECIFIC (disk->dev);
>> +
>> + /* Get map name from devicemapper */
>> + struct dm_task *task = dm_task_create (DM_DEVICE_INFO);
>> + if (!task)
>> + goto err;
>> +
>> + if (!dm_task_set_major_minor (task, arch_specific->major,
>> + arch_specific->minor, 0))
>> + goto err;
>> +
>> + if (!dm_task_run(task))
>> + goto err;
>> +
>> + const char *dev_name = dm_task_get_name (task);
>> + char *vol_name;
>> + if (isdigit (dev_name[strlen (dev_name) - 1])) {
>> + if ( ! (vol_name = zasprintf ("%sp%d", dev_name, part->num)))
>> + goto err;
>> + } else if ( ! (vol_name = zasprintf ("%s%d", dev_name, part->num)))
>> + goto err;
>
> Please combine those:
>
> char *vol_name
> = zasprintf ("%s%s%d",
> dev_name,
> isdigit (dev_name[strlen (dev_name) - 1]) ? "p" : "",
> part->num);
> if (vol_name == NULL)
> goto err;
Here's a 2nd amendment:
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 22556e8..c0aee14 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2618,7 +2618,7 @@ _dm_get_partition_start_and_length(PedPartition const *part,
int major, minor;
char *params;
- char *target_type;
+ char *target_type;
dm_get_next_target(task, NULL, (uint64_t *)start, (uint64_t *)length, &target_type, ¶ms);
if (sscanf (params, "%d:%d %Ld", &major, &minor, start) != 3)
goto err;
@@ -2650,6 +2650,14 @@ _dm_add_partition (PedDisk* disk, const PedPartition* part)
goto err;
const char *dev_name = dm_task_get_name (task);
+ size_t name_len = strlen (dev_name);
+ vol_name = zasprintf ("%s%s%d",
+ dev_name,
+ isdigit (dev_name[name_len - 1]) ? "p" : "",
+ part->num);
+ if (vol_name == NULL)
+ goto err;
+
if (isdigit (dev_name[strlen (dev_name) - 1])) {
if ( ! (vol_name = zasprintf ("%sp%d", dev_name, part->num)))
goto err;
More information about the parted-devel
mailing list