• 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(void);
57 
58       // Simple data retrieval:
GetType(void)59       PartType & GetType(void) {return partitionType;}
60       uint16_t GetHexType(void) const;
61       string GetTypeName(void);
62       UnicodeString GetUTypeName(void);
GetUniqueGUID(void)63       const GUIDData GetUniqueGUID(void) const {return uniqueGUID;}
GetFirstLBA(void)64       uint64_t GetFirstLBA(void) const {return firstLBA;}
GetLastLBA(void)65       uint64_t GetLastLBA(void) const {return lastLBA;}
66       uint64_t GetLengthLBA(void) const;
GetAttributes(void)67       Attributes GetAttributes(void) {return attributes;}
ShowAttributes(uint32_t partNum)68       void ShowAttributes(uint32_t partNum) {attributes.ShowAttributes(partNum);}
69       UnicodeString GetDescription(void);
70       int IsUsed(void);
71       int IsSizedForMBR(void);
72 
73       // Simple data assignment:
74       void SetType(PartType t);
SetType(uint16_t hex)75       void SetType(uint16_t hex) {partitionType = hex;}
SetUniqueGUID(GUIDData u)76       void SetUniqueGUID(GUIDData u) {uniqueGUID = u;}
RandomizeUniqueGUID(void)77       void RandomizeUniqueGUID(void) {uniqueGUID.Randomize();}
SetFirstLBA(uint64_t f)78       void SetFirstLBA(uint64_t f) {firstLBA = f;}
SetLastLBA(uint64_t l)79       void SetLastLBA(uint64_t l) {lastLBA = l;}
SetAttributes(uint64_t a)80       void SetAttributes(uint64_t a) {attributes = a;}
SetAttributes(void)81       void SetAttributes(void) {attributes.ChangeAttributes();}
82       void SetName(const string & theName);
83 #ifdef USE_UTF16
84       void SetName(const UnicodeString & theName);
85 #endif
86       void SetDefaultDescription(void);
87 
88       // Additional functions
89       GPTPart & operator=(const GPTPart & orig);
90       bool operator<(const GPTPart &other) const;
91       void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line)
92       void ShowDetails(uint32_t blockSize); // display detailed information (multi-line)
93       void BlankPartition(void); // empty partition of data
94       int DoTheyOverlap(const GPTPart & other); // returns 1 if there's overlap
95       void ReversePartBytes(void); // reverse byte order of all integer fields
96 
97       // Functions requiring user interaction
98       void ChangeType(void); // Change the type code
99 }; // struct GPTPart
100 
101 #endif
102