From e1f90c11f40d3ecc5fee8bcfc354e91c80ab38f6 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 10 Jan 2026 20:31:00 +0100 Subject: [PATCH 1/2] Allow sector sizes down to 256 bytes. --- source/ff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/ff.c b/source/ff.c index 7b3dbdc..84c92e4 100644 --- a/source/ff.c +++ b/source/ff.c @@ -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 From a2f912b7aab54004111abb7ee9e65bdf2ab8ae89 Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 10 Jan 2026 21:45:10 +0100 Subject: [PATCH 2/2] Add an option for case-insensitive SFN comparisons. --- source/ff.c | 26 ++++++++++++++++++++++++-- source/ffconf.h | 5 +++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/source/ff.c b/source/ff.c index 84c92e4..e103f0a 100644 --- a/source/ff.c +++ b/source/ff.c @@ -2350,6 +2350,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 */ ) @@ -2409,13 +2431,13 @@ static FRESULT dir_find ( /* FR_OK(0):succeeded, !=0:error */ } } else { /* An SFN entry is found */ 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; /* 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); diff --git a/source/ffconf.h b/source/ffconf.h index 3eefdf4..5a5e4dc 100644 --- a/source/ffconf.h +++ b/source/ffconf.h @@ -161,6 +161,11 @@ / 2: f_getcwd() function 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. +*/ /*---------------------------------------------------------------------------/ / Drive/Volume Configurations