blob: 1583bcab6b2a7183c2fe7a0d919765c0183227ca [file] [log] [blame]
srs5694a0eb11a2009-08-29 15:00:08 -04001//
2// C++ Implementation: gptpart
3//
4// Description: Class to implement a SINGLE GPT partition
5//
6//
Rod Smith44cda472018-07-05 09:07:58 -04007// Author: Rod Smith <rodsmith@rodsbooks.com>, (C) 2009-2018
srs5694a0eb11a2009-08-29 15:00:08 -04008//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
srs5694978041c2009-09-21 20:51:47 -040012// This program is copyright (c) 2009 by Roderick W. Smith. It is distributed
13// under the terms of the GNU GPL version 2, as detailed in the COPYING file.
srs5694a0eb11a2009-08-29 15:00:08 -040014
15#define __STDC_LIMIT_MACROS
Aurimas Liutikasfcad0602016-05-10 19:16:10 -070016#ifndef __STDC_CONSTANT_MACROS
srs5694a0eb11a2009-08-29 15:00:08 -040017#define __STDC_CONSTANT_MACROS
Aurimas Liutikasfcad0602016-05-10 19:16:10 -070018#endif
srs5694a0eb11a2009-08-29 15:00:08 -040019
srs569400b6d7a2011-06-26 22:40:06 -040020#ifdef USE_UTF16
srs5694699941e2011-03-21 21:33:57 -040021#include <unicode/ustdio.h>
22#else
23#define UnicodeString string
24#endif
25
srs5694a0eb11a2009-08-29 15:00:08 -040026#include <string.h>
srs5694fed16d02010-01-27 23:03:40 -050027#include <stdio.h>
28#include <iostream>
srs5694a0eb11a2009-08-29 15:00:08 -040029#include "gptpart.h"
30#include "attributes.h"
31
32using namespace std;
33
srs5694a0eb11a2009-08-29 15:00:08 -040034GPTPart::GPTPart(void) {
srs569455d92612010-03-07 22:16:07 -050035 partitionType.Zero();
36 uniqueGUID.Zero();
37 firstLBA = 0;
38 lastLBA = 0;
39 attributes = 0;
Roderick W. Smith84aaff62014-02-17 16:17:11 -050040 memset(name, 0, NAME_SIZE * sizeof(name[0]) );
srs5694a0eb11a2009-08-29 15:00:08 -040041} // Default constructor
42
Rod Smith9ae60192018-07-05 16:50:13 -040043GPTPart::GPTPart(const GPTPart & orig) {
44 partitionType = orig.partitionType;
45 uniqueGUID = orig.uniqueGUID;
46 firstLBA = orig.firstLBA;
47 lastLBA = orig.lastLBA;
48 attributes = orig.attributes;
49 memcpy(name, orig.name, NAME_SIZE * sizeof( name[ 0 ] ) );
50} // Copy constructor
51
srs5694a0eb11a2009-08-29 15:00:08 -040052GPTPart::~GPTPart(void) {
53} // destructor
54
srs5694a0eb11a2009-08-29 15:00:08 -040055// Return the gdisk-specific two-byte hex code for the partition
srs5694bf8950c2011-03-12 01:23:12 -050056uint16_t GPTPart::GetHexType(void) const {
srs56946699b012010-02-04 00:55:30 -050057 return partitionType.GetHexType();
srs5694a0eb11a2009-08-29 15:00:08 -040058} // GPTPart::GetHexType()
59
60// Return a plain-text description of the partition type (e.g., "Linux/Windows
61// data" or "Linux swap").
srs56946699b012010-02-04 00:55:30 -050062string GPTPart::GetTypeName(void) {
63 return partitionType.TypeName();
srs5694a0eb11a2009-08-29 15:00:08 -040064} // GPTPart::GetNameType()
65
Roderick W. Smith84aaff62014-02-17 16:17:11 -050066#ifdef USE_UTF16
srs56945a608532011-03-17 13:53:01 -040067// Return a Unicode description of the partition type (e.g., "Linux/Windows
68// data" or "Linux swap").
69UnicodeString GPTPart::GetUTypeName(void) {
70 return partitionType.UTypeName();
srs56945a608532011-03-17 13:53:01 -040071} // GPTPart::GetNameType()
Roderick W. Smith84aaff62014-02-17 16:17:11 -050072#endif
srs56945a608532011-03-17 13:53:01 -040073
srs5694a0eb11a2009-08-29 15:00:08 -040074// Compute and return the partition's length (or 0 if the end is incorrectly
75// set before the beginning).
srs5694bf8950c2011-03-12 01:23:12 -050076uint64_t GPTPart::GetLengthLBA(void) const {
srs5694a0eb11a2009-08-29 15:00:08 -040077 uint64_t length = 0;
srs569455d92612010-03-07 22:16:07 -050078
srs5694a0eb11a2009-08-29 15:00:08 -040079 if (firstLBA <= lastLBA)
80 length = lastLBA - firstLBA + UINT64_C(1);
81 return length;
82} // GPTPart::GetLengthLBA()
83
srs569400b6d7a2011-06-26 22:40:06 -040084#ifdef USE_UTF16
srs5694699941e2011-03-21 21:33:57 -040085// Return partition's name field, converted to a Unicode string
86UnicodeString GPTPart::GetDescription(void) {
87 return (UChar*) name;
88} // GPTPart::GetDescription()
89#else
Roderick W. Smith84aaff62014-02-17 16:17:11 -050090// Return partition's name field, converted to a C++ UTF-8 string
srs56946699b012010-02-04 00:55:30 -050091string GPTPart::GetDescription(void) {
Roderick W. Smith84aaff62014-02-17 16:17:11 -050092 // convert name to utf32 then to utf8
93 string utf8 ;
94 size_t pos = 0 ;
95 while ( ( pos < NAME_SIZE ) && ( name[ pos ] != 0 ) ) {
96 uint16_t cp = name[ pos ++ ] ;
97 if ( ! IsLittleEndian() ) ReverseBytes( & cp , 2 ) ;
98 // first to utf32
99 uint32_t uni ;
100 if ( cp < 0xd800 || cp > 0xdfff ) {
101 uni = cp ;
102 } // if
103 else if ( cp < 0xdc00 ) {
104 // lead surrogate
105 uni = ( (uint32_t)( cp & 0x3ff ) ) << 10 ;
106 if ( pos >= NAME_SIZE ) {
107 // missing trail surrogate, name[] is invalid
108 break ;
109 } // if
110 cp = name[ pos ++ ] ;
111 if ( cp < 0xdc00 || cp > 0xdfff ) {
112 // invalid trail surrogate, name[] is invalid
113 break ;
114 } // if
115 // trail surrogate
116 uni |= cp & 0x3ff ;
117 uni += 0x10000 ;
118 } // if
119 else {
120 // unexpected trail surrogate, name[] is invalid
121 break ;
122 } // if
123 // then to utf8
124 if ( uni < 0x80 ) {
125 utf8 += (char) uni ;
126 } // if
127 else if ( uni < 0x800 ) {
128 utf8 += (char) ( 0xc0 | ( uni >> 6 ) ) ;
129 utf8 += (char) ( 0x80 | ( uni & 0x3f ) ) ;
130 } // if
131 else if ( uni < 0x10000 ) {
132 utf8 += (char) ( 0xe0 | ( uni >> 12 ) ) ;
133 utf8 += (char) ( 0x80 | ( ( uni >> 6 ) & 0x3f ) ) ;
134 utf8 += (char) ( 0x80 | ( uni & 0x3f ) ) ;
135 } // if
136 else {
137 utf8 += (char) ( 0xf0 | ( uni >> 18 ) ) ;
138 utf8 += (char) ( 0xe0 | ( ( uni >> 12 ) & 0x3f ) ) ;
139 utf8 += (char) ( 0x80 | ( ( uni >> 6 ) & 0x3f ) ) ;
140 utf8 += (char) ( 0x80 | ( uni & 0x3f ) ) ;
141 } // if
142 }
143 return utf8 ;
144} // GPTPart::GetDescription(), UTF-8 version
srs5694699941e2011-03-21 21:33:57 -0400145#endif
srs56940a697312010-01-28 21:10:52 -0500146
srs569408bb0da2010-02-19 17:19:55 -0500147// Return 1 if the partition is in use
148int GPTPart::IsUsed(void) {
srs5694e69e6802012-01-20 22:37:12 -0500149 return (partitionType != GUIDData("0x00"));
srs569408bb0da2010-02-19 17:19:55 -0500150} // GPTPart::IsUsed()
151
Roderick W. Smitha345a922014-02-22 12:12:32 -0500152// Returns MBR_SIZED_GOOD, MBR_SIZED_IFFY, or MBR_SIZED_BAD; see comments
153// in header file for details.
Roderick W. Smith9b338c52014-02-20 11:13:36 -0500154int GPTPart::IsSizedForMBR(void) {
Roderick W. Smitha345a922014-02-22 12:12:32 -0500155 int retval = MBR_SIZED_GOOD;
156
157 if ((firstLBA > UINT32_MAX) || ((lastLBA - firstLBA) > UINT32_MAX) || (firstLBA > lastLBA))
158 retval = MBR_SIZED_BAD;
159 else if (lastLBA > UINT32_MAX)
160 retval = MBR_SIZED_IFFY;
161
162 return (retval);
Roderick W. Smith9b338c52014-02-20 11:13:36 -0500163} // GPTPart::IsSizedForMBR()
164
srs56940a697312010-01-28 21:10:52 -0500165// Set the type code to the specified one. Also changes the partition
166// name *IF* the current name is the generic one for the current partition
167// type.
srs56946699b012010-02-04 00:55:30 -0500168void GPTPart::SetType(PartType t) {
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500169#ifdef USE_UTF16
srs56945a608532011-03-17 13:53:01 -0400170 if (GetDescription() == partitionType.UTypeName()) {
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500171#else
172 if (GetDescription() == partitionType.TypeName()) {
173#endif
srs56946699b012010-02-04 00:55:30 -0500174 SetName(t.TypeName());
srs56940a697312010-01-28 21:10:52 -0500175 } // if
176 partitionType = t;
177} // GPTPart::SetType()
srs5694a0eb11a2009-08-29 15:00:08 -0400178
srs569400b6d7a2011-06-26 22:40:06 -0400179#ifdef USE_UTF16
srs5694699941e2011-03-21 21:33:57 -0400180// Set the name for a partition to theName, using a C++-style string as
181// input.
182void GPTPart::SetName(const string & theName) {
183 SetName((UnicodeString) theName.c_str());
srs56945a608532011-03-17 13:53:01 -0400184} // GPTPart::SetName()
185
srs5694699941e2011-03-21 21:33:57 -0400186// Set the name for a partition to theName, using a Unicode string as
187// input.
188void GPTPart::SetName(const UnicodeString & theName) {
189 if (theName.isBogus()) {
190 cerr << "Bogus UTF-16 name found in GPTPart::SetName()! Name not changed!\n";
191 } else {
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500192 memset(name, 0, NAME_SIZE * sizeof(name[0]) );
193 theName.extractBetween(0, NAME_SIZE, (UChar*) name);
srs5694699941e2011-03-21 21:33:57 -0400194 } // if/else
srs5694a0eb11a2009-08-29 15:00:08 -0400195} // GPTPart::SetName()
srs569400b6d7a2011-06-26 22:40:06 -0400196
srs5694699941e2011-03-21 21:33:57 -0400197#else
srs569400b6d7a2011-06-26 22:40:06 -0400198
srs5694699941e2011-03-21 21:33:57 -0400199// Set the name for a partition to theName. Note that theName is a
200// standard C++-style ASCII string, although the GUID partition definition
201// requires a UTF-16LE string. This function creates a simple-minded copy
202// for this.
203void GPTPart::SetName(const string & theName) {
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500204 // convert utf8 to utf32 then to utf16le
205 size_t len = theName.length() ;
206 size_t pos = 0 ;
207 for ( size_t i = 0 ; pos < NAME_SIZE && i < len ; ) {
208 uint32_t uni ;
209 uint8_t cp = theName[ i ++ ] ;
210 int todo ;
211 if ( cp < 0x80 ) {
212 uni = cp ;
213 todo = 0 ;
214 } // if
215 else if ( cp < 0xc0 || cp > 0xf7 ) {
216 // invalid byte, theName is broken
217 break ;
218 } // if
219 else if ( cp < 0xe0 ) {
220 uni = cp & 0x1f ;
221 todo = 1 ;
222 } // if
223 else if ( cp < 0xf0 ) {
224 uni = cp & 0x0f ;
225 todo = 2 ;
226 } // if
227 else {
228 uni = cp & 0x7 ;
229 todo = 3 ;
230 } // if
231 while ( todo > 0 ) {
232 if ( i >= len ) {
233 // missing continuation byte, theName is broken
234 goto break_converter ;
235 } // if
236 cp = theName[ i ++ ] ;
237 if ( cp > 0xbf || cp < 0x80 ) {
238 // invalid continuation byte, theName is broken
239 goto break_converter ;
240 } // if
241 uni <<= 6 ;
242 uni |= cp & 0x3f ;
243 todo -- ;
244 } // while
245 // then to utf16le
246 if ( uni < 0x10000 ) {
247 name[ pos ] = (uint16_t) uni ;
248 if ( ! IsLittleEndian() ) ReverseBytes( name + pos , 2 ) ;
249 pos ++ ;
250 } // if
251 else {
252 if ( pos > NAME_SIZE - 2 ) {
253 // not enough room for two surrogates, truncate
254 break ;
255 } // if
256 uni -= 0x10000 ;
257 name[ pos ] = (uint16_t)( uni >> 10 ) | 0xd800 ;
258 if ( ! IsLittleEndian() ) ReverseBytes( name + pos , 2 ) ;
259 pos ++ ;
260 name[ pos ] = (uint16_t)( uni & 0x3ff ) | 0xdc00 ;
261 if ( ! IsLittleEndian() ) ReverseBytes( name + pos , 2 ) ;
262 pos ++ ;
263 }
264 } // for
265 break_converter : ;
266 // finally fill with zeroes
267 while ( pos < NAME_SIZE ) {
268 name[ pos ++ ] = 0 ;
269 } // while
270} // GPTPart::SetName(), UTF-8 version
srs5694699941e2011-03-21 21:33:57 -0400271#endif
srs5694a0eb11a2009-08-29 15:00:08 -0400272
srs56946699b012010-02-04 00:55:30 -0500273// Set the name for the partition based on the current GUID partition type
274// code's associated name
275void GPTPart::SetDefaultDescription(void) {
276 SetName(partitionType.TypeName());
277} // GPTPart::SetDefaultDescription()
278
srs56940a697312010-01-28 21:10:52 -0500279GPTPart & GPTPart::operator=(const GPTPart & orig) {
srs56940a697312010-01-28 21:10:52 -0500280 partitionType = orig.partitionType;
281 uniqueGUID = orig.uniqueGUID;
282 firstLBA = orig.firstLBA;
283 lastLBA = orig.lastLBA;
284 attributes = orig.attributes;
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500285 memcpy(name, orig.name, NAME_SIZE * sizeof( name[ 0 ] ) );
srs56940a697312010-01-28 21:10:52 -0500286 return *this;
287} // assignment operator
288
srs56949a46b042011-03-15 00:34:10 -0400289// Compare the values, and return a bool result.
290// Because this is intended for sorting and a firstLBA value of 0 denotes
291// a partition that's not in use and so that should be sorted upwards,
292// we return the opposite of the usual arithmetic result when either
293// firstLBA value is 0.
294bool GPTPart::operator<(const GPTPart &other) const {
srs56949a46b042011-03-15 00:34:10 -0400295 if (firstLBA && other.firstLBA)
296 return (firstLBA < other.firstLBA);
297 else
298 return (other.firstLBA < firstLBA);
299} // GPTPart::operator<()
300
srs56940a697312010-01-28 21:10:52 -0500301// Display summary information; does nothing if the partition is empty.
302void GPTPart::ShowSummary(int partNum, uint32_t blockSize) {
srs569401f7f082011-03-15 23:53:31 -0400303 string sizeInIeee;
srs56945a608532011-03-17 13:53:01 -0400304 UnicodeString description;
srs569464cbd172011-03-01 22:03:54 -0500305 size_t i;
srs56940a697312010-01-28 21:10:52 -0500306
307 if (firstLBA != 0) {
srs569401f7f082011-03-15 23:53:31 -0400308 sizeInIeee = BytesToIeee(lastLBA - firstLBA + 1, blockSize);
srs569408bb0da2010-02-19 17:19:55 -0500309 cout.fill(' ');
srs56940a697312010-01-28 21:10:52 -0500310 cout.width(4);
311 cout << partNum + 1 << " ";
312 cout.width(14);
313 cout << firstLBA << " ";
314 cout.width(14);
315 cout << lastLBA << " ";
Roderick W. Smithf6948032014-03-29 00:27:33 -0400316 cout << sizeInIeee << " ";
srs569401f7f082011-03-15 23:53:31 -0400317 if (sizeInIeee.length() < 10)
318 for (i = 0; i < 10 - sizeInIeee.length(); i++)
319 cout << " ";
srs56940a697312010-01-28 21:10:52 -0500320 cout.fill('0');
321 cout.width(4);
322 cout.setf(ios::uppercase);
srs56946699b012010-02-04 00:55:30 -0500323 cout << hex << partitionType.GetHexType() << " " << dec;
srs56940a697312010-01-28 21:10:52 -0500324 cout.fill(' ');
srs569400b6d7a2011-06-26 22:40:06 -0400325#ifdef USE_UTF16
srs5694699941e2011-03-21 21:33:57 -0400326 GetDescription().extractBetween(0, 23, description);
srs56945a608532011-03-17 13:53:01 -0400327 cout << description << "\n";
srs5694699941e2011-03-21 21:33:57 -0400328#else
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500329 string desc = GetDescription() ;
330 size_t n = 0 ;
331 size_t i = 0 ;
332 size_t len = desc.length() ;
333 while ( n < 22 && i < len ) {
334 i ++ ;
335 if ( i >= len ) {
336 // short description
337 break ;
338 } // if
339 // skip continuation bytes
340 while ( i < len && ( ( desc[ i ] & 0xC0 ) == 0x80 ) ) {
341 // utf8 continuation byte
342 i ++ ;
343 } // while
344 n ++ ;
345 } // while
346 if ( i < len ) {
347 n = 0 ;
348 i = 0 ;
349 // description is long we will truncate it
350 while ( n < 19 && i < len ) {
351 i ++ ;
352 if ( i >= len ) {
353 // should not happen
354 break ;
355 } // if
356 // skip continuation bytes
357 while ( i < len && ( ( desc[ i ] & 0xC0 ) == 0x80 ) ) {
358 // utf8 continuation byte
359 i ++ ;
360 } // while
361 n ++ ;
362 } // while
363 } // for
364 cout << GetDescription().substr( 0 , i ) ;
365 if ( i < len ) cout << "..." ;
366 cout << "\n";
srs5694699941e2011-03-21 21:33:57 -0400367#endif
srs56940a697312010-01-28 21:10:52 -0500368 cout.fill(' ');
369 } // if
370} // GPTPart::ShowSummary()
371
372// Show detailed partition information. Does nothing if the partition is
373// empty (as determined by firstLBA being 0).
Jeff Sharkeyd761ff52015-02-28 19:18:39 -0800374void GPTPart::ShowDetails(uint32_t blockSize) {
srs56940a697312010-01-28 21:10:52 -0500375 uint64_t size;
376
377 if (firstLBA != 0) {
srs56945a081752010-09-24 20:39:41 -0400378 cout << "Partition GUID code: " << partitionType;
srs56946699b012010-02-04 00:55:30 -0500379 cout << " (" << partitionType.TypeName() << ")\n";
srs56945a081752010-09-24 20:39:41 -0400380 cout << "Partition unique GUID: " << uniqueGUID << "\n";
srs56940a697312010-01-28 21:10:52 -0500381
382 cout << "First sector: " << firstLBA << " (at "
Roderick W. Smithaf39cb42013-08-06 15:23:46 -0400383 << BytesToIeee(firstLBA, blockSize) << ")\n";
srs56940a697312010-01-28 21:10:52 -0500384 cout << "Last sector: " << lastLBA << " (at "
Roderick W. Smithaf39cb42013-08-06 15:23:46 -0400385 << BytesToIeee(lastLBA, blockSize) << ")\n";
srs56940a697312010-01-28 21:10:52 -0500386 size = (lastLBA - firstLBA + 1);
387 cout << "Partition size: " << size << " sectors ("
Roderick W. Smithaf39cb42013-08-06 15:23:46 -0400388 << BytesToIeee(size, blockSize) << ")\n";
srs56940a697312010-01-28 21:10:52 -0500389 cout << "Attribute flags: ";
390 cout.fill('0');
391 cout.width(16);
392 cout << hex;
393 cout << attributes << "\n";
394 cout << dec;
srs5694699941e2011-03-21 21:33:57 -0400395 cout << "Partition name: '" << GetDescription() << "'\n";
srs56940a697312010-01-28 21:10:52 -0500396 cout.fill(' ');
397 } // if
398} // GPTPart::ShowDetails()
399
400// Blank (delete) a single partition
401void GPTPart::BlankPartition(void) {
srs56946699b012010-02-04 00:55:30 -0500402 uniqueGUID.Zero();
403 partitionType.Zero();
srs56940a697312010-01-28 21:10:52 -0500404 firstLBA = 0;
405 lastLBA = 0;
406 attributes = 0;
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500407 memset(name, 0, NAME_SIZE * sizeof( name[0]) );
srs56940a697312010-01-28 21:10:52 -0500408} // GPTPart::BlankPartition
409
410// Returns 1 if the two partitions overlap, 0 if they don't
411int GPTPart::DoTheyOverlap(const GPTPart & other) {
srs56940a697312010-01-28 21:10:52 -0500412 // Don't bother checking unless these are defined (both start and end points
413 // are 0 for undefined partitions, so just check the start points)
srs569464cbd172011-03-01 22:03:54 -0500414 return firstLBA && other.firstLBA &&
415 (firstLBA <= other.lastLBA) != (lastLBA < other.firstLBA);
srs56940a697312010-01-28 21:10:52 -0500416} // GPTPart::DoTheyOverlap()
417
srs56945a608532011-03-17 13:53:01 -0400418// Reverse the bytes of integral data types and of the UTF-16LE name;
419// used on big-endian systems.
srs56940a697312010-01-28 21:10:52 -0500420void GPTPart::ReversePartBytes(void) {
srs56945a608532011-03-17 13:53:01 -0400421 int i;
422
srs56940a697312010-01-28 21:10:52 -0500423 ReverseBytes(&firstLBA, 8);
424 ReverseBytes(&lastLBA, 8);
425 ReverseBytes(&attributes, 8);
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500426 for (i = 0; i < NAME_SIZE; i ++ )
srs56945a608532011-03-17 13:53:01 -0400427 ReverseBytes(name + i, 2);
srs56940a697312010-01-28 21:10:52 -0500428} // GPTPart::ReverseBytes()
429
430/****************************************
431 * Functions requiring user interaction *
432 ****************************************/
433
srs56946699b012010-02-04 00:55:30 -0500434// Change the type code on the partition. Also changes the name if the original
435// name is the generic one for the partition type.
srs56940a697312010-01-28 21:10:52 -0500436void GPTPart::ChangeType(void) {
srs56945a608532011-03-17 13:53:01 -0400437 string line;
srs569464cbd172011-03-01 22:03:54 -0500438 int changeName;
srs569482f3f0b2010-09-22 10:50:24 -0400439 PartType tempType = (GUIDData) "00000000-0000-0000-0000-000000000000";
srs56940a697312010-01-28 21:10:52 -0500440
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500441#ifdef USE_UTF16
srs56945a608532011-03-17 13:53:01 -0400442 changeName = (GetDescription() == GetUTypeName());
Roderick W. Smith84aaff62014-02-17 16:17:11 -0500443#else
444 changeName = (GetDescription() == GetTypeName());
445#endif
srs569455d92612010-03-07 22:16:07 -0500446
srs56946699b012010-02-04 00:55:30 -0500447 cout << "Current type is '" << GetTypeName() << "'\n";
srs569482f3f0b2010-09-22 10:50:24 -0400448 do {
srs56940741fa22013-01-09 12:55:40 -0500449 cout << "Hex code or GUID (L to show codes, Enter = " << hex << DEFAULT_GPT_TYPE << dec << "): ";
srs56945a608532011-03-17 13:53:01 -0400450 line = ReadString();
srs569482f3f0b2010-09-22 10:50:24 -0400451 if ((line[0] == 'L') || (line[0] == 'l')) {
srs56946699b012010-02-04 00:55:30 -0500452 partitionType.ShowAllTypes();
srs569482f3f0b2010-09-22 10:50:24 -0400453 } else {
srs56945a608532011-03-17 13:53:01 -0400454 if (line.length() == 0)
srs56940741fa22013-01-09 12:55:40 -0500455 tempType = DEFAULT_GPT_TYPE;
srs569482f3f0b2010-09-22 10:50:24 -0400456 else
457 tempType = line;
458 } // if/else
459 } while (tempType == (GUIDData) "00000000-0000-0000-0000-000000000000");
460 partitionType = tempType;
srs56946699b012010-02-04 00:55:30 -0500461 cout << "Changed type of partition to '" << partitionType.TypeName() << "'\n";
462 if (changeName) {
463 SetDefaultDescription();
464 } // if
srs56940a697312010-01-28 21:10:52 -0500465} // GPTPart::ChangeType()