1 /* This program is copyright (c) 2009-2018 by Roderick W. Smith. It is distributed
2   under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
3 
4 #ifndef __GPTSUPPORT
5 #define __GPTSUPPORT
6 
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <string>
10 
11 #define GPTFDISK_VERSION "1.0.8"
12 
13 #if defined(__DragonFly__)
14 #define lseek64 lseek
15 #endif
16 
17 #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
18 // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64
19 #include <sys/disk.h>
20 #define lseek64 lseek
21 #endif
22 
23 #if defined (__DragonFly__)
24 //#include <sys/diskslice.h>
25 #define lseek64 lseek
26 #endif
27 
28 #if defined (__DragonFly__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
29 #define DEFAULT_GPT_TYPE 0xA503
30 #endif
31 
32 #ifdef __APPLE__
33 #define DEFAULT_GPT_TYPE 0xAF00
34 #endif
35 
36 #ifdef _WIN32
37 #define DEFAULT_GPT_TYPE 0x0700
38 #endif
39 
40 #ifdef __sun__
41 #define DEFAULT_GPT_TYPE 0xbf01
42 #endif
43 
44 // Microsoft Visual C++ only
45 #if defined (_MSC_VER)
46 #define sscanf sscanf_s
47 #define strcpy strcpy_s
48 #define sprintf sprintf_s
49 #endif
50 
51 // Linux only....
52 #ifdef __linux__
53 #include <linux/fs.h>
54 #define DEFAULT_GPT_TYPE 0x8300
55 #endif
56 
57 #ifndef DEFAULT_GPT_TYPE
58 #define DEFAULT_GPT_TYPE 0x8300
59 #endif
60 
61 // Set this as a default
62 #define SECTOR_SIZE UINT32_C(512)
63 
64 // Signatures for Apple (APM) disks, multiplied by 0x100000000
65 #define APM_SIGNATURE1 UINT64_C(0x00004D5000000000)
66 #define APM_SIGNATURE2 UINT64_C(0x0000535400000000)
67 
68 /**************************
69  * Some GPT constants.... *
70  **************************/
71 
72 #define GPT_SIGNATURE UINT64_C(0x5452415020494645)
73 
74 // Number and size of GPT entries...
75 #define NUM_GPT_ENTRIES 128
76 #define GPT_SIZE 128
77 #define HEADER_SIZE UINT32_C(92)
78 #define GPT_RESERVED 420
79 #define NAME_SIZE 36 // GPT allows 36 UTF-16LE code units for a name in a 128 byte partition entry
80 
81 using namespace std;
82 
83 string ReadString(void);
84 uint64_t GetNumber(uint64_t low, uint64_t high, uint64_t def, const string & prompt);
85 char GetYN(void);
86 uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt);
87 uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def = 0);
88 string BytesToIeee(uint64_t size, uint32_t sectorSize);
89 unsigned char StrToHex(const string & input, unsigned int position);
90 int IsHex(string input); // Returns 1 if input can be hexadecimal number....
91 int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian
92 void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
93 void WinWarning(void);
94 string ToLower(const string& input);
95 
96 #endif
97