Background is I have an existing application which lists directory entries; strace reveals it just calls getdents and lists them in the order returned. I would like them display
No, there is no way you can manipulate the filesystem metadata to have getdents(2)
return directory entires in the same order as the sort order that ls(1)
applies to the directory entires.
You can always modify your program to sort entries using the same algorithms that ls(1)
provides, though this requires at least O(N) memory and O(N Log N) time for sorting a directory with N entries. You'll have to decide if it is worth the implementation, memory, and time, to sort in the same manner as ls(1)
.