srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 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 | // |
srs5694 | 978041c | 2009-09-21 20:51:47 -0400 | [diff] [blame] | 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. |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 14 | |
| 15 | #ifndef __GPTPART_H |
| 16 | #define __GPTPART_H |
| 17 | |
| 18 | #include <stdint.h> |
srs5694 | 546a9c7 | 2010-01-26 16:00:26 -0500 | [diff] [blame] | 19 | #include <string> |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 20 | #include <sys/types.h> |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 21 | #include "support.h" |
| 22 | #include "parttypes.h" |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 23 | #include "guid.h" |
srs5694 | 0873e9d | 2010-10-07 13:00:45 -0400 | [diff] [blame] | 24 | #include "attributes.h" |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 25 | |
| 26 | using namespace std; |
| 27 | |
srs5694 | 978041c | 2009-09-21 20:51:47 -0400 | [diff] [blame] | 28 | /**************************************** |
| 29 | * * |
| 30 | * GPTPart class and related structures * |
| 31 | * * |
| 32 | ****************************************/ |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 33 | |
| 34 | class GPTPart { |
| 35 | protected: |
srs5694 | ba00fed | 2010-01-12 18:18:36 -0500 | [diff] [blame] | 36 | // Caution: The non-static data in GPTPart is precisely the right size |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 37 | // to enable easy loading of the data directly from disk. If any |
| 38 | // non-static variables are added to the below, the data size will |
| 39 | // change and the program will stop working. This can be corrected by |
| 40 | // adjusting the data-load operation in GPTData::LoadMainTable() and |
srs5694 | ba00fed | 2010-01-12 18:18:36 -0500 | [diff] [blame] | 41 | // GPTData::LoadSecondTableAsMain() and then removing the GPTPart |
| 42 | // size check in SizesOK() (in gpt.cc file). |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 43 | PartType partitionType; |
| 44 | GUIDData uniqueGUID; |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 45 | uint64_t firstLBA; |
| 46 | uint64_t lastLBA; |
srs5694 | 0873e9d | 2010-10-07 13:00:45 -0400 | [diff] [blame] | 47 | Attributes attributes; |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 48 | unsigned char name[NAME_SIZE]; |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 49 | public: |
| 50 | GPTPart(void); |
| 51 | ~GPTPart(void); |
| 52 | |
| 53 | // Simple data retrieval: |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 54 | PartType & GetType(void) {return partitionType;} |
srs5694 | bf8950c | 2011-03-12 01:23:12 -0500 | [diff] [blame] | 55 | uint16_t GetHexType(void) const; |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 56 | string GetTypeName(void); |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 57 | UnicodeString GetUTypeName(void); |
srs5694 | 5a08175 | 2010-09-24 20:39:41 -0400 | [diff] [blame] | 58 | const GUIDData GetUniqueGUID(void) const {return uniqueGUID;} |
| 59 | uint64_t GetFirstLBA(void) const {return firstLBA;} |
| 60 | uint64_t GetLastLBA(void) const {return lastLBA;} |
srs5694 | bf8950c | 2011-03-12 01:23:12 -0500 | [diff] [blame] | 61 | uint64_t GetLengthLBA(void) const; |
srs5694 | 0873e9d | 2010-10-07 13:00:45 -0400 | [diff] [blame] | 62 | Attributes GetAttributes(void) {return attributes;} |
| 63 | void ShowAttributes(uint32_t partNum) {attributes.ShowAttributes(partNum);} |
srs5694 | 5a60853 | 2011-03-17 13:53:01 -0400 | [diff] [blame] | 64 | UnicodeString GetDescription(void); |
srs5694 | 08bb0da | 2010-02-19 17:19:55 -0500 | [diff] [blame] | 65 | int IsUsed(void); |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 66 | |
| 67 | // Simple data assignment: |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 68 | void SetType(PartType t); |
| 69 | void SetType(uint16_t hex) {partitionType = hex;} |
| 70 | void SetUniqueGUID(GUIDData u) {uniqueGUID = u;} |
| 71 | void RandomizeUniqueGUID(void) {uniqueGUID.Randomize();} |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 72 | void SetFirstLBA(uint64_t f) {firstLBA = f;} |
| 73 | void SetLastLBA(uint64_t l) {lastLBA = l;} |
| 74 | void SetAttributes(uint64_t a) {attributes = a;} |
srs5694 | 0873e9d | 2010-10-07 13:00:45 -0400 | [diff] [blame] | 75 | void SetAttributes(void) {attributes.ChangeAttributes();} |
srs5694 | 699941e | 2011-03-21 21:33:57 -0400 | [diff] [blame] | 76 | void SetName(const string & theName); |
| 77 | #ifndef _WIN32 |
| 78 | void SetName(const UnicodeString & theName); |
| 79 | #endif |
srs5694 | 6699b01 | 2010-02-04 00:55:30 -0500 | [diff] [blame] | 80 | void SetDefaultDescription(void); |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 81 | |
| 82 | // Additional functions |
| 83 | GPTPart & operator=(const GPTPart & orig); |
srs5694 | 9a46b04 | 2011-03-15 00:34:10 -0400 | [diff] [blame] | 84 | bool operator<(const GPTPart &other) const; |
srs5694 | 978041c | 2009-09-21 20:51:47 -0400 | [diff] [blame] | 85 | void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line) |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 86 | void ShowDetails(uint32_t blockSize); // display detailed information (multi-line) |
| 87 | void BlankPartition(void); // empty partition of data |
srs5694 | 0a69731 | 2010-01-28 21:10:52 -0500 | [diff] [blame] | 88 | int DoTheyOverlap(const GPTPart & other); // returns 1 if there's overlap |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 89 | void ReversePartBytes(void); // reverse byte order of all integer fields |
| 90 | |
| 91 | // Functions requiring user interaction |
| 92 | void ChangeType(void); // Change the type code |
| 93 | }; // struct GPTPart |
| 94 | |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 95 | #endif |