cdown / rpms / util-linux

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