xref: /third_party/gptfdisk/gptpart.h (revision cf200d32)
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//
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.
14
15#ifndef __GPTPART_H
16#define __GPTPART_H
17
18#include <stdint.h>
19#include <string>
20#include <sys/types.h>
21#include "support.h"
22#include "parttypes.h"
23#include "guid.h"
24#include "attributes.h"
25
26// Values returned by GPTPart::IsSizedForMBR()
27#define MBR_SIZED_GOOD 0 /* Whole partition under 2^32 sectors */
28#define MBR_SIZED_IFFY 1 /* Partition starts under 2^32 & is less than 2^32, but ends over 2^32 */
29#define MBR_SIZED_BAD  2 /* Partition starts over 2^32, is bigger than 2^32, or otherwise bad */
30
31/****************************************
32 *                                      *
33 * GPTPart class and related structures *
34 *                                      *
35 ****************************************/
36
37class GPTPart {
38   protected:
39      // Caution: The non-static data in GPTPart is precisely the right size
40      // to enable easy loading of the data directly from disk. If any
41      // non-static variables are added to the below, the data size will
42      // change and the program will stop working. This can be corrected by
43      // adjusting the data-load operation in GPTData::LoadMainTable() and
44      // GPTData::LoadSecondTableAsMain() and then removing the GPTPart
45      // size check in SizesOK() (in gpt.cc file).
46      PartType partitionType;
47      GUIDData uniqueGUID;
48      uint64_t firstLBA;
49      uint64_t lastLBA;
50      Attributes attributes;
51      uint16_t name[NAME_SIZE];
52   public:
53      GPTPart(void);
54      GPTPart(const GPTPart &);
55      ~GPTPart(void);
56
57      // Simple data retrieval:
58      PartType & GetType(void) {return partitionType;}
59      uint16_t GetHexType(void) const;
60      std::string GetTypeName(void);
61      UnicodeString GetUTypeName(void);
62      const GUIDData GetUniqueGUID(void) const {return uniqueGUID;}
63      uint64_t GetFirstLBA(void) const {return firstLBA;}
64      uint64_t GetLastLBA(void) const {return lastLBA;}
65      uint64_t GetLengthLBA(void) const;
66      Attributes GetAttributes(void) {return attributes;}
67      void ShowAttributes(uint32_t partNum) {attributes.ShowAttributes(partNum);}
68      UnicodeString GetDescription(void);
69      int IsUsed(void);
70      int IsSizedForMBR(void);
71
72      // Simple data assignment:
73      void SetType(PartType t);
74      void SetType(uint16_t hex) {partitionType = hex;}
75      void SetUniqueGUID(GUIDData u) {uniqueGUID = u;}
76      void RandomizeUniqueGUID(void) {uniqueGUID.Randomize();}
77      void SetFirstLBA(uint64_t f) {firstLBA = f;}
78      void SetLastLBA(uint64_t l) {lastLBA = l;}
79      void SetAttributes(uint64_t a) {attributes = a;}
80      void SetAttributes(void) {attributes.ChangeAttributes();}
81      void SetName(const std::string & theName);
82#ifdef USE_UTF16
83      void SetName(const UnicodeString & theName);
84#endif
85      void SetDefaultDescription(void);
86
87      // Additional functions
88      GPTPart & operator=(const GPTPart & orig);
89      bool operator<(const GPTPart &other) const;
90      void ShowSummary(int partNum, uint32_t blockSize); // display summary information (1-line)
91      void ShowDetails(uint32_t blockSize); // display detailed information (multi-line)
92      void BlankPartition(void); // empty partition of data
93      int DoTheyOverlap(const GPTPart & other); // returns 1 if there's overlap
94      void ReversePartBytes(void); // reverse byte order of all integer fields
95      void ReverseNameBytes(void); // reverse byte order of partition's name field
96
97      // Functions requiring user interaction
98      void ChangeType(void); // Change the type code
99}; // struct GPTPart
100
101#endif
102