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