blob: be55294bcc8f8a7eb4e107467e7e98c86ea81125 [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>
srs569408bb0da2010-02-19 17:19:55 -05005//#include <unistd.h>
srs5694e7b4ff92009-08-18 13:16:10 -04006#include <stdlib.h>
srs5694fed16d02010-01-27 23:03:40 -05007#include <string>
srs5694978041c2009-09-21 20:51:47 -04008
9#ifndef __GPTSUPPORT
10#define __GPTSUPPORT
srs5694e7b4ff92009-08-18 13:16:10 -040011
srs569408bb0da2010-02-19 17:19:55 -050012#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__)
srs5694e7b4ff92009-08-18 13:16:10 -040013// Darwin (Mac OS) only: disk IOCTLs are different, and there is no lseek64
srs5694da79b852009-08-18 13:29:54 -040014// This used to use __DARWIN_UNIX03 rather than __APPLE__, but __APPLE__
15// is more general. If the code fails to work on older versions of OS X/
16// Darwin, this may need to be changed back (and in various .cc files).
srs5694e7b4ff92009-08-18 13:16:10 -040017#include <sys/disk.h>
18#define lseek64 lseek
srs5694546a9c72010-01-26 16:00:26 -050019#endif
srs5694e7b4ff92009-08-18 13:16:10 -040020
21// Linux only....
srs5694546a9c72010-01-26 16:00:26 -050022#ifdef __linux__
srs5694e7b4ff92009-08-18 13:16:10 -040023#include <linux/fs.h>
24#endif
25
srs5694e7b4ff92009-08-18 13:16:10 -040026// Set this as a default
27#define SECTOR_SIZE UINT32_C(512)
28
srs5694221e0872009-08-29 15:00:31 -040029// Signatures for Apple (APM) disks, multiplied by 0x100000000
30#define APM_SIGNATURE1 UINT64_C(0x00004D5000000000)
31#define APM_SIGNATURE2 UINT64_C(0x0000535400000000)
32
srs5694fed16d02010-01-27 23:03:40 -050033// Maximum line length ignored on some input functions
34#define MAX_IGNORED 999
35
srs5694221e0872009-08-29 15:00:31 -040036/**************************
37 * Some GPT constants.... *
38 **************************/
39
40#define GPT_SIGNATURE UINT64_C(0x5452415020494645)
41
42// Number and size of GPT entries...
43#define NUM_GPT_ENTRIES 128
44#define GPT_SIZE 128
srs5694978041c2009-09-21 20:51:47 -040045#define HEADER_SIZE UINT32_C(92)
srs5694221e0872009-08-29 15:00:31 -040046#define GPT_RESERVED 420
47#define NAME_SIZE 72
48
srs5694e7b4ff92009-08-18 13:16:10 -040049using namespace std;
50
srs5694fed16d02010-01-27 23:03:40 -050051int GetNumber(int low, int high, int def, const string & prompt);
srs5694e7b4ff92009-08-18 13:16:10 -040052char GetYN(void);
srs5694fed16d02010-01-27 23:03:40 -050053uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, const string & prompt);
54string BytesToSI(uint64_t size);
srs56946699b012010-02-04 00:55:30 -050055unsigned char StrToHex(const string & input, unsigned int position);
srs56942a9f5da2009-08-26 00:48:01 -040056int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian
srs5694221e0872009-08-29 15:00:31 -040057void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue
srs56949ddc14b2010-08-22 22:44:42 -040058
59// Extract colon-separated fields from a string....
60uint64_t GetInt(const string & argument, int itemNum);
61string GetString(const string & Info, int itemNum);
srs5694e7b4ff92009-08-18 13:16:10 -040062
63#endif