Whamcloud - gitweb
Only use the BLKGETSIZE64 ioctl on Linux 2.6 since it is
authorTheodore Ts'o <tytso@mit.edu>
Mon, 8 Mar 2004 19:12:09 +0000 (14:12 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 8 Mar 2004 19:12:09 +0000 (14:12 -0500)
unreliable in Linux 2.4.  (Addresses Debian Bug #236528).

Fix typo in the ioctl used for Mac OS X.

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

index 9ae3e6e..51647b4 100644 (file)
@@ -1,3 +1,10 @@
+2004-03-08  Theodore Ts'o  <tytso@mit.edu>
+
+       * getsize.c (blkid_get_dev_size): Only use the BLKGETSIZE64 ioctl
+               on Linux 2.6 since it is unreliable in Linux 2.4..
+               (Addresses Debian Bug #236528) Fix typo in the ioctl used
+               for Mac OS X.
+
 2004-03-04  Theodore Ts'o  <tytso@mit.edu>
 
        * probe.c (probe_ocfs), probe.h: Add support for the Oracle
index fb3f3fb..b099e4e 100644 (file)
@@ -29,6 +29,9 @@
 #include <sys/disklabel.h>
 #include <sys/stat.h>
 #endif /* HAVE_SYS_DISKLABEL_H */
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
 
 #include "blkidP.h"
 
@@ -63,6 +66,10 @@ static int valid_offset(int fd, blkid_loff_t offset)
  */
 blkid_loff_t blkid_get_dev_size(int fd)
 {
+       int valid_blkgetsize64 = 1;
+#ifdef __linux__
+       struct          utsname ut;
+#endif
        unsigned long long size64;
        unsigned long size;
        blkid_loff_t high, low;
@@ -78,7 +85,7 @@ blkid_loff_t blkid_get_dev_size(int fd)
 #endif /* HAVE_SYS_DISKLABEL_H */
 
 #ifdef DKIOCGETBLOCKCOUNT      /* For Apple Darwin */
-       if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+       if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) {
                if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
                    && ((size64 / (blocksize / 512)) > 0xFFFFFFFF))
                        return 0; /* EFBIG */
@@ -88,7 +95,14 @@ blkid_loff_t blkid_get_dev_size(int fd)
 #endif
 
 #ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+#ifdef __linux__
+       if ((uname(&ut) == 0) &&
+           ((ut.release[0] == '2') && (ut.release[1] == '.') &&
+            (ut.release[2] < '6') && (ut.release[3] == '.')))
+               valid_blkgetsize64 = 0;
+#endif
+       if (valid_blkgetsize64 &&
+           ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
                if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
                    && ((size64) > 0xFFFFFFFF))
                        return 0; /* EFBIG */
index 9ee7e57..68bd13b 100644 (file)
@@ -1,3 +1,10 @@
+2004-03-08  Theodore Ts'o  <tytso@mit.edu>
+
+       * getsize.c (ext2fs_get_device_size): Only use the BLKGETSIZE64
+               ioctl on Linux 2.6 since it is unreliable in Linux 2.4.
+               (Addresses Debian Bug #236528).  Fix typo in the ioctl
+               used for Mac OS X.
+
 2004-03-02  Theodore Ts'o  <tytso@mit.edu>
 
        * getsize.c (ext2fs_get_device_size): Update getsize functions to
index bfd25b5..4cc4a71 100644 (file)
@@ -36,6 +36,9 @@
 #include <sys/queue.h> /* for LIST_HEAD */
 #include <sys/disk.h>
 #endif /* HAVE_SYS_DISK_H */
+#ifdef __linux__
+#include <sys/utsname.h>
+#endif
 
 #if defined(__linux__) && defined(_IO) && !defined(BLKGETSIZE)
 #define BLKGETSIZE _IO(0x12,96)        /* return device size */
@@ -119,6 +122,10 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
                                 blk_t *retblocks)
 {
        int     fd;
+       int valid_blkgetsize64 = 1;
+#ifdef __linux__
+       struct          utsname ut;
+#endif
        unsigned long long size64;
        unsigned long   size;
        ext2_loff_t high, low;
@@ -141,7 +148,7 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
                return errno;
 
 #ifdef DKIOCGETBLOCKCOUNT      /* For Apple Darwin */
-       if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+       if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) {
                if ((sizeof(*retblocks) < sizeof(unsigned long long))
                    && ((size64 / (blocksize / 512)) > 0xFFFFFFFF))
                        return EFBIG;
@@ -152,7 +159,14 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize,
 #endif
 
 #ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+#ifdef __linux__
+       if ((uname(&ut) == 0) &&
+           ((ut.release[0] == '2') && (ut.release[1] == '.') &&
+            (ut.release[2] < '6') && (ut.release[3] == '.')))
+               valid_blkgetsize64 = 0;
+#endif
+       if (valid_blkgetsize64 &&
+           ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
                if ((sizeof(*retblocks) < sizeof(unsigned long long))
                    && ((size64 / blocksize) > 0xFFFFFFFF))
                        return EFBIG;