blob: 2ae27e3facc1e9628e17d64e0d9afc8fc494bd60 [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"
23
24using namespace std;
25
srs5694978041c2009-09-21 20:51:47 -040026/****************************************
27 * *
28 * GPTPart class and related structures *
29 * *
30 ****************************************/
srs5694a0eb11a2009-08-29 15:00:08 -040031
32class GPTPart {
33 protected:
srs5694ba00fed2010-01-12 18:18:36 -050034 // Caution: The non-static data in GPTPart is precisely the right size
srs5694a0eb11a2009-08-29 15:00:08 -040035 // 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
srs5694ba00fed2010-01-12 18:18:36 -050039 // GPTData::LoadSecondTableAsMain() and then removing the GPTPart
40 // size check in SizesOK() (in gpt.cc file).
srs5694a0eb11a2009-08-29 15:00:08 -040041 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);
srs5694546a9c72010-01-26 16:00:26 -050056 string GetNameType(void);
srs5694a0eb11a2009-08-29 15:00:08 -040057 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;}
srs5694546a9c72010-01-26 16:00:26 -050062 string GetName(void);
srs5694a0eb11a2009-08-29 15:00:08 -040063
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);
srs5694978041c2009-09-21 20:51:47 -040076 void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line)
srs5694a0eb11a2009-08-29 15:00:08 -040077 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....
87void QuickSortGPT(GPTPart* partitions, int start, int finish);
88
89#endif