bug-parted
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] Add legacy_boot flag for GPT parititons


From: Brian C. Lane
Subject: [PATCH 2/2] Add legacy_boot flag for GPT parititons
Date: Fri, 25 Feb 2011 14:09:19 -0800

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         |    2 +-
 doc/parted.texi        |    4 ++++
 include/parted/disk.h  |    5 +++--
 libparted/disk.c       |    2 ++
 libparted/labels/gpt.c |   13 +++++++++++++
 5 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/doc/C/parted.8 b/doc/C/parted.8
index 2a8992e..f4b940c 100644
--- a/doc/C/parted.8
+++ b/doc/C/parted.8
@@ -132,7 +132,7 @@ or an LVM logical volume if necessary.
 .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
diff --git a/doc/parted.texi b/doc/parted.texi
index 1111efd..1a57c07 100644
--- a/doc/parted.texi
+++ b/doc/parted.texi
@@ -1049,6 +1049,10 @@ depending on what disk label you are using:
 (GPT) - Enable this to record that the selected partition is a
 GRUB BIOS partition.
 
address@hidden 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
diff --git a/include/parted/disk.h b/include/parted/disk.h
index 3a1450c..dd461fb 100644
--- a/include/parted/disk.h
+++ b/include/parted/disk.h
@@ -69,10 +69,11 @@ enum _PedPartitionFlag {
         PED_PARTITION_MSFT_RESERVED=11,
         PED_PARTITION_BIOS_GRUB=12,
         PED_PARTITION_APPLE_TV_RECOVERY=13,
-        PED_PARTITION_DIAG=14
+        PED_PARTITION_DIAG=14,
+        PED_PARTITION_LEGACY_BOOT=15
 };
 #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
-#define PED_PARTITION_LAST_FLAG         PED_PARTITION_DIAG
+#define PED_PARTITION_LAST_FLAG         PED_PARTITION_LEGACY_BOOT
 
 enum _PedDiskTypeFeature {
         PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
diff --git a/libparted/disk.c b/libparted/disk.c
index 376571e..f6f795f 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -2442,6 +2442,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");
 
        default:
                ped_exception_throw (
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 0396ad7..31d41bb 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -278,6 +278,7 @@ typedef struct _GPTPartitionData
   int msftres;
   int atvrecv;
   int msftrecv;
+  int legacy_boot;
 } GPTPartitionData;
 
 static PedDiskType gpt_disk_type;
@@ -783,10 +784,13 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t 
*pte)
     = 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;
@@ -1163,6 +1167,8 @@ _partition_generate_part_entry (PedPartition *part, 
GuidPartitionEntry_t *pte)
 
   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]
@@ -1305,6 +1311,7 @@ gpt_partition_new (const PedDisk *disk,
   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);
@@ -1592,6 +1599,9 @@ 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:
+      gpt_part_data->legacy_boot = state;
+      return 1;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_ROOT:
     case PED_PARTITION_LBA:
@@ -1628,6 +1638,8 @@ 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:
+      return gpt_part_data->legacy_boot;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_LBA:
     case PED_PARTITION_ROOT:
@@ -1652,6 +1664,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:
       return 1;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_ROOT:
-- 
1.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]