From: Theodore Ts'o Date: Mon, 8 Mar 2004 19:12:09 +0000 (-0500) Subject: Only use the BLKGETSIZE64 ioctl on Linux 2.6 since it is X-Git-Tag: APPLE_UUID_SNAP_1~24 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=2c5cfbcb99f70d90f8e679bd2994b263ca6d11d6;p=tools%2Fe2fsprogs.git 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. --- diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index 9ae3e6e..51647b4 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,10 @@ +2004-03-08 Theodore Ts'o + + * 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 * probe.c (probe_ocfs), probe.h: Add support for the Oracle diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c index fb3f3fb..b099e4e 100644 --- a/lib/blkid/getsize.c +++ b/lib/blkid/getsize.c @@ -29,6 +29,9 @@ #include #include #endif /* HAVE_SYS_DISKLABEL_H */ +#ifdef __linux__ +#include +#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 */ diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 9ee7e57..68bd13b 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,10 @@ +2004-03-08 Theodore Ts'o + + * 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 * getsize.c (ext2fs_get_device_size): Update getsize functions to diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index bfd25b5..4cc4a71 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -36,6 +36,9 @@ #include /* for LIST_HEAD */ #include #endif /* HAVE_SYS_DISK_H */ +#ifdef __linux__ +#include +#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;