Add support for BIOS Boot partition in GPT.

Robert Millan rmh at aybabtu.com
Thu Feb 21 20:56:50 UTC 2008


---
 include/parted/disk.h  |    7 ++--
 libparted/disk.c       |    2 +
 libparted/labels/gpt.c |   34 +++++++++++++++++++-
 tests/Makefile.am      |    3 +-
 tests/t5000-tags.sh    |   81 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 121 insertions(+), 6 deletions(-)

diff --git a/include/parted/disk.h b/include/parted/disk.h
index b82ea0f..5144a74 100644
--- a/include/parted/disk.h
+++ b/include/parted/disk.h
@@ -1,6 +1,6 @@
 /*
     libparted - a library for manipulating disk partitions
-    Copyright (C) 1999, 2000, 2001, 2002, 2007 Free Software Foundation, Inc.
+    Copyright (C) 1999, 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -52,10 +52,11 @@ enum _PedPartitionFlag {
         PED_PARTITION_HPSERVICE=8,
         PED_PARTITION_PALO=9,
         PED_PARTITION_PREP=10,
-        PED_PARTITION_MSFT_RESERVED=11
+        PED_PARTITION_MSFT_RESERVED=11,
+        PED_PARTITION_BOOT_BIOS=12
 };
 #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
-#define PED_PARTITION_LAST_FLAG         PED_PARTITION_MSFT_RESERVED
+#define PED_PARTITION_LAST_FLAG         PED_PARTITION_BOOT_BIOS
 
 enum _PedDiskTypeFeature {
         PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
diff --git a/libparted/disk.c b/libparted/disk.c
index ec09996..a2d3295 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -2227,6 +2227,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag)
 	switch (flag) {
 	case PED_PARTITION_BOOT:
 		return N_("boot");
+	case PED_PARTITION_BOOT_BIOS:
+		return N_("boot_bios");
 	case PED_PARTITION_ROOT:
 		return N_("root");
 	case PED_PARTITION_SWAP:
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 4dc4f10..8e082c2 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -4,7 +4,7 @@
     original version by Matt Domsch <Matt_Domsch at dell.com>
     Disclaimed into the Public Domain
 
-    Portions Copyright (C) 2001, 2002, 2003, 2005, 2006, 2007
+    Portions Copyright (C) 2001, 2002, 2003, 2005, 2006, 2007, 2008
         Free Software Foundation, Inc.
 
     EFI GUID Partition Table handling
@@ -86,6 +86,10 @@ typedef struct {
     ((efi_guid_t) { PED_CPU_TO_LE32 (0xC12A7328), PED_CPU_TO_LE16 (0xF81F), \
     		    PED_CPU_TO_LE16 (0x11d2), 0xBA, 0x4B, \
 		    { 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B }})
+#define PARTITION_BOOT_BIOS_GUID \
+    ((efi_guid_t) { PED_CPU_TO_LE32 (0x21686148), PED_CPU_TO_LE16 (0x6449), \
+    		    PED_CPU_TO_LE16 (0x6E6f), 0x74, 0x4E, \
+		    { 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 }})
 #define LEGACY_MBR_PARTITION_GUID \
     ((efi_guid_t) { PED_CPU_TO_LE32 (0x024DEE41), PED_CPU_TO_LE16 (0x33E7), \
 		    PED_CPU_TO_LE16 (0x11d3, 0x9D, 0x69, \
@@ -245,6 +249,7 @@ typedef struct _GPTPartitionData {
 	int		lvm;
 	int		raid;
 	int		boot;
+	int		boot_bios;
 	int		hp_service;
         int             hidden;
         int             msftres;
@@ -753,13 +758,16 @@ _parse_part_entry (PedDisk* disk, GuidPartitionEntry_t* pte)
         
         gpt_part_data->lvm = gpt_part_data->raid 
                 = gpt_part_data->boot = gpt_part_data->hp_service
-                = gpt_part_data->hidden = gpt_part_data->msftres = 0;
+                = gpt_part_data->hidden = gpt_part_data->msftres
+                = gpt_part_data->boot_bios = 0;
 
         if (pte->Attributes.RequiredToFunction & 0x1)
                 gpt_part_data->hidden = 1;
        
 	if (!guid_cmp (gpt_part_data->type, PARTITION_SYSTEM_GUID))
 		gpt_part_data->boot = 1;
+	else if (!guid_cmp (gpt_part_data->type, PARTITION_BOOT_BIOS_GUID))
+		gpt_part_data->boot_bios = 1;
 	else if (!guid_cmp (gpt_part_data->type, PARTITION_RAID_GUID))
 		gpt_part_data->raid = 1;
 	else if (!guid_cmp (gpt_part_data->type, PARTITION_LVM_GUID))
@@ -1130,6 +1138,7 @@ gpt_partition_new (const PedDisk* disk,
 	gpt_part_data->lvm = 0;
 	gpt_part_data->raid = 0;
 	gpt_part_data->boot = 0;
+	gpt_part_data->boot_bios = 0;
 	gpt_part_data->hp_service = 0;
         gpt_part_data->hidden = 0;
         gpt_part_data->msftres = 0;
@@ -1208,6 +1217,10 @@ gpt_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type)
 		gpt_part_data->type = PARTITION_SYSTEM_GUID;
 		return 1;
 	}
+	if (gpt_part_data->boot_bios) {
+		gpt_part_data->type = PARTITION_BOOT_BIOS_GUID;
+		return 1;
+	}
 	if (gpt_part_data->hp_service) {
 		gpt_part_data->type = PARTITION_HPSERVICE_GUID;
 		return 1;
@@ -1306,6 +1319,16 @@ gpt_partition_set_flag(PedPartition *part,
 		if (state)
                         gpt_part_data->raid 
                                 = gpt_part_data->lvm
+                                = gpt_part_data->boot_bios
+                                = gpt_part_data->hp_service
+                                = gpt_part_data->msftres = 0;
+		return gpt_partition_set_system (part, part->fs_type);
+	case PED_PARTITION_BOOT_BIOS:
+		gpt_part_data->boot_bios = state;
+		if (state)
+                        gpt_part_data->raid 
+                                = gpt_part_data->lvm
+                                = gpt_part_data->boot
                                 = gpt_part_data->hp_service
                                 = gpt_part_data->msftres = 0;
 		return gpt_partition_set_system (part, part->fs_type);
@@ -1314,6 +1337,7 @@ gpt_partition_set_flag(PedPartition *part,
 		if (state)
                         gpt_part_data->boot
                                 = gpt_part_data->lvm
+                                = gpt_part_data->boot_bios
                                 = gpt_part_data->hp_service
                                 = gpt_part_data->msftres = 0;
 		return gpt_partition_set_system (part, part->fs_type);
@@ -1322,6 +1346,7 @@ gpt_partition_set_flag(PedPartition *part,
 		if (state)
                         gpt_part_data->boot
                                 = gpt_part_data->raid
+                                = gpt_part_data->boot_bios
                                 = gpt_part_data->hp_service
                                 = gpt_part_data->msftres = 0;
 		return gpt_partition_set_system (part, part->fs_type);
@@ -1331,6 +1356,7 @@ gpt_partition_set_flag(PedPartition *part,
                         gpt_part_data->boot
                                 = gpt_part_data->raid
                                 = gpt_part_data->lvm
+                                = gpt_part_data->boot_bios
                                 = gpt_part_data->msftres = 0;
 		return gpt_partition_set_system (part, part->fs_type);
         case PED_PARTITION_MSFT_RESERVED:
@@ -1339,6 +1365,7 @@ gpt_partition_set_flag(PedPartition *part,
                         gpt_part_data->boot
                                 = gpt_part_data->raid
                                 = gpt_part_data->lvm
+                                = gpt_part_data->boot_bios
                                 = gpt_part_data->hp_service = 0;
                 return gpt_partition_set_system (part, part->fs_type);
         case PED_PARTITION_HIDDEN:
@@ -1367,6 +1394,8 @@ gpt_partition_get_flag(const PedPartition *part, PedPartitionFlag flag)
 		return gpt_part_data->lvm;
 	case PED_PARTITION_BOOT:
 		return gpt_part_data->boot;
+	case PED_PARTITION_BOOT_BIOS:
+		return gpt_part_data->boot_bios;
 	case PED_PARTITION_HPSERVICE:
 		return gpt_part_data->hp_service;
         case PED_PARTITION_MSFT_RESERVED:
@@ -1390,6 +1419,7 @@ gpt_partition_is_flag_available(const PedPartition * part,
 	case PED_PARTITION_RAID:
 	case PED_PARTITION_LVM:
 	case PED_PARTITION_BOOT:
+	case PED_PARTITION_BOOT_BIOS:
 	case PED_PARTITION_HPSERVICE:
         case PED_PARTITION_MSFT_RESERVED:
         case PED_PARTITION_HIDDEN:        
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e493e46..d9b0878 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,7 +9,8 @@ TESTS = \
   t3000-constraints.sh \
   t3100-resize-ext2-partion.sh \
   t4100-msdos-partition-limits.sh \
-  t4100-dvh-partition-limits.sh
+  t4100-dvh-partition-limits.sh \
+  t5000-tags.sh
 
 EXTRA_DIST = \
   $(TESTS) test-lib.sh mkdtemp
diff --git a/tests/t5000-tags.sh b/tests/t5000-tags.sh
new file mode 100644
index 0000000..558dfa7
--- /dev/null
+++ b/tests/t5000-tags.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+
+# Copyright (C) 2007,2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+test_description="test boot_bios flag in gpt labels"
+
+. ./init.sh
+
+dev=loop-file
+
+test_expect_success \
+    "setup: create zeroed device" \
+    '{ dd if=/dev/zero bs=1024 count=64; } > $dev'
+
+test_expect_success \
+    'create gpt label' \
+    'parted -s $dev mklabel gpt >out 2>&1'
+
+test_expect_success \
+    'add a partition' \
+    'parted -s $dev mkpart primary 0 1 >>out 2>&1'
+
+test_expect_success \
+    'print the table (before manual modification)' \
+    'parted -s $dev print >>out 2>&1'
+
+# Using bios_boot_magic='\x48\x61' looks nicer, but isn't portable.
+# dash's builtin printf doesn't recognize such \xHH hexadecimal escapes.
+bios_boot_magic='\110\141\150\41\111\144\157\156\164\116\145\145\144\105\106\111'
+
+printf "$bios_boot_magic" | dd of=$dev bs=1024 seek=1 conv=notrunc
+
+test_expect_success \
+    'print the table (after manual modification)' \
+    'parted -s $dev print >>out 2>&1'
+
+pwd=`pwd`
+
+fail=0
+{
+  cat <<EOF
+Model:  (file)
+Disk .../$dev: 65.5kB
+Sector size (logical/physical): 512B/512B
+Partition Table: gpt
+
+Number  Start   End     Size    File system  Name     Flags
+ 1      17.4kB  48.6kB  31.2kB               primary       
+
+Model:  (file)
+Disk .../$dev: 65.5kB
+Sector size (logical/physical): 512B/512B
+Partition Table: gpt
+
+Number  Start   End     Size    File system  Name     Flags    
+ 1      17.4kB  48.6kB  31.2kB               primary  boot_bios
+
+EOF
+} > exp || fail=1
+
+test_expect_success \
+    'prepare actual and expected output' \
+    'test $fail = 0 &&
+     mv out o2 && sed "s,^Disk .*/$dev:,Disk .../$dev:," o2 > out'
+
+test_expect_success 'check for expected output' '$compare out exp'
+
+test_done
-- 
1.4.4.4


--tThc/1wpZn/ma/RB--



More information about the parted-devel mailing list