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> |
| 19 | #include <sys/types.h> |
| 20 | #include <sys/ioctl.h> |
| 21 | #include "support.h" |
| 22 | #include "parttypes.h" |
| 23 | |
| 24 | using namespace std; |
| 25 | |
srs5694 | 978041c | 2009-09-21 20:51:47 -0400 | [diff] [blame] | 26 | /**************************************** |
| 27 | * * |
| 28 | * GPTPart class and related structures * |
| 29 | * * |
| 30 | ****************************************/ |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 31 | |
| 32 | class GPTPart { |
| 33 | protected: |
| 34 | // Caution: The non-static data in GUIDPart is precisely the right size |
| 35 | // to enable easy loading of the data directly from disk. If any |
| 36 | // non-static variables are added to the below, the data size will |
| 37 | // change and the program will stop working. This can be corrected by |
| 38 | // adjusting the data-load operation in GPTData::LoadMainTable() and |
| 39 | // GPTData::LoadSecondTableAsMain() and then removing the GUIDPart |
| 40 | // size check in SizesOK(). |
| 41 | struct GUIDData partitionType; |
| 42 | struct GUIDData uniqueGUID; |
| 43 | uint64_t firstLBA; |
| 44 | uint64_t lastLBA; |
| 45 | uint64_t attributes; |
| 46 | unsigned char name[NAME_SIZE]; |
| 47 | |
| 48 | static PartTypes typeHelper; |
| 49 | public: |
| 50 | GPTPart(void); |
| 51 | ~GPTPart(void); |
| 52 | |
| 53 | // Simple data retrieval: |
| 54 | struct GUIDData GetType(void) {return partitionType;} |
| 55 | uint16_t GetHexType(void); |
| 56 | char* GetNameType(char* theName); |
| 57 | struct GUIDData GetUniqueGUID(void) {return uniqueGUID;} |
| 58 | uint64_t GetFirstLBA(void) {return firstLBA;} |
| 59 | uint64_t GetLastLBA(void) {return lastLBA;} |
| 60 | uint64_t GetLengthLBA(void); |
| 61 | uint64_t GetAttributes(void) {return attributes;} |
| 62 | unsigned char* GetName(unsigned char* theName); |
| 63 | |
| 64 | // Simple data assignment: |
| 65 | void SetType(struct GUIDData t) {partitionType = t;} |
| 66 | void SetType(uint16_t hex) {partitionType = typeHelper.IDToGUID(hex);} |
| 67 | void SetUniqueGUID(struct GUIDData u) {uniqueGUID = u;} |
| 68 | void SetUniqueGUID(int zeroOrRandom); |
| 69 | void SetFirstLBA(uint64_t f) {firstLBA = f;} |
| 70 | void SetLastLBA(uint64_t l) {lastLBA = l;} |
| 71 | void SetAttributes(uint64_t a) {attributes = a;} |
| 72 | void SetName(unsigned char* n); |
| 73 | |
| 74 | // Additional functions |
| 75 | GPTPart & operator=(const GPTPart & orig); |
srs5694 | 978041c | 2009-09-21 20:51:47 -0400 | [diff] [blame] | 76 | void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line) |
srs5694 | a0eb11a | 2009-08-29 15:00:08 -0400 | [diff] [blame] | 77 | void ShowDetails(uint32_t blockSize); // display detailed information (multi-line) |
| 78 | void BlankPartition(void); // empty partition of data |
| 79 | int DoTheyOverlap(GPTPart* other); // returns 1 if there's overlap |
| 80 | void ReversePartBytes(void); // reverse byte order of all integer fields |
| 81 | |
| 82 | // Functions requiring user interaction |
| 83 | void ChangeType(void); // Change the type code |
| 84 | }; // struct GPTPart |
| 85 | |
| 86 | // A support function that doesn't quite belong in the class.... |
| 87 | void QuickSortGPT(GPTPart* partitions, int start, int finish); |
| 88 | |
| 89 | #endif |