blob: da09cc96780ce3b00a35c284fc9f263989a21b14 [file] [log] [blame]
srs5694221e0872009-08-29 15:00:31 -04001/* 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
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
srs56946aae2a92011-06-10 01:16:51 -040011#define GPTFDISK_VERSION "0.7.1.1"
srs5694bf8950c2011-03-12 01:23:12 -050012
srs569408bb0da2010-02-19 17:19:55 -050013#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
srs5694e7b4ff92009-08-18 13:16:10 -040014// Darwin (Mac OS) only: disk IOCTLs are different, and there is no lseek64
srs5694da79b852009-08-18 13:29:54 -040015// This used to use __DARWIN_UNIX03 rather than __APPLE__, but __APPLE__
16// is more general. If the code fails to work on older versions of OS X/
17// Darwin, this may need to be changed back (and in various .cc files).
srs5694e7b4ff92009-08-18 13:16:10 -040018#include <sys/disk.h>
19#define lseek64 lseek
srs5694546a9c72010-01-26 16:00:26 -050020#endif
srs5694e7b4ff92009-08-18 13:16:10 -040021
22// Linux only....
srs5694546a9c72010-01-26 16:00:26 -050023#ifdef __linux__
srs5694e7b4ff92009-08-18 13:16:10 -040024#include <linux/fs.h>
25#endif
26
srs5694bf8950c2011-03-12 01:23:12 -050027// Microsoft Visual C++ only
28#if defined (_MSC_VER)
29#define sscanf sscanf_s
30#define strcpy strcpy_s
31#define sprintf sprintf_s
32#endif
33
srs5694e7b4ff92009-08-18 13:16:10 -040034// Set this as a default
35#define SECTOR_SIZE UINT32_C(512)
36
srs5694221e0872009-08-29 15:00:31 -040037// Signatures for Apple (APM) disks, multiplied by 0x100000000
38#define APM_SIGNATURE1 UINT64_C(0x00004D5000000000)
39#define APM_SIGNATURE2 UINT64_C(0x0000535400000000)
40
srs56945a608532011-03-17 13:53:01 -040041// Maximum line length on some input functions
42#define MAX_LINE_LENGTH 255
srs5694fed16d02010-01-27 23:03:40 -050043
srs5694221e0872009-08-29 15:00:31 -040044/**************************
45 * Some GPT constants.... *
46 **************************/
47
48#define GPT_SIGNATURE UINT64_C(0x5452415020494645)
49
50// Number and size of GPT entries...
51#define NUM_GPT_ENTRIES 128
52#define GPT_SIZE 128
srs5694978041c2009-09-21 20:51:47 -040053#define HEADER_SIZE UINT32_C(92)
srs5694221e0872009-08-29 15:00:31 -040054#define GPT_RESERVED 420
55#define NAME_SIZE 72
56
srs5694e7b4ff92009-08-18 13:16:10 -040057using namespace std;
58
srs56945a608532011-03-17 13:53:01 -040059string ReadString(void);
srs5694fed16d02010-01-27 23:03:40 -050060int GetNumber(int low, int high, int def, const string & prompt);
srs5694e7b4ff92009-08-18 13:16:10 -040061char GetYN(void);
srs56940873e9d2010-10-07 13:00:45 -040062uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt);
srs569401f7f082011-03-15 23:53:31 -040063uint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def = 0);
64string BytesToIeee(uint64_t size, uint32_t sectorSize = 1);
srs56946699b012010-02-04 00:55:30 -050065unsigned char StrToHex(const string & input, unsigned int position);
srs56946aae2a92011-06-10 01:16:51 -040066int IsHex(string input); // Returns 1 if input can be hexadecimal number....
srs56942a9f5da2009-08-26 00:48:01 -040067int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian
srs5694221e0872009-08-29 15:00:31 -040068void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
srs56949ddc14b2010-08-22 22:44:42 -040069
srs5694e7b4ff92009-08-18 13:16:10 -040070#endif