New release: 0.4.0
This version adds support for FreeBSD and big-endian systems. It also adds support for BSD disklabels and an assortment of other changes, improvements, and bug fixes.
This commit is contained in:
22
support.cc
22
support.cc
@@ -3,6 +3,9 @@
|
||||
// Primarily by Rod Smith, February 2009, but with a few functions
|
||||
// copied from other sources (see attributions below).
|
||||
|
||||
/* This program is copyright (c) 2009 by Roderick W. Smith. It is distributed
|
||||
under the terms of the GNU GPL version 2, as detailed in the COPYING file. */
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
|
||||
@@ -176,8 +179,12 @@ int GetBlockSize(int fd) {
|
||||
|
||||
#ifdef __APPLE__
|
||||
err = ioctl(fd, DKIOCGETBLOCKSIZE, &result);
|
||||
#else
|
||||
#ifdef __FreeBSD__
|
||||
err = ioctl(fd, DIOCGSECTORSIZE, &result);
|
||||
#else
|
||||
err = ioctl(fd, BLKSSZGET, &result);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (result != 512) {
|
||||
@@ -319,15 +326,17 @@ int IsLittleEndian(void) {
|
||||
} // IsLittleEndian()
|
||||
|
||||
// Reverse the byte order of theValue; numBytes is number of bytes
|
||||
void ReverseBytes(char* theValue, int numBytes) {
|
||||
void ReverseBytes(void* theValue, int numBytes) {
|
||||
char* origValue;
|
||||
char* tempValue;
|
||||
int i;
|
||||
|
||||
origValue = (char*) theValue;
|
||||
tempValue = (char*) malloc(numBytes);
|
||||
for (i = 0; i < numBytes; i++)
|
||||
tempValue[i] = theValue[i];
|
||||
tempValue[i] = origValue[i];
|
||||
for (i = 0; i < numBytes; i++)
|
||||
theValue[i] = tempValue[numBytes - i - 1];
|
||||
origValue[i] = tempValue[numBytes - i - 1];
|
||||
free(tempValue);
|
||||
} // ReverseBytes()
|
||||
|
||||
@@ -345,6 +354,7 @@ uint64_t PowerOf2(int value) {
|
||||
return retval;
|
||||
} // PowerOf2()
|
||||
|
||||
|
||||
/**************************************************************************************
|
||||
* *
|
||||
* Below functions are lifted from various sources, as documented in comments before *
|
||||
@@ -366,6 +376,11 @@ uint64_t disksize(int fd, int *err) {
|
||||
// 32/64-bit issues on MacOS....
|
||||
#ifdef __APPLE__
|
||||
*err = ioctl(fd, DKIOCGETBLOCKCOUNT, §ors);
|
||||
#else
|
||||
#ifdef __FreeBSD__
|
||||
*err = ioctl(fd, DIOCGMEDIASIZE, &sz);
|
||||
b = GetBlockSize(fd);
|
||||
sectors = sz / b;
|
||||
#else
|
||||
*err = ioctl(fd, BLKGETSIZE, &sz);
|
||||
if (*err) {
|
||||
@@ -378,6 +393,7 @@ uint64_t disksize(int fd, int *err) {
|
||||
sectors = sz;
|
||||
else
|
||||
sectors = (b >> 9);
|
||||
#endif
|
||||
#endif
|
||||
return sectors;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user