diff options
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | gpt.cc | 17 | ||||
-rw-r--r-- | support.cc | 33 | ||||
-rw-r--r-- | support.h | 2 |
4 files changed, 43 insertions, 13 deletions
@@ -1,6 +1,10 @@ 0.8.11 (?/?/2014): ------------------ +- Small code changes to support compilation as EFI application with the + UEFI GPT fdisk library + (http://sourceforge.net/projects/uefigptfdisk/?source=directory) + - Added new partition type codes for Ceph (https://github.com/ceph/ceph/blob/9bcc42a3e6b08521694b5c0228b2c6ed7b3d312e/src/ceph-disk#L76-L81): 4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D/0xf800 (Ceph OSD), @@ -38,6 +38,23 @@ using namespace std; #define log2(x) (log((double) x) / log(2.0)) #endif // Microsoft Visual C++ +#ifdef EFI +// in UEFI mode MMX registers are not yet available so using the +// x86_64 ABI to move "double" values around is not an option. +#ifdef log2 +#undef log2 +#endif +#define log2(x) log2_32( x ) +static inline uint32_t log2_32(uint32_t v) { + int r = -1; + while (v >= 1) { + r++; + v >>= 1; + } + return r; +} +#endif + /**************************************** * * * GPTData class and related structures * @@ -217,30 +217,39 @@ uint64_t IeeeToInt(string inValue, uint64_t sSize, uint64_t low, uint64_t high, // Takes a size and converts this to a size in IEEE-1541-2002 units (KiB, MiB, // GiB, TiB, PiB, or EiB), returned in C++ string form. The size is either in // units of the sector size or, if that parameter is omitted, in bytes. -// (sectorSize defaults to 1). +// (sectorSize defaults to 1). Note that this function uses peculiar +// manual computation of decimal value rather than simply setting +// theValue.precision() because this isn't possible using the available +// EFI library. string BytesToIeee(uint64_t size, uint32_t sectorSize) { - float sizeInIeee; - unsigned int index = 0; + uint64_t sizeInIeee; + uint64_t previousIeee; + float decimalIeee; + uint index = 0; string units, prefixes = " KMGTPEZ"; ostringstream theValue; - sizeInIeee = size * (float) sectorSize; - while ((sizeInIeee > 1024.0) && (index < (prefixes.length() - 1))) { + sizeInIeee = previousIeee = size * (uint64_t) sectorSize; + while ((sizeInIeee > 1024) && (index < (prefixes.length() - 1))) { index++; - sizeInIeee /= 1024.0; + previousIeee = sizeInIeee; + sizeInIeee /= 1024; } // while - theValue.setf(ios::fixed); if (prefixes[index] == ' ') { - units = " bytes"; - theValue.precision(0); + theValue << sizeInIeee << " bytes"; } else { units = " iB"; units[1] = prefixes[index]; - theValue.precision(1); + decimalIeee = ((float) previousIeee - + ((float) sizeInIeee * 1024.0) + 51.2) / 102.4; + if (decimalIeee >= 10.0) { + decimalIeee = 0.0; + sizeInIeee++; + } + theValue << sizeInIeee << "." << (uint32_t) decimalIeee << units; } // if/else - theValue << sizeInIeee << units; return theValue.str(); -} // BlocksToIeee() +} // BytesToIeee() // Converts two consecutive characters in the input string into a // number, interpreting the string as a hexadecimal number, starting @@ -8,7 +8,7 @@ #ifndef __GPTSUPPORT #define __GPTSUPPORT -#define GPTFDISK_VERSION "0.8.10.1" +#define GPTFDISK_VERSION "0.8.10.2" #if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) // Darwin (Mac OS) & FreeBSD: disk IOCTLs are different, and there is no lseek64 |