Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast open thousands of files in linux/c

Tags:

c

android

file-io

I am doing SDCARD scanner which scans each folder and image file.

I am using C code & using opendir, readdir, fopen APIs to enumerate directory and file open. i have dirent, DIR variables.

Problem is fopen() is taking too much time (300 sec for 10000 files) while director traversing is taking ~25 seconds.

Is there any API which allows me to speed up file open operation, using handle, dir_ino or similar so that i can open file using directory handle or similar.

So far i have looked n tried to use dirent->dir_ino, DIR* but no luck.

I m seeking for low-level api which takes lesser time than fopen.

edit will fts and ftw apis be usefull? they seems to be related to traversing directory only...any other hack or method?

like image 310
JRC Avatar asked Nov 13 '22 12:11

JRC


1 Answers

The only "low level" function is open

int fd = open(dirent->d_name, O_RDONLY);

Though, fopen shouldn't be a lot slower.

like image 178
Olaf Dietsche Avatar answered Nov 15 '22 05:11

Olaf Dietsche