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