blob: 3e6fe08e66e6c04d5757856ee4746ae405dd54e4 [file] [log] [blame]
Roderick W. Smithe3ee7332013-09-24 12:56:11 -04001/* This program is copyright (c) 2009-2013 by Roderick W. Smith. It is distributed
srs5694221e0872009-08-29 15:00:31 -04002 under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
3
srs5694e7b4ff92009-08-18 13:16:10 -04004#include <stdint.h>
srs5694e7b4ff92009-08-18 13:16:10 -04005#include <stdlib.h>
srs5694fed16d02010-01-27 23:03:40 -05006#include <string>
srs5694978041c2009-09-21 20:51:47 -04007
8#ifndef __GPTSUPPORT
9#define __GPTSUPPORT
srs5694e7b4ff92009-08-18 13:16:10 -040010
Aurimas Liutikasbdbab022017-03-07 09:50:36 -080011#define GPTFDISK_VERSION "0.8.10.2"
srs5694bf8950c2011-03-12 01:23:12 -050012
srs569408bb0da2010-02-19 17:19:55 -050013#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
srs569400b6d7a2011-06-26 22:40:06 -040014// Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64
srs5694e7b4ff92009-08-18 13:16:10 -040015#include <sys/disk.h>
16#define lseek64 lseek
srs5694546a9c72010-01-26 16:00:26 -050017#endif
srs5694e7b4ff92009-08-18 13:16:10 -040018
srs569400b6d7a2011-06-26 22:40:06 -040019#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
srs56940741fa22013-01-09 12:55:40 -050020#define DEFAULT_GPT_TYPE 0xA503
srs569400b6d7a2011-06-26 22:40:06 -040021#endif
22
23#ifdef __APPLE__
srs56940741fa22013-01-09 12:55:40 -050024#define DEFAULT_GPT_TYPE 0xAF00
srs569400b6d7a2011-06-26 22:40:06 -040025#endif
26
27#ifdef _WIN32
srs56940741fa22013-01-09 12:55:40 -050028#define DEFAULT_GPT_TYPE 0x0700
29#endif
30
31#ifdef __sun__
32#define DEFAULT_GPT_TYPE 0xbf01
srs5694e7b4ff92009-08-18 13:16:10 -040033#endif
34
srs5694bf8950c2011-03-12 01:23:12 -050035// 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
srs569400b6d7a2011-06-26 22:40:06 -040042// Linux only....
43#ifdef __linux__
44#include <linux/fs.h>
srs56940741fa22013-01-09 12:55:40 -050045#define DEFAULT_GPT_TYPE 0x8300
srs569400b6d7a2011-06-26 22:40:06 -040046#endif
47
srs56940741fa22013-01-09 12:55:40 -050048#ifndef DEFAULT_GPT_TYPE
49#define DEFAULT_GPT_TYPE 0x8300
srs569400b6d7a2011-06-26 22:40:06 -040050#endif
51
srs5694e7b4ff92009-08-18 13:16:10 -040052// Set this as a default
53#define SECTOR_SIZE UINT32_C(512)
54
srs5694221e0872009-08-29 15:00:31 -040055// 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
srs5694978041c2009-09-21 20:51:47 -040068#define HEADER_SIZE UINT32_C(92)
srs5694221e0872009-08-29 15:00:31 -040069#define GPT_RESERVED 420
Roderick W. Smith84aaff62014-02-17 16:17:11 -050070#define NAME_SIZE 36 // GPT allows 36 UTF-16LE code units for a name in a 128 byte partition entry
srs5694221e0872009-08-29 15:00:31 -040071
srs5694e7b4ff92009-08-18 13:16:10 -040072using namespace std;
73
srs56945a608532011-03-17 13:53:01 -040074string ReadString(void);
srs5694fed16d02010-01-27 23:03:40 -050075int GetNumber(int low, int high, int def, const string & prompt);
srs5694e7b4ff92009-08-18 13:16:10 -040076char GetYN(void);
srs56940873e9d2010-10-07 13:00:45 -040077uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt);
srs569401f7f082011-03-15 23:53:31 -040078uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def = 0);
srs5694a17fe692011-09-10 20:30:20 -040079string BytesToIeee(uint64_t size, uint32_t sectorSize);
srs56946699b012010-02-04 00:55:30 -050080unsigned char StrToHex(const string & input, unsigned int position);
srs56946aae2a92011-06-10 01:16:51 -040081int IsHex(string input); // Returns 1 if input can be hexadecimal number....
srs56942a9f5da2009-08-26 00:48:01 -040082int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian
srs5694221e0872009-08-29 15:00:31 -040083void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
srs5694a17fe692011-09-10 20:30:20 -040084void WinWarning(void);
srs56949ddc14b2010-08-22 22:44:42 -040085
srs5694e7b4ff92009-08-18 13:16:10 -040086#endif