summaryrefslogtreecommitdiff
path: root/support.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2009-09-21 20:51:47 -0400
committersrs5694 <srs5694@users.sourceforge.net>2009-09-21 20:51:47 -0400
commit978041ca613dcb881763b36cf53639d924e52a56 (patch)
treebcb9e01e2c62812085a7195b0e8cc4bc20cc4c2d /support.cc
parente35eb1beb6381977ff0dd8443d91f4569779cf2d (diff)
downloadsgdisk-978041ca613dcb881763b36cf53639d924e52a56.tar.gz
GPT fdisk 0.5.0
Added several features, including a restructuring of the menu system, GPT-to-MBR conversion, and the ability to re-read the MBR to generate a fresh GPT from the current on-disk MBR.
Diffstat (limited to 'support.cc')
-rw-r--r--support.cc22
1 files changed, 7 insertions, 15 deletions
diff --git a/support.cc b/support.cc
index e5b1860..337dfce 100644
--- a/support.cc
+++ b/support.cc
@@ -205,7 +205,9 @@ int GetBlockSize(int fd) {
result = SECTOR_SIZE;
// ENOTTY = inappropriate ioctl; probably being called on a disk image
// file, so don't display the warning message....
- if (errno != ENOTTY) {
+ // 32-bit code returns EINVAL, I don't know why. I know I'm treading on
+ // thin ice here, but it should be OK in all but very weird cases....
+ if ((errno != ENOTTY) && (errno != EINVAL)) {
printf("\aError %d when determining sector size! Setting sector size to %d\n",
errno, SECTOR_SIZE);
} // if
@@ -434,8 +436,9 @@ void DiskSync(int fd) {
uint64_t disksize(int fd, int *err) {
long sz; // Do not delete; needed for Linux
long long b; // Do not delete; needed for Linux
- uint64_t sectors = 0, bytes = 0; // size in sectors & bytes
- struct stat st;
+ uint64_t sectors = 0; // size in sectors
+ off_t bytes = 0; // size in bytes
+ struct stat64 st;
// Note to self: I recall testing a simplified version of
// this code, similar to what's in the __APPLE__ block,
@@ -462,17 +465,6 @@ uint64_t disksize(int fd, int *err) {
sectors = (b >> 9);
} // if
-// if (*err) {
-// sz = 0;
-// if (errno != EFBIG)
-// return sz;
-// }
-// *err = ioctl(fd, BLKGETSIZE64, &b);
-// if (*err || b == 0 || b == sz)
-// sectors = sz;
-// else
-// sectors = (b >> 9);
-
#endif
#endif
@@ -480,7 +472,7 @@ uint64_t disksize(int fd, int *err) {
// so let's assume it's a regular file (a QEMU image, dd backup, or
// what have you) and see what stat() gives us....
if (sectors == 0) {
- if (fstat(fd, &st) == 0) {
+ if (fstat64(fd, &st) == 0) {
bytes = (uint64_t) st.st_size;
if ((bytes % UINT64_C(512)) != 0)
fprintf(stderr, "Warning: File size is not a multiple of 512 bytes!"