hi,
in my program, I'm using stat() to get some info about the entries in a given directory.
If the entry is a file (not a directory) I want more info concerning the file's type, so I intended to use the 'file' command which provides exactly the information I need.
But now I've read that 'file' uses stat() to gather its output info, and that means that stat() is applied twice on each directory entry, what could be a performance impact.
So my question is:
is there a way (linux command or c function) that provides the required info by one single call? Besides the mentioned file type I need size, date of change, and permissions.
It is unlikely to be a performance issue unless you are doing this on a gazillion files.
Your first stat() call will cause the kernel to read the disk cluster containing the directory
entry. This cluster will be cached in the page cache such that the next stat() call done on
the file will not need to access the disk -- it will get the information from the page cache.
thanks for your answer.
I don't know what gazillion file means, but the performance issue I worried about occured on any directory containing more than 10 files. Now I'm trying to get the detailed information in a separate thread.