Update getsize functions to use the Apple Darwin and Linux 64-bit

ioctl's.
bitmap-optimize
Theodore Ts'o 2004-03-02 10:11:11 -05:00
parent 434661f8d5
commit 85b8700344
4 changed files with 65 additions and 5 deletions

View File

@ -1,3 +1,8 @@
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

View File

@ -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 <sys/ioctl.h>
#include <sys/disk.h>
@ -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;

View File

@ -1,3 +1,8 @@
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

View File

@ -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 <sys/ioctl.h>
#include <sys/disk.h>
@ -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) {