From: Fedor Uporov Date: Sun, 19 Mar 2017 19:29:26 +0000 (+0300) Subject: libext2fs: support devices w/ non-512 byte block size on Apple Darwin X-Git-Tag: v1.44.4~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cdca044059ac8f6dec8bb641ef1bdd9bac0910e2;p=thirdparty%2Fe2fsprogs.git libext2fs: support devices w/ non-512 byte block size on Apple Darwin Signed-off-by: Fedor Uporov Signed-off-by: Theodore Ts'o --- diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c index 4e2835f65..75f21d5c1 100644 --- a/lib/blkid/getsize.c +++ b/lib/blkid/getsize.c @@ -78,12 +78,15 @@ blkid_loff_t blkid_get_dev_size(int fd) unsigned long long size64; blkid_loff_t high, low; -#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */ - if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) { +#if defined DKIOCGETBLOCKCOUNT && defined DKIOCGETBLOCKSIZE /* For Apple Darwin */ + unsigned int size; + + if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0 && + ioctl(fd, DKIOCGETBLOCKSIZE, &size) >= 0) { if (sizeof(blkid_loff_t) < sizeof(unsigned long long) && - (size64 << 9) > 0xFFFFFFFF) + (size64 * size) > 0xFFFFFFFF) return 0; /* EFBIG */ - return (blkid_loff_t)size64 << 9; + return (blkid_loff_t)size64 * size; } #endif diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index f3839ba3a..be067755f 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -151,9 +151,12 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, if (fd < 0) return errno; -#ifdef DKIOCGETBLOCKCOUNT /* For Apple Darwin */ - if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0) { - *retblocks = size64 / (blocksize / 512); +#if defined DKIOCGETBLOCKCOUNT && defined DKIOCGETBLOCKSIZE /* For Apple Darwin */ + unsigned int size; + + if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size64) >= 0 && + ioctl(fd, DKIOCGETBLOCKSIZE, &size) >= 0) { + *retblocks = size64 * size / blocksize; goto out; } #endif