This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A question about function readdir and stat


On Fri, Mar 28, 2008 at 05:04:04PM +0800, eCos@sunnorth.com.cn wrote:
> Dear all??
> We have to do a total sd card scanning and check for some certain type of 
> files in our application, some application code is as below:
> 
> -----------------------------------------------
> DIR *d;
> struct dirent *de;
> struct stat s;
> d = opendir("/");
> while((de = readdir(d)) != NULL)
> {
>         stat(de->d_name,&s);
>         ...
> }
> -----------------------------------------------
> In order to accomplish the purpose, we have to call stat function to 
> distinguish file and directories, i.e. stat(de->d_name, &s), however, this 
> does makes speep slow.
> 
> Suppose that we have nearly 10000 files on our sd card root directory, so 
> root directory has entries:
> ..
> .
> f1
> f2
> f3
> ......
> f10000
> ......

Why not impose a directory structure. eg my camera has a directory for
every 100 images. That would mean you only need a maximum of 100
comparisons for the last file in the directory and for 10000 files you
need 100 directories.

Another option which would give a speed up is not to use numbers, but
a more dense naming scheme. eg fAA, fAB, fAC, ..., fAZ, fAa, ... fAz,
You still end up doing 10000 comparisons, but the strings you are
comparing are shorted so there is less work to do.

> On linux, readdir's mannual 3, we found that the struct dirent has another 
> field named d_type, which is not in eCos(eCos has only one field d_name). 
> So on linux, when readdir returns a struct dirent, we could check the 
> d_type field to pass the direcoties,  without function stat's comparing 
> names with all the entries. Of course, using of d_type will harm the 
> portability of our program, but we could accept this fact.

I assume you are using fatfs? Looking at fatfs_fo_dirread, this would
be easy to implement. You have the information you need in dentry. So
just add the new member d_type and fill it in.

     Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]