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

Eugene Grosbein eugen at grosbein.net
Sun Sep 11 22:57:25 UTC 2016


12.09.2016 5:34, Matthias Andree пишет:
> 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?

Take a look at system cat(1) sources. It uses several system interfaces
and some logic to optimize its read buffer size: fstat(2)/sbuf.st_blksize for file descriptor,
sysconf(_SC_PHYS_PAGES) for system having plenty of RAM,
BUFSIZE_SMALL and BUFSIZE_MAX constanst for lower/upper limits.




More information about the freebsd-hackers mailing list