Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
}
Expand Down
2 changes: 1 addition & 1 deletion src/ff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
32 changes: 26 additions & 6 deletions tests/fatfs1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/fatfs1.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/fatfs1_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down