diff --git a/src/ff.c b/src/ff.c index 171b599..8385fdf 100644 --- a/src/ff.c +++ b/src/ff.c @@ -4429,6 +4429,7 @@ FRESULT f_findnext ( /*-----------------------------------------------------------------------*/ FRESULT f_findfirst ( + FATFS *fatfs, DIR* dp, /* Pointer to the blank directory object */ FILINFO* fno, /* Pointer to the file information structure */ const TCHAR* path, /* Pointer to the directory to open */ @@ -4439,7 +4440,7 @@ FRESULT f_findfirst ( dp->pat = pattern; /* Save pointer to pattern string */ - res = f_opendir(dp, path); /* Open the target directory */ + res = f_opendir(fatfs, dp, path); /* Open the target directory */ if (res == FR_OK) { res = f_findnext(dp, fno); /* Find the first item */ } diff --git a/src/ff.h b/src/ff.h index 1cb8cb2..b1f76cc 100644 --- a/src/ff.h +++ b/src/ff.h @@ -289,7 +289,7 @@ FRESULT f_sync (FIL* fp); /* Flush cac FRESULT f_opendir (FATFS *fs, FF_DIR* dp, const TCHAR* path); /* Open a directory */ FRESULT f_closedir (FF_DIR* dp); /* Close an open directory */ FRESULT f_readdir (FF_DIR* dp, FILINFO* fno); /* Read a directory item */ -FRESULT f_findfirst (FF_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */ +FRESULT f_findfirst (FATFS* fs, FF_DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */ FRESULT f_findnext (FF_DIR* dp, FILINFO* fno); /* Find next file */ FRESULT f_mkdir (FATFS *fs, const TCHAR* path); /* Create a sub directory */ FRESULT f_unlink (FATFS *fs, const TCHAR* path); /* Delete an existing file or directory */ diff --git a/tests/fatfs1.c b/tests/fatfs1.c index d327017..22b75ff 100644 --- a/tests/fatfs1.c +++ b/tests/fatfs1.c @@ -57,6 +57,15 @@ DWORD get_fattime(void) { return 0; } +static void print_filinfo(const char *msg, FRESULT res, FILINFO *fno) { + #if FF_USE_LFN + // note: lfname is empty string if it fits in 12 chars in fname + printf("readdir res=%d size=%u name=/%s/ lname=/%s/\n", res, fno->fsize, fno->altname, fno->fname); + #else + printf("readdir res=%d size=%u name=/%s/\n", res, fno->fsize, fno->fname); + #endif +} + int main() { struct _bdev_t bdev = {0}; FATFS fatfs; @@ -172,12 +181,23 @@ int main() { if (res != FR_OK || fno.fname[0] == 0) { break; } - #if FF_USE_LFN - // note: lfname is empty string if it fits in 12 chars in fname - printf("readdir res=%d size=%u name=/%s/ lname=/%s/\n", res, fno.fsize, fno.altname, fno.fname); - #else - printf("readdir res=%d size=%u name=/%s/\n", res, fno.fsize, fno.fname); - #endif + print_filinfo("readdir", res, &fno); + } + res = f_closedir(&dp); + printf("closedir res=%d\n", res); + } + + printf("== FIND FIRST ==\n"); + { + FF_DIR dp; + FILINFO fno; + FRESULT res = f_findfirst(&fatfs, &dp, &fno, "/", "*.txt"); + for (;;) { + if (res != FR_OK || fno.fname[0] == 0) { + break; + } + print_filinfo("findfirst", res, &fno); + res = f_findnext(&dp, &fno); } res = f_closedir(&dp); printf("closedir res=%d\n", res); diff --git a/tests/fatfs1.exp b/tests/fatfs1.exp index 2bfb6e3..6060a10 100644 --- a/tests/fatfs1.exp +++ b/tests/fatfs1.exp @@ -164,6 +164,16 @@ readdir res=0 size=0 name=/DIR/ lname=/dir/ disk_ioctl(0, 6) disk_ioctl(0, 6) closedir res=0 +== FIND FIRST == +disk_ioctl(0, 6) +disk_ioctl(0, 6) +readdir res=0 size=10 name=/TEST.TXT/ lname=/test.txt/ +disk_ioctl(0, 6) +readdir res=0 size=1000 name=/FILENA~1.TXT/ lname=/filename-that-is-long.txt/ +disk_ioctl(0, 6) +disk_ioctl(0, 6) +disk_ioctl(0, 6) +closedir res=0 == RENAME FILE == disk_ioctl(0, 6) disk_write(0, 2, 1, 0xcdb1e73c) diff --git a/tests/fatfs1_conf.h b/tests/fatfs1_conf.h index 5d3f9c7..74ba920 100644 --- a/tests/fatfs1_conf.h +++ b/tests/fatfs1_conf.h @@ -2,7 +2,7 @@ #define FF_FS_READONLY 0 #define FF_FS_MINIMIZE 0 #define FF_USE_STRFUNC 0 -#define FF_USE_FIND 0 +#define FF_USE_FIND 1 #define FF_USE_MKFS 1 #define FF_USE_FASTSEEK 0 #define FF_USE_EXPAND 0