blob: 47c0f726baaa25f5743cce53e2826a58d3ad850d [file] [log] [blame]
srs5694e7b4ff92009-08-18 13:16:10 -04001// parttypes.cc
2// Class to manage partition type codes -- a slight variant on MBR type
3// codes, GUID type codes, and associated names.
4
Aurimas Liutikas74b74902016-05-10 18:53:54 -07005/* This program is copyright (c) 2009-2015 by Roderick W. Smith. It is distributed
srs5694221e0872009-08-29 15:00:31 -04006 under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
7
srs5694e7b4ff92009-08-18 13:16:10 -04008#define __STDC_LIMIT_MACROS
Aurimas Liutikasfcad0602016-05-10 19:16:10 -07009#ifndef __STDC_CONSTANT_MACROS
srs5694e7b4ff92009-08-18 13:16:10 -040010#define __STDC_CONSTANT_MACROS
Aurimas Liutikasfcad0602016-05-10 19:16:10 -070011#endif
srs5694e7b4ff92009-08-18 13:16:10 -040012
13#include <string.h>
14#include <stdint.h>
15#include <stdio.h>
srs5694fed16d02010-01-27 23:03:40 -050016#include <iostream>
srs5694e7b4ff92009-08-18 13:16:10 -040017#include "parttypes.h"
18
19using namespace std;
20
srs56946699b012010-02-04 00:55:30 -050021int PartType::numInstances = 0;
22AType* PartType::allTypes = NULL;
23AType* PartType::lastType = NULL;
srs5694e7b4ff92009-08-18 13:16:10 -040024
25// Constructor. Its main task is to initialize the data list, but only
26// if this is the first instance, since it's a static linked list.
27// Partition type codes are MBR type codes multiplied by 0x0100, with
28// additional related codes taking on following numbers. For instance,
29// the FreeBSD disklabel code in MBR is 0xa5; here, it's 0xa500, with
30// additional FreeBSD codes being 0xa501, 0xa502, and so on. This gives
31// related codes similar numbers and (given appropriate entry positions
32// in the linked list) keeps them together in the listings generated
33// by typing "L" at the main gdisk menu.
srs56946699b012010-02-04 00:55:30 -050034PartType::PartType(void) : GUIDData() {
srs5694e7b4ff92009-08-18 13:16:10 -040035 numInstances++;
36 if (numInstances == 1) {
srs56946699b012010-02-04 00:55:30 -050037 AddAllTypes();
srs5694e7b4ff92009-08-18 13:16:10 -040038 } // if
39} // default constructor
40
srs56946699b012010-02-04 00:55:30 -050041PartType::PartType(const PartType & orig) : GUIDData(orig) {
42 numInstances++;
43 if (numInstances == 1) { // should never happen; just being paranoid
44 AddAllTypes();
45 } // if
46} // PartType copy constructor
47
48PartType::PartType(const GUIDData & orig) : GUIDData(orig) {
49 numInstances++;
50 if (numInstances == 1) {
51 AddAllTypes();
52 } // if
53} // PartType copy constructor
54
55PartType::~PartType(void) {
srs5694e7b4ff92009-08-18 13:16:10 -040056 AType* tempType;
57
58 numInstances--;
59 if (numInstances == 0) {
60 while (allTypes != NULL) {
61 tempType = allTypes;
62 allTypes = allTypes->next;
63 delete tempType;
64 } // while
65 } // if
66} // destructor
67
srs56946699b012010-02-04 00:55:30 -050068// Add all partition type codes to the internal linked-list structure.
69// Used by constructors.
srs569455d92612010-03-07 22:16:07 -050070// See http://www.win.tue.nl/~aeb/partitions/partition_types-1.html
71// for a list of MBR partition type codes.
srs56946699b012010-02-04 00:55:30 -050072void PartType::AddAllTypes(void) {
73 // Start with the "unused entry," which should normally appear only
74 // on empty partition table entries....
75 AddType(0x0000, "00000000-0000-0000-0000-000000000000", "Unused entry", 0);
76
srs5694d8eed462012-12-15 01:55:21 -050077 // DOS/Windows partition types, most of which are hidden from the "L" listing
78 // (they're available mainly for MBR-to-GPT conversions).
srs569400b6d7a2011-06-26 22:40:06 -040079 AddType(0x0100, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-12
80 AddType(0x0400, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16 < 32M
81 AddType(0x0600, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16
82 AddType(0x0700, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 1); // NTFS (or HPFS)
83 AddType(0x0b00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-32
84 AddType(0x0c00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-32 LBA
srs56946699b012010-02-04 00:55:30 -050085 AddType(0x0c01, "E3C9E316-0B5C-4DB8-817D-F92DF00215AE", "Microsoft reserved");
srs569400b6d7a2011-06-26 22:40:06 -040086 AddType(0x0e00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // FAT-16 LBA
87 AddType(0x1100, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-12
88 AddType(0x1400, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-16 < 32M
89 AddType(0x1600, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-16
90 AddType(0x1700, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden NTFS (or HPFS)
91 AddType(0x1b00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-32
92 AddType(0x1c00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-32 LBA
93 AddType(0x1e00, "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7", "Microsoft basic data", 0); // Hidden FAT-16 LBA
srs56946699b012010-02-04 00:55:30 -050094 AddType(0x2700, "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC", "Windows RE");
Roderick W. Smith0fde58b2013-10-10 22:28:17 -040095
Roderick W. Smithb784e0c2014-01-25 22:55:26 -050096 // Open Network Install Environment (ONIE) specific types.
Roderick W. Smith5435fcf2014-02-17 12:01:51 -050097 // See http://www.onie.org/ and
98 // https://github.com/onie/onie/blob/master/rootconf/x86_64/sysroot-lib-onie/onie-blkdev-common
Roderick W. Smithb784e0c2014-01-25 22:55:26 -050099 AddType(0x3000, "7412F7D5-A156-4B13-81DC-867174929325", "ONIE boot");
100 AddType(0x3001, "D4E6E2CD-4469-46F3-B5CB-1BFF57AFC149", "ONIE config");
101
Aurimas Liutikas74b74902016-05-10 18:53:54 -0700102 // Plan 9; see http://man.cat-v.org/9front/8/prep
103 AddType(0x3900, "C91818F9-8025-47AF-89D2-F030D7000C2C", "Plan 9");
104
Roderick W. Smith0fde58b2013-10-10 22:28:17 -0400105 // PowerPC reference platform boot partition
106 AddType(0x4100, "9E1A2D38-C612-4316-AA26-8B49521E5A8B", "PowerPC PReP boot");
107
108 // Windows LDM ("dynamic disk") types
srs56946699b012010-02-04 00:55:30 -0500109 AddType(0x4200, "AF9B60A0-1431-4F62-BC68-3311714A69AD", "Windows LDM data"); // Logical disk manager
110 AddType(0x4201, "5808C8AA-7E8F-42E0-85D2-E1E90434CFB3", "Windows LDM metadata"); // Logical disk manager
Aurimas Liutikas74b74902016-05-10 18:53:54 -0700111 AddType(0x4202, "E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D", "Windows Storage Spaces"); // A newer LDM-type setup
srs56946699b012010-02-04 00:55:30 -0500112
113 // An oddball IBM filesystem....
114 AddType(0x7501, "37AFFC90-EF7D-4E96-91C3-2D7AE055B174", "IBM GPFS"); // General Parallel File System (GPFS)
115
srs5694df9d3632011-01-08 18:33:24 -0500116 // ChromeOS-specific partition types...
117 // Values taken from vboot_reference/firmware/lib/cgptlib/include/gpt.h in
118 // ChromeOS source code, retrieved 12/23/2010. They're also at
119 // http://www.chromium.org/chromium-os/chromiumos-design-docs/disk-format.
120 // These have no MBR equivalents, AFAIK, so I'm using 0x7Fxx values, since they're close
121 // to the Linux values.
122 AddType(0x7f00, "FE3A2A5D-4F32-41A7-B725-ACCC3285A309", "ChromeOS kernel");
123 AddType(0x7f01, "3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC", "ChromeOS root");
124 AddType(0x7f02, "2E0A753D-9E48-43B0-8337-B15192CB1B5E", "ChromeOS reserved");
125
srs56946699b012010-02-04 00:55:30 -0500126 // Linux-specific partition types....
srs5694d8eed462012-12-15 01:55:21 -0500127 AddType(0x8200, "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F", "Linux swap"); // Linux swap (or Solaris on MBR)
srs569400b6d7a2011-06-26 22:40:06 -0400128 AddType(0x8300, "0FC63DAF-8483-4772-8E79-3D69D8477DE4", "Linux filesystem"); // Linux native
srs56946699b012010-02-04 00:55:30 -0500129 AddType(0x8301, "8DA63339-0007-60C0-C436-083AC8230908", "Linux reserved");
Roderick W. Smith0fde58b2013-10-10 22:28:17 -0400130 // See http://www.freedesktop.org/software/systemd/man/systemd-gpt-auto-generator.html
Roderick W. Smith1a651322014-03-22 16:08:00 -0400131 // and http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/
Roderick W. Smith0fde58b2013-10-10 22:28:17 -0400132 AddType(0x8302, "933AC7E1-2EB4-4F13-B844-0E14E2AEF915", "Linux /home"); // Linux /home (auto-mounted by systemd)
Roderick W. Smith1a651322014-03-22 16:08:00 -0400133 AddType(0x8303, "44479540-F297-41B2-9AF7-D131D5F0458A", "Linux x86 root (/)"); // Linux / on x86 (auto-mounted by systemd)
134 AddType(0x8304, "4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709", "Linux x86-64 root (/)"); // Linux / on x86-64 (auto-mounted by systemd)
135 AddType(0x8305, "B921B045-1DF0-41C3-AF44-4C6F280D3FAE", "Linux ARM64 root (/)"); // Linux / on 64-bit ARM (auto-mounted by systemd)
136 AddType(0x8306, "3B8F8425-20E0-4F3B-907F-1A25A76F98E8", "Linux /srv"); // Linux /srv (auto-mounted by systemd)
Aurimas Liutikas74b74902016-05-10 18:53:54 -0700137 AddType(0x8307, "69DAD710-2CE4-4E3C-B16C-21A1D49ABED3", "Linux ARM32 root (/)"); // Linux / on 32-bit ARM (auto-mounted by systemd)
Roderick W. Smith1eea9b02013-07-06 22:52:58 -0400138
139 // Used by Intel Rapid Start technology
140 AddType(0x8400, "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593", "Intel Rapid Start");
141
142 // Another Linux type code....
srs56946699b012010-02-04 00:55:30 -0500143 AddType(0x8e00, "E6D6D379-F507-44C2-A23C-238F2A3DF928", "Linux LVM");
144
145 // FreeBSD partition types....
146 // Note: Rather than extract FreeBSD disklabel data, convert FreeBSD
147 // partitions in-place, and let FreeBSD sort out the details....
srs5694cb76c672010-02-11 22:22:22 -0500148 AddType(0xa500, "516E7CB4-6ECF-11D6-8FF8-00022D09712B", "FreeBSD disklabel");
srs56946699b012010-02-04 00:55:30 -0500149 AddType(0xa501, "83BD6B9D-7F41-11DC-BE0B-001560B84F0F", "FreeBSD boot");
150 AddType(0xa502, "516E7CB5-6ECF-11D6-8FF8-00022D09712B", "FreeBSD swap");
151 AddType(0xa503, "516E7CB6-6ECF-11D6-8FF8-00022D09712B", "FreeBSD UFS");
152 AddType(0xa504, "516E7CBA-6ECF-11D6-8FF8-00022D09712B", "FreeBSD ZFS");
153 AddType(0xa505, "516E7CB8-6ECF-11D6-8FF8-00022D09712B", "FreeBSD Vinum/RAID");
154
srs5694fa3868e2012-03-28 01:45:57 -0400155 // Midnight BSD partition types....
156 AddType(0xa580, "85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD data");
157 AddType(0xa581, "85D5E45E-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD boot");
158 AddType(0xa582, "85D5E45B-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD swap");
159 AddType(0xa583, "0394Ef8B-237E-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD UFS");
160 AddType(0xa584, "85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD ZFS");
161 AddType(0xa585, "85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7", "Midnight BSD Vinum");
162
Aurimas Liutikas74b74902016-05-10 18:53:54 -0700163 // OpenBSD partition type....
164 AddType(0xa600, "824CC7A0-36A8-11E3-890A-952519AD3F61", "OpenBSD disklabel");
165
srs56946699b012010-02-04 00:55:30 -0500166 // A MacOS partition type, separated from others by NetBSD partition types...
167 AddType(0xa800, "55465300-0000-11AA-AA11-00306543ECAC", "Apple UFS"); // Mac OS X
168
169 // NetBSD partition types. Note that the main entry sets it up as a
170 // FreeBSD disklabel. I'm not 100% certain this is the correct behavior.
171 AddType(0xa900, "516E7CB4-6ECF-11D6-8FF8-00022D09712B", "FreeBSD disklabel", 0); // NetBSD disklabel
172 AddType(0xa901, "49F48D32-B10E-11DC-B99B-0019D1879648", "NetBSD swap");
173 AddType(0xa902, "49F48D5A-B10E-11DC-B99B-0019D1879648", "NetBSD FFS");
174 AddType(0xa903, "49F48D82-B10E-11DC-B99B-0019D1879648", "NetBSD LFS");
175 AddType(0xa904, "2DB519C4-B10F-11DC-B99B-0019D1879648", "NetBSD concatenated");
176 AddType(0xa905, "2DB519EC-B10F-11DC-B99B-0019D1879648", "NetBSD encrypted");
177 AddType(0xa906, "49F48DAA-B10E-11DC-B99B-0019D1879648", "NetBSD RAID");
178
179 // Mac OS partition types (See also 0xa800, above)....
Aurimas Liutikas74b74902016-05-10 18:53:54 -0700180 AddType(0xab00, "426F6F74-0000-11AA-AA11-00306543ECAC", "Recovery HD");
srs56946699b012010-02-04 00:55:30 -0500181 AddType(0xaf00, "48465300-0000-11AA-AA11-00306543ECAC", "Apple HFS/HFS+");
182 AddType(0xaf01, "52414944-0000-11AA-AA11-00306543ECAC", "Apple RAID");
183 AddType(0xaf02, "52414944-5F4F-11AA-AA11-00306543ECAC", "Apple RAID offline");
184 AddType(0xaf03, "4C616265-6C00-11AA-AA11-00306543ECAC", "Apple label");
185 AddType(0xaf04, "5265636F-7665-11AA-AA11-00306543ECAC", "AppleTV recovery");
srs5694a17fe692011-09-10 20:30:20 -0400186 AddType(0xaf05, "53746F72-6167-11AA-AA11-00306543ECAC", "Apple Core Storage");
srs56946699b012010-02-04 00:55:30 -0500187
Aurimas Liutikas74b74902016-05-10 18:53:54 -0700188 // Acronis Secure Zone
189 AddType(0xbc00, "0311FC50-01CA-4725-AD77-9ADBB20ACE98", "Acronis Secure Zone");
190
srs56946699b012010-02-04 00:55:30 -0500191 // Solaris partition types (one of which is shared with MacOS)
192 AddType(0xbe00, "6A82CB45-1DD2-11B2-99A6-080020736631", "Solaris boot");
193 AddType(0xbf00, "6A85CF4D-1DD2-11B2-99A6-080020736631", "Solaris root");
194 AddType(0xbf01, "6A898CC3-1DD2-11B2-99A6-080020736631", "Solaris /usr & Mac ZFS"); // Solaris/MacOS
195 AddType(0xbf02, "6A87C46F-1DD2-11B2-99A6-080020736631", "Solaris swap");
196 AddType(0xbf03, "6A8B642B-1DD2-11B2-99A6-080020736631", "Solaris backup");
197 AddType(0xbf04, "6A8EF2E9-1DD2-11B2-99A6-080020736631", "Solaris /var");
198 AddType(0xbf05, "6A90BA39-1DD2-11B2-99A6-080020736631", "Solaris /home");
199 AddType(0xbf06, "6A9283A5-1DD2-11B2-99A6-080020736631", "Solaris alternate sector");
200 AddType(0xbf07, "6A945A3B-1DD2-11B2-99A6-080020736631", "Solaris Reserved 1");
201 AddType(0xbf08, "6A9630D1-1DD2-11B2-99A6-080020736631", "Solaris Reserved 2");
202 AddType(0xbf09, "6A980767-1DD2-11B2-99A6-080020736631", "Solaris Reserved 3");
203 AddType(0xbf0a, "6A96237F-1DD2-11B2-99A6-080020736631", "Solaris Reserved 4");
204 AddType(0xbf0b, "6A8D2AC7-1DD2-11B2-99A6-080020736631", "Solaris Reserved 5");
205
206 // I can find no MBR equivalents for these, but they're on the
207 // Wikipedia page for GPT, so here we go....
208 AddType(0xc001, "75894C1E-3AEB-11D3-B7C1-7B03A0000000", "HP-UX data");
209 AddType(0xc002, "E2A1E728-32E3-11D6-A682-7B03A0000000", "HP-UX service");
210
Roderick W. Smith1eea9b02013-07-06 22:52:58 -0400211 // See http://www.freedesktop.org/wiki/Specifications/BootLoaderSpec
212 AddType(0xea00, "BC13C2FF-59E6-4262-A352-B275FD6F7172", "Freedesktop $BOOT");
213
srs5694df231c12013-01-09 14:50:30 -0500214 // Type code for Haiku; uses BeOS MBR code as hex code base
215 AddType(0xeb00, "42465331-3BA3-10F1-802A-4861696B7521", "Haiku BFS");
216
Roderick W. Smithb784e0c2014-01-25 22:55:26 -0500217 // Manufacturer-specific ESP-like partitions (in order in which they were added)
srs5694d8eed462012-12-15 01:55:21 -0500218 AddType(0xed00, "F4019732-066E-4E12-8273-346C5641494F", "Sony system partition");
Roderick W. Smithb784e0c2014-01-25 22:55:26 -0500219 AddType(0xed01, "BFBFAFE7-A34F-448A-9A5B-6213EB736C22", "Lenovo system partition");
srs5694d8eed462012-12-15 01:55:21 -0500220
srs56946699b012010-02-04 00:55:30 -0500221 // EFI system and related partitions
srs569464cbd172011-03-01 22:03:54 -0500222 AddType(0xef00, "C12A7328-F81F-11D2-BA4B-00A0C93EC93B", "EFI System"); // Parted identifies these as having the "boot flag" set
srs56946699b012010-02-04 00:55:30 -0500223 AddType(0xef01, "024DEE41-33E7-11D3-9D69-0008C781F39F", "MBR partition scheme"); // Used to nest MBR in GPT
srs5694d8eed462012-12-15 01:55:21 -0500224 AddType(0xef02, "21686148-6449-6E6F-744E-656564454649", "BIOS boot partition"); // Used by GRUB
225
Roderick W. Smith1a651322014-03-22 16:08:00 -0400226 // Ceph type codes; see https://github.com/ceph/ceph/blob/9bcc42a3e6b08521694b5c0228b2c6ed7b3d312e/src/ceph-disk#L76-L81
227 AddType(0xf800, "4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D", "Ceph OSD"); // Ceph Object Storage Daemon
228 AddType(0xf801, "4FBD7E29-9D25-41B8-AFD0-5EC00CEFF05D", "Ceph dm-crypt OSD"); // Ceph Object Storage Daemon (encrypted)
Aurimas Liutikas74b74902016-05-10 18:53:54 -0700229 AddType(0xf802, "45B0969E-9B03-4F30-B4C6-B4B80CEFF106", "Ceph journal");
Roderick W. Smith1a651322014-03-22 16:08:00 -0400230 AddType(0xf803, "45B0969E-9B03-4F30-B4C6-5EC00CEFF106", "Ceph dm-crypt journal");
231 AddType(0xf804, "89C57F98-2FE5-4DC0-89C1-F3AD0CEFF2BE", "Ceph disk in creation");
232 AddType(0xf805, "89C57F98-2FE5-4DC0-89C1-5EC00CEFF2BE", "Ceph dm-crypt disk in creation");
233
srs5694d8eed462012-12-15 01:55:21 -0500234 // VMWare ESX partition types codes
235 AddType(0xfb00, "AA31E02A-400F-11DB-9590-000C2911D1B8", "VMWare VMFS");
236 AddType(0xfb01, "9198EFFC-31C0-11DB-8F78-000C2911D1B8", "VMWare reserved");
237 AddType(0xfc00, "9D275380-40AD-11DB-BF97-000C2911D1B8", "VMWare kcore crash protection");
srs56946699b012010-02-04 00:55:30 -0500238
239 // A straggler Linux partition type....
240 AddType(0xfd00, "A19D880F-05FC-4D3B-A006-743F0F84911E", "Linux RAID");
241
242 // Note: DO NOT use the 0xffff code; that's reserved to indicate an
srs569455d92612010-03-07 22:16:07 -0500243 // unknown GUID type code.
srs56946699b012010-02-04 00:55:30 -0500244} // PartType::AddAllTypes()
245
srs5694e7b4ff92009-08-18 13:16:10 -0400246// Add a single type to the linked list of types. Returns 1 if operation
srs5694e321d442010-01-29 17:44:04 -0500247// succeeds, 0 otherwise.
srs56946699b012010-02-04 00:55:30 -0500248int PartType::AddType(uint16_t mbrType, const char * guidData, const char * name,
249 int toDisplay) {
srs5694e7b4ff92009-08-18 13:16:10 -0400250 AType* tempType;
251 int allOK = 1;
252
253 tempType = new AType;
254 if (tempType != NULL) {
255 tempType->MBRType = mbrType;
srs56946699b012010-02-04 00:55:30 -0500256 tempType->GUIDType = guidData;
257 tempType->name = name;
srs5694e7b4ff92009-08-18 13:16:10 -0400258 tempType->display = toDisplay;
259 tempType->next = NULL;
260 if (allTypes == NULL) { // first entry
261 allTypes = tempType;
262 } else {
263 lastType->next = tempType;
264 } // if/else
265 lastType = tempType;
266 } else {
srs56946aae2a92011-06-10 01:16:51 -0400267 cerr << "Unable to allocate memory in PartType::AddType()! Partition type list will\n";
268 cerr << "be incomplete!\n";
srs5694e7b4ff92009-08-18 13:16:10 -0400269 allOK = 0;
270 } // if/else
271 return allOK;
srs56946699b012010-02-04 00:55:30 -0500272} // GUID::AddType(const char* variant)
273
srs569482f3f0b2010-09-22 10:50:24 -0400274// Assignment operator by string. If the original string is short,
275// interpret it as a gdisk hex code; if it's longer, interpret it as
srs56940873e9d2010-10-07 13:00:45 -0400276// a direct entry of a GUID value. If a short string isn't a hex
277// number, do nothing.
srs569482f3f0b2010-09-22 10:50:24 -0400278PartType & PartType::operator=(const string & orig) {
279 uint32_t hexCode;
280
281 if (orig.length() < 32) {
srs56940873e9d2010-10-07 13:00:45 -0400282 if (IsHex(orig)) {
283 sscanf(orig.c_str(), "%x", &hexCode);
284 *this = hexCode;
srs5694a17fe692011-09-10 20:30:20 -0400285 }
srs569482f3f0b2010-09-22 10:50:24 -0400286 } else {
287 GUIDData::operator=(orig);
288 } // if/else hexCode or GUID
289 return *this;
290} // PartType::operator=(const char * orig)
291
292// Assignment from C-style string; rely on C++ casting....
293PartType & PartType::operator=(const char * orig) {
294 return operator=((string) orig);
295} // PartType::operator=(const char * orig)
296
srs56946699b012010-02-04 00:55:30 -0500297// Assign a GUID based on my custom 2-byte (16-bit) MBR hex ID variant
srs5694cb76c672010-02-11 22:22:22 -0500298PartType & PartType::operator=(uint16_t ID) {
srs56946699b012010-02-04 00:55:30 -0500299 AType* theItem = allTypes;
300 int found = 0;
301
srs56946699b012010-02-04 00:55:30 -0500302 // Now search the type list for a match to the ID....
303 while ((theItem != NULL) && (!found)) {
srs569455d92612010-03-07 22:16:07 -0500304 if (theItem->MBRType == ID) {
srs56946699b012010-02-04 00:55:30 -0500305 GUIDData::operator=(theItem->GUIDType);
306 found = 1;
307 } else {
308 theItem = theItem->next;
309 } // if/else
310 } // while
311 if (!found) {
srs569455d92612010-03-07 22:16:07 -0500312 // Assign a default value....
srs56940741fa22013-01-09 12:55:40 -0500313 operator=(DEFAULT_GPT_TYPE);
srs56946699b012010-02-04 00:55:30 -0500314 cout.setf(ios::uppercase);
315 cout.fill('0');
316 cout << "Exact type match not found for type code ";
317 cout.width(4);
srs569400b6d7a2011-06-26 22:40:06 -0400318 cout << hex << ID << "; assigning type code for\n'" << TypeName() << "'\n" << dec;
srs56946699b012010-02-04 00:55:30 -0500319 cout.fill(' ');
320 } // if (!found)
321 return *this;
322} // PartType::operator=(uint16_t ID)
323
srs569400b6d7a2011-06-26 22:40:06 -0400324// Return the English description of the partition type (e.g., "Linux filesystem")
srs56945a081752010-09-24 20:39:41 -0400325string PartType::TypeName(void) const {
srs56946699b012010-02-04 00:55:30 -0500326 AType* theItem = allTypes;
327 int found = 0;
328 string typeName;
329
330 while ((theItem != NULL) && (!found)) {
331 if (theItem->GUIDType == *this) { // found it!
332 typeName = theItem->name;
333 found = 1;
334 } else {
335 theItem = theItem->next;
336 } // if/else
337 } // while
338 if (!found) {
339 typeName = "Unknown";
340 } // if (!found)
341 return typeName;
342} // PartType::TypeName()
343
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500344#ifdef USE_UTF16
srs569400b6d7a2011-06-26 22:40:06 -0400345// Return the Unicode description of the partition type (e.g., "Linux filesystem")
srs56945a608532011-03-17 13:53:01 -0400346UnicodeString PartType::UTypeName(void) const {
347 AType* theItem = allTypes;
348 int found = 0;
349 UnicodeString typeName;
350
351 while ((theItem != NULL) && (!found)) {
352 if (theItem->GUIDType == *this) { // found it!
353 typeName = theItem->name.c_str();
354 found = 1;
355 } else {
356 theItem = theItem->next;
357 } // if/else
358 } // while
359 if (!found) {
360 typeName = "Unknown";
361 } // if (!found)
362 return typeName;
363} // PartType::TypeName()
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500364#endif
srs56945a608532011-03-17 13:53:01 -0400365
srs56946699b012010-02-04 00:55:30 -0500366// Return the custom GPT fdisk 2-byte (16-bit) hex code for this GUID partition type
367// Note that this function ignores entries for which the display variable
368// is set to 0. This enables control of which values get returned when
369// there are multiple possibilities, but opens the algorithm up to the
370// potential for problems should the data in the list be bad.
srs56945a081752010-09-24 20:39:41 -0400371uint16_t PartType::GetHexType() const {
srs56946699b012010-02-04 00:55:30 -0500372 AType* theItem = allTypes;
373 int found = 0;
374 uint16_t theID = 0xFFFF;
375
376 while ((theItem != NULL) && (!found)) {
377 if ((theItem->GUIDType == *this) && (theItem->display == 1)) { // found it!
378 theID = theItem->MBRType;
379 found = 1;
380 } else {
381 theItem = theItem->next;
382 } // if/else
383 } // while
384 if (!found) {
385 theID = 0xFFFF;
386 } // if (!found)
387 return theID;
388} // PartType::GetHex()
srs5694e7b4ff92009-08-18 13:16:10 -0400389
390// Displays the available types and my extended MBR codes for same....
391// Note: This function assumes an 80-column display. On wider displays,
392// it stops at under 80 columns; on narrower displays, lines will wrap
Roderick W. Smithe3ee7332013-09-24 12:56:11 -0400393// in an ugly way. The maxLines value is the maximum number of lines
394// to display before prompting to continue, or 0 (or a negative value)
395// for no limit.
396void PartType::ShowAllTypes(int maxLines) const {
397 int colCount = 1, lineCount = 1;
srs5694e321d442010-01-29 17:44:04 -0500398 size_t i;
srs5694e7b4ff92009-08-18 13:16:10 -0400399 AType* thisType = allTypes;
Roderick W. Smithe3ee7332013-09-24 12:56:11 -0400400 string line;
srs5694e7b4ff92009-08-18 13:16:10 -0400401
srs5694fed16d02010-01-27 23:03:40 -0500402 cout.unsetf(ios::uppercase);
srs5694e7b4ff92009-08-18 13:16:10 -0400403 while (thisType != NULL) {
404 if (thisType->display == 1) { // show it
srs5694fed16d02010-01-27 23:03:40 -0500405 cout.fill('0');
406 cout.width(4);
407 cout << hex << thisType->MBRType << " ";
srs5694e321d442010-01-29 17:44:04 -0500408 cout << thisType->name.substr(0, 20);
srs569455d92612010-03-07 22:16:07 -0500409 for (i = 0; i < (20 - (thisType->name.substr(0, 20).length())); i++)
410 cout << " ";
Roderick W. Smithe3ee7332013-09-24 12:56:11 -0400411 if ((colCount % 3) == 0) {
412 if (thisType->next) {
413 cout << "\n";
414 if ((maxLines > 0) && (lineCount++ % maxLines) == 0) {
415 cout << "Press the <Enter> key to see more codes: ";
416 getline(cin, line);
417 } // if reached screen line limit
418 } // if there's another entry following this one
419 } else {
srs5694e321d442010-01-29 17:44:04 -0500420 cout << " ";
Roderick W. Smithe3ee7332013-09-24 12:56:11 -0400421 }
srs5694e7b4ff92009-08-18 13:16:10 -0400422 colCount++;
423 } // if
424 thisType = thisType->next;
425 } // while
srs56940a697312010-01-28 21:10:52 -0500426 cout.fill(' ');
427 cout << "\n" << dec;
Roderick W. Smithe3ee7332013-09-24 12:56:11 -0400428} // PartType::ShowAllTypes(int maxLines)
srs5694e7b4ff92009-08-18 13:16:10 -0400429
430// Returns 1 if code is a valid extended MBR code, 0 if it's not
srs56945a081752010-09-24 20:39:41 -0400431int PartType::Valid(uint16_t code) const {
srs5694e7b4ff92009-08-18 13:16:10 -0400432 AType* thisType = allTypes;
433 int found = 0;
434
435 while ((thisType != NULL) && (!found)) {
436 if (thisType->MBRType == code) {
437 found = 1;
438 } // if
439 thisType = thisType->next;
440 } // while
441 return found;
srs56946699b012010-02-04 00:55:30 -0500442} // PartType::Valid()