Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Sep 2016 10:08:00 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Alan Somers <asomers@freebsd.org>
Cc:        Matthias Andree <mandree@freebsd.org>,  "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   Re: User-space API to inquire block alignment requirements for open file descriptor?
Message-ID:  <CANCZdfoo2i0gs3T0-CF42q-O6vFAikF7siCoYw0HuhvzWNHTGg@mail.gmail.com>
In-Reply-To: <CAOtMX2hOfp=_w4LuEhqah4AEhrZ6rpPRzYSMKtfdaREioPEZGw@mail.gmail.com>
References:  <c9063edd-a3c1-fce4-483c-a192addc6b86@FreeBSD.org> <20586.1473664368@critter.freebsd.dk> <69e12778-75d0-fd79-2dc4-a7727ccab522@FreeBSD.org> <CAOtMX2hOfp=_w4LuEhqah4AEhrZ6rpPRzYSMKtfdaREioPEZGw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Sep 14, 2016 at 8:05 AM, Alan Somers <asomers@freebsd.org> wrote:
> On Wed, Sep 14, 2016 at 12:03 AM, Matthias Andree <mandree@freebsd.org> wrote:
>> Am 12.09.2016 um 09:12 schrieb Poul-Henning Kamp:
>>> --------
>>> In message <c9063edd-a3c1-fce4-483c-a192addc6b86@FreeBSD.org>, Matthias Andree
>>> writes:
>>>> Greetings,
>>>>
>>>> given an open file descriptor, do we have a system interface to inquire
>>>> about the block size of the underlying devices? In the past, we used to
>>>> deal with 512-byte blocks, but how about drives using 4096-byte blocks?
>>> DIOCGSECTORSIZE in sys/disk.h
>>>
>> Thanks Alan, Eugene, Poul-Henning.
>>
>>
>> Now for the next two interesting questions for file system utilities
>> (think sysutils/e2fsprogs) running on advanced-format (4096-block)
>> drives - many provide internal read-modify-write approaches to emulate
>> 512-byte blocks at substantial performance impact.
>>
>> Ted Y. Ts'o, the upstream e2fsprogs maintainer, asked me this question:
>>
>>> So how to fill in this matrix?
>>>
>>>                             HDD     Linux             Mac OS                      FreeBSD
>>> Logical Block Size    512     BLKGETSSZGET    DKIOCGETBLOCKSIZE           DIOCGSECTORSIZE
>>> Physical Block Size  4096     BLKGETPSZGET    DKIOCGETPHYSICALBLOCKSIZE   ?
>>
>> I have found one hint in the BSD forums that in certain situations the
>> DIOCGSTRIPESIZE and DIOCGSTRIPEOFFSET can contain the latter, but on
>> RAID it often does not.
>
> Correct.  DIOCGSTRIPESIZE is what you want.  A quick tests shows that
> it works correctly for both gmirror and zvols as well as native disks.
>
>>
>>
>> And while we're here, and for the records:
>>
>> how do we query the *erase block size* on flash (solid-state) drives?
>> It's often much bigger than a sector size.
>
> Sorry, I don't know.

This information isn't aways easily exported. But for SD/MMC cards
where it is easy and reliable to get, we use it for the stripe size.

Warner



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfoo2i0gs3T0-CF42q-O6vFAikF7siCoYw0HuhvzWNHTGg>