Blob Blame History Raw
From 4d0cd271069997e7d44ed3b52426ccf2570048c8 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Wed, 11 Sep 2013 12:25:03 -0700
Subject: [PATCH 75/89] libparted: Add Intel Rapid Start Technology partition
 flag.

This adds support for the irst partition type flag. Sets the type to
0x84 on MS-DOS and D3BFE2DE-3DAF-11DF-BA-40-E3A556D89593 on GPT.

* NEWS (New Features): Mention it.
* doc/C/parted.8: Document irst flag.
* doc/parted.texti: Document irst flag.
* include/parted/disk.in.h (_PedPartitionFlag): Add PED_PARTITION_IRST flag
* libparted/disk.c (ped_partition_flag_get_name): Add irst flag
* libparted/labels/dos.c (DosPartitionData): Likewise
(raw_part_parse): Likewise
(msdos_partition_new): Likewise
(msdos_partition_duplicate): Likewise
(msdos_partition_set_system): Likewise
(clear_flags): Likewise
(msdos_partition_set_flag): Likewise
(msdos_partition_get_flag): Likewise
(msdos_partition_is_flag_available): Likewise
* libparted/labels/gpt.c: Add PARTITION_IRST_GUID
(GPTPartitionData): Add irst flag
(_parse_part_entry): Likewise
(gpt_partition_new): Likewise
(gpt_partition_set_system): Likewise
(gpt_partition_set_flag): Likewise
(gpt_partition_get_flag): Likewise
(gpt_partition_is_flag_available): Likewise
---
 NEWS                     |  4 ++++
 doc/C/parted.8           |  2 +-
 doc/parted.texi          |  4 ++++
 include/parted/disk.in.h |  5 +++--
 libparted/disk.c         |  2 ++
 libparted/labels/dos.c   | 21 +++++++++++++++++++++
 libparted/labels/gpt.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 74b7697..27710b6 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** New Features
 
+  Added new partition type flag, irst, for use with Intel Rapid Start
+  Technology. On MS-DOS disk labels it sets the type to 0x84 and on GPT
+  it sets the GUID to D3BFE2DE-3DAF-11DF-BA-40-E3A556D89593.
+
   You can now choose to ignore errors about partitions that overlap,
   or are longer than the disk.  This allows you to use parted to
   repair the problem.
diff --git a/doc/C/parted.8 b/doc/C/parted.8
index a9f73f5..2f8e9f5 100644
--- a/doc/C/parted.8
+++ b/doc/C/parted.8
@@ -104,7 +104,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",
-"legacy_boot" and "palo".
+"legacy_boot", "irst" 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 25a02c7..4c63fe3 100644
--- a/doc/parted.texi
+++ b/doc/parted.texi
@@ -836,6 +836,10 @@ used by Windows on GPT disks.  Note that this flag should not normally be
 set on Windows filesystem partitions (those that contain NTFS or FAT
 filesystems).
 
+@item irst
+(MS-DOS, GPT) - this flag identifies an Intel Rapid Start Technology
+partition.
+
 @item lba
 (MS-DOS) - this flag can be enabled to tell MS DOS, MS Windows 9x and
 MS Windows ME based operating systems to use Linear (LBA) mode.
diff --git a/include/parted/disk.in.h b/include/parted/disk.in.h
index aa905c5..585383d 100644
--- a/include/parted/disk.in.h
+++ b/include/parted/disk.in.h
@@ -73,10 +73,11 @@ enum _PedPartitionFlag {
         PED_PARTITION_APPLE_TV_RECOVERY=13,
         PED_PARTITION_DIAG=14,
         PED_PARTITION_LEGACY_BOOT=15,
-        PED_PARTITION_MSFT_DATA=16
+        PED_PARTITION_MSFT_DATA=16,
+        PED_PARTITION_IRST=17
 };
 #define PED_PARTITION_FIRST_FLAG        PED_PARTITION_BOOT
-#define PED_PARTITION_LAST_FLAG         PED_PARTITION_MSFT_DATA
+#define PED_PARTITION_LAST_FLAG         PED_PARTITION_IRST
 
 enum _PedDiskTypeFeature {
         PED_DISK_TYPE_EXTENDED=1,       /**< supports extended partitions */
diff --git a/libparted/disk.c b/libparted/disk.c
index ce71bfc..18c94ac 100644
--- a/libparted/disk.c
+++ b/libparted/disk.c
@@ -2402,6 +2402,8 @@ ped_partition_flag_get_name (PedPartitionFlag flag)
                 return N_("diag");
         case PED_PARTITION_LEGACY_BOOT:
                 return N_("legacy_boot");
+        case PED_PARTITION_IRST:
+                return N_("irst");
 
 	default:
 		ped_exception_throw (
diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c
index 6bddd79..c754970 100644
--- a/libparted/labels/dos.c
+++ b/libparted/labels/dos.c
@@ -85,6 +85,7 @@ static const char MBR_BOOT_CODE[] = {
 #define PARTITION_LDM		0x42
 #define PARTITION_LINUX_SWAP	0x82
 #define PARTITION_LINUX		0x83
+#define PARTITION_IRST		0x84
 #define PARTITION_LINUX_EXT	0x85
 #define PARTITION_LINUX_LVM	0x8e
 #define PARTITION_HFS		0xaf
@@ -159,6 +160,7 @@ typedef struct {
 	int		palo;
 	int		prep;
 	int		diag;
+	int		irst;
 	OrigState*	orig;			/* used for CHS stuff */
 } DosPartitionData;
 
@@ -924,6 +926,7 @@ raw_part_parse (const PedDisk* disk, const DosRawPartition* raw_part,
 	dos_data->lba = raw_part_is_lba (raw_part);
 	dos_data->palo = raw_part->type == PARTITION_PALO;
 	dos_data->prep = raw_part->type == PARTITION_PREP;
+	dos_data->irst = raw_part->type == PARTITION_IRST;
 	dos_data->orig = ped_malloc (sizeof (OrigState));
 	if (!dos_data->orig) {
 		ped_partition_destroy (part);
@@ -1316,6 +1319,7 @@ msdos_partition_new (const PedDisk* disk, PedPartitionType part_type,
 		dos_data->lba = 0;
 		dos_data->palo = 0;
 		dos_data->prep = 0;
+		dos_data->irst = 0;
 	} else {
 		part->disk_specific = NULL;
 	}
@@ -1351,6 +1355,7 @@ msdos_partition_duplicate (const PedPartition* part)
 	new_dos_data->lba = old_dos_data->lba;
 	new_dos_data->palo = old_dos_data->palo;
 	new_dos_data->prep = old_dos_data->prep;
+	new_dos_data->irst = old_dos_data->irst;
 
 	if (old_dos_data->orig) {
 		new_dos_data->orig = ped_malloc (sizeof (OrigState));
@@ -1399,6 +1404,7 @@ msdos_partition_set_system (PedPartition* part,
 		dos_data->lvm = 0;
 		dos_data->palo = 0;
 		dos_data->prep = 0;
+		dos_data->irst = 0;
 		if (dos_data->lba)
 			dos_data->system = PARTITION_EXT_LBA;
 		else
@@ -1431,6 +1437,10 @@ msdos_partition_set_system (PedPartition* part,
 		dos_data->system = PARTITION_PREP;
 		return 1;
 	}
+	if (dos_data->irst) {
+		dos_data->system = PARTITION_IRST;
+		return 1;
+	}
 
 	if (!fs_type)
 		dos_data->system = PARTITION_LINUX;
@@ -1467,6 +1477,7 @@ clear_flags (DosPartitionData *dos_data)
   dos_data->lvm = 0;
   dos_data->palo = 0;
   dos_data->prep = 0;
+  dos_data->irst = 0;
   dos_data->raid = 0;
 }
 
@@ -1545,6 +1556,12 @@ msdos_partition_set_flag (PedPartition* part,
 		dos_data->prep = state;
 		return ped_partition_set_system (part, part->fs_type);
 
+	case PED_PARTITION_IRST:
+		if (state)
+			clear_flags (dos_data);
+		dos_data->irst = state;
+		return ped_partition_set_system (part, part->fs_type);
+
 	default:
 		return 0;
 	}
@@ -1587,6 +1604,9 @@ msdos_partition_get_flag (const PedPartition* part, PedPartitionFlag flag)
 	case PED_PARTITION_PREP:
 		return dos_data->prep;
 
+	case PED_PARTITION_IRST:
+		return dos_data->irst;
+
 	default:
 		return 0;
 	}
@@ -1609,6 +1629,7 @@ msdos_partition_is_flag_available (const PedPartition* part,
 	case PED_PARTITION_LBA:
 	case PED_PARTITION_PALO:
 	case PED_PARTITION_PREP:
+	case PED_PARTITION_IRST:
 	case PED_PARTITION_DIAG:
 		return 1;
 
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 6fd8880..ff87708 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -152,6 +152,10 @@ typedef struct
     ((efi_guid_t) { PED_CPU_TO_LE32 (0x9e1a2d38), PED_CPU_TO_LE16 (0xc612), \
                     PED_CPU_TO_LE16 (0x4316), 0xaa, 0x26, \
                     { 0x8b, 0x49, 0x52, 0x1e, 0x5a, 0x8b }})
+#define PARTITION_IRST_GUID \
+    ((efi_guid_t) { PED_CPU_TO_LE32 (0xD3BFE2DE), PED_CPU_TO_LE16 (0x3DAF), \
+                    PED_CPU_TO_LE16 (0x11DF), 0xba, 0x40, \
+                    { 0xE3, 0xA5, 0x56, 0xD8, 0x95, 0x93 }})
 
 struct __attribute__ ((packed)) _GuidPartitionTableHeader_t
 {
@@ -297,6 +301,7 @@ typedef struct _GPTPartitionData
   int msftrecv;
   int legacy_boot;
   int prep;
+  int irst;
 } GPTPartitionData;
 
 static PedDiskType gpt_disk_type;
@@ -814,6 +819,7 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
     = gpt_part_data->msftrecv
     = gpt_part_data->legacy_boot
     = gpt_part_data->prep
+    = gpt_part_data->irst
     = gpt_part_data->bios_grub = gpt_part_data->atvrecv = 0;
 
   if (pte->Attributes.RequiredToFunction & 0x1)
@@ -841,6 +847,8 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
     gpt_part_data->atvrecv = 1;
   else if (!guid_cmp (gpt_part_data->type, PARTITION_PREP_GUID))
     gpt_part_data->prep = 1;
+  else if (!guid_cmp (gpt_part_data->type, PARTITION_IRST_GUID))
+    gpt_part_data->irst = 1;
 
   return part;
 }
@@ -1359,6 +1367,7 @@ gpt_partition_new (const PedDisk *disk,
   gpt_part_data->legacy_boot = 0;
   gpt_part_data->prep = 0;
   gpt_part_data->translated_name = 0;
+  gpt_part_data->irst = 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);
@@ -1477,6 +1486,11 @@ gpt_partition_set_system (PedPartition *part,
       gpt_part_data->type = PARTITION_APPLE_TV_RECOVERY_GUID;
       return 1;
     }
+  if (gpt_part_data->irst)
+    {
+      gpt_part_data->type = PARTITION_IRST_GUID;
+      return 1;
+    }
 
   if (fs_type)
     {
@@ -1619,6 +1633,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftdata
           = gpt_part_data->msftrecv
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_BIOS_GRUB:
@@ -1632,6 +1647,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftdata
           = gpt_part_data->msftrecv
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_RAID:
@@ -1645,6 +1661,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftdata
           = gpt_part_data->msftrecv
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_LVM:
@@ -1658,6 +1675,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftdata
           = gpt_part_data->msftrecv
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_HPSERVICE:
@@ -1671,6 +1689,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftdata
           = gpt_part_data->msftrecv
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_MSFT_RESERVED:
@@ -1684,6 +1703,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftdata
           = gpt_part_data->msftrecv
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_MSFT_DATA:
@@ -1697,6 +1717,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftres
           = gpt_part_data->msftrecv
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
         gpt_part_data->msftdata = 1;
       } else {
@@ -1714,6 +1735,7 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->msftdata
           = gpt_part_data->msftres
           = gpt_part_data->prep
+          = gpt_part_data->irst
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_APPLE_TV_RECOVERY:
@@ -1738,7 +1760,22 @@ gpt_partition_set_flag (PedPartition *part, PedPartitionFlag flag, int state)
           = gpt_part_data->bios_grub
           = gpt_part_data->hp_service
           = gpt_part_data->msftres
+          = gpt_part_data->irst
+          = gpt_part_data->atvrecv
+          = gpt_part_data->msftrecv = 0;
+      return gpt_partition_set_system (part, part->fs_type);
+    case PED_PARTITION_IRST:
+      gpt_part_data->irst = state;
+      if (state)
+        gpt_part_data->boot
+          = gpt_part_data->raid
+          = gpt_part_data->lvm
+          = gpt_part_data->bios_grub
+          = gpt_part_data->hp_service
+          = gpt_part_data->msftres
+          = gpt_part_data->msftdata
           = gpt_part_data->msftrecv
+          = gpt_part_data->prep
           = gpt_part_data->atvrecv = 0;
       return gpt_partition_set_system (part, part->fs_type);
     case PED_PARTITION_HIDDEN:
@@ -1789,6 +1826,8 @@ gpt_partition_get_flag (const PedPartition *part, PedPartitionFlag flag)
       return gpt_part_data->legacy_boot;
     case PED_PARTITION_PREP:
       return gpt_part_data->prep;
+    case PED_PARTITION_IRST:
+      return gpt_part_data->irst;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_LBA:
     case PED_PARTITION_ROOT:
@@ -1816,6 +1855,7 @@ gpt_partition_is_flag_available (const PedPartition *part,
     case PED_PARTITION_HIDDEN:
     case PED_PARTITION_LEGACY_BOOT:
     case PED_PARTITION_PREP:
+    case PED_PARTITION_IRST:
       return 1;
     case PED_PARTITION_SWAP:
     case PED_PARTITION_ROOT:
-- 
1.8.5.3