srs5694 | 221e087 | 2009-08-29 15:00:31 -0400 | [diff] [blame] | 1 | /* This program is copyright (c) 2009 by Roderick W. Smith. It is distributed |
| 2 | under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ |
| 3 | |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 4 | #include <stdint.h> |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 5 | #include <stdlib.h> |
srs5694 | 00b6d7a | 2011-06-26 22:40:06 -0400 | [diff] [blame] | 6 | #ifdef USE_UTF16 |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 7 | #include <unicode/ustream.h> |
srs5694 | 699941e | 2011-03-21 21:33:57 -0400 | [diff] [blame] | 8 | #else |
| 9 | #define UnicodeString string |
| 10 | #endif |
srs5694 | fed16d0 | 2010-01-27 23:03:40 -0500 | [diff] [blame] | 11 | #include <string> |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 12 | #include "support.h" |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 13 | #include "guid.h" |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef __PARTITION_TYPES |
| 16 | #define __PARTITION_TYPES |
| 17 | |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 18 | using namespace std; |
| 19 | |
| 20 | // A partition type |
| 21 | struct AType { |
| 22 | // I'm using a custom 16-bit extension of the original MBR 8-bit |
| 23 | // type codes, so as to permit disambiguation and use of new |
| 24 | // codes required by GPT |
| 25 | uint16_t MBRType; |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 26 | GUIDData GUIDType; |
srs5694 | e321d44 | 2010-01-29 17:44:04 -0500 | [diff] [blame] | 27 | string name; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 28 | int display; // 1 to show to users as available type, 0 not to |
| 29 | AType* next; |
| 30 | }; // struct AType |
| 31 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 32 | class PartType : public GUIDData { |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 33 | protected: |
| 34 | static int numInstances; |
| 35 | static AType* allTypes; // Linked list holding all the data |
| 36 | static AType* lastType; // Pointer to last entry in the list |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 37 | void AddAllTypes(void); |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 38 | public: |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 39 | PartType(void); |
| 40 | PartType(const PartType & orig); |
| 41 | PartType(const GUIDData & orig); |
| 42 | ~PartType(void); |
| 43 | |
| 44 | // Set up type information |
| 45 | int AddType(uint16_t mbrType, const char * guidData, const char * name, int toDisplay = 1); |
| 46 | |
srs5694 | 82f3f0b | 2010-09-22 10:50:24 -0400 | [diff] [blame] | 47 | // New assignment operators.... |
| 48 | PartType & operator=(const string & orig); |
| 49 | PartType & operator=(const char * orig); |
| 50 | |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 51 | // Assignment operators based on base class.... |
| 52 | GUIDData & operator=(const GUIDData & orig) {return GUIDData::operator=(orig);} |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 53 | |
| 54 | // New data assignment |
srs5694 | cb76c67 | 2010-02-11 22:22:22 -0500 | [diff] [blame] | 55 | PartType & operator=(uint16_t ID); // Use MBR type code times 0x0100 to assign GUID |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 56 | |
| 57 | // Retrieve transformed GUID data based on type code matches |
srs5694 | 5a08175 | 2010-09-24 20:39:41 -0400 | [diff] [blame] | 58 | string TypeName(void) const; |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 59 | UnicodeString UTypeName(void) const; |
srs5694 | 5a08175 | 2010-09-24 20:39:41 -0400 | [diff] [blame] | 60 | uint16_t GetHexType() const; |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 61 | |
| 62 | // Information relating to all type data |
srs5694 | 5a08175 | 2010-09-24 20:39:41 -0400 | [diff] [blame] | 63 | void ShowAllTypes(void) const; |
| 64 | int Valid(uint16_t code) const; |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
srs5694 | e7b4ff9 | 2009-08-18 13:16:10 -0400 | [diff] [blame] | 67 | #endif |