Here is another idea:
It seems getdents64 is indeed returning "." and "..", but not necessarily first, like Windows does. I think we could swap first 2 entries returned, whatever they are, with "." and "..". It would work like this:
- read the 2 first entries to advance file pointer, but ignore them, return "." or ".." instead - return other entries normally - after "." or ".." is encountered, save current file offset and seek to first or second entry (respectively) and return that instead. For a corner case where that spot has ".." or ".", return the other one of first 2. - seek back where we were
I think this would also fix fake_dot_dot + single_entry case. What do you think?