srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 1 | // parttypes.cc |
| 2 | // Class to manage partition type codes -- a slight variant on MBR type |
| 3 | // codes, GUID type codes, and associated names. |
| 4 | |
Roderick W. Smith | e3ee733 | 2013-09-24 12:56:11 -0400 | [diff] [blame] | 5 | /* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed |
srs5694 | 221e087 | 2009-08-29 15:00:31 -0400 | [diff] [blame] | 6 | under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ |
| 7 | |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 8 | #define __STDC_LIMIT_MACROS |
| 9 | #define __STDC_CONSTANT_MACROS |
| 10 | |
| 11 | #include <string.h> |
| 12 | #include <stdint.h> |
| 13 | #include <stdio.h> |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 14 | #include <iostream> |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 15 | #include "parttypes.h" |
| 16 | |
| 17 | using namespace std; |
| 18 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 19 | int PartType::numInstances = 0; |
| 20 | AType* PartType::allTypes = NULL; |
| 21 | AType* PartType::lastType = NULL; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 22 | |
| 23 | // Constructor. Its main task is to initialize the data list, but only |
| 24 | // if this is the first instance, since it's a static linked list. |
| 25 | // Partition type codes are MBR type codes multiplied by 0x0100, with |
| 26 | // additional related codes taking on following numbers. For instance, |
| 27 | // the FreeBSD disklabel code in MBR is 0xa5; here, it's 0xa500, with |
| 28 | // additional FreeBSD codes being 0xa501, 0xa502, and so on. This gives |
| 29 | // related codes similar numbers and (given appropriate entry positions |
| 30 | // in the linked list) keeps them together in the listings generated |
| 31 | // by typing "L" at the main gdisk menu. |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 32 | PartType::PartType(void) : GUIDData() { |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 33 | numInstances++; |
| 34 | if (numInstances == 1) { |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 35 | AddAllTypes(); |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 36 | } // if |
| 37 | } // default constructor |
| 38 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 39 | PartType::PartType(const PartType & orig) : GUIDData(orig) { |
| 40 | numInstances++; |
| 41 | if (numInstances == 1) { // should never happen; just being paranoid |
| 42 | AddAllTypes(); |
| 43 | } // if |
| 44 | } // PartType copy constructor |
| 45 | |
| 46 | PartType::PartType(const GUIDData & orig) : GUIDData(orig) { |
| 47 | numInstances++; |
| 48 | if (numInstances == 1) { |
| 49 | AddAllTypes(); |
| 50 | } // if |
| 51 | } // PartType copy constructor |
| 52 | |
| 53 | PartType::~PartType(void) { |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 54 | AType* tempType; |
| 55 | |
| 56 | numInstances--; |
| 57 | if (numInstances == 0) { |
| 58 | while (allTypes != NULL) { |
| 59 | tempType = allTypes; |
| 60 | allTypes = allTypes->next; |
| 61 | delete tempType; |
| 62 | } // while |
| 63 | } // if |
| 64 | } // destructor |
| 65 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 66 | // Add all partition type codes to the internal linked-list structure. |
| 67 | // Used by constructors. |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 68 | // See http://www.win.tue.nl/~aeb/partitions/partition_types-1.html |
| 69 | // for a list of MBR partition type codes. |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 70 | void PartType::AddAllTypes(void) { |
| 71 | // Start with the "unused entry," which should normally appear only |
| 72 | // on empty partition table entries.... |
| 73 | AddType(0x0000, "00000000-0000-0000-0000-000000000000", "Unused entry", 0); |
| 74 | |
srs5694 | d8eed46 | 2012-12-15 01:55:21 -0500 | [diff] [blame] | 75 | // DOS/Windows partition types, most of which are hidden from the "L" listing |
| 76 | // (they're available mainly for MBR-to-GPT conversions). |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 77 | AddType(0x0100, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-12 |
| 78 | AddType(0x0400, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16 < 32M |
| 79 | AddType(0x0600, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16 |
| 80 | AddType(0x0700, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 1); // NTFS (or HPFS) |
| 81 | AddType(0x0b00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-32 |
| 82 | AddType(0x0c00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-32 LBA |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 83 | AddType(0x0c01, "E3C9E316-0B5C-4DB8-817D-F92DF00215AE", "Microsoft reserved"); |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 84 | AddType(0x0e00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16 LBA |
| 85 | AddType(0x1100, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-12 |
| 86 | AddType(0x1400, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-16 < 32M |
| 87 | AddType(0x1600, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-16 |
| 88 | AddType(0x1700, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden NTFS (or HPFS) |
| 89 | AddType(0x1b00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-32 |
| 90 | AddType(0x1c00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-32 LBA |
| 91 | AddType(0x1e00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-16 LBA |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 92 | AddType(0x2700, "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC", "Windows RE"); |
Roderick W. Smith | 0fde58b | 2013-10-10 22:28:17 -0400 | [diff] [blame] | 93 | |
Roderick W. Smith | b784e0c | 2014-01-25 22:55:26 -0500 | [diff] [blame] | 94 | // Open Network Install Environment (ONIE) specific types. |
| 95 | // See http://www.onie.org/ |
| 96 | AddType(0x3000, "7412F7D5-A156-4B13-81DC-867174929325", "ONIE boot"); |
| 97 | AddType(0x3001, "D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149", "ONIE config"); |
| 98 | |
Roderick W. Smith | 0fde58b | 2013-10-10 22:28:17 -0400 | [diff] [blame] | 99 | // PowerPC reference platform boot partition |
| 100 | AddType(0x4100, "9E1A2D38-C612-4316-AA26-8B49521E5A8B", "PowerPC PReP boot"); |
| 101 | |
| 102 | // Windows LDM ("dynamic disk") types |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 103 | AddType(0x4200, "AF9B60A0-1431-4F62-BC68-3311714A69AD", "Windows LDM data"); // Logical disk manager |
| 104 | AddType(0x4201, "5808C8AA-7E8F-42E0-85D2-E1E90434CFB3", "Windows LDM metadata"); // Logical disk manager |
| 105 | |
| 106 | // An oddball IBM filesystem.... |
| 107 | AddType(0x7501, "37AFFC90-EF7D-4E96-91C3-2D7AE055B174", "IBM GPFS"); // General Parallel File System (GPFS) |
| 108 | |
srs5694 | df9d363 | 2011-01-08 18:33:24 -0500 | [diff] [blame] | 109 | // ChromeOS-specific partition types... |
| 110 | // Values taken from vboot_reference/firmware/lib/cgptlib/include/gpt.h in |
| 111 | // ChromeOS source code, retrieved 12/23/2010. They're also at |
| 112 | // http://www.chromium.org/chromium-os/chromiumos-design-docs/disk-format. |
| 113 | // These have no MBR equivalents, AFAIK, so I'm using 0x7Fxx values, since they're close |
| 114 | // to the Linux values. |
| 115 | AddType(0x7f00, "FE3A2A5D-4F32-41A7-B725-ACCC3285A309", "ChromeOS kernel"); |
| 116 | AddType(0x7f01, "3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC", "ChromeOS root"); |
| 117 | AddType(0x7f02, "2E0A753D-9E48-43B0-8337-B15192CB1B5E", "ChromeOS reserved"); |
| 118 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 119 | // Linux-specific partition types.... |
srs5694 | d8eed46 | 2012-12-15 01:55:21 -0500 | [diff] [blame] | 120 | AddType(0x8200, "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", "Linux swap"); // Linux swap (or Solaris on MBR) |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 121 | AddType(0x8300, "0FC63DAF-8483-4772-8E79-3D69D8477DE4", "Linux filesystem"); // Linux native |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 122 | AddType(0x8301, "8DA63339-0007-60C0-C436-083AC8230908", "Linux reserved"); |
Roderick W. Smith | 0fde58b | 2013-10-10 22:28:17 -0400 | [diff] [blame] | 123 | // See http://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html |
| 124 | AddType(0x8302, "933AC7E1-2EB4-4F13-B844-0E14E2AEF915", "Linux /home"); // Linux /home (auto-mounted by systemd) |
Roderick W. Smith | 1eea9b0 | 2013-07-06 22:52:58 -0400 | [diff] [blame] | 125 | |
| 126 | // Used by Intel Rapid Start technology |
| 127 | AddType(0x8400, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Rapid Start"); |
| 128 | |
| 129 | // Another Linux type code.... |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 130 | AddType(0x8e00, "E6D6D379-F507-44C2-A23C-238F2A3DF928", "Linux LVM"); |
| 131 | |
| 132 | // FreeBSD partition types.... |
| 133 | // Note: Rather than extract FreeBSD disklabel data, convert FreeBSD |
| 134 | // partitions in-place, and let FreeBSD sort out the details.... |
srs5694 | cb76c67 | 2010-02-11 22:22:22 -0500 | [diff] [blame] | 135 | AddType(0xa500, "516E7CB4-6ECF-11D6-8FF8-00022D09712B", "FreeBSD disklabel"); |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 136 | AddType(0xa501, "83BD6B9D-7F41-11DC-BE0B-001560B84F0F", "FreeBSD boot"); |
| 137 | AddType(0xa502, "516E7CB5-6ECF-11D6-8FF8-00022D09712B", "FreeBSD swap"); |
| 138 | AddType(0xa503, "516E7CB6-6ECF-11D6-8FF8-00022D09712B", "FreeBSD UFS"); |
| 139 | AddType(0xa504, "516E7CBA-6ECF-11D6-8FF8-00022D09712B", "FreeBSD ZFS"); |
| 140 | AddType(0xa505, "516E7CB8-6ECF-11D6-8FF8-00022D09712B", "FreeBSD Vinum/RAID"); |
| 141 | |
srs5694 | fa3868e | 2012-03-28 01:45:57 -0400 | [diff] [blame] | 142 | // Midnight BSD partition types.... |
| 143 | AddType(0xa580, "85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD data"); |
| 144 | AddType(0xa581, "85D5E45E-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD boot"); |
| 145 | AddType(0xa582, "85D5E45B-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD swap"); |
| 146 | AddType(0xa583, "0394Ef8B-237E-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD UFS"); |
| 147 | AddType(0xa584, "85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD ZFS"); |
| 148 | AddType(0xa585, "85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD Vinum"); |
| 149 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 150 | // A MacOS partition type, separated from others by NetBSD partition types... |
| 151 | AddType(0xa800, "55465300-0000-11AA-AA11-00306543ECAC", "Apple UFS"); // Mac OS X |
| 152 | |
| 153 | // NetBSD partition types. Note that the main entry sets it up as a |
| 154 | // FreeBSD disklabel. I'm not 100% certain this is the correct behavior. |
| 155 | AddType(0xa900, "516E7CB4-6ECF-11D6-8FF8-00022D09712B", "FreeBSD disklabel", 0); // NetBSD disklabel |
| 156 | AddType(0xa901, "49F48D32-B10E-11DC-B99B-0019D1879648", "NetBSD swap"); |
| 157 | AddType(0xa902, "49F48D5A-B10E-11DC-B99B-0019D1879648", "NetBSD FFS"); |
| 158 | AddType(0xa903, "49F48D82-B10E-11DC-B99B-0019D1879648", "NetBSD LFS"); |
| 159 | AddType(0xa904, "2DB519C4-B10F-11DC-B99B-0019D1879648", "NetBSD concatenated"); |
| 160 | AddType(0xa905, "2DB519EC-B10F-11DC-B99B-0019D1879648", "NetBSD encrypted"); |
| 161 | AddType(0xa906, "49F48DAA-B10E-11DC-B99B-0019D1879648", "NetBSD RAID"); |
| 162 | |
| 163 | // Mac OS partition types (See also 0xa800, above).... |
| 164 | AddType(0xab00, "426F6F74-0000-11AA-AA11-00306543ECAC", "Apple boot"); |
| 165 | AddType(0xaf00, "48465300-0000-11AA-AA11-00306543ECAC", "Apple HFS/HFS+"); |
| 166 | AddType(0xaf01, "52414944-0000-11AA-AA11-00306543ECAC", "Apple RAID"); |
| 167 | AddType(0xaf02, "52414944-5F4F-11AA-AA11-00306543ECAC", "Apple RAID offline"); |
| 168 | AddType(0xaf03, "4C616265-6C00-11AA-AA11-00306543ECAC", "Apple label"); |
| 169 | AddType(0xaf04, "5265636F-7665-11AA-AA11-00306543ECAC", "AppleTV recovery"); |
srs5694 | a17fe69 | 2011-09-10 20:30:20 -0400 | [diff] [blame] | 170 | AddType(0xaf05, "53746F72-6167-11AA-AA11-00306543ECAC", "Apple Core Storage"); |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 171 | |
| 172 | // Solaris partition types (one of which is shared with MacOS) |
| 173 | AddType(0xbe00, "6A82CB45-1DD2-11B2-99A6-080020736631", "Solaris boot"); |
| 174 | AddType(0xbf00, "6A85CF4D-1DD2-11B2-99A6-080020736631", "Solaris root"); |
| 175 | AddType(0xbf01, "6A898CC3-1DD2-11B2-99A6-080020736631", "Solaris /usr & Mac ZFS"); // Solaris/MacOS |
| 176 | AddType(0xbf02, "6A87C46F-1DD2-11B2-99A6-080020736631", "Solaris swap"); |
| 177 | AddType(0xbf03, "6A8B642B-1DD2-11B2-99A6-080020736631", "Solaris backup"); |
| 178 | AddType(0xbf04, "6A8EF2E9-1DD2-11B2-99A6-080020736631", "Solaris /var"); |
| 179 | AddType(0xbf05, "6A90BA39-1DD2-11B2-99A6-080020736631", "Solaris /home"); |
| 180 | AddType(0xbf06, "6A9283A5-1DD2-11B2-99A6-080020736631", "Solaris alternate sector"); |
| 181 | AddType(0xbf07, "6A945A3B-1DD2-11B2-99A6-080020736631", "Solaris Reserved 1"); |
| 182 | AddType(0xbf08, "6A9630D1-1DD2-11B2-99A6-080020736631", "Solaris Reserved 2"); |
| 183 | AddType(0xbf09, "6A980767-1DD2-11B2-99A6-080020736631", "Solaris Reserved 3"); |
| 184 | AddType(0xbf0a, "6A96237F-1DD2-11B2-99A6-080020736631", "Solaris Reserved 4"); |
| 185 | AddType(0xbf0b, "6A8D2AC7-1DD2-11B2-99A6-080020736631", "Solaris Reserved 5"); |
| 186 | |
| 187 | // I can find no MBR equivalents for these, but they're on the |
| 188 | // Wikipedia page for GPT, so here we go.... |
| 189 | AddType(0xc001, "75894C1E-3AEB-11D3-B7C1-7B03A0000000", "HP-UX data"); |
| 190 | AddType(0xc002, "E2A1E728-32E3-11D6-A682-7B03A0000000", "HP-UX service"); |
| 191 | |
Roderick W. Smith | 1eea9b0 | 2013-07-06 22:52:58 -0400 | [diff] [blame] | 192 | // See http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec |
| 193 | AddType(0xea00, "BC13C2FF-59E6-4262-A352-B275FD6F7172", "Freedesktop $BOOT"); |
| 194 | |
srs5694 | df231c1 | 2013-01-09 14:50:30 -0500 | [diff] [blame] | 195 | // Type code for Haiku; uses BeOS MBR code as hex code base |
| 196 | AddType(0xeb00, "42465331-3BA3-10F1-802A-4861696B7521", "Haiku BFS"); |
| 197 | |
Roderick W. Smith | b784e0c | 2014-01-25 22:55:26 -0500 | [diff] [blame] | 198 | // Manufacturer-specific ESP-like partitions (in order in which they were added) |
srs5694 | d8eed46 | 2012-12-15 01:55:21 -0500 | [diff] [blame] | 199 | AddType(0xed00, "F4019732-066E-4E12-8273-346C5641494F", "Sony system partition"); |
Roderick W. Smith | b784e0c | 2014-01-25 22:55:26 -0500 | [diff] [blame] | 200 | AddType(0xed01, "BFBFAFE7-A34F-448A-9A5B-6213EB736C22", "Lenovo system partition"); |
srs5694 | d8eed46 | 2012-12-15 01:55:21 -0500 | [diff] [blame] | 201 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 202 | // EFI system and related partitions |
srs5694 | 64cbd17 | 2011-03-01 22:03:54 -0500 | [diff] [blame] | 203 | AddType(0xef00, "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "EFI System"); // Parted identifies these as having the "boot flag" set |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 204 | AddType(0xef01, "024DEE41-33E7-11D3-9D69-0008C781F39F", "MBR partition scheme"); // Used to nest MBR in GPT |
srs5694 | d8eed46 | 2012-12-15 01:55:21 -0500 | [diff] [blame] | 205 | AddType(0xef02, "21686148-6449-6E6F-744E-656564454649", "BIOS boot partition"); // Used by GRUB |
| 206 | |
| 207 | // VMWare ESX partition types codes |
| 208 | AddType(0xfb00, "AA31E02A-400F-11DB-9590-000C2911D1B8", "VMWare VMFS"); |
| 209 | AddType(0xfb01, "9198EFFC-31C0-11DB-8F78-000C2911D1B8", "VMWare reserved"); |
| 210 | AddType(0xfc00, "9D275380-40AD-11DB-BF97-000C2911D1B8", "VMWare kcore crash protection"); |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 211 | |
| 212 | // A straggler Linux partition type.... |
| 213 | AddType(0xfd00, "A19D880F-05FC-4D3B-A006-743F0F84911E", "Linux RAID"); |
| 214 | |
| 215 | // Note: DO NOT use the 0xffff code; that's reserved to indicate an |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 216 | // unknown GUID type code. |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 217 | } // PartType::AddAllTypes() |
| 218 | |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 219 | // Add a single type to the linked list of types. Returns 1 if operation |
srs5694 | e321d44 | 2010-01-29 17:44:04 -0500 | [diff] [blame] | 220 | // succeeds, 0 otherwise. |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 221 | int PartType::AddType(uint16_t mbrType, const char * guidData, const char * name, |
| 222 | int toDisplay) { |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 223 | AType* tempType; |
| 224 | int allOK = 1; |
| 225 | |
| 226 | tempType = new AType; |
| 227 | if (tempType != NULL) { |
| 228 | tempType->MBRType = mbrType; |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 229 | tempType->GUIDType = guidData; |
| 230 | tempType->name = name; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 231 | tempType->display = toDisplay; |
| 232 | tempType->next = NULL; |
| 233 | if (allTypes == NULL) { // first entry |
| 234 | allTypes = tempType; |
| 235 | } else { |
| 236 | lastType->next = tempType; |
| 237 | } // if/else |
| 238 | lastType = tempType; |
| 239 | } else { |
srs5694 | 6aae2a9 | 2011-06-10 01:16:51 -0400 | [diff] [blame] | 240 | cerr << "Unable to allocate memory in PartType::AddType()! Partition type list will\n"; |
| 241 | cerr << "be incomplete!\n"; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 242 | allOK = 0; |
| 243 | } // if/else |
| 244 | return allOK; |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 245 | } // GUID::AddType(const char* variant) |
| 246 | |
srs5694 | 82f3f0b | 2010-09-22 10:50:24 -0400 | [diff] [blame] | 247 | // Assignment operator by string. If the original string is short, |
| 248 | // interpret it as a gdisk hex code; if it's longer, interpret it as |
srs5694 | 0873e9d | 2010-10-07 13:00:45 -0400 | [diff] [blame] | 249 | // a direct entry of a GUID value. If a short string isn't a hex |
| 250 | // number, do nothing. |
srs5694 | 82f3f0b | 2010-09-22 10:50:24 -0400 | [diff] [blame] | 251 | PartType & PartType::operator=(const string & orig) { |
| 252 | uint32_t hexCode; |
| 253 | |
| 254 | if (orig.length() < 32) { |
srs5694 | 0873e9d | 2010-10-07 13:00:45 -0400 | [diff] [blame] | 255 | if (IsHex(orig)) { |
| 256 | sscanf(orig.c_str(), "%x", &hexCode); |
| 257 | *this = hexCode; |
srs5694 | a17fe69 | 2011-09-10 20:30:20 -0400 | [diff] [blame] | 258 | } |
srs5694 | 82f3f0b | 2010-09-22 10:50:24 -0400 | [diff] [blame] | 259 | } else { |
| 260 | GUIDData::operator=(orig); |
| 261 | } // if/else hexCode or GUID |
| 262 | return *this; |
| 263 | } // PartType::operator=(const char * orig) |
| 264 | |
| 265 | // Assignment from C-style string; rely on C++ casting.... |
| 266 | PartType & PartType::operator=(const char * orig) { |
| 267 | return operator=((string) orig); |
| 268 | } // PartType::operator=(const char * orig) |
| 269 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 270 | // Assign a GUID based on my custom 2-byte (16-bit) MBR hex ID variant |
srs5694 | cb76c67 | 2010-02-11 22:22:22 -0500 | [diff] [blame] | 271 | PartType & PartType::operator=(uint16_t ID) { |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 272 | AType* theItem = allTypes; |
| 273 | int found = 0; |
| 274 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 275 | // Now search the type list for a match to the ID.... |
| 276 | while ((theItem != NULL) && (!found)) { |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 277 | if (theItem->MBRType == ID) { |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 278 | GUIDData::operator=(theItem->GUIDType); |
| 279 | found = 1; |
| 280 | } else { |
| 281 | theItem = theItem->next; |
| 282 | } // if/else |
| 283 | } // while |
| 284 | if (!found) { |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 285 | // Assign a default value.... |
srs5694 | 0741fa2 | 2013-01-09 12:55:40 -0500 | [diff] [blame] | 286 | operator=(DEFAULT_GPT_TYPE); |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 287 | cout.setf(ios::uppercase); |
| 288 | cout.fill('0'); |
| 289 | cout << "Exact type match not found for type code "; |
| 290 | cout.width(4); |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 291 | cout << hex << ID << "; assigning type code for\n'" << TypeName() << "'\n" << dec; |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 292 | cout.fill(' '); |
| 293 | } // if (!found) |
| 294 | return *this; |
| 295 | } // PartType::operator=(uint16_t ID) |
| 296 | |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 297 | // Return the English description of the partition type (e.g., "Linux filesystem") |
srs5694 | 5a08175 | 2010-09-24 20:39:41 -0400 | [diff] [blame] | 298 | string PartType::TypeName(void) const { |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 299 | AType* theItem = allTypes; |
| 300 | int found = 0; |
| 301 | string typeName; |
| 302 | |
| 303 | while ((theItem != NULL) && (!found)) { |
| 304 | if (theItem->GUIDType == *this) { // found it! |
| 305 | typeName = theItem->name; |
| 306 | found = 1; |
| 307 | } else { |
| 308 | theItem = theItem->next; |
| 309 | } // if/else |
| 310 | } // while |
| 311 | if (!found) { |
| 312 | typeName = "Unknown"; |
| 313 | } // if (!found) |
| 314 | return typeName; |
| 315 | } // PartType::TypeName() |
| 316 | |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 317 | // Return the Unicode description of the partition type (e.g., "Linux filesystem") |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 318 | UnicodeString PartType::UTypeName(void) const { |
| 319 | AType* theItem = allTypes; |
| 320 | int found = 0; |
| 321 | UnicodeString typeName; |
| 322 | |
| 323 | while ((theItem != NULL) && (!found)) { |
| 324 | if (theItem->GUIDType == *this) { // found it! |
| 325 | typeName = theItem->name.c_str(); |
| 326 | found = 1; |
| 327 | } else { |
| 328 | theItem = theItem->next; |
| 329 | } // if/else |
| 330 | } // while |
| 331 | if (!found) { |
| 332 | typeName = "Unknown"; |
| 333 | } // if (!found) |
| 334 | return typeName; |
| 335 | } // PartType::TypeName() |
| 336 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 337 | // Return the custom GPT fdisk 2-byte (16-bit) hex code for this GUID partition type |
| 338 | // Note that this function ignores entries for which the display variable |
| 339 | // is set to 0. This enables control of which values get returned when |
| 340 | // there are multiple possibilities, but opens the algorithm up to the |
| 341 | // potential for problems should the data in the list be bad. |
srs5694 | 5a08175 | 2010-09-24 20:39:41 -0400 | [diff] [blame] | 342 | uint16_t PartType::GetHexType() const { |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 343 | AType* theItem = allTypes; |
| 344 | int found = 0; |
| 345 | uint16_t theID = 0xFFFF; |
| 346 | |
| 347 | while ((theItem != NULL) && (!found)) { |
| 348 | if ((theItem->GUIDType == *this) && (theItem->display == 1)) { // found it! |
| 349 | theID = theItem->MBRType; |
| 350 | found = 1; |
| 351 | } else { |
| 352 | theItem = theItem->next; |
| 353 | } // if/else |
| 354 | } // while |
| 355 | if (!found) { |
| 356 | theID = 0xFFFF; |
| 357 | } // if (!found) |
| 358 | return theID; |
| 359 | } // PartType::GetHex() |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 360 | |
| 361 | // Displays the available types and my extended MBR codes for same.... |
| 362 | // Note: This function assumes an 80-column display. On wider displays, |
| 363 | // it stops at under 80 columns; on narrower displays, lines will wrap |
Roderick W. Smith | e3ee733 | 2013-09-24 12:56:11 -0400 | [diff] [blame] | 364 | // in an ugly way. The maxLines value is the maximum number of lines |
| 365 | // to display before prompting to continue, or 0 (or a negative value) |
| 366 | // for no limit. |
| 367 | void PartType::ShowAllTypes(int maxLines) const { |
| 368 | int colCount = 1, lineCount = 1; |
srs5694 | e321d44 | 2010-01-29 17:44:04 -0500 | [diff] [blame] | 369 | size_t i; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 370 | AType* thisType = allTypes; |
Roderick W. Smith | e3ee733 | 2013-09-24 12:56:11 -0400 | [diff] [blame] | 371 | string line; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 372 | |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 373 | cout.unsetf(ios::uppercase); |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 374 | while (thisType != NULL) { |
| 375 | if (thisType->display == 1) { // show it |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 376 | cout.fill('0'); |
| 377 | cout.width(4); |
| 378 | cout << hex << thisType->MBRType << " "; |
srs5694 | e321d44 | 2010-01-29 17:44:04 -0500 | [diff] [blame] | 379 | cout << thisType->name.substr(0, 20); |
srs5694 | 55d9261 | 2010-03-07 22:16:07 -0500 | [diff] [blame] | 380 | for (i = 0; i < (20 - (thisType->name.substr(0, 20).length())); i++) |
| 381 | cout << " "; |
Roderick W. Smith | e3ee733 | 2013-09-24 12:56:11 -0400 | [diff] [blame] | 382 | if ((colCount % 3) == 0) { |
| 383 | if (thisType->next) { |
| 384 | cout << "\n"; |
| 385 | if ((maxLines > 0) && (lineCount++ % maxLines) == 0) { |
| 386 | cout << "Press the <Enter> key to see more codes: "; |
| 387 | getline(cin, line); |
| 388 | } // if reached screen line limit |
| 389 | } // if there's another entry following this one |
| 390 | } else { |
srs5694 | e321d44 | 2010-01-29 17:44:04 -0500 | [diff] [blame] | 391 | cout << " "; |
Roderick W. Smith | e3ee733 | 2013-09-24 12:56:11 -0400 | [diff] [blame] | 392 | } |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 393 | colCount++; |
| 394 | } // if |
| 395 | thisType = thisType->next; |
| 396 | } // while |
srs5694 | 0a69731 | 2010-01-28 21:10:52 -0500 | [diff] [blame] | 397 | cout.fill(' '); |
| 398 | cout << "\n" << dec; |
Roderick W. Smith | e3ee733 | 2013-09-24 12:56:11 -0400 | [diff] [blame] | 399 | } // PartType::ShowAllTypes(int maxLines) |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 400 | |
| 401 | // Returns 1 if code is a valid extended MBR code, 0 if it's not |
srs5694 | 5a08175 | 2010-09-24 20:39:41 -0400 | [diff] [blame] | 402 | int PartType::Valid(uint16_t code) const { |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 403 | AType* thisType = allTypes; |
| 404 | int found = 0; |
| 405 | |
| 406 | while ((thisType != NULL) && (!found)) { |
| 407 | if (thisType->MBRType == code) { |
| 408 | found = 1; |
| 409 | } // if |
| 410 | thisType = thisType->next; |
| 411 | } // while |
| 412 | return found; |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 413 | } // PartType::Valid() |