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