]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
getsize.c (ext2fs_get_device_size): Add support for Windows
authorTheodore Ts'o <tytso@mit.edu>
Fri, 8 Oct 2004 16:45:24 +0000 (12:45 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 8 Oct 2004 16:45:24 +0000 (12:45 -0400)
9x/NT under Cygwin.  Thanks to Sam Robb
(samrobb@users.sourceforge.net) for pointing this and the
suggested code patch.

lib/ext2fs/ChangeLog
lib/ext2fs/getsize.c

index 036a5028b3a051d5e67f4a40f2d7762a197cb486..2bc4c2035aed2761cf1840d9139a07b4e936e100 100644 (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.
index 360ecdfc56d4338a39397c080347cdc621e4c24c..ad7ac1c3eb6757154b896da61d1d9a583ea5f2a1 100644 (file)
 #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;