• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // C++ Interface: gptpart
3 //
4 // Description: Class to implement a single GPT partition
5 //
6 //
7 // Author: Rod Smith <rodsmith@rodsbooks.com>, (C) 2009
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 // 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.
14 
15 #ifndef __GPTPART_H
16 #define __GPTPART_H
17 
18 #include <stdint.h>
19 #include <string>
20 #include <sys/types.h>
21 #include "support.h"
22 #include "parttypes.h"
23 #include "guid.h"
24 #include "attributes.h"
25 
26 using namespace std;
27 
28 // Values returned by GPTPart::IsSizedForMBR()
29 #define MBR_SIZED_GOOD 0 /* Whole partition under 2^32 sectors */
30 #define MBR_SIZED_IFFY 1 /* Partition starts under 2^32 & is less than 2^32, but ends over 2^32 */
31 #define MBR_SIZED_BAD  2 /* Partition starts over 2^32, is bigger than 2^32, or otherwise bad */
32 
33 /****************************************
34  *                                      *
35  * GPTPart class and related structures *
36  *                                      *
37  ****************************************/
38 
39 class GPTPart {
40    protected:
41       // Caution: The non-static data in GPTPart is precisely the right size
42       // to enable easy loading of the data directly from disk. If any
43       // non-static variables are added to the below, the data size will
44       // change and the program will stop working. This can be corrected by
45       // adjusting the data-load operation in GPTData::LoadMainTable() and
46       // GPTData::LoadSecondTableAsMain() and then removing the GPTPart
47       // size check in SizesOK() (in gpt.cc file).
48       PartType partitionType;
49       GUIDData uniqueGUID;
50       uint64_t firstLBA;
51       uint64_t lastLBA;
52       Attributes attributes;
53       uint16_t name[NAME_SIZE];
54    public:
55       GPTPart(void);
56       GPTPart(const GPTPart &);
57       ~GPTPart(void);
58 
59       // Simple data retrieval:
GetType(void)60       PartType & GetType(void) {return partitionType;}
61       uint16_t GetHexType(void) const;
62       string GetTypeName(void);
63       UnicodeString GetUTypeName(void);
GetUniqueGUID(void)64       const GUIDData GetUniqueGUID(void) const {return uniqueGUID;}
GetFirstLBA(void)65       uint64_t GetFirstLBA(void) const {return firstLBA;}
GetLastLBA(void)66       uint64_t GetLastLBA(void) const {return lastLBA;}
67       uint64_t GetLengthLBA(void) const;
GetAttributes(void)68       Attributes GetAttributes(void) {return attributes;}
ShowAttributes(uint32_t partNum)69       void ShowAttributes(uint32_t partNum) {attributes.ShowAttributes(partNum);}
70       UnicodeString GetDescription(void);
71       int IsUsed(void);
72       int IsSizedForMBR(void);
73 
74       // Simple data assignment:
75       void SetType(PartType t);
SetType(uint16_t hex)76       void SetType(uint16_t hex) {partitionType = hex;}
SetUniqueGUID(GUIDData u)77       void SetUniqueGUID(GUIDData u) {uniqueGUID = u;}
RandomizeUniqueGUID(void)78       void RandomizeUniqueGUID(void) {uniqueGUID.Randomize();}
SetFirstLBA(uint64_t f)79       void SetFirstLBA(uint64_t f) {firstLBA = f;}
SetLastLBA(uint64_t l)80       void SetLastLBA(uint64_t l) {lastLBA = l;}
SetAttributes(uint64_t a)81       void SetAttributes(uint64_t a) {attributes = a;}
SetAttributes(void)82       void SetAttributes(void) {attributes.ChangeAttributes();}
83       void SetName(const string & theName);
84 #ifdef USE_UTF16
85       void SetName(const UnicodeString & theName);
86 #endif
87       void SetDefaultDescription(void);
88 
89       // Additional functions
90       GPTPart & operator=(const GPTPart & orig);
91       bool operator<(const GPTPart &other) const;
92       void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line)
93       void ShowDetails(uint32_t blockSize); // display detailed information (multi-line)
94       void BlankPartition(void); // empty partition of data
95       int DoTheyOverlap(const GPTPart & other); // returns 1 if there's overlap
96       void ReversePartBytes(void); // reverse byte order of all integer fields
97 
98       // Functions requiring user interaction
99       void ChangeType(void); // Change the type code
100 }; // struct GPTPart
101 
102 #endif
103