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