John Reiser <jreiser(a)bitwagon.com> wrote:
On 3/16/21, David Howells wrote:
> John Reiser <jreiser(a)bitwagon.com> wrote:
>
>> See the manual page "man 2 getdents".
> Um, which bit? I don't see anything obvious to that end.
On that manual page:
=====
The system call getdents() reads several linux_dirent structures from the directory
referred to by the open file descriptor fd into the buffer pointed to by dirp.
[snip]]
On success, the number of bytes read is returned.
=====
It doesn't say anything about the size of the directory there. "Number of
bytes read is returned" should be taken as how much of the user buffer was
filled - information you need to know to be able to parse it.
Further, there's getdents() and there's getdents64() and their structs are of
different sizes. By your logic st_size would have to be the number of
linux_dirent structs for use with the former and the number of linux_dirent64
structs for use with the latter... And then there's readdir() as well with
it's old_linux_dirent struct.
So, no, it cannot work like that.
David