diff options
author | srs5694 <srs5694@users.sourceforge.net> | 2009-08-29 15:00:08 -0400 |
---|---|---|
committer | srs5694 <srs5694@users.sourceforge.net> | 2009-08-29 15:00:08 -0400 |
commit | a0eb11a64b4a5b78caff58f804a5fb78ddf3a5df (patch) | |
tree | 051682307561a5afca920c14d787219255cdf637 /gptpart.h | |
parent | 86dd784a0410a689a5423632b346eb398839ee2a (diff) | |
download | sgdisk-a0eb11a64b4a5b78caff58f804a5fb78ddf3a5df.tar.gz |
Added new files
Diffstat (limited to 'gptpart.h')
-rw-r--r-- | gptpart.h | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/gptpart.h b/gptpart.h new file mode 100644 index 0000000..6b834ca --- /dev/null +++ b/gptpart.h @@ -0,0 +1,89 @@ +// +// C++ Interface: gptpart +// +// Description: Class to implement a single GPT partition +// +// +// Author: Rod Smith <rodsmith@rodsbooks.com>, (C) 2009 +// +// Copyright: See COPYING file that comes with this distribution +// +// +/* This program is copyright (c) 2009 by Roderick W. Smith. It is distributed + under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ + +#ifndef __GPTPART_H +#define __GPTPART_H + +#include <stdint.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include "support.h" +#include "parttypes.h" + +using namespace std; + +/***************************************** + * * + * GUIDPart class and related structures * + * * + *****************************************/ + +class GPTPart { + protected: + // Caution: The non-static data in GUIDPart is precisely the right size + // to enable easy loading of the data directly from disk. If any + // non-static variables are added to the below, the data size will + // change and the program will stop working. This can be corrected by + // adjusting the data-load operation in GPTData::LoadMainTable() and + // GPTData::LoadSecondTableAsMain() and then removing the GUIDPart + // size check in SizesOK(). + struct GUIDData partitionType; + struct GUIDData uniqueGUID; + uint64_t firstLBA; + uint64_t lastLBA; + uint64_t attributes; + unsigned char name[NAME_SIZE]; + + static PartTypes typeHelper; + public: + GPTPart(void); + ~GPTPart(void); + + // Simple data retrieval: + struct GUIDData GetType(void) {return partitionType;} + uint16_t GetHexType(void); + char* GetNameType(char* theName); + struct GUIDData GetUniqueGUID(void) {return uniqueGUID;} + uint64_t GetFirstLBA(void) {return firstLBA;} + uint64_t GetLastLBA(void) {return lastLBA;} + uint64_t GetLengthLBA(void); + uint64_t GetAttributes(void) {return attributes;} + unsigned char* GetName(unsigned char* theName); + + // Simple data assignment: + void SetType(struct GUIDData t) {partitionType = t;} + void SetType(uint16_t hex) {partitionType = typeHelper.IDToGUID(hex);} + void SetUniqueGUID(struct GUIDData u) {uniqueGUID = u;} + void SetUniqueGUID(int zeroOrRandom); + void SetFirstLBA(uint64_t f) {firstLBA = f;} + void SetLastLBA(uint64_t l) {lastLBA = l;} + void SetAttributes(uint64_t a) {attributes = a;} + void SetName(unsigned char* n); + + // Additional functions + GPTPart & operator=(const GPTPart & orig); + void ShowSummary(int i, uint32_t blockSize, char* sizeInSI); // display summary information (1-line) + void ShowDetails(uint32_t blockSize); // display detailed information (multi-line) + void BlankPartition(void); // empty partition of data + int DoTheyOverlap(GPTPart* other); // returns 1 if there's overlap + void ReversePartBytes(void); // reverse byte order of all integer fields + + // Functions requiring user interaction + void ChangeType(void); // Change the type code +}; // struct GPTPart + +// A support function that doesn't quite belong in the class.... +void QuickSortGPT(GPTPart* partitions, int start, int finish); + +#endif |