blob: 25da6df26a58a5cd8c00fd2d70f71b9efd2aa78e [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
srs5694978041c2009-09-21 20:51:47 -040028/****************************************
29 * *
30 * GPTPart class and related structures *
31 * *
32 ****************************************/
srs5694a0eb11a2009-08-29 15:00:08 -040033
34class GPTPart {
35 protected:
srs5694ba00fed2010-01-12 18:18:36 -050036 // Caution: The non-static data in GPTPart is precisely the right size
srs5694a0eb11a2009-08-29 15:00:08 -040037 // 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
srs5694ba00fed2010-01-12 18:18:36 -050041 // GPTData::LoadSecondTableAsMain() and then removing the GPTPart
42 // size check in SizesOK() (in gpt.cc file).
srs56946699b012010-02-04 00:55:30 -050043 PartType partitionType;
44 GUIDData uniqueGUID;
srs5694a0eb11a2009-08-29 15:00:08 -040045 uint64_t firstLBA;
46 uint64_t lastLBA;
srs56940873e9d2010-10-07 13:00:45 -040047 Attributes attributes;
48// uint64_t attributes;
srs5694a0eb11a2009-08-29 15:00:08 -040049 unsigned char name[NAME_SIZE];
srs5694a0eb11a2009-08-29 15:00:08 -040050 public:
51 GPTPart(void);
52 ~GPTPart(void);
53
54 // Simple data retrieval:
srs56946699b012010-02-04 00:55:30 -050055 PartType & GetType(void) {return partitionType;}
srs5694a0eb11a2009-08-29 15:00:08 -040056 uint16_t GetHexType(void);
srs56946699b012010-02-04 00:55:30 -050057 string GetTypeName(void);
srs56945a081752010-09-24 20:39:41 -040058 const GUIDData GetUniqueGUID(void) const {return uniqueGUID;}
59 uint64_t GetFirstLBA(void) const {return firstLBA;}
60 uint64_t GetLastLBA(void) const {return lastLBA;}
srs5694a0eb11a2009-08-29 15:00:08 -040061 uint64_t GetLengthLBA(void);
srs56940873e9d2010-10-07 13:00:45 -040062 Attributes GetAttributes(void) {return attributes;}
63 void ShowAttributes(uint32_t partNum) {attributes.ShowAttributes(partNum);}
srs56946699b012010-02-04 00:55:30 -050064 string GetDescription(void);
srs569408bb0da2010-02-19 17:19:55 -050065 int IsUsed(void);
srs5694a0eb11a2009-08-29 15:00:08 -040066
67 // Simple data assignment:
srs56946699b012010-02-04 00:55:30 -050068 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();}
srs5694a0eb11a2009-08-29 15:00:08 -040072 void SetFirstLBA(uint64_t f) {firstLBA = f;}
73 void SetLastLBA(uint64_t l) {lastLBA = l;}
74 void SetAttributes(uint64_t a) {attributes = a;}
srs56940873e9d2010-10-07 13:00:45 -040075 void SetAttributes(void) {attributes.ChangeAttributes();}
srs56940a697312010-01-28 21:10:52 -050076 void SetName(const string & n);
srs56946699b012010-02-04 00:55:30 -050077 void SetDefaultDescription(void);
srs5694a0eb11a2009-08-29 15:00:08 -040078
79 // Additional functions
80 GPTPart & operator=(const GPTPart & orig);
srs5694978041c2009-09-21 20:51:47 -040081 void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line)
srs5694a0eb11a2009-08-29 15:00:08 -040082 void ShowDetails(uint32_t blockSize); // display detailed information (multi-line)
83 void BlankPartition(void); // empty partition of data
srs56940a697312010-01-28 21:10:52 -050084 int DoTheyOverlap(const GPTPart & other); // returns 1 if there's overlap
srs5694a0eb11a2009-08-29 15:00:08 -040085 void ReversePartBytes(void); // reverse byte order of all integer fields
86
87 // Functions requiring user interaction
88 void ChangeType(void); // Change the type code
89}; // struct GPTPart
90
srs5694a0eb11a2009-08-29 15:00:08 -040091#endif