support.h revision 6aae2a9b70e9f88926baad94c1eea40e0b534f01
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.7.1.1" 12 13#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) 14// Darwin (Mac OS) only: disk IOCTLs are different, and there is no lseek64 15// 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). 18#include <sys/disk.h> 19#define lseek64 lseek 20#endif 21 22// Linux only.... 23#ifdef __linux__ 24#include <linux/fs.h> 25#endif 26 27// 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 34// Set this as a default 35#define SECTOR_SIZE UINT32_C(512) 36 37// Signatures for Apple (APM) disks, multiplied by 0x100000000 38#define APM_SIGNATURE1 UINT64_C(0x00004D5000000000) 39#define APM_SIGNATURE2 UINT64_C(0x0000535400000000) 40 41// Maximum line length on some input functions 42#define MAX_LINE_LENGTH 255 43 44/************************** 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 53#define HEADER_SIZE UINT32_C(92) 54#define GPT_RESERVED 420 55#define NAME_SIZE 72 56 57using namespace std; 58 59string ReadString(void); 60int GetNumber(int low, int high, int def, const string & prompt); 61char GetYN(void); 62uint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt); 63uint64_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); 65unsigned char StrToHex(const string & input, unsigned int position); 66int IsHex(string input); // Returns 1 if input can be hexadecimal number.... 67int IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian 68void ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue 69 70#endif 71