This patch updates the struct dirent to be on par with glibc (by adding
a missing d_type member) and update the readdir call to use SYS_getdents64
instead of SYS_getdents.
The change to SYS_getdents64 was necessary because SYS_getdents returns
a slightly different struct (without the d_type member), so when
returning a pointer to our internal buffer holding the directory entries,
the contents of the buffer would be off-by-one, resulting in garbage.
To support SYS_getdents, buffer is rewritten everytime the syscall is
called: as per the documentation, d_type is always the last byte in the
structure, so the rewrite:
- gets d_type from the last byte in the structure
- shifts d_name by one
- stores d_type where d_name was previously
- clears previous d_type location
Is this required for this change? If not, remove it. If yes, can explain why?
Defining ino_t to be a typedef of __UINTPTR_TYPE__ might not be the best but it was done because the size of ino_t matches the pointer size on most platforms. If have ways to do this better, feel free to send a separate patch.