blob: 657b3f96b7246c4bc581d7b21516a9a39fd8a878 [file] [log] [blame]
srs5694a0eb11a2009-08-29 15:00:08 -04001//
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//
srs5694978041c2009-09-21 20:51:47 -040012// 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.
srs5694a0eb11a2009-08-29 15:00:08 -040014
15#ifndef __GPTPART_H
16#define __GPTPART_H
17
18#include <stdint.h>
srs5694546a9c72010-01-26 16:00:26 -050019#include <string>
srs5694a0eb11a2009-08-29 15:00:08 -040020#include <sys/types.h>
srs5694a0eb11a2009-08-29 15:00:08 -040021#include "support.h"
22#include "parttypes.h"
srs56946699b012010-02-04 00:55:30 -050023#include "guid.h"
srs56940873e9d2010-10-07 13:00:45 -040024#include "attributes.h"
srs5694a0eb11a2009-08-29 15:00:08 -040025
26using namespace std;
27
Roderick W. Smitha345a922014-02-22 12:12:32 -050028// 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
srs5694978041c2009-09-21 20:51:47 -040033/****************************************
34 * *
35 * GPTPart class and related structures *
36 * *
37 ****************************************/
srs5694a0eb11a2009-08-29 15:00:08 -040038
39class GPTPart {
40 protected:
srs5694ba00fed2010-01-12 18:18:36 -050041 // Caution: The non-static data in GPTPart is precisely the right size
srs5694a0eb11a2009-08-29 15:00:08 -040042 // 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
srs5694ba00fed2010-01-12 18:18:36 -050046 // GPTData::LoadSecondTableAsMain() and then removing the GPTPart
47 // size check in SizesOK() (in gpt.cc file).
srs56946699b012010-02-04 00:55:30 -050048 PartType partitionType;
49 GUIDData uniqueGUID;
srs5694a0eb11a2009-08-29 15:00:08 -040050 uint64_t firstLBA;
51 uint64_t lastLBA;
srs56940873e9d2010-10-07 13:00:45 -040052 Attributes attributes;
Roderick W. Smith84aaff62014-02-17 16:17:11 -050053 uint16_t name[NAME_SIZE];
srs5694a0eb11a2009-08-29 15:00:08 -040054 public:
55 GPTPart(void);
56 ~GPTPart(void);
57
58 // Simple data retrieval:
srs56946699b012010-02-04 00:55:30 -050059 PartType & GetType(void) {return partitionType;}
srs5694bf8950c2011-03-12 01:23:12 -050060 uint16_t GetHexType(void) const;
srs56946699b012010-02-04 00:55:30 -050061 string GetTypeName(void);
srs56945a608532011-03-17 13:53:01 -040062 UnicodeString GetUTypeName(void);
srs56945a081752010-09-24 20:39:41 -040063 const GUIDData GetUniqueGUID(void) const {return uniqueGUID;}
64 uint64_t GetFirstLBA(void) const {return firstLBA;}
65 uint64_t GetLastLBA(void) const {return lastLBA;}
srs5694bf8950c2011-03-12 01:23:12 -050066 uint64_t GetLengthLBA(void) const;
srs56940873e9d2010-10-07 13:00:45 -040067 Attributes GetAttributes(void) {return attributes;}
68 void ShowAttributes(uint32_t partNum) {attributes.ShowAttributes(partNum);}
srs56945a608532011-03-17 13:53:01 -040069 UnicodeString GetDescription(void);
srs569408bb0da2010-02-19 17:19:55 -050070 int IsUsed(void);
Roderick W. Smith9b338c52014-02-20 11:13:36 -050071 int IsSizedForMBR(void);
srs5694a0eb11a2009-08-29 15:00:08 -040072
73 // Simple data assignment:
srs56946699b012010-02-04 00:55:30 -050074 void SetType(PartType t);
75 void SetType(uint16_t hex) {partitionType = hex;}
76 void SetUniqueGUID(GUIDData u) {uniqueGUID = u;}
77 void RandomizeUniqueGUID(void) {uniqueGUID.Randomize();}
srs5694a0eb11a2009-08-29 15:00:08 -040078 void SetFirstLBA(uint64_t f) {firstLBA = f;}
79 void SetLastLBA(uint64_t l) {lastLBA = l;}
80 void SetAttributes(uint64_t a) {attributes = a;}
srs56940873e9d2010-10-07 13:00:45 -040081 void SetAttributes(void) {attributes.ChangeAttributes();}
srs5694699941e2011-03-21 21:33:57 -040082 void SetName(const string & theName);
srs569400b6d7a2011-06-26 22:40:06 -040083#ifdef USE_UTF16
srs5694699941e2011-03-21 21:33:57 -040084 void SetName(const UnicodeString & theName);
85#endif
srs56946699b012010-02-04 00:55:30 -050086 void SetDefaultDescription(void);
srs5694a0eb11a2009-08-29 15:00:08 -040087
88 // Additional functions
89 GPTPart & operator=(const GPTPart & orig);
srs56949a46b042011-03-15 00:34:10 -040090 bool operator<(const GPTPart &other) const;
srs5694978041c2009-09-21 20:51:47 -040091 void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line)
Jeff Sharkeyd761ff52015-02-28 19:18:39 -080092 void ShowDetails(uint32_t blockSize); // display detailed information (multi-line)
srs5694a0eb11a2009-08-29 15:00:08 -040093 void BlankPartition(void); // empty partition of data
srs56940a697312010-01-28 21:10:52 -050094 int DoTheyOverlap(const GPTPart & other); // returns 1 if there's overlap
srs5694a0eb11a2009-08-29 15:00:08 -040095 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
srs5694a0eb11a2009-08-29 15:00:08 -0400101#endif