IIRC that test originated from a freebsd-only fix for parsing direntries retuned from the cooked syscall.
I notice that the test has a seemingly-arbitrary direntBufSize constant that lacks any comment as to its derivation..
I think direntBufSize relates to a constant called DIRBLKSIZ which is set to 1024 bytes on all BSDs. It is the minimum size supported for that familiy of syscalls. So 2048 was chosen to be big enought.
But I also think 128 seems too low, probably on Linux as well. There is even a bug related to a too-small buffer size: #24015 on CIFS in Linux.
All the size calculations in that test with multiples of 4 or 8 are due to the freebsd 11/12 inode64 compatability shim which can now be removed, now that freebsd 11 is no longer supported.
ReadDirent returns only as many directory entries as will fit in the
buffer, and each entry is variable-length — so we have no guarantee in
general that a buffer of a given arbitrary size can hold even one
entry, let alone all ten entries expected by the test.
Instead, iterate calls to ReadDirent until one of the calls returns
zero entries and no error, indicating that the directory has been read
Trust: Bryan Mills <email@example.com>
Reviewed-by: Ian Lance Taylor <firstname.lastname@example.org>
Run-TryBot: Bryan Mills <email@example.com>
TryBot-Result: Gopher Robot <firstname.lastname@example.org>