summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoderick W. Smith <rodsmith@rodsbooks.com>2014-03-28 23:54:21 -0400
committerRoderick W. Smith <rodsmith@rodsbooks.com>2014-03-28 23:54:21 -0400
commit1f7822eb54337766002431f01e5934c7d4703628 (patch)
tree7008707bbc852136bfc5c879cfde1078ebd52f5d
parent1a65132980bfef8f9c898afbefcda00277b5ee48 (diff)
downloadsgdisk-1f7822eb54337766002431f01e5934c7d4703628.tar.gz
Changes to support compilation with UEFI GPT fdisk library.
-rw-r--r--NEWS4
-rw-r--r--gpt.cc17
-rw-r--r--support.cc33
-rw-r--r--support.h2
4 files changed, 43 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index 468943d..96810c7 100644
--- a/NEWS
+++ b/NEWS
@@ -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),
diff --git a/gpt.cc b/gpt.cc
index fdffb25..18247c5 100644
--- a/gpt.cc
+++ b/gpt.cc
@@ -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 *
diff --git a/support.cc b/support.cc
index dbcfa00..ef53444 100644
--- a/support.cc
+++ b/support.cc
@@ -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
diff --git a/support.h b/support.h
index 14102fd..3e6fe08 100644
--- a/support.h
+++ b/support.h
@@ -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