From: Fedor Uporov <thisisadrgreenthumb@gmail.com>
To: linux-ext4@vger.kernel.org
Subject: [PATCH] e2fsprogs: Apple Darwin, fix case of device with not 512 bytes block size
Date: Sun, 19 Mar 2017 22:29:26 +0300 [thread overview]
Message-ID: <20170319192926.GA3509@localhost.localdomain> (raw)
Signed-off-by: Fedor Uporov <thisisadrgreenthumb@gmail.com>
---
lib/blkid/getsize.c | 11 +++++++----
lib/ext2fs/getsize.c | 9 ++++++---
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/lib/blkid/getsize.c b/lib/blkid/getsize.c
index 8e8eb4c..3d26338 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 89c33d4..68480c6 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
--
2.1.4
next reply other threads:[~2017-03-19 19:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-19 19:29 Fedor Uporov [this message]
2017-03-19 20:45 ` [PATCH] e2fsprogs: Apple Darwin, fix case of device with not 512 bytes block size Theodore Ts'o
2017-03-20 20:31 ` drgreenthumb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170319192926.GA3509@localhost.localdomain \
--to=thisisadrgreenthumb@gmail.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).