From e2e9e68f300b5f46ab0b27fc99f8a076d81dc8fc Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 26 Mar 2026 12:51:20 +0000 Subject: [PATCH] [build] Work around syslinux bugs in FAT cluster counting The syslinux function check_fat_bootsect() performs some sanity checks to ensure that the filesystem type string (e.g. "FAT12") is correct for the total number of clusters in the FAT. There is unfortunately a bug in its calculation of the number of sectors occupied by the root directory, which causes it to underestimate the number of sectors by a factor of 32. When the total number of clusters is close to the FAT12 limit of 4096, this bug can cause syslinux to erroneously report that the filesystem has "more than 4084 clusters but claims FAT12". Work around this bug by selecting an explicit cluster size in order to avoid potentially problematic cluster counts. We default to using 4kB clusters, doubling to 8kB if using 4kB would result in a total cluster count near 4096 (the FAT12 limit) or near 65536 (the FAT16 limit). Signed-off-by: Michael Brown --- src/util/genfsimg | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/genfsimg b/src/util/genfsimg index 0309c9134..54e9d4354 100755 --- a/src/util/genfsimg +++ b/src/util/genfsimg @@ -349,7 +349,14 @@ if [ -n "${FATIMG}" ] ; then FATALIGN=$(( FATHEADS * FATSECTS )) FATCYLS=$(( ( FATSIZE + FATALIGN - 1 ) / FATALIGN )) FATSIZE=$(( FATCYLS * FATALIGN )) - FATARGS="-t ${FATCYLS} -h ${FATHEADS} -s ${FATSECTS}" + FATCLUST=8 + if [ "${FATSIZE}" -eq $(( FATCLUST * 4096 )) -o \ + "${FATSIZE}" -eq $(( FATCLUST * 65536 )) ] ; then + # Avoid cluster counts close to the FAT12/FAT16 limits to + # work around syslinux bugs + FATCLUST=$(( FATCLUST * 2 )) + fi + FATARGS="-t ${FATCYLS} -h ${FATHEADS} -s ${FATSECTS} -c ${FATCLUST}" else FATSIZE=2880 FATARGS="-f 1440"