aboutsummaryrefslogtreecommitdiff
path: root/diskio-windows.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-03-07 22:16:07 -0500
committersrs5694 <srs5694@users.sourceforge.net>2010-03-07 22:16:07 -0500
commit55d926192adc984462509b2966e23bc0d1129bbd (patch)
treebff8bea805e3fb0e15f7f3a0cd26a20fa12c5f29 /diskio-windows.cc
parentea17cffd083c839b7af3560d55ba697667277901 (diff)
downloadgptfdisk-55d926192adc984462509b2966e23bc0d1129bbd.tar.gz
Updated project files for 0.6.5 release version.
Diffstat (limited to 'diskio-windows.cc')
-rw-r--r--diskio-windows.cc38
1 files changed, 9 insertions, 29 deletions
diff --git a/diskio-windows.cc b/diskio-windows.cc
index aaf5c64..6c9aee6 100644
--- a/diskio-windows.cc
+++ b/diskio-windows.cc
@@ -64,9 +64,7 @@ int DiskIO::OpenForRead(void) {
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fd == INVALID_HANDLE_VALUE) {
CloseHandle(fd);
- cerr << "Problem opening ";
- cerr << realFilename;
- cerr << " for reading!\n";
+ cerr << "Problem opening " << realFilename << " for reading!\n";
realFilename = "";
userFilename = "";
isOpen = 0;
@@ -123,11 +121,11 @@ void DiskIO::Close(void) {
} // DiskIO::Close()
// Returns block size of device pointed to by fd file descriptor. If the ioctl
-// returns an error condition, print a warning but return a value of SECTOR_SIZE
-// (512)..
+// returns an error condition, assume it's a disk file and return a value of
+// SECTOR_SIZE (512). If the disk can't be opened at all, return a value of 0.
int DiskIO::GetBlockSize(void) {
- int err;
- DWORD blockSize, junk1, junk2, junk3;
+ DWORD blockSize = 0, retBytes;
+ DISK_GEOMETRY_EX geom;
// If disk isn't open, try to open it....
if (!isOpen) {
@@ -135,29 +133,11 @@ int DiskIO::GetBlockSize(void) {
} // if
if (isOpen) {
-/* BOOL WINAPI GetDiskFreeSpace(
- __in LPCTSTR lpRootPathName,
- __out LPDWORD lpSectorsPerCluster,
- __out LPDWORD lpBytesPerSector,
- __out LPDWORD lpNumberOfFreeClusters,
- __out LPDWORD lpTotalNumberOfClusters
- ); */
-// err = GetDiskFreeSpace(realFilename.c_str(), &junk1, &blockSize, &junk2, &junk3);
- // Above call is fubared -- returns weird values for blockSize....
- err = 1;
- blockSize = 512;
-
- if (err == 0) {
+ if (DeviceIoControl(fd, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &geom, sizeof(geom), &retBytes, NULL)) {
+ blockSize = geom.Geometry.BytesPerSector;
+ } else { // was probably an ordinary file; set default value....
blockSize = SECTOR_SIZE;
- // ENOTTY = inappropriate ioctl; probably being called on a disk image
- // file, so don't display the warning message....
- // 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 != 267) { // 267 is returned on ordinary files
- cerr << "\aError " << GetLastError() << " when determining sector size! "
- << "Setting sector size to " << SECTOR_SIZE << "\n";
- } // if
- } // if (err == -1)
+ } // if/else
} // if (isOpen)
return (blockSize);