ioctl's.
+2004-03-02 Theodore Ts'o <tytso@mit.edu>
+
+ * getsize.c (blkid_get_dev_size): Update getsize functions to use
+ Apple Darwin and Linux 64-bit ioctl's
+
2004-02-29 Brian Bergstrand <brian@bergstrand.org>
* Makefile.in: Use $(BSDLIB_PIC_FLAG) to determine whether to use
#define BLKGETSIZE _IO(0x12,96) /* return device size */
#endif
+#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
+#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
+#endif
+
#ifdef APPLE_DARWIN
#include <sys/ioctl.h>
#include <sys/disk.h>
*/
blkid_loff_t blkid_get_dev_size(int fd)
{
-#ifdef BLKGETSIZE
+ unsigned long long size64;
unsigned long size;
-#endif
blkid_loff_t high, low;
#ifdef FDGETPRM
struct floppy_struct this_floppy;
struct stat st;
#endif /* HAVE_SYS_DISKLABEL_H */
+#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */
+ if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+ if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
+ && ((size64 / (blocksize / 512)) > 0xFFFFFFFF))
+ return 0; /* EFBIG */
+ close(fd);
+ return (blkid_loff_t) size64 << 9;
+ }
+#endif
+
+#ifdef BLKGETSIZE64
+ if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+ if ((sizeof(blkid_loff_t) < sizeof(unsigned long long))
+ && ((size64) > 0xFFFFFFFF))
+ return 0; /* EFBIG */
+ close(fd);
+ return size64;
+ }
+#endif
+
#ifdef BLKGETSIZE
if (ioctl(fd, BLKGETSIZE, &size) >= 0)
return (blkid_loff_t)size << 9;
#endif
+
#ifdef FDGETPRM
if (ioctl(fd, FDGETPRM, &this_floppy) >= 0)
return (blkid_loff_t)this_floppy.size << 9;
+2004-03-02 Theodore Ts'o <tytso@mit.edu>
+
+ * getsize.c (ext2fs_get_device_size): Update getsize functions to
+ use Apple Darwin and Linux 64-bit ioctl's
+
2004-02-29 Brian Bergstrand <brian@bergstrand.org>
* Makefile.in: Use $(BSDLIB_PIC_FLAG) to determine whether to use
#define BLKGETSIZE _IO(0x12,96) /* return device size */
#endif
+#if defined(__linux__) && defined(_IOR) && !defined(BLKGETSIZE64)
+#define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
+#endif
+
#ifdef APPLE_DARWIN
#include <sys/ioctl.h>
#include <sys/disk.h>
blk_t *retblocks)
{
int fd;
-#ifdef BLKGETSIZE
+ unsigned long long size64;
unsigned long size;
-#endif
ext2_loff_t high, low;
#ifdef FDGETPRM
struct floppy_struct this_floppy;
if (fd < 0)
return errno;
+#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */
+ if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+ if ((sizeof(*retblocks) < sizeof(unsigned long long))
+ && ((size64 / (blocksize / 512)) > 0xFFFFFFFF))
+ return EFBIG;
+ close(fd);
+ *retblocks = size64 / (blocksize / 512);
+ return 0;
+ }
+#endif
+
+#ifdef BLKGETSIZE64
+ if (ioctl(fd, BLKGETSIZE64, &size64) >= 0) {
+ if ((sizeof(*retblocks) < sizeof(unsigned long long))
+ && ((size64 / blocksize) > 0xFFFFFFFF))
+ return EFBIG;
+ close(fd);
+ *retblocks = size64 / blocksize;
+ return 0;
+ }
+#endif
+
#ifdef BLKGETSIZE
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
close(fd);
return 0;
}
#endif
+
#ifdef FDGETPRM
if (ioctl(fd, FDGETPRM, &this_floppy) >= 0) {
close(fd);
}
#endif
#ifdef HAVE_SYS_DISKLABEL_H
-#if defined(__FreeBSD__) && __FreeBSD_version < 500040
+#if (defined(__FreeBSD__) && __FreeBSD_version < 500040) || defined(APPLE_DARWIN)
/* old disklabel interface */
part = strlen(file) - 1;
if (part >= 0) {