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