* Steven Whitehouse:
If you are looking for a hint on how large a buffer to allocate,
then
st_blksize is generally used as a hint for directory reads, or
otherwise, a fixed size buffer or a page or two. The st_size field is
meaningless for directories and you'll get all kinds of odd results
depending on the filesystem that is in use, so best avoided,
One caveat is that st_blksize can be unreasonably large, particularly
with NFS and large configured read buffers. So maybe cap that value at
32 KiB, but then why not use 32 KiB unconditionally?
Another issue is that too small a buffer might make some directories
unreadable, given that Linux does not actually enforce NAME_MAX. Some
file systems support NAME_MAX Unicode codepoints in a name, which is
encoded to roughly 0.75 KiB in UTF-8.
Thanks,
Florian