User-space API to inquire block alignment requirements for open file descriptor?

Matthias Andree mandree at FreeBSD.org
Wed Sep 14 06:03:47 UTC 2016


Am 12.09.2016 um 09:12 schrieb Poul-Henning Kamp:
> --------
> In message <c9063edd-a3c1-fce4-483c-a192addc6b86 at 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.


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.


Thanks,

Matthias




More information about the freebsd-hackers mailing list