resetting manifest requested domain to floor
[platform/upstream/gptfdisk.git] / support.h
1 /* This program is copyright (c) 2009 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.5"
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_TYPE 0xA503
21 #endif
22
23 #ifdef __APPLE__
24 #define DEFAULT_TYPE 0xAF00
25 #endif
26
27 #ifdef _WIN32
28 #define DEFAULT_TYPE 0x0700
29 #endif
30
31 // Microsoft Visual C++ only
32 #if defined (_MSC_VER)
33 #define sscanf sscanf_s
34 #define strcpy strcpy_s
35 #define sprintf sprintf_s
36 #endif
37
38 // Linux only....
39 #ifdef __linux__
40 #include <linux/fs.h>
41 #define DEFAULT_TYPE 0x8300
42 #endif
43
44 #ifndef DEFAULT_TYPE
45 #define DEFAULT_TYPE 0x8300
46 #endif
47
48 // Set this as a default
49 #define SECTOR_SIZE UINT32_C(512)
50
51 // Signatures for Apple (APM) disks, multiplied by 0x100000000
52 #define APM_SIGNATURE1 UINT64_C(0x00004D5000000000)
53 #define APM_SIGNATURE2 UINT64_C(0x0000535400000000)
54
55 /**************************
56  * Some GPT constants.... *
57  **************************/
58
59 #define GPT_SIGNATURE UINT64_C(0x5452415020494645)
60
61 // Number and size of GPT entries...
62 #define NUM_GPT_ENTRIES 128
63 #define GPT_SIZE 128
64 #define HEADER_SIZE UINT32_C(92)
65 #define GPT_RESERVED 420
66 #define NAME_SIZE 72
67
68 using namespace std;
69
70 string ReadString(void);
71 int GetNumber(int low, int high, int def, const string & prompt);
72 char GetYN(void);
73 uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt);
74 uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def = 0);
75 string BytesToIeee(uint64_t size, uint32_t sectorSize);
76 unsigned char StrToHex(const string & input, unsigned int position);
77 int IsHex(string input); // Returns 1 if input can be hexadecimal number....
78 int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian
79 void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
80 void WinWarning(void);
81
82 #endif