I wrote:
> Thanks for the report.
>
> You're right that in some cases ls could be optimized to avoid the
> lstat calls. However deciding when to do it is not easy.
> It is possible
> - when dirent.d_ino is available (this is easy), and
> - when dirent.d_ino is guaranteed to be valid (this is tricky)
>
> The latter is harder because for some files (mount points in a chroot
> with a buggy glibc) d_ino is nonzero and wrong. In those cases, you have
> to use lstat to get the true value. The invalid d_ino problem came up
> recently with the report of pwd failing on systems with a losing (and
> slightly old) glibc.
>
> If someone else does all the work to make ensure the optimization
> is safe, I'd accept a patch.
After writing that, I remembered that this optimization
has already been done on the trunk. However, there's no check
for the glibc problem:
2006-02-25 Eric Blake <[EMAIL PROTECTED]>
In ls, avoid calling stat for --inode (-i), when possible.
* src/pwd.c (NOT_AN_INODE_NUMBER, D_INO): Move to ...
* src/system.h: ... here, for use in ...
* src/ls.c (main): ... here. Prefer dirent.d_ino to stat when
possible.
(gobble_file): Add inode argument.
(print_dir): Pass inode if available.
(usage): Remove inaccuracy.
The problem is rare enough that I won't be losing any
sleep over it. But it would be good to fix it, or at least
add a test case comparing st_ino vs. d_ino for every readable
directory from "." up to "/". Then (from test failure reports)
we can hope to get an idea of how often the problem arises.
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils