summaryrefslogtreecommitdiff
path: root/support.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-01-20 16:56:30 -0500
committersrs5694 <srs5694@users.sourceforge.net>2010-01-20 16:56:30 -0500
commit7dbb932233c77cc91ea202ddf5a6198034558ae2 (patch)
tree16153a72419f9acc9c211c071e8e0394d95e9405 /support.cc
parent519b5bb70ae8a185e9e158bba484abf9c11353ea (diff)
downloadsgdisk-7dbb932233c77cc91ea202ddf5a6198034558ae2.tar.gz
Version 0.6.1; very minor changes from last commit
Diffstat (limited to 'support.cc')
-rw-r--r--support.cc10
1 files changed, 5 insertions, 5 deletions
diff --git a/support.cc b/support.cc
index 186fd21..81801f3 100644
--- a/support.cc
+++ b/support.cc
@@ -585,10 +585,10 @@ int myWrite(int fd, char* buffer, int numBytes) {
**************************************************************************************/
// The disksize function is taken from the Linux fdisk code and modified
-// to work around a problem returning a uint64_t value on Mac OS.
+// greatly since then to enable FreeBSD and MacOS support, as well as to
+// return correct values for disk image files.
uint64_t disksize(int fd, int *err) {
long sz; // Do not delete; needed for Linux
- off_t size = 0; // Do not delete; needed for FreeBSD
long long b; // Do not delete; needed for Linux
uint64_t sectors = 0; // size in sectors
off_t bytes = 0; // size in bytes
@@ -603,9 +603,9 @@ uint64_t disksize(int fd, int *err) {
*err = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
#else
#ifdef __FreeBSD__
- *err = ioctl(fd, DIOCGMEDIASIZE, &size);
+ *err = ioctl(fd, DIOCGMEDIASIZE, &bytes);
b = GetBlockSize(fd);
- sectors = size / b;
+ sectors = bytes / b;
#else
*err = ioctl(fd, BLKGETSIZE, &sz);
if (*err) {
@@ -629,7 +629,7 @@ uint64_t disksize(int fd, int *err) {
// what have you) and see what stat() gives us....
if ((sectors == 0) || (*err == -1)) {
if (fstat64(fd, &st) == 0) {
- bytes = (uint64_t) st.st_size;
+ bytes = (off_t) st.st_size;
if ((bytes % UINT64_C(512)) != 0)
fprintf(stderr, "Warning: File size is not a multiple of 512 bytes!"
" Misbehavior is likely!\n\a");