No point doing a stat on each node when we don't actually need it !
We should chdir into the directory before doing the stats on the short path.
That avoids all the name walking overhead and thrash. Likewise it might be
sensible to stat in inode order and batched, but that may cost more than
the saving !
/* The "ls" standard command.
+ *
+ * FIXME: we should chdir into the directory we are listing if doing stats
+ * and then stat the shortname (this saves lots of filename walks and the
+ * resulting touches of atime).
*/
#include <stdio.h>
#include <string.h>
/* Now finally list the filenames. */
for (i = 0; i < listused; i++, free(name)) {
name = list[i];
- if (LSTAT(name, &statbuf) < 0) {
+ /* Only do expensive stat calls if we actually need the data ! */
+ if ((flags & (LSF_DIR|LSF_FILE|LSF_INODE|LSF_LONG)) && LSTAT(name, &statbuf) < 0) {
perror(name);
continue;
}