getsize.c (ext2fs_get_device_size): Add support for Windows

9x/NT under Cygwin.  Thanks to Sam Robb
	(samrobb@users.sourceforge.net) for pointing this and the
	suggested code patch.
bitmap-optimize
Theodore Ts'o 2004-10-08 12:45:24 -04:00
parent 029de63277
commit 1a9c8c35ba
2 changed files with 24 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2004-10-08 Theodore Ts'o <tytso@mit.edu>
* getsize.c (ext2fs_get_device_size): Add support for Windows
9x/NT under Cygwin. Thanks to Sam Robb
(samrobb@users.sourceforge.net) for pointing this and the
suggested code patch.
2004-09-17 Theodore Ts'o <tytso@mit.edu>
* getsize.c: Clean up header #include's.

View File

@ -61,6 +61,10 @@
#include "windows.h"
#include "winioctl.h"
#if (_WIN32_WINNT >= 0x0500)
#define HAVE_GET_FILE_SIZE_EX 1
#endif
errcode_t ext2fs_get_device_size(const char *file, int blocksize,
blk_t *retblocks)
{
@ -68,7 +72,11 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
PARTITION_INFORMATION pi;
DISK_GEOMETRY gi;
DWORD retbytes;
#ifdef HAVE_GET_FILE_SIZE_EX
LARGE_INTEGER filesize;
#else
DWORD filesize;
#endif /* HAVE_GET_FILE_SIZE_EX */
dev = CreateFile(file, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE ,
@ -93,9 +101,18 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
gi.TracksPerCylinder *
gi.Cylinders.QuadPart / blocksize;
#ifdef HAVE_GET_FILE_SIZE_EX
} else if (GetFileSizeEx(dev, &filesize)) {
*retblocks = filesize.QuadPart / blocksize;
}
#else
} else {
filesize = GetFileSize(dev, NULL);
if (INVALID_FILE_SIZE != filesize) {
*retblocks = filesize / blocksize;
}
}
#endif /* HAVE_GET_FILE_SIZE_EX */
CloseHandle(dev);
return 0;