Skip to content

Commit dde7804

Browse files
eduard-sukharevthinkyhead
authored andcommitted
🐛 Fix Long FIlename lookup (MarlinFirmware#25598)
1 parent da2520d commit dde7804

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

Marlin/src/inc/Conditionals_post.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3262,10 +3262,11 @@
32623262

32633263
// Number of VFAT entries used. Each entry has 13 UTF-16 characters
32643264
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
3265-
#define MAX_VFAT_ENTRIES 5
3265+
#define VFAT_ENTRIES_LIMIT 5
32663266
#else
3267-
#define MAX_VFAT_ENTRIES 2
3267+
#define VFAT_ENTRIES_LIMIT 2
32683268
#endif
3269+
#define MAX_VFAT_ENTRIES 20 // by VFAT specs to fit LFN of length 255
32693270

32703271
// Nozzle park for Delta
32713272
#if BOTH(NOZZLE_PARK_FEATURE, DELTA)

Marlin/src/inc/SanityCheck.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,9 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE, "Movement bounds (X_MIN_POS, X_MAX_POS
10481048
#if ENABLED(SDSORT_CACHE_NAMES) && DISABLED(SDSORT_DYNAMIC_RAM)
10491049
#if SDSORT_CACHE_VFATS < 2
10501050
#error "SDSORT_CACHE_VFATS must be 2 or greater!"
1051-
#elif SDSORT_CACHE_VFATS > MAX_VFAT_ENTRIES
1051+
#elif SDSORT_CACHE_VFATS > VFAT_ENTRIES_LIMIT
10521052
#undef SDSORT_CACHE_VFATS
1053-
#define SDSORT_CACHE_VFATS MAX_VFAT_ENTRIES
1053+
#define SDSORT_CACHE_VFATS VFAT_ENTRIES_LIMIT
10541054
#define SDSORT_CACHE_VFATS_WARNING 1
10551055
#endif
10561056
#endif

Marlin/src/inc/Warnings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@
810810
#endif
811811

812812
#if SDSORT_CACHE_VFATS_WARNING
813-
#warning "SDSORT_CACHE_VFATS has been reduced to MAX_VFAT_ENTRIES."
813+
#warning "SDSORT_CACHE_VFATS has been reduced to VFAT_ENTRIES_LIMIT."
814814
#endif
815815
#if SDSORT_CACHE_LPC1768_WARNING
816816
#warning "SDCARD_SORT_ALPHA sub-options overridden for LPC1768 with DOGM LCD SCK overlap."

Marlin/src/sd/SdBaseFile.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,8 @@ bool SdBaseFile::openNext(SdBaseFile *dirFile, uint8_t oflag) {
10031003
bool SdBaseFile::isDirLFN(const dir_t* dir) {
10041004
if (DIR_IS_LONG_NAME(dir)) {
10051005
vfat_t *VFAT = (vfat_t*)dir;
1006-
// Sanity-check the VFAT entry. The first cluster is always set to zero. And the sequence number should be higher than 0
1006+
// Sanity-check the VFAT entry. The first cluster is always set to zero.
1007+
// The sequence number should be higher than 0 and lower than maximum allowed by VFAT spec
10071008
if ((VFAT->firstClusterLow == 0) && WITHIN((VFAT->sequenceNumber & 0x1F), 1, MAX_VFAT_ENTRIES)) return true;
10081009
}
10091010
return false;
@@ -1463,7 +1464,7 @@ int8_t SdBaseFile::readDir(dir_t *dir, char * const longFilename) {
14631464
// Sanity-check the VFAT entry. The first cluster is always set to zero. And the sequence number should be higher than 0
14641465
if (VFAT->firstClusterLow == 0) {
14651466
const uint8_t seq = VFAT->sequenceNumber & 0x1F;
1466-
if (WITHIN(seq, 1, MAX_VFAT_ENTRIES)) {
1467+
if (WITHIN(seq, 1, VFAT_ENTRIES_LIMIT)) {
14671468
if (seq == 1) {
14681469
checksum = VFAT->checksum;
14691470
checksum_error = 0;
@@ -1627,7 +1628,7 @@ bool SdBaseFile::remove() {
16271628
// Check if the entry has a LFN
16281629
bool lastEntry = false;
16291630
// loop back to search for any LFN entries related to this file
1630-
LOOP_S_LE_N(sequenceNumber, 1, MAX_VFAT_ENTRIES) {
1631+
LOOP_S_LE_N(sequenceNumber, 1, VFAT_ENTRIES_LIMIT) {
16311632
dirIndex_ = (dirIndex_ - 1) & 0xF;
16321633
if (dirBlock_ == 0) break;
16331634
if (dirIndex_ == 0xF) dirBlock_--;

Marlin/src/sd/SdFatConfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@
109109
#define LONG_FILENAME_CHARSIZE TERN(UTF_FILENAME_SUPPORT, 2, 1)
110110

111111
// Total bytes needed to store a single long filename
112-
#define LONG_FILENAME_LENGTH (FILENAME_LENGTH * LONG_FILENAME_CHARSIZE * MAX_VFAT_ENTRIES + 1)
112+
#define LONG_FILENAME_LENGTH (FILENAME_LENGTH * LONG_FILENAME_CHARSIZE * VFAT_ENTRIES_LIMIT + 1)

0 commit comments

Comments
 (0)