From: Theodore Ts'o Date: Tue, 2 Mar 2004 15:11:11 +0000 (-0500) Subject: Update getsize functions to use the Apple Darwin and Linux 64-bit X-Git-Tag: APPLE_UUID_SNAP_1~30 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=85b870034437e590e4aca77e325f3f5d6815eb39;p=tools%2Fe2fsprogs.git Update getsize functions to use the Apple Darwin and Linux 64-bit ioctl's. --- diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog index e09768e..ecb60d0 100644 --- a/lib/blkid/ChangeLog +++ b/lib/blkid/ChangeLog @@ -1,3 +1,8 @@ +2004-03-02 Theodore Ts'o + + * getsize.c (blkid_get_dev_size): Update getsize functions to use + Apple Darwin and Linux 64-bit ioctl's + 2004-02-29 Brian Bergstrand * Makefile.in: Use $(BSDLIB_PIC_FLAG) to determine whether to use diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c index 55c22b0..fb3f3fb 100644 --- a/lib/blkid/getsize.c +++ b/lib/blkid/getsize.c @@ -36,6 +36,10 @@ #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 #include @@ -59,9 +63,8 @@ static int valid_offset(int fd, blkid_loff_t offset) */ 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; @@ -74,10 +77,31 @@ blkid_loff_t blkid_get_dev_size(int fd) 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; diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 4737f31..9ee7e57 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,8 @@ +2004-03-02 Theodore Ts'o + + * getsize.c (ext2fs_get_device_size): Update getsize functions to + use Apple Darwin and Linux 64-bit ioctl's + 2004-02-29 Brian Bergstrand * Makefile.in: Use $(BSDLIB_PIC_FLAG) to determine whether to use diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index 25169cd..bfd25b5 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -41,6 +41,10 @@ #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 #include @@ -115,9 +119,8 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, 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; @@ -137,6 +140,28 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, 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); @@ -144,6 +169,7 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, return 0; } #endif + #ifdef FDGETPRM if (ioctl(fd, FDGETPRM, &this_floppy) >= 0) { close(fd); @@ -152,7 +178,7 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, } #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) {