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
28 changes: 25 additions & 3 deletions source/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@


/* Definitions of sector size */
#if (FF_MAX_SS < FF_MIN_SS) || (FF_MAX_SS != 512 && FF_MAX_SS != 1024 && FF_MAX_SS != 2048 && FF_MAX_SS != 4096) || (FF_MIN_SS != 512 && FF_MIN_SS != 1024 && FF_MIN_SS != 2048 && FF_MIN_SS != 4096)
#if (FF_MAX_SS < FF_MIN_SS) || (FF_MAX_SS != 256 && FF_MAX_SS != 512 && FF_MAX_SS != 1024 && FF_MAX_SS != 2048 && FF_MAX_SS != 4096) || (FF_MIN_SS != 256 && FF_MIN_SS != 512 && FF_MIN_SS != 1024 && FF_MIN_SS != 2048 && FF_MIN_SS != 4096)
#error Wrong sector size configuration
#endif
#if FF_MAX_SS == FF_MIN_SS
Expand Down Expand Up @@ -2409,6 +2409,28 @@ static FRESULT dir_read (
/* Directory handling - Find an object in the directory */
/*-----------------------------------------------------------------------*/

static int compare_filenames(const char* s1, const char* s2, size_t n)
{
#if FF_CASE_INSENSITIVE_COMPARISONS
while (n--)
{
char c1 = *s1++;
char c2 = *s2++;
int d;

if (IsLower(c1)) c1 -= 0x20; /* To upper ASCII char */
if (IsLower(c2)) c2 -= 0x20; /* To upper ASCII char */

d = c1 - c2;
if (d)
return d;
}
return 0;
#else
return memcmp(s1, s2, n);
#endif
}

static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
DIR* dp /* Pointer to the directory object with the file name */
)
Expand Down Expand Up @@ -2469,13 +2491,13 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */
}
} else { /* SFN entry */
if (ord == 0 && sum == sum_sfn(dp->dir)) break; /* LFN matched? */
if (!(dp->fn[NSFLAG] & NS_LOSS) && !memcmp(dp->dir, dp->fn, 11)) break; /* SFN matched? */
if (!(dp->fn[NSFLAG] & NS_LOSS) && !compare_filenames(dp->dir, dp->fn, 11)) break; /* SFN matched? */
ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF; /* Not matched, reset LFN sequence */
}
}
#else /* Non LFN configuration */
dp->obj.attr = dp->dir[DIR_Attr] & AM_MASK;
if (!(dp->dir[DIR_Attr] & AM_VOL) && !memcmp(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */
if (!(dp->dir[DIR_Attr] & AM_VOL) && !compare_filenames(dp->dir, dp->fn, 11)) break; /* Is it a valid entry? */
#endif
res = dir_next(dp, 0); /* Next entry */
} while (res == FR_OK);
Expand Down
5 changes: 5 additions & 0 deletions source/ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@
/ 2: f_getcwd() is available in addition to 1.
*/

#define FF_CASE_INSENSITIVE_COMPARISONS 0
/* This option enables case insensitive comparisons for SFNs, needed by some
/ FATFS variants which store lowercase filenames instead of the usual uppercase
/ ones.
*/

#define FF_PATH_DEPTH 10
/* This option defines maximum depth of directory in the exFAT volume. It is NOT
Expand Down