Index: sys/fs/msdosfs/msdosfs_fat.c =================================================================== --- sys/fs/msdosfs/msdosfs_fat.c +++ sys/fs/msdosfs/msdosfs_fat.c @@ -908,6 +908,25 @@ * zero. These represent free clusters. */ pmp->pm_freeclustercount = 0; + + /* + * Check if the FAT is valid and starts in the correct sector. + */ + fatblock(pmp, FATOFS(pmp, CLUST_FIRST), &bn, &bsize, NULL); + error = bread(pmp->pm_devvp, bn, bsize, NOCRED, &bp); + if (error) { + brelse(bp); + return (error); + } + if ((uint8_t)bp->b_data[0] != pmp->pm_bpb.bpbMedia) { + brelse(bp); +#ifdef MSDOSFS_DEBUG + printf("mountmsdosfs(): Media descriptor in BPB" + "does not match FAT ID\n"); +#endif + return EINVAL; + } + for (cn = CLUST_FIRST; cn <= pmp->pm_maxcluster; cn++) { byteoffset = FATOFS(pmp, cn); bo = byteoffset % pmp->pm_fatblocksize;