* [PATCH] e2fsprogs: Apple Darwin, fix case of device with not 512 bytes block size
@ 2017-03-19 19:29 Fedor Uporov
2017-03-19 20:45 ` Theodore Ts'o
0 siblings, 1 reply; 3+ messages in thread
From: Fedor Uporov @ 2017-03-19 19:29 UTC (permalink / raw)
To: linux-ext4
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] e2fsprogs: Apple Darwin, fix case of device with not 512 bytes block size
2017-03-19 19:29 [PATCH] e2fsprogs: Apple Darwin, fix case of device with not 512 bytes block size Fedor Uporov
@ 2017-03-19 20:45 ` Theodore Ts'o
2017-03-20 20:31 ` drgreenthumb
0 siblings, 1 reply; 3+ messages in thread
From: Theodore Ts'o @ 2017-03-19 20:45 UTC (permalink / raw)
To: Fedor Uporov; +Cc: linux-ext4
Thanks for the patch. Can you tell me how far back support for
DKIOCGETBLOCKSIZE goes? i.e., is it worth adding a fallback if
DKIOCGETBLOCKSIZE is not available? I suppose in the worst case we
can fall back to using a binary search to find size of the device.
Also, could I perhaps ask you to take a look at
lib/ext2fs/getsectsize.c while you are at it? Does Mac OS X have
support for DIOCGSECTORSIZE, and how does this related to
DKIOCGETBLOCKSIZE? Do you know what Mac OS X's alignment restrictions
are for Direct I/O?
Many thanks for helping me improve Apple Darwin support for e2fsprogs! :-)
- Ted
On Sun, Mar 19, 2017 at 10:29:26PM +0300, Fedor Uporov wrote:
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] e2fsprogs: Apple Darwin, fix case of device with not 512 bytes block size
2017-03-19 20:45 ` Theodore Ts'o
@ 2017-03-20 20:31 ` drgreenthumb
0 siblings, 0 replies; 3+ messages in thread
From: drgreenthumb @ 2017-03-20 20:31 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: linux-ext4
On 03/19/2017 11:45 PM, Theodore Ts'o wrote:
> Thanks for the patch. Can you tell me how far back support for
> DKIOCGETBLOCKSIZE goes? i.e., is it worth adding a fallback if
> DKIOCGETBLOCKSIZE is not available? I suppose in the worst case we
> can fall back to using a binary search to find size of the device.
I checked that DKIOCGETBLOCKSIZE and DKIOCGETBLOCKCOUNT are both
available in file xnu/bsd/sys/disk.h from version 10.1 to 10.12.
> Also, could I perhaps ask you to take a look at
> lib/ext2fs/getsectsize.c while you are at it? Does Mac OS X have
> support for DIOCGSECTORSIZE, and how does this related to
> DKIOCGETBLOCKSIZE? Do you know what Mac OS X's alignment restrictions
> are for Direct I/O?
There is no definition of DIOCGSECTORSIZE for Mac OS X.
Seems like, it exist only for FreeBSD.
Not sure about alignment restriction for Direct I/O,
but for for Intel based Mac's the 4k page size will have place.
> Many thanks for helping me improve Apple Darwin support for e2fsprogs! :-)
>
> - Ted
>
> On Sun, Mar 19, 2017 at 10:29:26PM +0300, Fedor Uporov wrote:
>> 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
>>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-03-20 20:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-19 19:29 [PATCH] e2fsprogs: Apple Darwin, fix case of device with not 512 bytes block size Fedor Uporov
2017-03-19 20:45 ` Theodore Ts'o
2017-03-20 20:31 ` drgreenthumb
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.