From 653f64c061f6291ff8e3714e8b845a3586ee66ce Mon Sep 17 00:00:00 2001 From: yumimint Date: Sun, 12 Apr 2026 20:01:59 +0900 Subject: [PATCH 1/8] Implement Human68k extended filename support in FatFs --- fatfs/ff.c | 41 ++++++++++++++++++++++++++++++++++++++++- fatfs/ff.h | 4 ++++ fatfs/ffconf.h | 4 +++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/fatfs/ff.c b/fatfs/ff.c index ccf7114..bc6ca7e 100644 --- a/fatfs/ff.c +++ b/fatfs/ff.c @@ -456,6 +456,7 @@ typedef struct { #define DIR_Name 0 /* Short file name (11) */ #define DIR_Attr 11 /* Attribute (1) */ +#define DIR_HU68K_EXNAME 12 /* Human68k extended filename part (10) */ #define DIR_NTres 12 /* NT flag (1) */ #define DIR_CrtTimeTenth 13 /* Created time sub-second (1) */ #define DIR_CrtTime 14 /* Created time (2) */ @@ -1751,7 +1752,7 @@ void get_fileinfo ( /* No return code */ p = fno->fname; if (dp->sect) { /* Get SFN */ - BYTE *dir = dp->dir; + const BYTE *dir = dp->dir; i = 0; while (i < 11) { /* Copy name body and extension */ @@ -1778,6 +1779,44 @@ void get_fileinfo ( /* No return code */ } *p = 0; /* Terminate SFN string by a \0 */ + // ------------------------------------------------------------------------- + // update FILINFO.fname for Human68k + // Human68K can handle filenames of (18+3) characters, + // but it does not use the VFAT format. + // ------------------------------------------------------------------------- +#if _USE_HUMAN68K_FNAME + p += 1; + const BYTE * const begin = dp->dir + DIR_HU68K_EXNAME; + const BYTE *end = dp->dir + DIR_HU68K_EXNAME + 10; + const BYTE *q = begin; + while (*q && q < end) + q++; + end = q; + if (q > begin) { + // move suffix to tail. (get space for extend.) + TCHAR *const base = p; + TCHAR *dot = NULL; + while (--p > fno->fname) { + if (*p == '.') { + dot = p; + // p = dot + extend + suffix + p += (end - begin) + (base - dot); + const TCHAR *s = base; + while (s > dot) + *--p = *--s; + p = dot; + break; + } + } + if (!dot) + p = base; + // insert/append extended part. + const BYTE *s = begin; + while (s < end) + *p++ = *s++; + } +#endif + #if _USE_LFN if (fno->lfname) { WCHAR w, *lfn; diff --git a/fatfs/ff.h b/fatfs/ff.h index a93d9a2..92e0d5e 100644 --- a/fatfs/ff.h +++ b/fatfs/ff.h @@ -166,7 +166,11 @@ typedef struct { WORD fdate; /* Last modified date */ WORD ftime; /* Last modified time */ BYTE fattrib; /* Attribute */ +#if _USE_HUMAN68K_FNAME + TCHAR fname[23]; /* Short file name (18.3 human68k format) */ +#else TCHAR fname[13]; /* Short file name (8.3 format) */ +#endif #if _USE_LFN TCHAR* lfname; /* Pointer to the LFN buffer */ UINT lfsize; /* Size of LFN buffer in TCHAR */ diff --git a/fatfs/ffconf.h b/fatfs/ffconf.h index 21d0bed..1bad9cd 100644 --- a/fatfs/ffconf.h +++ b/fatfs/ffconf.h @@ -5,6 +5,8 @@ #ifndef _FFCONF #define _FFCONF 8051 /* Revision ID */ +#define _USE_HUMAN68K_FNAME 1 + /*---------------------------------------------------------------------------/ / Functions and Buffer Configurations @@ -89,7 +91,7 @@ / 1 - ASCII (Valid for only non-LFN configuration) */ -#define _USE_LFN 2 /* 0 to 3 */ +#define _USE_LFN 0 /* 0 to 3 */ #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ /* The _USE_LFN option switches the LFN feature. / From 470a0986f3dcc5d886e885c8881759ed179013da Mon Sep 17 00:00:00 2001 From: yumimint Date: Tue, 14 Apr 2026 00:31:52 +0900 Subject: [PATCH 2/8] Implement Human68k extended filename handling in FatFs --- fatfs/ff.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 14 deletions(-) diff --git a/fatfs/ff.c b/fatfs/ff.c index bc6ca7e..0ebf71e 100644 --- a/fatfs/ff.c +++ b/fatfs/ff.c @@ -508,25 +508,30 @@ static FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */ #endif + +// #define lengthof(a) ((int)(sizeof(a)/sizeof((a)[0]))) +// #define SFN_LEN lengthof(((FILINFO*)0)->fname) +#define SFN_LEN 32 + #if _USE_LFN == 0 /* No LFN feature */ -#define DEF_NAMEBUF BYTE sfn[12] +#define DEF_NAMEBUF BYTE sfn[SFN_LEN] #define INIT_BUF(dobj) (dobj).fn = sfn #define FREE_BUF() #elif _USE_LFN == 1 /* LFN feature with static working buffer */ static WCHAR LfnBuf[_MAX_LFN+1]; -#define DEF_NAMEBUF BYTE sfn[12] +#define DEF_NAMEBUF BYTE sfn[SFN_LEN] #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; } #define FREE_BUF() #elif _USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */ -#define DEF_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1] +#define DEF_NAMEBUF BYTE sfn[SFN_LEN]; WCHAR lbuf[_MAX_LFN+1] #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; } #define FREE_BUF() #elif _USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */ -#define DEF_NAMEBUF BYTE sfn[12]; WCHAR *lfn +#define DEF_NAMEBUF BYTE sfn[SFN_LEN]; WCHAR *lfn #define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); \ if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); \ (dobj).lfn = lfn; (dobj).fn = sfn; } @@ -1540,8 +1545,14 @@ FRESULT dir_find ( // printf("mem_cmp(%c%c%c%c%c%c%c%c.%c%c%c, %c%c%c%c%c%c%c%c.%c%c%c, 11);\n", // dir[0], dir[1], dir[2], dir[3], dir[4], dir[5], dir[6], dir[7], dir[8], dir[9], dir[10], // dp->fn[0], dp->fn[1], dp->fn[2], dp->fn[3], dp->fn[4], dp->fn[5], dp->fn[6], dp->fn[7], dp->fn[8], dp->fn[9], dp->fn[10]); +#if _USE_HUMAN68K_FNAME + if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dp->fn, 11) && + !mem_cmp(dir + DIR_HU68K_EXNAME, dp->fn + DIR_HU68K_EXNAME, 10)) /* Is it a valid entry? */ + break; +#else if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dp->fn, 11)) /* Is it a valid entry? */ break; +#endif /* #if _USE_HUMAN68K_FNAME */ #endif res = dir_next(dp, 0); /* Next entry */ } while (res == FR_OK); @@ -1793,27 +1804,34 @@ void get_fileinfo ( /* No return code */ q++; end = q; if (q > begin) { - // move suffix to tail. (get space for extend.) TCHAR *const base = p; TCHAR *dot = NULL; + // move suffix to tail. (get space for ex_name.) while (--p > fno->fname) { if (*p == '.') { dot = p; - // p = dot + extend + suffix + // p = dot + ex_name + suffix p += (end - begin) + (base - dot); const TCHAR *s = base; while (s > dot) *--p = *--s; - p = dot; break; } } - if (!dot) - p = base; - // insert/append extended part. - const BYTE *s = begin; - while (s < end) - *p++ = *s++; + if (dot) { + // [name] + + [suffix] + const BYTE *s = begin; + p = dot; + while (s < end) + *p++ = *s++; + } else { + // [name] + + const BYTE *s = begin; + p = base - 1; + while (s < end) + *p++ = *s++; + *p = 0; + } } #endif @@ -1984,6 +2002,7 @@ FRESULT create_name ( for (p = *path; *p == '/' || *p == '\\'; p++) ; /* Strip duplicated separator */ sfn = dp->fn; mem_set(sfn, ' ', 11); + si = i = b = 0; ni = 8; #if _FS_RPATH if (p[si] == '.') { /* Is this a dot entry? */ @@ -1998,6 +2017,55 @@ FRESULT create_name ( return FR_OK; } #endif +#if _USE_HUMAN68K_FNAME + mem_set(sfn + DIR_HU68K_EXNAME, 0, 10); + const char *const start = p; + for (;; p++) { + c = *p; + if (c < ' ' || c == '/') + break; + } + sfn[NS] = (c < ' ') ? NS_LAST : 0; + + const char *end = p; + if (start == end) return FR_INVALID_NAME; + + // find last dot + const char *dot = NULL; + while (--p > start) { /* NOT include first dot */ + if (*p == '.') { + dot = p; + break; + } + } + + // store ext(3) + if (dot == p && (end - p) <= 4 /* && p != start*/) { + char *q = sfn + 8; + p += 1; // skip dot + while (p < end) + *q++ = *p++; + end = dot; + } + + // store name(8) + p = start; + if ((p - end) > 18) + return FR_INVALID_NAME; /* too long name*/ + const char *pend = p + 8; + if (pend > end) pend = end; + char *q = sfn; + while (p < pend) + *q++ = *p++; + + // store ex-name(10) + q = sfn + DIR_HU68K_EXNAME; + while (p < end) + *q++ = *p++; + + *path = p; /* Return pointer to the next segment */ + +#else /* #if _USE_HUMAN68K_FNAME */ for (;;) { c = (BYTE)p[si++]; if (c <= ' ' || c == '/' || c == '\\') break; /* Break on end of segment */ @@ -2046,9 +2114,10 @@ FRESULT create_name ( if ((b & 0x0C) == 0x04) c |= NS_BODY; /* NT flag (Name body has only small capital) */ sfn[NS] = c; /* Store NT flag, File name is created */ +#endif /* #if _USE_HUMAN68K_FNAME */ return FR_OK; -#endif +#endif /* #if _USE_LFN */ } From f873bf7a274545f27dc9b3e0ac3e616e9263ebb3 Mon Sep 17 00:00:00 2001 From: yumimint Date: Tue, 14 Apr 2026 01:53:44 +0900 Subject: [PATCH 3/8] Allow filenames starting with a dot in Human68k configuration --- fatfs/ff.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fatfs/ff.c b/fatfs/ff.c index 0ebf71e..c7d01c9 100644 --- a/fatfs/ff.c +++ b/fatfs/ff.c @@ -1606,8 +1606,14 @@ FRESULT dir_read ( } } #else /* Non LFN configuration */ +#if _USE_HUMAN68K_FNAME + // Allow filenames that start with a dot. + if (c != DDE && a != AM_LFN && (int)(a == AM_VOL) == vol) /* Is it a valid entry? */ + break; +#else if (c != DDE && (_FS_RPATH || c != '.') && a != AM_LFN && (int)(a == AM_VOL) == vol) /* Is it a valid entry? */ break; +#enfif #endif res = dir_next(dp, 0); /* Next entry */ if (res != FR_OK) break; From c94541616706e745f3571d1d93b6451bf1df9e00 Mon Sep 17 00:00:00 2001 From: yumimint Date: Tue, 14 Apr 2026 02:57:25 +0900 Subject: [PATCH 4/8] Remove unnecessary object file from Makefile and fix preprocessor directive in ff.c --- Makefile | 2 +- fatfs/ff.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2206d9e..b95c12c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ endif all: fathuman -fathuman: main.o fatfs/ff.o fatfs/option/cc932.o +fathuman: main.o fatfs/ff.o gcc $^ -o $@ $(LDFLAGS) %.o: %.c diff --git a/fatfs/ff.c b/fatfs/ff.c index c7d01c9..defe6fb 100644 --- a/fatfs/ff.c +++ b/fatfs/ff.c @@ -1613,7 +1613,7 @@ FRESULT dir_read ( #else if (c != DDE && (_FS_RPATH || c != '.') && a != AM_LFN && (int)(a == AM_VOL) == vol) /* Is it a valid entry? */ break; -#enfif +#endif #endif res = dir_next(dp, 0); /* Next entry */ if (res != FR_OK) break; From f0f784a93cd84a8ded1e468828f09a43f8cab39a Mon Sep 17 00:00:00 2001 From: yumimint Date: Tue, 14 Apr 2026 10:15:43 +0900 Subject: [PATCH 5/8] Bug Fix Fixed an issue where the correct result was not obtained when the first 8 characters contained a dot. --- fatfs/ff.c | 93 +++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/fatfs/ff.c b/fatfs/ff.c index defe6fb..6b7ac46 100644 --- a/fatfs/ff.c +++ b/fatfs/ff.c @@ -1763,13 +1763,58 @@ void get_fileinfo ( /* No return code */ FILINFO* fno /* Pointer to the file information to be filled */ ) { +#if _USE_HUMAN68K_FNAME +// ------------------------------------------------------------------------- +// Human68K can handle filenames of (18+3) characters, +// but it does not use the VFAT format. +// ------------------------------------------------------------------------- + /* Get SFN */ + TCHAR *p = fno->fname; + if (dp->sect == 0) { + *p = 0; /* Terminate SFN string by a \0 */ + return; + } + + const BYTE *const dir = dp->dir; + const BYTE *s = dir; + const BYTE *q = dir + 8; + + while (q > dir && q[-1] == ' ') + --q; + while (s < q) + *p++ = *s++; + + s = dir + DIR_HU68K_EXNAME; + q = s + 10; + while (s < q) { + if (*s == 0) + break; + *p++ = *s++; + } + + s = dir + 8; + if (*s != ' ') { + *p++ = '.'; + q = s + 3; + while (q > (dir + 8) && q[-1] == ' ') + --q; + while (s < q) + *p++ = *s++; + } + *p = 0; + + fno->fattrib = dir[DIR_Attr]; /* Attribute */ + fno->fsize = LD_DWORD(dir+DIR_FileSize); /* Size */ + fno->fdate = LD_WORD(dir+DIR_WrtDate); /* Date */ + fno->ftime = LD_WORD(dir+DIR_WrtTime); /* Time */ +#else UINT i; TCHAR *p, c; p = fno->fname; if (dp->sect) { /* Get SFN */ - const BYTE *dir = dp->dir; + BYTE *dir = dp->dir; i = 0; while (i < 11) { /* Copy name body and extension */ @@ -1796,51 +1841,6 @@ void get_fileinfo ( /* No return code */ } *p = 0; /* Terminate SFN string by a \0 */ - // ------------------------------------------------------------------------- - // update FILINFO.fname for Human68k - // Human68K can handle filenames of (18+3) characters, - // but it does not use the VFAT format. - // ------------------------------------------------------------------------- -#if _USE_HUMAN68K_FNAME - p += 1; - const BYTE * const begin = dp->dir + DIR_HU68K_EXNAME; - const BYTE *end = dp->dir + DIR_HU68K_EXNAME + 10; - const BYTE *q = begin; - while (*q && q < end) - q++; - end = q; - if (q > begin) { - TCHAR *const base = p; - TCHAR *dot = NULL; - // move suffix to tail. (get space for ex_name.) - while (--p > fno->fname) { - if (*p == '.') { - dot = p; - // p = dot + ex_name + suffix - p += (end - begin) + (base - dot); - const TCHAR *s = base; - while (s > dot) - *--p = *--s; - break; - } - } - if (dot) { - // [name] + + [suffix] - const BYTE *s = begin; - p = dot; - while (s < end) - *p++ = *s++; - } else { - // [name] + - const BYTE *s = begin; - p = base - 1; - while (s < end) - *p++ = *s++; - *p = 0; - } - } -#endif - #if _USE_LFN if (fno->lfname) { WCHAR w, *lfn; @@ -1862,6 +1862,7 @@ void get_fileinfo ( /* No return code */ p[i] = 0; /* Terminate LFN string by a \0 */ } #endif +#endif } #endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2*/ From 25e1bc8a2bd29976c469693468d99b3f76b9c1de Mon Sep 17 00:00:00 2001 From: yumimint Date: Tue, 14 Apr 2026 12:59:33 +0900 Subject: [PATCH 6/8] Refactor Human68K filename handling: unify feature flags and adjust buffer sizes --- fatfs/ff.c | 33 ++++++++++++++++++--------------- fatfs/ff.h | 2 +- fatfs/ffconf.h | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/fatfs/ff.c b/fatfs/ff.c index 6b7ac46..148ba43 100644 --- a/fatfs/ff.c +++ b/fatfs/ff.c @@ -508,30 +508,33 @@ static FILESEM Files[_FS_LOCK]; /* Open object lock semaphores */ #endif - -// #define lengthof(a) ((int)(sizeof(a)/sizeof((a)[0]))) -// #define SFN_LEN lengthof(((FILINFO*)0)->fname) -#define SFN_LEN 32 +#if _USE_HUMAN68K && _USE_LFN != 0 +#error Cannot use LFN feature with HUMAN68K +#endif #if _USE_LFN == 0 /* No LFN feature */ -#define DEF_NAMEBUF BYTE sfn[SFN_LEN] +#if _USE_HUMAN68K +#define DEF_NAMEBUF BYTE sfn[22] +#else +#define DEF_NAMEBUF BYTE sfn[12] +#endif #define INIT_BUF(dobj) (dobj).fn = sfn #define FREE_BUF() #elif _USE_LFN == 1 /* LFN feature with static working buffer */ static WCHAR LfnBuf[_MAX_LFN+1]; -#define DEF_NAMEBUF BYTE sfn[SFN_LEN] +#define DEF_NAMEBUF BYTE sfn[12] #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; } #define FREE_BUF() #elif _USE_LFN == 2 /* LFN feature with dynamic working buffer on the stack */ -#define DEF_NAMEBUF BYTE sfn[SFN_LEN]; WCHAR lbuf[_MAX_LFN+1] +#define DEF_NAMEBUF BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1] #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = lbuf; } #define FREE_BUF() #elif _USE_LFN == 3 /* LFN feature with dynamic working buffer on the heap */ -#define DEF_NAMEBUF BYTE sfn[SFN_LEN]; WCHAR *lfn +#define DEF_NAMEBUF BYTE sfn[12]; WCHAR *lfn #define INIT_BUF(dobj) { lfn = ff_memalloc((_MAX_LFN + 1) * 2); \ if (!lfn) LEAVE_FF((dobj).fs, FR_NOT_ENOUGH_CORE); \ (dobj).lfn = lfn; (dobj).fn = sfn; } @@ -1545,14 +1548,14 @@ FRESULT dir_find ( // printf("mem_cmp(%c%c%c%c%c%c%c%c.%c%c%c, %c%c%c%c%c%c%c%c.%c%c%c, 11);\n", // dir[0], dir[1], dir[2], dir[3], dir[4], dir[5], dir[6], dir[7], dir[8], dir[9], dir[10], // dp->fn[0], dp->fn[1], dp->fn[2], dp->fn[3], dp->fn[4], dp->fn[5], dp->fn[6], dp->fn[7], dp->fn[8], dp->fn[9], dp->fn[10]); -#if _USE_HUMAN68K_FNAME +#if _USE_HUMAN68K if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dp->fn, 11) && !mem_cmp(dir + DIR_HU68K_EXNAME, dp->fn + DIR_HU68K_EXNAME, 10)) /* Is it a valid entry? */ break; #else if (!(dir[DIR_Attr] & AM_VOL) && !mem_cmp(dir, dp->fn, 11)) /* Is it a valid entry? */ break; -#endif /* #if _USE_HUMAN68K_FNAME */ +#endif /* #if _USE_HUMAN68K */ #endif res = dir_next(dp, 0); /* Next entry */ } while (res == FR_OK); @@ -1606,7 +1609,7 @@ FRESULT dir_read ( } } #else /* Non LFN configuration */ -#if _USE_HUMAN68K_FNAME +#if _USE_HUMAN68K // Allow filenames that start with a dot. if (c != DDE && a != AM_LFN && (int)(a == AM_VOL) == vol) /* Is it a valid entry? */ break; @@ -1763,7 +1766,7 @@ void get_fileinfo ( /* No return code */ FILINFO* fno /* Pointer to the file information to be filled */ ) { -#if _USE_HUMAN68K_FNAME +#if _USE_HUMAN68K // ------------------------------------------------------------------------- // Human68K can handle filenames of (18+3) characters, // but it does not use the VFAT format. @@ -2024,7 +2027,7 @@ FRESULT create_name ( return FR_OK; } #endif -#if _USE_HUMAN68K_FNAME +#if _USE_HUMAN68K mem_set(sfn + DIR_HU68K_EXNAME, 0, 10); const char *const start = p; for (;; p++) { @@ -2072,7 +2075,7 @@ FRESULT create_name ( *path = p; /* Return pointer to the next segment */ -#else /* #if _USE_HUMAN68K_FNAME */ +#else /* #if _USE_HUMAN68K */ for (;;) { c = (BYTE)p[si++]; if (c <= ' ' || c == '/' || c == '\\') break; /* Break on end of segment */ @@ -2121,7 +2124,7 @@ FRESULT create_name ( if ((b & 0x0C) == 0x04) c |= NS_BODY; /* NT flag (Name body has only small capital) */ sfn[NS] = c; /* Store NT flag, File name is created */ -#endif /* #if _USE_HUMAN68K_FNAME */ +#endif /* #if _USE_HUMAN68K */ return FR_OK; #endif /* #if _USE_LFN */ diff --git a/fatfs/ff.h b/fatfs/ff.h index 92e0d5e..1c0ded5 100644 --- a/fatfs/ff.h +++ b/fatfs/ff.h @@ -166,7 +166,7 @@ typedef struct { WORD fdate; /* Last modified date */ WORD ftime; /* Last modified time */ BYTE fattrib; /* Attribute */ -#if _USE_HUMAN68K_FNAME +#if _USE_HUMAN68K TCHAR fname[23]; /* Short file name (18.3 human68k format) */ #else TCHAR fname[13]; /* Short file name (8.3 format) */ diff --git a/fatfs/ffconf.h b/fatfs/ffconf.h index 1bad9cd..65ae692 100644 --- a/fatfs/ffconf.h +++ b/fatfs/ffconf.h @@ -5,7 +5,7 @@ #ifndef _FFCONF #define _FFCONF 8051 /* Revision ID */ -#define _USE_HUMAN68K_FNAME 1 +#define _USE_HUMAN68K 1 /*---------------------------------------------------------------------------/ From cb2bc385af849cb36bef94d3a9993ac7adfe9449 Mon Sep 17 00:00:00 2001 From: yumimint Date: Wed, 22 Apr 2026 02:40:34 +0900 Subject: [PATCH 7/8] Fix name length validation logic in create_name function --- fatfs/ff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fatfs/ff.c b/fatfs/ff.c index 148ba43..e2ec872 100644 --- a/fatfs/ff.c +++ b/fatfs/ff.c @@ -117,7 +117,7 @@ #include "ff.h" /* Declarations of FatFs API */ #include "diskio.h" /* Declarations of disk I/O functions */ - +#include @@ -2060,7 +2060,7 @@ FRESULT create_name ( // store name(8) p = start; - if ((p - end) > 18) + if ((end - p) > 18) return FR_INVALID_NAME; /* too long name*/ const char *pend = p + 8; if (pend > end) pend = end; From 79b048df44e45df87e7c9ee4f2b5012cff6837fe Mon Sep 17 00:00:00 2001 From: yumimint Date: Wed, 22 Apr 2026 02:55:30 +0900 Subject: [PATCH 8/8] ffconf.h: Disable unused features for mkfs, label, and string encoding --- fatfs/ffconf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fatfs/ffconf.h b/fatfs/ffconf.h index 65ae692..4ece666 100644 --- a/fatfs/ffconf.h +++ b/fatfs/ffconf.h @@ -39,7 +39,7 @@ /* To enable string functions, set _USE_STRFUNC to 1 or 2. */ -#define _USE_MKFS 1 /* 0:Disable or 1:Enable */ +#define _USE_MKFS 0 /* 0:Disable or 1:Enable */ /* To enable f_mkfs() function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */ @@ -47,7 +47,7 @@ /* To enable fast seek feature, set _USE_FASTSEEK to 1. */ -#define _USE_LABEL 1 /* 0:Disable or 1:Enable */ +#define _USE_LABEL 0 /* 0:Disable or 1:Enable */ /* To enable volume label functions, set _USE_LAVEL to 1 */ @@ -116,7 +116,7 @@ / functions. This option must be 0 when LFN feature is not enabled. */ -#define _STRF_ENCODE 3 /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */ +#define _STRF_ENCODE 0 /* 0:ANSI/OEM, 1:UTF-16LE, 2:UTF-16BE, 3:UTF-8 */ /* When Unicode API is enabled by _LFN_UNICODE option, this option selects the character / encoding on the file to be read/written via string I/O functions, f_gets(), f_putc(), / f_puts and f_printf(). This option has no effect when Unicode API is not enabled. */