[parted-devel] [PATCH 1/2] libparted: copy flags when duplicating GPT partitions

Jim Meyering jim at meyering.net
Wed Nov 2 16:09:32 UTC 2011


Brian C. Lane wrote:
> From: "Brian C. Lane" <bcl at redhat.com>
>
>  * libparted/labels/gpt.c (gpt_partition_duplicate): copy flags to new
>    partition.
>  * NEWS: Mention this fix.
> ---
>  NEWS                   |    3 +++
>  libparted/labels/gpt.c |   12 ++++++++++++
>  2 files changed, 15 insertions(+), 0 deletions(-)
>
> diff --git a/NEWS b/NEWS
> index b7fb56b..915b5ff 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -8,6 +8,9 @@ GNU parted NEWS                                    -*- outline -*-
>
>  ** Bug fixes
>
> +  libparted: gpt_disk_duplicate now copies the flags over to the new
> +  disk object. Previously the flags would be undefined.
> +
>    libparted: no longer aborts (failed assertion) due to a nilfs2_probe bug
>    [bug introduced in parted-2.4 with the addition of nilfs2 support]
>
> diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
> index 8c9816f..7b4e014 100644
> --- a/libparted/labels/gpt.c
> +++ b/libparted/labels/gpt.c
> @@ -1365,6 +1365,18 @@ gpt_partition_duplicate (const PedPartition *part)
>    result_data->type = part_data->type;
>    result_data->uuid = part_data->uuid;
>    strcpy (result_data->name, part_data->name);
> +
> +  /* Copy over all the flags */
> +  result_data->lvm = part_data->lvm;
> +  result_data->raid = part_data->raid;
> +  result_data->boot = part_data->boot;
> +  result_data->bios_grub = part_data->bios_grub;
> +  result_data->hp_service = part_data->hp_service;
> +  result_data->hidden = part_data->hidden;
> +  result_data->msftres = part_data->msftres;
> +  result_data->atvrecv = part_data->atvrecv;
> +  result_data->msftrecv = part_data->msftrecv;
> +  result_data->legacy_boot = part_data->legacy_boot;
>    return result;

Hi Brian,

Thanks for that fix, and especially for the added test case (which I'm
about to look at).  Does this have an associated bugzilla number?
If so, let me know and I'll mention it in the log message before I push.

>From a maintainability standpoint, I'll adjust it just to copy the entire
struct; then there's no need to adjust whenever we add a new flag:

diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 7b4e014..f2bda41 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -1362,21 +1362,7 @@ gpt_partition_duplicate (const PedPartition *part)
   if (!result_data)
     goto error_free_part;

-  result_data->type = part_data->type;
-  result_data->uuid = part_data->uuid;
-  strcpy (result_data->name, part_data->name);
-
-  /* Copy over all the flags */
-  result_data->lvm = part_data->lvm;
-  result_data->raid = part_data->raid;
-  result_data->boot = part_data->boot;
-  result_data->bios_grub = part_data->bios_grub;
-  result_data->hp_service = part_data->hp_service;
-  result_data->hidden = part_data->hidden;
-  result_data->msftres = part_data->msftres;
-  result_data->atvrecv = part_data->atvrecv;
-  result_data->msftrecv = part_data->msftrecv;
-  result_data->legacy_boot = part_data->legacy_boot;
+  *result_data = *part_data;
   return result;

 error_free_part:



More information about the parted-devel mailing list