05ad79
diff -up util-linux-2.23.2/libblkid/src/partitions/dos.c.kzak util-linux-2.23.2/libblkid/src/partitions/dos.c
05ad79
--- util-linux-2.23.2/libblkid/src/partitions/dos.c.kzak	2015-08-21 10:16:45.244332027 +0200
05ad79
+++ util-linux-2.23.2/libblkid/src/partitions/dos.c	2015-08-21 10:22:07.181340367 +0200
05ad79
@@ -151,16 +151,6 @@ static int probe_dos_pt(blkid_probe pr,
05ad79
 	if (memcmp(data, BLKID_AIX_MAGIC_STRING, BLKID_AIX_MAGIC_STRLEN) == 0)
05ad79
 		goto nothing;
05ad79
 
05ad79
-	/*
05ad79
-	 * Now that the 55aa signature is present, this is probably
05ad79
-	 * either the boot sector of a FAT filesystem or a DOS-type
05ad79
-	 * partition table.
05ad79
-	 */
05ad79
-	if (blkid_probe_is_vfat(pr) == 1) {
05ad79
-		DBG(LOWPROBE, blkid_debug("probably FAT -- ignore"));
05ad79
-		goto nothing;
05ad79
-	}
05ad79
-
05ad79
 	p0 = (struct dos_partition *) (data + BLKID_MSDOS_PT_OFFSET);
05ad79
 
05ad79
 	/*
05ad79
@@ -182,6 +172,16 @@ static int probe_dos_pt(blkid_probe pr,
05ad79
 		}
05ad79
 	}
05ad79
 
05ad79
+	/*
05ad79
+	 * Now that the 55aa signature is present, this is probably
05ad79
+	 * either the boot sector of a FAT filesystem or a DOS-type
05ad79
+	 * partition table.
05ad79
+	 */
05ad79
+	if (blkid_probe_is_vfat(pr) == 1) {
05ad79
+		DBG(LOWPROBE, blkid_debug("probably FAT -- ignore"));
05ad79
+		goto nothing;
05ad79
+	}
05ad79
+
05ad79
 	blkid_probe_use_wiper(pr, BLKID_MSDOS_PT_OFFSET,
05ad79
 				  512 - BLKID_MSDOS_PT_OFFSET);
05ad79
 
05ad79
diff -up util-linux-2.23.2/libblkid/src/partitions/dos.h.kzak util-linux-2.23.2/libblkid/src/partitions/dos.h
05ad79
--- util-linux-2.23.2/libblkid/src/partitions/dos.h.kzak	2015-08-21 10:34:14.919380422 +0200
05ad79
+++ util-linux-2.23.2/libblkid/src/partitions/dos.h	2015-08-21 10:35:45.221807669 +0200
05ad79
@@ -12,6 +12,12 @@ struct dos_partition {
05ad79
 
05ad79
 #define BLKID_MSDOS_PT_OFFSET		0x1be
05ad79
 
05ad79
+static inline struct dos_partition *mbr_get_partition(unsigned char *mbr, int i)
05ad79
+{
05ad79
+	return (struct dos_partition *)
05ad79
+		(mbr + BLKID_MSDOS_PT_OFFSET + (i * sizeof(struct dos_partition)));
05ad79
+}
05ad79
+
05ad79
 /* assemble badly aligned little endian integer */
05ad79
 static inline unsigned int assemble4le(const unsigned char *p)
05ad79
 {
05ad79
diff -up util-linux-2.23.2/libblkid/src/superblocks/vfat.c.kzak util-linux-2.23.2/libblkid/src/superblocks/vfat.c
05ad79
--- util-linux-2.23.2/libblkid/src/superblocks/vfat.c.kzak	2015-08-21 10:10:12.111906711 +0200
05ad79
+++ util-linux-2.23.2/libblkid/src/superblocks/vfat.c	2015-08-21 10:35:07.733045452 +0200
05ad79
@@ -16,6 +16,7 @@
05ad79
 #include <ctype.h>
05ad79
 #include <stdint.h>
05ad79
 
05ad79
+#include "partitions/dos.h"
05ad79
 #include "superblocks.h"
05ad79
 
05ad79
 /* Yucky misaligned values */
05ad79
@@ -169,7 +170,8 @@ static unsigned char *search_fat_label(b
05ad79
 	return NULL;
05ad79
 }
05ad79
 
05ad79
-static int fat_valid_superblock(const struct blkid_idmag *mag,
05ad79
+static int fat_valid_superblock(blkid_probe pr,
05ad79
+			const struct blkid_idmag *mag,
05ad79
 			struct msdos_super_block *ms,
05ad79
 			struct vfat_super_block *vs,
05ad79
 			uint32_t *cluster_count, uint32_t *fat_size)
05ad79
@@ -243,6 +245,20 @@ static int fat_valid_superblock(const st
05ad79
 	if (cluster_count)
05ad79
 		*cluster_count = __cluster_count;
05ad79
 
05ad79
+	if (blkid_probe_is_wholedisk(pr)) {
05ad79
+		/* OK, seems like FAT, but it's possible that we found boot
05ad79
+		 * sector with crazy FAT-like stuff (magic strings, media,
05ad79
+		 * etc..) before MBR. Let's make sure that there is no MBR with
05ad79
+		 * usable partition. */
05ad79
+		unsigned char *buf = (unsigned char *) ms;
05ad79
+		if (is_valid_mbr_signature(buf)) {
05ad79
+			struct dos_partition *p0 = mbr_get_partition(buf, 0);
05ad79
+			if (dos_partition_size(p0) != 0 &&
05ad79
+			    (p0->boot_ind == 0 || p0->boot_ind == 0x80))
05ad79
+				return 0;
05ad79
+		}
05ad79
+	}
05ad79
+
05ad79
 	return 1;	/* valid */
05ad79
 }
05ad79
 
05ad79
@@ -270,7 +286,7 @@ int blkid_probe_is_vfat(blkid_probe pr)
05ad79
 	if (!vs)
05ad79
 		return errno ? -errno : 0;
05ad79
 
05ad79
-	return fat_valid_superblock(mag, ms, vs, NULL, NULL);
05ad79
+	return fat_valid_superblock(pr, mag, ms, vs, NULL, NULL);
05ad79
 }
05ad79
 
05ad79
 /* FAT label extraction from the root directory taken from Kay
05ad79
@@ -293,7 +309,7 @@ static int probe_vfat(blkid_probe pr, co
05ad79
 	if (!vs)
05ad79
 		return errno ? -errno : 1;
05ad79
 
05ad79
-	if (!fat_valid_superblock(mag, ms, vs, &cluster_count, &fat_size))
05ad79
+	if (!fat_valid_superblock(pr, mag, ms, vs, &cluster_count, &fat_size))
05ad79
 		return 1;
05ad79
 
05ad79
 	sector_size = unaligned_le16(&ms->ms_sector_size);