support.h revision 5a6085310b7f8fe1c35e56bcab7de161808b488d
1221e08768de7fe42ba533ca22baf671420569c07srs/* This program is copyright (c) 2009 by Roderick W. Smith. It is distributed 2221e08768de7fe42ba533ca22baf671420569c07srs under the terms of the GNU GPL version 2, as detailed in the COPYING file. */ 3221e08768de7fe42ba533ca22baf671420569c07srs 4e7b4ff9317fc4e551cf974684eaa88697de5a28srs#include <stdint.h> 5e7b4ff9317fc4e551cf974684eaa88697de5a28srs#include <stdlib.h> 6fed16d043a14e8b86c97a6413aec7281fefcbcb5srs#include <string> 7978041ca613dcb881763b36cf53639d924e52a56srs 8978041ca613dcb881763b36cf53639d924e52a56srs#ifndef __GPTSUPPORT 9978041ca613dcb881763b36cf53639d924e52a56srs#define __GPTSUPPORT 10e7b4ff9317fc4e551cf974684eaa88697de5a28srs 115a6085310b7f8fe1c35e56bcab7de161808b488dsrs#define GPTFDISK_VERSION "0.7.1-pre2" 12bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs 1308bb0da07953af605b4918e268272de15ac151aasrs#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) 14e7b4ff9317fc4e551cf974684eaa88697de5a28srs// Darwin (Mac OS) only: disk IOCTLs are different, and there is no lseek64 15da79b858c9b64823f5c039dc13a3e05e3f2df69asrs// This used to use __DARWIN_UNIX03 rather than __APPLE__, but __APPLE__ 16da79b858c9b64823f5c039dc13a3e05e3f2df69asrs// is more general. If the code fails to work on older versions of OS X/ 17da79b858c9b64823f5c039dc13a3e05e3f2df69asrs// Darwin, this may need to be changed back (and in various .cc files). 18e7b4ff9317fc4e551cf974684eaa88697de5a28srs#include <sys/disk.h> 19e7b4ff9317fc4e551cf974684eaa88697de5a28srs#define lseek64 lseek 20546a9c7c369df465021feecb20f6a8f81b6df6bcsrs#endif 21e7b4ff9317fc4e551cf974684eaa88697de5a28srs 22e7b4ff9317fc4e551cf974684eaa88697de5a28srs// Linux only.... 23546a9c7c369df465021feecb20f6a8f81b6df6bcsrs#ifdef __linux__ 24e7b4ff9317fc4e551cf974684eaa88697de5a28srs#include <linux/fs.h> 25e7b4ff9317fc4e551cf974684eaa88697de5a28srs#endif 26e7b4ff9317fc4e551cf974684eaa88697de5a28srs 27bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs// Microsoft Visual C++ only 28bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs#if defined (_MSC_VER) 29bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs#define sscanf sscanf_s 30bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs#define strcpy strcpy_s 31bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs#define sprintf sprintf_s 32bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs#endif 33bf8950cad0285ee6ab8a896e8d0a30c5fb62c7afsrs 34e7b4ff9317fc4e551cf974684eaa88697de5a28srs// Set this as a default 35e7b4ff9317fc4e551cf974684eaa88697de5a28srs#define SECTOR_SIZE UINT32_C(512) 36e7b4ff9317fc4e551cf974684eaa88697de5a28srs 37221e08768de7fe42ba533ca22baf671420569c07srs// Signatures for Apple (APM) disks, multiplied by 0x100000000 38221e08768de7fe42ba533ca22baf671420569c07srs#define APM_SIGNATURE1 UINT64_C(0x00004D5000000000) 39221e08768de7fe42ba533ca22baf671420569c07srs#define APM_SIGNATURE2 UINT64_C(0x0000535400000000) 40221e08768de7fe42ba533ca22baf671420569c07srs 415a6085310b7f8fe1c35e56bcab7de161808b488dsrs// Maximum line length on some input functions 425a6085310b7f8fe1c35e56bcab7de161808b488dsrs#define MAX_LINE_LENGTH 255 43fed16d043a14e8b86c97a6413aec7281fefcbcb5srs 44221e08768de7fe42ba533ca22baf671420569c07srs/************************** 45221e08768de7fe42ba533ca22baf671420569c07srs * Some GPT constants.... * 46221e08768de7fe42ba533ca22baf671420569c07srs **************************/ 47221e08768de7fe42ba533ca22baf671420569c07srs 48221e08768de7fe42ba533ca22baf671420569c07srs#define GPT_SIGNATURE UINT64_C(0x5452415020494645) 49221e08768de7fe42ba533ca22baf671420569c07srs 50221e08768de7fe42ba533ca22baf671420569c07srs// Number and size of GPT entries... 51221e08768de7fe42ba533ca22baf671420569c07srs#define NUM_GPT_ENTRIES 128 52221e08768de7fe42ba533ca22baf671420569c07srs#define GPT_SIZE 128 53978041ca613dcb881763b36cf53639d924e52a56srs#define HEADER_SIZE UINT32_C(92) 54221e08768de7fe42ba533ca22baf671420569c07srs#define GPT_RESERVED 420 55221e08768de7fe42ba533ca22baf671420569c07srs#define NAME_SIZE 72 56221e08768de7fe42ba533ca22baf671420569c07srs 57e7b4ff9317fc4e551cf974684eaa88697de5a28srsusing namespace std; 58e7b4ff9317fc4e551cf974684eaa88697de5a28srs 595a6085310b7f8fe1c35e56bcab7de161808b488dsrsstring ReadString(void); 60fed16d043a14e8b86c97a6413aec7281fefcbcb5srsint GetNumber(int low, int high, int def, const string & prompt); 61e7b4ff9317fc4e551cf974684eaa88697de5a28srschar GetYN(void); 620873e9d0e9345a2c4418b4718db525c9f1111c83srsuint64_t GetSectorNum(uint64_t low, uint64_t high, uint64_t def, uint64_t sSize, const std::string& prompt); 6301f7f08624f0c942001977415214a578621f6495srsuint64_t IeeeToInt(string IeeeValue, uint64_t sSize, uint64_t low, uint64_t high, uint64_t def = 0); 6401f7f08624f0c942001977415214a578621f6495srsstring BytesToIeee(uint64_t size, uint32_t sectorSize = 1); 656699b01eda84d24bfaf80ad725304fef2b0e1b2asrsunsigned char StrToHex(const string & input, unsigned int position); 660873e9d0e9345a2c4418b4718db525c9f1111c83srsint IsHex(const string & input); // Returns 1 if input can be hexadecimal number.... 672a9f5da3c3c4ccccd291462bda9d2aefcd485ff8srsint IsLittleEndian(void); // Returns 1 if CPU is little-endian, 0 if it's big-endian 68221e08768de7fe42ba533ca22baf671420569c07srsvoid ReverseBytes(void* theValue, int numBytes); // Reverses byte-order of theValue 699ddc14bb9b154518e2b8384d3f4571cf657c7920srs 70e7b4ff9317fc4e551cf974684eaa88697de5a28srs#endif 71