Backport support for legacy_boot flag to support booting from GPT disk via
legacy BIOS. I've taken the relevant git commits from parted 2.4 and only
changed PED_PARTITION_LEGACY_BOOT from 15 to 16 as 15 was used in 2.3
already by PED_PARTITION_TYPE which is gone in 2.4.


commit 7fc2cf02e1e6a4b02d989db68511224f1bc341c5
Author: Brian C. Lane <bcl@redhat.com>
Date:   Fri Feb 25 14:09:18 2011 -0800

    gpt: add partition attribute bits: NoBlockIOProtocol, LegacyBIOSBootable
    
    Add NoBlockIOProtocol and LegacyBIOSBootable flags to the GPT partition
    Attributes entry.

commit 3dd52c822a40f9787765f21f7cbd6f1c37b42f7e
Author: Brian C. Lane <bcl@redhat.com>
Date:   Fri Feb 25 14:09:19 2011 -0800

    gpt: add legacy_boot partition flag
    
    Add support for the Legacy BIOS Bootable flag in the GPT
    Attribute field.  This is used by software like syslinux to
    determine which partition to boot when in BIOS mode.
    
    See Page 105, Table 19 Bit 2 of the UEFI Spec 2.3 book.
    
    * doc/C/parted.8: Document legacy_boot.
    * doc/parted.texi: Document legacy_boot.
    * include/parted/disk.h: Add PED_PARTITION_LEGACY_BOOT flag.
    * libparted/disk.c (ped_partition_flag_get_name): Add legacy_boot flag.
    * libparted/labels/gpt.c (_parse_part_entry):
    (_partition_generate_part_entry, gpt_partition_new):
    (gpt_partition_set_flag, gpt_partition_get_flag):
    (gpt_partition_is_flag_available): Add legacy_boot flag support.


--- doc/C/parted.8
+++ doc/C/parted.8
@@ -132,7 +132,7 @@
 .B set \fIpartition\fP \fIflag\fP \fIstate\fP
 Change the state of the \fIflag\fP on \fIpartition\fP to \fIstate\fP.
 Supported flags are: "boot", "root", "swap", "hidden", "raid", "lvm", "lba",
-and "palo".
+"legacy_boot" and "palo".
 \fIstate\fP should be either "on" or "off".
 .TP
 .B unit \fIunit\fP
--- doc/parted.texi
+++ doc/parted.texi
@@ -1049,6 +1049,10 @@
 (GPT) - Enable this to record that the selected partition is a
 GRUB BIOS partition.
 
+@item legacy_boot
+(GPT) - this flag is used to tell special purpose software that the GPT
+partition may be bootable.
+
 @item boot
 (Mac, MS-DOS, PC98) - should be enabled if you want to boot off the
 partition.  The semantics vary between disk labels.  For MS-DOS disk
--- include/parted/disk.h
+++ include/parted/disk.h
@@ -70,10 +70,11 @@
         PED_PARTITION_BIOS_GRUB=12,
         PED_PARTITION_APPLE_TV_RECOVERY=13,
         PED_PARTITION_DIAG=14,
-        PED_PARTITION_TYPE=15
+        PED_PARTITION_TYPE=15,
+        PED_PARTITION_LEGACY_BOOT=16
 };
 #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
-#define PED_PARTITION_LAST_FLAG         PED_PARTITION_TYPE
+#define PED_PARTITION_LAST_FLAG         PED_PARTITION_LEGACY_BOOT
 
 enum _PedDiskTypeFeature {
         PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
--- libparted/disk.c
+++ libparted/disk.c
@@ -2480,6 +2480,8 @@
                 return N_("atvrecv");
         case PED_PARTITION_DIAG:
                 return N_("diag");
+        case PED_PARTITION_LEGACY_BOOT:
+                return N_("legacy_boot");
 
 	default:
 		ped_exception_throw (
--- libparted/labels/gpt.c
+++ libparted/labels/gpt.c
@@ -4,7 +4,7 @@
     original version by Matt Domsch <Matt_Domsch@dell.com>
     Disclaimed into the Public Domain
 
-    Portions Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc.
+    Portions Copyright (C) 2001-2003, 2005-2011 Free Software Foundation, Inc.
 
     EFI GUID Partition Table handling
     Per Intel EFI Specification v1.02
@@ -163,12 +163,16 @@
 {
 #ifdef __GNUC__			/* XXX narrow this down to !TinyCC */
   uint64_t RequiredToFunction:1;
-  uint64_t Reserved:47;
+  uint64_t NoBlockIOProtocol:1;
+  uint64_t LegacyBIOSBootable:1;
+  uint64_t Reserved:45;
   uint64_t GuidSpecific:16;
 #else
 #       warning "Using crippled partition entry type"
   uint32_t RequiredToFunction:1;
-  uint32_t Reserved:32;
+  uint32_t NoBlockIOProtocol:1;
+  uint32_t LegacyBIOSBootable:1;
+  uint32_t Reserved:30;
   uint32_t LOST:5;
   uint32_t GuidSpecific:16;
 #endif
@@ -274,6 +278,7 @@
   int msftres;
   int atvrecv;
   int msftrecv;
+  int legacy_boot;
 } GPTPartitionData;
 
 static PedDiskType gpt_disk_type;
@@ -865,10 +870,13 @@
     = gpt_part_data->boot = gpt_part_data->hp_service
     = gpt_part_data->hidden = gpt_part_data->msftres
     = gpt_part_data->msftrecv
+    = gpt_part_data->legacy_boot
     = gpt_part_data->bios_grub = gpt_part_data->atvrecv = 0;
 
   if (pte->Attributes.RequiredToFunction & 0x1)
     gpt_part_data->hidden = 1;
+  if (pte->Attributes.LegacyBIOSBootable & 0x1)
+    gpt_part_data->legacy_boot = 1;
 
   if (!guid_cmp (gpt_part_data->type, PARTITION_SYSTEM_GUID))
     gpt_part_data->boot = 1;
@@ -1349,6 +1357,8 @@
 
   if (gpt_part_data->hidden)
     pte->Attributes.RequiredToFunction = 1;
+  if (gpt_part_data->legacy_boot)
+    pte->Attributes.LegacyBIOSBootable = 1;
 
   for (i = 0; i < 72 / sizeof (efi_char16_t); i++)
     pte->PartitionName[i]
@@ -1491,6 +1501,7 @@
   gpt_part_data->msftres = 0;
   gpt_part_data->msftrecv = 0;
   gpt_part_data->atvrecv = 0;
+  gpt_part_data->legacy_boot = 0;
   uuid_generate ((unsigned char *) &gpt_part_data->uuid);
   swap_uuid_and_efi_guid ((unsigned char *) (&gpt_part_data->uuid));
   memset (gpt_part_data->name, 0, sizeof gpt_part_data->name);
@@ -1778,6 +1789,9 @@
     case PED_PARTITION_HIDDEN:
       gpt_part_data->hidden = state;
       return 1;
+    case PED_PARTITION_LEGACY_BOOT:
+      gpt_part_data->legacy_boot = state;
+      return 1;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_ROOT:
     case PED_PARTITION_LBA:
@@ -1814,6 +1828,8 @@
       return gpt_part_data->atvrecv;
     case PED_PARTITION_HIDDEN:
       return gpt_part_data->hidden;
+    case PED_PARTITION_LEGACY_BOOT:
+      return gpt_part_data->legacy_boot;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_LBA:
     case PED_PARTITION_ROOT:
@@ -1838,6 +1854,7 @@
     case PED_PARTITION_DIAG:
     case PED_PARTITION_APPLE_TV_RECOVERY:
     case PED_PARTITION_HIDDEN:
+    case PED_PARTITION_LEGACY_BOOT:
       return 1;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_ROOT:
