Home | History | Annotate | Download | only in gptfdisk
      1 /* This program is copyright (c) 2009-2013 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 #include <stdint.h>
      5 #include <stdlib.h>
      6 #include <string>
      7 
      8 #ifndef __GPTSUPPORT
      9 #define __GPTSUPPORT
     10 
     11 #define GPTFDISK_VERSION "0.8.10.2"
     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 using namespace std;
     73 
     74 string ReadString(void);
     75 int GetNumber(int low, int high, int def, const string & prompt);
     76 char GetYN(void);
     77 uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt);
     78 uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def = 0);
     79 string BytesToIeee(uint64_t size, uint32_t sectorSize);
     80 unsigned char StrToHex(const string & input, unsigned int position);
     81 int IsHex(string input); // Returns 1 if input can be hexadecimal number....
     82 int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian
     83 void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
     84 void WinWarning(void);
     85 
     86 #endif
     87