The FAT type determination in fsck_msdosfs is wrong. In the code we used NumClusters as the upper (non-inclusive) boundary of valid cluster number, so the actual value was 2 (CLUST_FIRST) more than the real number of clusters. Therefore, it's not right to use NumClusters as it is today to determine FAT type.
Proposed fix: https://reviews.freebsd.org/D23082
A commit references this bug: Author: delphij Date: Sat Jan 11 17:41:20 UTC 2020 New revision: 356636 URL: https://svnweb.freebsd.org/changeset/base/356636 Log: Correct off-by-two issue when determining FAT type. In the code we used NumClusters as the upper (non-inclusive) boundary of valid cluster number, so the actual value was 2 (CLUST_FIRST) more than the real number of clusters. This causes a FAT16 media with 65524 clusters be treated as FAT32 and might affect FAT12 media with 4084 clusters as well. To fix this, we increment NumClusters by CLUST_FIRST after the type determination. PR: 243179 MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D23082 Changes: head/sbin/fsck_msdosfs/boot.c
A commit references this bug: Author: delphij Date: Tue Jan 28 07:49:52 UTC 2020 New revision: 357196 URL: https://svnweb.freebsd.org/changeset/base/357196 Log: MFC r356629, r356636 r356629: Apply typo fix from NetBSD, we have already applied all NetBSD changes so update the NetBSD tag while I'm there. r356636: Correct off-by-two issue when determining FAT type. In the code we used NumClusters as the upper (non-inclusive) boundary of valid cluster number, so the actual value was 2 (CLUST_FIRST) more than the real number of clusters. This causes a FAT16 media with 65524 clusters be treated as FAT32 and might affect FAT12 media with 4084 clusters as well. To fix this, we increment NumClusters by CLUST_FIRST after the type determination. PR: 243179 Changes: _U stable/12/ stable/12/sbin/fsck_msdosfs/boot.c