[parted-devel] [PATCH 1/4] libparted: Add legacy_boot flag to GPT PMBR (#754850)

Jim Meyering jim at meyering.net
Thu Feb 2 12:16:30 UTC 2012


Jim Meyering wrote:

> bcl at redhat.com wrote:
>
>> From: Matthew Garrett <mjg at redhat.com>
>>
>> Some BIOS systems will only boot from GPT partitions if the boot flag is
>> set on the protective MBR partition. This adds the ability to set this
>> flag using the disk_set and disk_toggle commands.
>>
>> * include/parted/disk.h (_PedDiskFlag): Add PED_DISK_LEGACY_BOOT
>> * libparted/disk.c (ped_disk_flag_get_name): Add PED_DISK_LEGACY_BOOT
>> * libparted/labels/gpt.c (_GPTDiskData): Add legacy_boot flag.
>> (gpt_alloc): Init legacy_boot to 0.
>> (gpt_read_headers): Set legacy_boot state from PMBR boot flag.
>> (_write_pmbr): Add legacy_boot flag and set PMBR boot flag from it.
>> (gpt_write): Pass legacy_boot flag through to _write_pmbr
>> (gpt_disk_set_flag): New function
>> (gpt_disk_is_flag_available): New function
>> (gpt_disk_get_flag): New function
>> (gpt_disk_ops): Add disk_set_flag, disk_get_flag, disk_is_flag_available
>> * parted/parted.c (do_disk_set): New function
>> (do_disk_toggle): New function
>> (_init_commands): Add do_disk_set and do_disk_toggle
>> * parted/ui.c (command_line_get_disk_flag): New function
>> * parted/ui.h: Add command_line_get_disk_flag prototype.
>
> Thanks to you and Matthew for the patch.
> The new names are a little too generic -- i.e., what if some other
> legacy boot flag needs support in a different partition table type?
> So I've renamed the cpp symbols like this:
>
>   git grep -l LEGACY_BOOT|xargs perl -pi -e 's/_LEGACY_BOOT/_GPT_PMBR_BOOT/g'
>
> and manually changed the "legacy_boot" command argument to "pmbr_boot".
> I'll squash this into your 1/4 commit and update the log above.

Whoops.
I need to restrict that change to the uses of _LEGACY_BOOT
with the PED_DISK prefix.  I don't want to change the
preexisting PED_PARTITION_LEGACY_BOOT name.

This is yet another good reason for this renaming.

I'll post the full series for review shortly.

> diff --git a/include/parted/disk.in.h b/include/parted/disk.in.h
> index 4ae1a7d..d42bc07 100644
> --- a/include/parted/disk.in.h
> +++ b/include/parted/disk.in.h
> @@ -37,10 +37,10 @@ enum _PedDiskFlag {
>             it only controls the aligning of the end of the partition) */
>          PED_DISK_CYLINDER_ALIGNMENT=1,
>          /* This flag controls whether the boot flag of a GPT PMBR is set */
> -        PED_DISK_LEGACY_BOOT=2,
> +        PED_DISK_GPT_PMBR_BOOT=2,
>  };
>  #define PED_DISK_FIRST_FLAG             PED_DISK_CYLINDER_ALIGNMENT
> -#define PED_DISK_LAST_FLAG              PED_DISK_LEGACY_BOOT
> +#define PED_DISK_LAST_FLAG              PED_DISK_GPT_PMBR_BOOT
>
>  /**
>   * Partition types
> @@ -72,10 +72,10 @@ enum _PedPartitionFlag {
>          PED_PARTITION_BIOS_GRUB=12,
>          PED_PARTITION_APPLE_TV_RECOVERY=13,
>          PED_PARTITION_DIAG=14,
> -        PED_PARTITION_LEGACY_BOOT=15
> +        PED_PARTITION_GPT_PMBR_BOOT=15
>  };
>  #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
> -#define PED_PARTITION_LAST_FLAG         PED_PARTITION_LEGACY_BOOT
> +#define PED_PARTITION_LAST_FLAG         PED_PARTITION_GPT_PMBR_BOOT
>
>  enum _PedDiskTypeFeature {
>          PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
> diff --git a/libparted/disk.c b/libparted/disk.c
> index 7fcf9c9..8684a02 100644
> --- a/libparted/disk.c
> +++ b/libparted/disk.c
> @@ -836,8 +836,8 @@ ped_disk_flag_get_name(PedDiskFlag flag)
>          switch (flag) {
>          case PED_DISK_CYLINDER_ALIGNMENT:
>                  return N_("cylinder_alignment");
> -        case PED_DISK_LEGACY_BOOT:
> -                return N_("legacy_boot");
> +        case PED_DISK_GPT_PMBR_BOOT:
> +                return N_("pmbr_boot");
>          default:
>                  ped_exception_throw (
>                          PED_EXCEPTION_BUG,
> @@ -2437,8 +2437,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag)
>                  return N_("atvrecv");
>          case PED_PARTITION_DIAG:
>                  return N_("diag");
> -        case PED_PARTITION_LEGACY_BOOT:
> -                return N_("legacy_boot");
> +        case PED_PARTITION_GPT_PMBR_BOOT:
> +                return N_("pmbr_boot");
>
>  	default:
>  		ped_exception_throw (
> diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
> index 33cbf67..6972943 100644
> --- a/libparted/labels/gpt.c
> +++ b/libparted/labels/gpt.c
> @@ -1527,7 +1527,7 @@ gpt_disk_set_flag (PedDisk *disk, PedDiskFlag flag, int state)
>    GPTDiskData *gpt_disk_data = disk->disk_specific;
>    switch (flag)
>      {
> -    case PED_DISK_LEGACY_BOOT:
> +    case PED_DISK_GPT_PMBR_BOOT:
>        gpt_disk_data->legacy_boot = state;
>        return 1;
>      default:
> @@ -1540,7 +1540,7 @@ gpt_disk_is_flag_available(const PedDisk *disk, PedDiskFlag flag)
>  {
>    switch (flag)
>      {
> -    case PED_DISK_LEGACY_BOOT:
> +    case PED_DISK_GPT_PMBR_BOOT:
>        return 1;
>      default:
>        return 0;
> @@ -1553,7 +1553,7 @@ gpt_disk_get_flag (const PedDisk *disk, PedDiskFlag flag)
>    GPTDiskData *gpt_disk_data = disk->disk_specific;
>    switch (flag)
>      {
> -    case PED_DISK_LEGACY_BOOT:
> +    case PED_DISK_GPT_PMBR_BOOT:
>        return gpt_disk_data->legacy_boot;
>        break;
>      default:
> @@ -1662,7 +1662,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
>      case PED_PARTITION_HIDDEN:
>        gpt_part_data->hidden = state;
>        return 1;
> -    case PED_PARTITION_LEGACY_BOOT:
> +    case PED_PARTITION_GPT_PMBR_BOOT:
>        gpt_part_data->legacy_boot = state;
>        return 1;
>      case PED_PARTITION_SWAP:
> @@ -1701,7 +1701,7 @@ gpt_partition_get_flag (const PedPartition *part, PedPartitionFlag flag)
>        return gpt_part_data->atvrecv;
>      case PED_PARTITION_HIDDEN:
>        return gpt_part_data->hidden;
> -    case PED_PARTITION_LEGACY_BOOT:
> +    case PED_PARTITION_GPT_PMBR_BOOT:
>        return gpt_part_data->legacy_boot;
>      case PED_PARTITION_SWAP:
>      case PED_PARTITION_LBA:
> @@ -1727,7 +1727,7 @@ gpt_partition_is_flag_available (const PedPartition *part,
>      case PED_PARTITION_DIAG:
>      case PED_PARTITION_APPLE_TV_RECOVERY:
>      case PED_PARTITION_HIDDEN:
> -    case PED_PARTITION_LEGACY_BOOT:
> +    case PED_PARTITION_GPT_PMBR_BOOT:
>        return 1;
>      case PED_PARTITION_SWAP:
>      case PED_PARTITION_ROOT:



More information about the parted-devel mailing list