rpms/util-linux-ng/F-13 util-linux-ng-2.17-blkid-cdrom.patch, NONE, 1.1 util-linux-ng-2.17-blkid-raid.patch, NONE, 1.1 util-linux-ng.spec, 1.82, 1.83

kzak kzak at fedoraproject.org
Tue May 4 09:06:38 UTC 2010


Author: kzak

Update of /cvs/pkgs/rpms/util-linux-ng/F-13
In directory cvs01.phx2.fedoraproject.org:/tmp/cvs-serv18728

Modified Files:
	util-linux-ng.spec 
Added Files:
	util-linux-ng-2.17-blkid-cdrom.patch 
	util-linux-ng-2.17-blkid-raid.patch 
Log Message:
* Tue May  4 2010 Karel Zak <kzak at redhat.com> 2.17.2-4
- #588668 - F13: don't probe for RAIDs on CD-ROMs
- #543749 - After upgrade from Fedora 11, RAID-1 mdraid assembles incorrectly 


util-linux-ng-2.17-blkid-cdrom.patch:
 blkidP.h                  |    2 ++
 probe.c                   |   14 ++++++++++++++
 superblocks/superblocks.c |    5 +++++
 3 files changed, 21 insertions(+)

--- NEW FILE util-linux-ng-2.17-blkid-cdrom.patch ---

based on upstream patch:

	commit 55113b15afe5f61fc917c22a9d8d47f89b37c757
	Author: M.S.Colclough <m.s.colclough at bham.ac.uk>
	Date:   Wed Mar 31 18:11:00 2010 +0200

	    libblkid: avoid probing CDs for RAID
	    
	    RAID probing of CD/DVD can yield errors because of well-known problem
	    in reading the end of the disk with some disk/drive combinations.
	    Borrow CD detection method from udev and skip the RAID tests for
	    these devices.
	    
	    [kzak at redhat.com: - check for linux/cdrom.h in ./configure
			      - add #ifdef around the ioctl call
			      - call the ioctl for block devices only]
	    
	    Signed-off-by: Mark Colclough <m.s.colclough at bham.ac.uk>
	    Signed-off-by: Karel Zak <kzak at redhat.com>


diff -up util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h.kzak util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h
--- util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h.kzak	2010-05-03 11:46:12.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h	2010-05-03 11:48:23.000000000 +0200
@@ -210,6 +210,7 @@ struct blkid_struct_probe
 /* flags */
 #define BLKID_PRIVATE_FD	(1 << 1)	/* see blkid_new_probe_from_filename() */
 #define BLKID_TINY_DEV		(1 << 2)	/* <= 1.47MiB (floppy or so) */
+#define BLKID_CDROM_DEV		(1 << 3)	/* is a CD/DVD drive */
 
 /*
  * Evaluation methods (for blkid_eval_* API)
@@ -364,6 +365,7 @@ extern void blkid_free_dev(blkid_dev dev
 
 /* probe.c */
 extern int blkid_probe_is_tiny(blkid_probe pr);
+extern int blkid_probe_is_cdrom(blkid_probe pr);
 extern unsigned char *blkid_probe_get_buffer(blkid_probe pr,
                                 blkid_loff_t off, blkid_loff_t len);
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/probe.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/probe.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/probe.c.kzak	2010-03-22 09:14:21.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/probe.c	2010-05-03 11:48:23.000000000 +0200
@@ -77,6 +77,7 @@
 #include <fcntl.h>
 #include <ctype.h>
 #include <sys/types.h>
+#include <linux/cdrom.h>
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
@@ -545,6 +546,14 @@ int blkid_probe_is_tiny(blkid_probe pr)
 	return pr && (pr->flags & BLKID_TINY_DEV);
 }
 
+/*
+ * CDROMs may fail when probed for RAID (last sector problem)
+ */
+int blkid_probe_is_cdrom(blkid_probe pr)
+{
+	return pr && (pr->flags & BLKID_CDROM_DEV);
+}
+
 /**
  * blkid_probe_set_device:
  * @pr: probe
@@ -570,6 +579,7 @@ int blkid_probe_set_device(blkid_probe p
 
 	pr->flags &= ~BLKID_PRIVATE_FD;
 	pr->flags &= ~BLKID_TINY_DEV;
+	pr->flags &= ~BLKID_CDROM_DEV;
 	pr->fd = fd;
 	pr->off = off;
 	pr->size = 0;
@@ -615,6 +625,10 @@ int blkid_probe_set_device(blkid_probe p
 	if (pr->size <= 1440 * 1024 && !S_ISCHR(pr->mode))
 		pr->flags |= BLKID_TINY_DEV;
 
+#ifdef CDROM_GET_CAPABILITY
+	if (S_ISBLK(pr->mode) && ioctl(fd, CDROM_GET_CAPABILITY, NULL) >= 0)
+		pr->flags |= BLKID_CDROM_DEV;
+#endif
 	return 0;
 err:
 	DBG(DEBUG_LOWPROBE,
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak	2010-03-22 09:14:21.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c	2010-05-03 11:48:23.000000000 +0200
@@ -342,6 +342,11 @@ static int superblocks_probe(blkid_probe
 		    blkid_probe_is_tiny(pr))
 			continue;
 
+		/* don't probe for RAIDs, swap or journal on floppies or CD/DVDs */
+		if ((id->usage & (BLKID_USAGE_RAID | BLKID_USAGE_OTHER)) &&
+		    (blkid_probe_is_tiny(pr) || blkid_probe_is_cdrom(pr)))
+			continue;
+
 		DBG(DEBUG_LOWPROBE, printf("[%d] %s:\n", i, id->name));
 
 		/* try to detect by magic string */

util-linux-ng-2.17-blkid-raid.patch:
 misc-utils/blkid.c                            |   37 +++---
 shlibs/blkid/src/blkidP.h                     |   11 +-
 shlibs/blkid/src/partitions/partitions.c      |   79 ++++++++++++++
 shlibs/blkid/src/probe.c                      |   95 ++++++++++++++++-
 shlibs/blkid/src/superblocks/adaptec_raid.c   |    4 
 shlibs/blkid/src/superblocks/ddf_raid.c       |    7 +
 shlibs/blkid/src/superblocks/drbd.c           |   13 +-
 shlibs/blkid/src/superblocks/highpoint_raid.c |    3 
 shlibs/blkid/src/superblocks/isw_raid.c       |    4 
 shlibs/blkid/src/superblocks/jmicron_raid.c   |    4 
 shlibs/blkid/src/superblocks/linux_raid.c     |    8 +
 shlibs/blkid/src/superblocks/lsi_raid.c       |    4 
 shlibs/blkid/src/superblocks/nvidia_raid.c    |    5 
 shlibs/blkid/src/superblocks/promise_raid.c   |    7 +
 shlibs/blkid/src/superblocks/silicon_raid.c   |    7 +
 shlibs/blkid/src/superblocks/superblocks.c    |  141 +++++++++++++++++++++++---
 shlibs/blkid/src/superblocks/superblocks.h    |    2 
 shlibs/blkid/src/superblocks/sysv.c           |   14 ++
 shlibs/blkid/src/superblocks/ufs.c            |    8 +
 shlibs/blkid/src/superblocks/via_raid.c       |    4 
 tests/expected/blkid/md-raid1-part            |   58 ++++++++++
 tests/expected/blkid/md-raid1-whole           |   58 ++++++++++
 tests/functions.sh                            |    2 
 tests/ts/blkid/md-raid1-part                  |   92 ++++++++++++++++
 tests/ts/blkid/md-raid1-whole                 |   88 ++++++++++++++++
 25 files changed, 699 insertions(+), 56 deletions(-)

--- NEW FILE util-linux-ng-2.17-blkid-raid.patch ---
>From f3705bac52dcbdfa7000081d06cd9f7b3caf134f Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak at redhat.com>
Date: Fri, 30 Apr 2010 10:12:39 +0200
Subject: [PATCH 1/7] libblkid: add functions to get whole-disk devno

Note that these functions are exported to the library API
in the next version (2.18).

Signed-off-by: Karel Zak <kzak at redhat.com>
---
 shlibs/blkid/src/blkidP.h |    3 +++
 shlibs/blkid/src/probe.c  |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff -up util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h.kzak util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h
--- util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h.kzak	2010-05-03 13:11:27.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h	2010-05-03 13:11:46.000000000 +0200
@@ -193,6 +193,7 @@ struct blkid_struct_probe
 	blkid_loff_t		size;		/* end of data on the device */
 
 	dev_t			devno;		/* device number (st.st_rdev) */
+	dev_t			disk_devno;	/* devno of the whole-disk or 0 */
 	unsigned int		blkssz;		/* sector size (BLKSSZGET ioctl) */
 	mode_t			mode;		/* struct stat.sb_mode */
 
@@ -364,6 +365,8 @@ extern blkid_dev blkid_new_dev(void);
 extern void blkid_free_dev(blkid_dev dev);
 
 /* probe.c */
+extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr);
+extern int blkid_probe_is_wholedisk(blkid_probe pr);
 extern int blkid_probe_is_tiny(blkid_probe pr);
 extern int blkid_probe_is_cdrom(blkid_probe pr);
 extern unsigned char *blkid_probe_get_buffer(blkid_probe pr,
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/probe.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/probe.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/probe.c.kzak	2010-05-03 13:11:27.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/probe.c	2010-05-03 13:11:46.000000000 +0200
@@ -988,6 +988,48 @@ dev_t blkid_probe_get_devno(blkid_probe 
 }
 
 /**
+ * blkid_probe_get_wholedisk_devno:
+ * @pr: probe
+ *
+ * Returns: device number of the wholedisk, or 0 for regilar files.
+ */
+dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
+{
+	if (!pr->disk_devno) {
+		dev_t devno, disk_devno = 0;
+
+		devno = blkid_probe_get_devno(pr);
+		if (!devno)
+			return 0;
+
+		 if (blkid_devno_to_wholedisk(devno, NULL, 0, &disk_devno) == 0)
+			pr->disk_devno = disk_devno;
+	}
+	return pr->disk_devno;
+}
+
+/**
+ * blkid_probe_is_wholedisk:
+ * @pr: probe
+ *
+ * Returns: 1 if the device is whole-disk or 0.
+ */
+int blkid_probe_is_wholedisk(blkid_probe pr)
+{
+	dev_t devno, disk_devno;
+
+	devno = blkid_probe_get_devno(pr);
+	if (!devno)
+		return 0;
+
+	disk_devno = blkid_probe_get_wholedisk_devno(pr);
+	if (!disk_devno)
+		return 0;
+
+	return devno == disk_devno;
+}
+
+/**
  * blkid_probe_get_size:
  * @pr: probe
  *

>From c5a5ec0018013b2b97b702efa1d05250d7031e44 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak at redhat.com>
Date: Fri, 30 Apr 2010 09:16:36 +0200
Subject: [PATCH 2/7] libblkid: add partial support for superblock binary API

The API is used only internally.

Signed-off-by: Karel Zak <kzak at redhat.com>
---
 shlibs/blkid/src/superblocks/superblocks.c |  101 +++++++++++++++++++++++++---
 shlibs/blkid/src/superblocks/superblocks.h |    2 +
 2 files changed, 94 insertions(+), 9 deletions(-)

diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak	2010-05-03 13:11:27.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c	2010-05-03 13:14:43.000000000 +0200
@@ -71,6 +71,7 @@
 
 static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn);
 static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn);
+static void superblocks_free(blkid_probe pr, void *data);
 
 static int blkid_probe_set_usage(blkid_probe pr, int usage);
 
@@ -153,9 +154,23 @@ const struct blkid_chaindrv superblocks_
 	.nidinfos     = ARRAY_SIZE(idinfos),
 	.has_fltr     = TRUE,
 	.probe        = superblocks_probe,
-	.safeprobe    = superblocks_safeprobe
+	.safeprobe    = superblocks_safeprobe,
+	.free_data    = superblocks_free
 };
 
+/*
+ * Private chain data
+ *
+ * TODO: export this data by binary interface (see topology.c or partitions.c
+ *       for more details) by blkid_probe_get_superblock() or so.
+ */
+struct blkid_struct_superblock {
+	blkid_loff_t	magic_off;		/* offset of the magic string */
+	int		usage;
+};
+
+/* TODO: move to blkid.h */
+typedef struct blkid_struct_superblock *blkid_superblock;
 
 /**
  * blkid_probe_enable_superblocks:
@@ -295,6 +310,39 @@ int blkid_known_fstype(const char *fstyp
 	return 0;
 }
 
+/* init and returns private data */
+static blkid_superblock superblocks_init_data(blkid_probe pr,
+					struct blkid_chain *chn)
+{
+	DBG(DEBUG_LOWPROBE, printf("initialize superblocks binary data\n"));
+
+	if (chn->data)
+		memset(chn->data, 0,
+			sizeof(struct blkid_struct_superblock));
+	else {
+		chn->data = calloc(1,
+				sizeof(struct blkid_struct_superblock));
+		if (!chn->data)
+			return NULL;
+	}
+	return chn->data;
+}
+
+static void superblocks_free(blkid_probe pr, void *data)
+{
+	free(data);
+}
+
+static blkid_superblock superblocks_copy_data(blkid_superblock dest,
+						blkid_superblock src)
+{
+	if (!src || !dest)
+		return NULL;
+
+	memcpy(dest, src, sizeof(struct blkid_struct_superblock));
+	return dest;
+}
+
 /*
  * The blkid_do_probe() backend.
  */
@@ -316,6 +364,9 @@ static int superblocks_probe(blkid_probe
 		 * is 1 byte */
 		goto nothing;
 
+	if (chn->binary)
+		superblocks_init_data(pr, chn);
+
 	i = chn->idx + 1;
 
 	for ( ; i < ARRAY_SIZE(idinfos); i++) {
@@ -385,15 +436,11 @@ static int superblocks_probe(blkid_probe
 				(unsigned char *) id->name,
 				strlen(id->name) + 1);
 
-		if (chn->flags & BLKID_SUBLKS_USAGE)
-			blkid_probe_set_usage(pr, id->usage);
+		blkid_probe_set_usage(pr, id->usage);
 
-		if (hasmag && (chn->flags & BLKID_SUBLKS_MAGIC)) {
-			blkid_probe_set_value(pr, "SBMAGIC",
-				(unsigned char *) mag->magic, mag->len);
-			blkid_probe_sprintf_value(pr, "SBMAGIC_OFFSET",
-				"%llu",	off);
-		}
+		if (hasmag)
+			blkid_probe_set_magic(pr, off, mag->len,
+					(unsigned char *) mag->magic);
 
 		DBG(DEBUG_LOWPROBE,
 			printf("<-- leaving probing loop (type=%s) [SUBLKS idx=%d]\n",
@@ -422,6 +469,9 @@ nothing:
  */
 static int superblocks_safeprobe(blkid_probe pr, struct blkid_chain *chn)
 {
+	blkid_superblock sb = NULL;
+	struct blkid_struct_superblock sb_buff;
+
 	struct blkid_prval vals[BLKID_NVALS_SUBLKS];
 	int nvals = BLKID_NVALS_SUBLKS;
 	int idx = -1;
@@ -439,6 +489,8 @@ static int superblocks_safeprobe(blkid_p
 			/* save the first result */
 			nvals = blkid_probe_chain_copy_vals(pr, chn, vals, nvals);
 			idx = chn->idx;
+			if (chn->data)
+				sb = superblocks_copy_data(&sb_buff, chn->data);
 		}
 		count++;
 
@@ -462,11 +514,33 @@ static int superblocks_safeprobe(blkid_p
 	/* restore the first result */
 	blkid_probe_chain_reset_vals(pr, chn);
 	blkid_probe_append_vals(pr, vals, nvals);
+	if (sb && chn->data)
+		superblocks_copy_data(chn->data, sb);
 	chn->idx = idx;
 
 	return 0;
 }
 
+int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset,
+			size_t len, unsigned char *magic)
+{
+	int rc = 0;
+	struct blkid_chain *chn = blkid_probe_get_chain(pr);
+
+	if (chn->flags & BLKID_SUBLKS_MAGIC) {
+		if (magic && len)
+			rc = blkid_probe_set_value(pr, "SBMAGIC", magic, len);
+		if (!rc && offset)
+			rc = blkid_probe_sprintf_value(pr, "SBMAGIC_OFFSET",
+					"%llu",	offset);
+	}
+	if (!rc && chn->data) {
+		blkid_superblock sb = (blkid_superblock) chn->data;
+		sb->magic_off = offset;
+	}
+	return rc;
+}
+
 int blkid_probe_set_version(blkid_probe pr, const char *version)
 {
 	struct blkid_chain *chn = blkid_probe_get_chain(pr);
@@ -494,8 +568,17 @@ int blkid_probe_sprintf_version(blkid_pr
 
 static int blkid_probe_set_usage(blkid_probe pr, int usage)
 {
+	struct blkid_chain *chn = blkid_probe_get_chain(pr);
 	char *u = NULL;
 
+	if (chn->data) {
+		blkid_superblock sb = (blkid_superblock) chn->data;
+		sb->usage = usage;
+	}
+
+	if (!(chn->flags & BLKID_SUBLKS_USAGE))
+		return 0;
+
 	if (usage & BLKID_USAGE_FILESYSTEM)
 		u = "filesystem";
 	else if (usage & BLKID_USAGE_RAID)
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.h.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.h
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.h.kzak	2010-03-22 09:05:43.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.h	2010-05-03 13:14:43.000000000 +0200
@@ -68,6 +68,8 @@ extern const struct blkid_idinfo drbd_id
 /*
  * superblock functions
  */
+extern int blkid_probe_set_magic(blkid_probe pr, blkid_loff_t offset,
+		size_t len, unsigned char *magic);
 extern int blkid_probe_set_version(blkid_probe pr, const char *version);
 extern int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...)
 		__attribute__ ((format (printf, 2, 3)));


>From a467be9c5191083612f9fc557d16f801cc1db7ee Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak at redhat.com>
Date: Fri, 30 Apr 2010 09:41:48 +0200
Subject: [PATCH 3/7] libblkid: export magic strings from raids

The library provides detected magic strings by SBMAGIC= and offsets of
the magic strings by SBMAGIC_OFFSET= variables. This patch allows to
support this feature for RAIDs and filesystems where the magic string
is not on fixed position.

Signed-off-by: Karel Zak <kzak at redhat.com>
---
 shlibs/blkid/src/superblocks/adaptec_raid.c   |    4 +++-
 shlibs/blkid/src/superblocks/ddf_raid.c       |    7 ++++++-
 shlibs/blkid/src/superblocks/drbd.c           |   13 ++++++++++---
 shlibs/blkid/src/superblocks/highpoint_raid.c |    3 +++
 shlibs/blkid/src/superblocks/isw_raid.c       |    4 +++-
 shlibs/blkid/src/superblocks/jmicron_raid.c   |    4 +++-
 shlibs/blkid/src/superblocks/linux_raid.c     |    8 ++++++--
 shlibs/blkid/src/superblocks/lsi_raid.c       |    4 +++-
 shlibs/blkid/src/superblocks/nvidia_raid.c    |    5 +++--
 shlibs/blkid/src/superblocks/promise_raid.c   |    7 ++++++-
 shlibs/blkid/src/superblocks/silicon_raid.c   |    7 ++++++-
 shlibs/blkid/src/superblocks/sysv.c           |   14 +++++++++++++-
 shlibs/blkid/src/superblocks/ufs.c            |    8 ++++++++
 shlibs/blkid/src/superblocks/via_raid.c       |    4 ++++
 14 files changed, 77 insertions(+), 15 deletions(-)

diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/adaptec_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/adaptec_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/adaptec_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/adaptec_raid.c	2010-05-03 13:20:20.000000000 +0200
@@ -94,7 +94,9 @@ static int probe_adraid(blkid_probe pr, 
 		return -1;
 	if (blkid_probe_sprintf_version(pr, "%u", ad->resver) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr, off, sizeof(ad->b0idcode),
+				(unsigned char *) &ad->b0idcode))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ddf_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ddf_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ddf_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ddf_raid.c	2010-05-03 13:20:20.000000000 +0200
@@ -32,12 +32,13 @@ static int probe_ddf(blkid_probe pr, con
 	int i;
 	struct ddf_header *ddf = NULL;
 	char version[DDF_REV_LENGTH + 1];
+	uint64_t off;
 
 	if (pr->size < 0x30000)
 		return -1;
 
 	for (i = 0; i < ARRAY_SIZE(hdrs); i++) {
-		uint64_t off = ((pr->size / 0x200) - hdrs[i]) * 0x200;
+		off = ((pr->size / 0x200) - hdrs[i]) * 0x200;
 
 		ddf = (struct ddf_header *) blkid_probe_get_buffer(pr,
 					off,
@@ -61,6 +62,10 @@ static int probe_ddf(blkid_probe pr, con
 
 	if (blkid_probe_set_version(pr, version) != 0)
 		return -1;
+	if (blkid_probe_set_magic(pr, off,
+			sizeof(ddf->signature),
+			(unsigned char *) ddf->signature))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/drbd.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/drbd.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/drbd.c.kzak	2010-03-22 09:13:48.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/drbd.c	2010-05-03 13:20:21.000000000 +0200
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <inttypes.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -75,9 +76,9 @@ static int probe_drbd(blkid_probe pr, co
 		return -1;
 
 	md = (struct md_on_disk_08 *)
-		blkid_probe_get_buffer(pr,
-		off,
-		sizeof(struct md_on_disk_08));
+			blkid_probe_get_buffer(pr,
+					off,
+					sizeof(struct md_on_disk_08));
 	if (!md)
 		return -1;
 
@@ -94,6 +95,12 @@ static int probe_drbd(blkid_probe pr, co
 
 	blkid_probe_set_version(pr, "v08");
 
+	if (blkid_probe_set_magic(pr,
+				off + offsetof(struct md_on_disk_08, magic),
+				sizeof(md->magic),
+				(unsigned char *) &md->magic))
+		return -1;
+
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/highpoint_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/highpoint_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/highpoint_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/highpoint_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -41,6 +41,9 @@ static int probe_highpoint45x(blkid_prob
 	magic = le32_to_cpu(hpt->magic);
 	if (magic != HPT45X_MAGIC_OK && magic != HPT45X_MAGIC_BAD)
 		return -1;
+	if (blkid_probe_set_magic(pr, off, sizeof(hpt->magic),
+				(unsigned char *) &hpt->magic))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/isw_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/isw_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/isw_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/isw_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -46,7 +46,9 @@ static int probe_iswraid(blkid_probe pr,
 	if (blkid_probe_sprintf_version(pr, "%6s",
 			&isw->sig[sizeof(ISW_SIGNATURE)-1]) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr, off, sizeof(isw->sig),
+				(unsigned char *) isw->sig))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/jmicron_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/jmicron_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/jmicron_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/jmicron_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -45,7 +45,9 @@ static int probe_jmraid(blkid_probe pr, 
 	if (blkid_probe_sprintf_version(pr, "%u.%u",
 				jm->major_version, jm->minor_version) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr, off, sizeof(jm->signature),
+				(unsigned char *) jm->signature))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/linux_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/linux_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/linux_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/linux_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -95,7 +95,9 @@ static int probe_raid0(blkid_probe pr, o
 
 	if (blkid_probe_set_uuid(pr, (unsigned char *) uuid.bytes) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr, off, sizeof(mdp0->md_magic),
+				(unsigned char *) &mdp0->md_magic))
+		return -1;
 	return 0;
 }
 
@@ -118,7 +120,9 @@ static int probe_raid1(blkid_probe pr, o
 	if (blkid_probe_set_label(pr, mdp1->set_name,
 				sizeof(mdp1->set_name)) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr, off, sizeof(mdp1->magic),
+				(unsigned char *) &mdp1->magic))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/lsi_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/lsi_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/lsi_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/lsi_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -41,7 +41,9 @@ static int probe_lsiraid(blkid_probe pr,
 
 	if (memcmp(lsi->sig, LSI_SIGNATURE, sizeof(LSI_SIGNATURE)-1) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr, off, sizeof(lsi->sig),
+				(unsigned char *) lsi->sig))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/nvidia_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/nvidia_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/nvidia_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/nvidia_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -43,10 +43,11 @@ static int probe_nvraid(blkid_probe pr, 
 
 	if (memcmp(nv->vendor, NVIDIA_SIGNATURE, sizeof(NVIDIA_SIGNATURE)-1) != 0)
 		return -1;
-
 	if (blkid_probe_sprintf_version(pr, "%u", le16_to_cpu(nv->version)) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr, off, sizeof(nv->vendor),
+				(unsigned char *) nv->vendor))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/promise_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/promise_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/promise_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/promise_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -47,8 +47,13 @@ static int probe_pdcraid(blkid_probe pr,
 			return -1;
 
 		if (memcmp(pdc->sig, PDC_SIGNATURE,
-				sizeof(PDC_SIGNATURE) - 1) == 0)
+				sizeof(PDC_SIGNATURE) - 1) == 0) {
+
+			if (blkid_probe_set_magic(pr, off, sizeof(pdc->sig),
+						(unsigned char *) pdc->sig))
+				return -1;
 			return 0;
+		}
 	}
 	return -1;
 }
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/silicon_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/silicon_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/silicon_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/silicon_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <stdint.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -63,7 +64,11 @@ static int probe_silraid(blkid_probe pr,
 				le16_to_cpu(sil->major_ver),
 				le16_to_cpu(sil->minor_ver)) != 0)
 		return -1;
-
+	if (blkid_probe_set_magic(pr,
+			off + offsetof(struct silicon_metadata, magic),
+			sizeof(sil->magic),
+			(unsigned char *) &sil->magic))
+		return -1;
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/sysv.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/sysv.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/sysv.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/sysv.c	2010-05-03 13:20:21.000000000 +0200
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdint.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -107,7 +108,18 @@ static int probe_sysv(blkid_probe pr, co
 
 		if (sb->s_magic == cpu_to_le32(0xfd187e20) ||
 		    sb->s_magic == cpu_to_be32(0xfd187e20)) {
-			blkid_probe_set_label(pr, sb->s_fname, sizeof(sb->s_fname));
+
+			if (blkid_probe_set_label(pr, sb->s_fname,
+						sizeof(sb->s_fname)))
+				return -1;
+
+			if (blkid_probe_set_magic(pr,
+					off + offsetof(struct sysv_super_block,
+								s_magic),
+					sizeof(sb->s_magic),
+					(unsigned char *) &sb->s_magic))
+				return -1;
+
 			return 0;
 		}
 	}
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ufs.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ufs.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ufs.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/ufs.c	2010-05-03 13:20:21.000000000 +0200
@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <stdint.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -205,6 +206,13 @@ found:
 	} else
 		blkid_probe_set_version(pr, "1");
 
+	if (blkid_probe_set_magic(pr,
+			(offsets[i] * 1024) +
+				offsetof(struct ufs_super_block, fs_magic),
+			sizeof(ufs->fs_magic),
+			(unsigned char *) &ufs->fs_magic))
+		return -1;
+
 	return 0;
 }
 
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/via_raid.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/via_raid.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/via_raid.c.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/via_raid.c	2010-05-03 13:20:21.000000000 +0200
@@ -69,6 +69,10 @@ static int probe_viaraid(blkid_probe pr,
 		return -1;
 	if (blkid_probe_sprintf_version(pr, "%u", v->version_number) != 0)
 		return -1;
+	if (blkid_probe_set_magic(pr, off,
+				sizeof(v->signature),
+				(unsigned char *) &v->signature))
+		return -1;
 	return 0;
 }
 

>From 49879b3db3c62ad2be9362e86ad94e1511863d42 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak at redhat.com>
Date: Fri, 30 Apr 2010 10:35:20 +0200
Subject: [PATCH 4/7] libblkid: fix collision between RAID and PT probing

The RAID signature is usually at end of the block device. We have to
differentiate between:

	- RAID signature at the end of disk, and
	- RAID signature at the end of the last partition

The position of the signature is same in both cases... It means we have
to the parse partition table and check if the area where is RAID signature
is covered by any partition. If yes, then the RAID signature belongs to the
partition and has to be ignored during whole-disk probing.

The second problem are RAID1 underlaying disks (=raid members).  The
RAID device could be partitioned, in such a case the partition table
is visible from underlaying devices. These partition tables has to be
ignored. The libblkid ignores partition tables on raid members now.

Note that all these changes are implemented for blkid_do_safeprobe()
only. The others functions allow to access all detected superblocks or
partition tables.

Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=543749
Signed-off-by: Karel Zak <kzak at redhat.com>
---
 shlibs/blkid/src/blkidP.h                  |    8 +++-
 shlibs/blkid/src/partitions/partitions.c   |   79 ++++++++++++++++++++++++++++
 shlibs/blkid/src/probe.c                   |   53 ++++++++++++++++---
 shlibs/blkid/src/superblocks/superblocks.c |   36 ++++++++++++-
 4 files changed, 164 insertions(+), 12 deletions(-)

diff -up util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h.kzak util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h
--- util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h.kzak	2010-05-03 13:19:22.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/blkidP.h	2010-05-03 13:21:25.000000000 +0200
@@ -198,6 +198,7 @@ struct blkid_struct_probe
 	mode_t			mode;		/* struct stat.sb_mode */
 
 	int			flags;		/* private libray flags */
+	int			prob_flags;	/* always zeroized by blkid_do_*() */
 
 	struct list_head	buffers;	/* list of buffers */
 
@@ -208,10 +209,12 @@ struct blkid_struct_probe
 	int			nvals;		/* number of assigned vals */
 };
 
-/* flags */
+/* private flags */
 #define BLKID_PRIVATE_FD	(1 << 1)	/* see blkid_new_probe_from_filename() */
 #define BLKID_TINY_DEV		(1 << 2)	/* <= 1.47MiB (floppy or so) */
 #define BLKID_CDROM_DEV		(1 << 3)	/* is a CD/DVD drive */
+/* private probing flags */
+#define BLKID_PARTS_IGNORE_PT	(1 << 1)	/* ignore partition table */
 
 /*
  * Evaluation methods (for blkid_eval_* API)
@@ -387,6 +390,9 @@ extern int blkid_probe_set_dimension(blk
 
 extern blkid_partlist blkid_probe_get_partlist(blkid_probe pr);
 
+extern int blkid_probe_is_covered_by_pt(blkid_probe pr,
+					blkid_loff_t offset, blkid_loff_t size);
+
 extern void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn);
 extern int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn,
 			                struct blkid_prval *vals, int nvals);
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/partitions/partitions.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/partitions/partitions.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/partitions/partitions.c.kzak	2010-03-22 09:05:43.000000000 +0100
+++ util-linux-ng-2.17.2/shlibs/blkid/src/partitions/partitions.c	2010-05-03 13:21:25.000000000 +0200
@@ -566,6 +566,9 @@ static int partitions_probe(blkid_probe 
 	if (chn->binary)
 		partitions_init_data(pr, chn);
 
+	if (pr->prob_flags & BLKID_PARTS_IGNORE_PT)
+		return 1;
+
 	DBG(DEBUG_LOWPROBE,
 		printf("--> starting probing loop [PARTS idx=%d]\n",
 		chn->idx));
@@ -652,6 +655,82 @@ int blkid_partitions_do_subprobe(blkid_p
 	return rc;
 }
 
+/*
+ * This function is compatible with blkid_probe_get_partitions(), but the
+ * result is not stored in @pr and all probing is independent on the
+ * status of @pr. It's possible to call this function from arbitrary
+ * place without a care about @pr.
+ */
+static blkid_partlist blkid_probe_get_independent_partlist(blkid_probe pr)
+{
+
+	blkid_partlist ls = NULL, org_ls = NULL;
+	struct blkid_chain *chn = &pr->chains[BLKID_CHAIN_PARTS];
+	struct blkid_prval vals[BLKID_NVALS_PARTS];
+	int nvals = BLKID_NVALS_PARTS;
+	int idx;
+
+	/* save old results */
+	nvals = blkid_probe_chain_copy_vals(pr, chn, vals, nvals);
+	idx = chn->idx;
+	if (chn->data) {
+		org_ls = chn->data;
+		chn->data = NULL;
+	}
+
+	ls = blkid_probe_get_partitions(pr);
+
+	/* restore original results */
+	chn->data = org_ls;
+	chn->idx = idx;
+
+	blkid_probe_chain_reset_vals(pr, chn);
+	blkid_probe_append_vals(pr, vals, nvals);
+
+	return ls;
+}
+
+/*
+ * Returns 1 if the device is whole-disk and the area specified by @offset and
+ * @size is covered by any partition.
+ */
+int blkid_probe_is_covered_by_pt(blkid_probe pr,
+				 blkid_loff_t offset, blkid_loff_t size)
+{
+	blkid_partlist ls = NULL;
+	blkid_loff_t start, end;
+	int nparts, i, rc = 0;
+
+	DBG(DEBUG_LOWPROBE, printf(
+		"=> checking if off=%jd size=%jd covered by PT\n",
+		offset, size));
+
+	ls = blkid_probe_get_independent_partlist(pr);
+	if (!ls)
+		goto done;
+
+	nparts = blkid_partlist_numof_partitions(ls);
+	if (!nparts)
+		goto done;
+
+	end = (offset + size) >> 9;
+	start = offset >> 9;
+
+	for (i = 0; i < nparts; i++) {
+		blkid_partition par = &ls->parts[i];
+
+		if (start >= par->start && end <= par->start + par->size) {
+			rc = 1;
+			break;
+		}
+	}
+done:
+	partitions_free_data(pr, (void *)ls);
+
+	DBG(DEBUG_LOWPROBE, printf("<= %s covered by PT\n", rc ? "IS" : "NOT"));
+	return rc;
+}
+
 /**
  * blkid_known_pttype:
  * @pttype: partiton name
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/probe.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/probe.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/probe.c.kzak	2010-05-03 13:19:22.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/probe.c	2010-05-03 13:21:25.000000000 +0200
@@ -288,21 +288,33 @@ struct blkid_chain *blkid_probe_get_chai
 
 void *blkid_probe_get_binary_data(blkid_probe pr, struct blkid_chain *chn)
 {
-	int rc;
+	int rc, org_prob_flags;
+	struct blkid_chain *org_chn;
 
 	if (!pr || !chn)
 		return NULL;
 
+	/* save the current setting -- the binary API has to be completely
+	 * independent on the current probing status
+	 */
+	org_chn = pr->cur_chain;
+	org_prob_flags = pr->prob_flags;
+
 	pr->cur_chain = chn;
+	pr->prob_flags = 0;
 	chn->binary = TRUE;
 	blkid_probe_chain_reset_position(chn);
 
 	rc = chn->driver->probe(pr, chn);
 
 	chn->binary = FALSE;
-	pr->cur_chain = NULL;
 	blkid_probe_chain_reset_position(chn);
 
+	/* restore the original setting
+	 */
+	pr->cur_chain = org_chn;
+	pr->prob_flags = org_prob_flags;
+
 	if (rc != 0)
 		return NULL;
 
@@ -674,6 +686,22 @@ int blkid_probe_set_dimension(blkid_prob
 	return 0;
 }
 
+static inline void blkid_probe_start(blkid_probe pr)
+{
+	if (pr) {
+		pr->cur_chain = NULL;
+		pr->prob_flags = 0;
+	}
+}
+
+static inline void blkid_probe_end(blkid_probe pr)
+{
+	if (pr) {
+		pr->cur_chain = NULL;
+		pr->prob_flags = 0;
+	}
+}
+
 /**
  * blkid_do_probe:
  * @pr: prober
@@ -725,9 +753,10 @@ int blkid_do_probe(blkid_probe pr)
 	do {
 		struct blkid_chain *chn = pr->cur_chain;
 
-		if (!chn)
+		if (!chn) {
+			blkid_probe_start(pr);
 			chn = pr->cur_chain = &pr->chains[0];
-
+		}
 		/* we go to the next chain only when the previous probing
 		 * result was nothing (rc == 1) and when the current chain is
 		 * disabled or we are at end of the current chain (chain->idx +
@@ -742,8 +771,10 @@ int blkid_do_probe(blkid_probe pr)
 
 			if (idx < BLKID_NCHAINS)
 				chn = pr->cur_chain = &pr->chains[idx];
-			else
+			else {
+				blkid_probe_end(pr);
 				return 1;	/* all chains already probed */
+			}
 		}
 
 		chn->binary = FALSE;		/* for sure... */
@@ -775,7 +806,9 @@ int blkid_do_probe(blkid_probe pr)
  *
  * Note about suberblocks chain -- the function does not check for filesystems
  * when a RAID signature is detected.  The function also does not check for
- * collision between RAIDs. The first detected RAID is returned.
+ * collision between RAIDs. The first detected RAID is returned. The function
+ * checks for collision between partition table and RAID signature -- it's
+ * recommended to enable partitions chain together with superblocks chain.
  *
  * Returns: 0 on success, 1 if nothing is detected, -2 if ambivalen result is
  * detected and -1 on case of error.
@@ -787,6 +820,8 @@ int blkid_do_safeprobe(blkid_probe pr)
 	if (!pr)
 		return -1;
 
+	blkid_probe_start(pr);
+
 	for (i = 0; i < BLKID_NCHAINS; i++) {
 		struct blkid_chain *chn;
 
@@ -814,7 +849,7 @@ int blkid_do_safeprobe(blkid_probe pr)
 	}
 
 done:
-	pr->cur_chain = NULL;
+	blkid_probe_end(pr);
 	if (rc < 0)
 		return rc;
 	return count ? 0 : 1;
@@ -839,6 +874,8 @@ int blkid_do_fullprobe(blkid_probe pr)
 	if (!pr)
 		return -1;
 
+	blkid_probe_start(pr);
+
 	for (i = 0; i < BLKID_NCHAINS; i++) {
 		int rc;
 		struct blkid_chain *chn;
@@ -867,7 +904,7 @@ int blkid_do_fullprobe(blkid_probe pr)
 	}
 
 done:
-	pr->cur_chain = NULL;
+	blkid_probe_end(pr);
 	if (rc < 0)
 		return rc;
 	return count ? 0 : 1;
diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak	2010-05-03 13:19:22.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c	2010-05-03 13:21:25.000000000 +0200
@@ -477,14 +477,17 @@ static int superblocks_safeprobe(blkid_p
 	int idx = -1;
 	int count = 0;
 	int intol = 0;
-	int rc;
+	int rc, bin_org = chn->binary;
+
+	chn->binary = TRUE;
 
 	while ((rc = superblocks_probe(pr, chn)) == 0) {
 
-		if (blkid_probe_is_tiny(pr) && !count)
+		if (blkid_probe_is_tiny(pr) && !count) {
 			/* floppy or so -- returns the first result. */
+			chn->binary = bin_org;
 			return 0;
-
+		}
 		if (!count) {
 			/* save the first result */
 			nvals = blkid_probe_chain_copy_vals(pr, chn, vals, nvals);
@@ -499,6 +502,9 @@ static int superblocks_safeprobe(blkid_p
 		if (!(idinfos[chn->idx]->flags & BLKID_IDINFO_TOLERANT))
 			intol++;
 	}
+
+	chn->binary = bin_org;
+
 	if (rc < 0)
 		return rc;		/* error */
 	if (count > 1 && intol) {
@@ -518,6 +524,30 @@ static int superblocks_safeprobe(blkid_p
 		superblocks_copy_data(chn->data, sb);
 	chn->idx = idx;
 
+	/*
+	 * Check for collisions between RAID and partition table
+	 */
+	if (sb && sb->usage == BLKID_USAGE_RAID &&
+	    sb->magic_off > pr->size / 2 &&
+	    (S_ISREG(pr->mode) || blkid_probe_is_wholedisk(pr)) &&
+	    blkid_probe_is_covered_by_pt(pr, sb->magic_off, 0x200)) {
+		/*
+		 * Ignore the result if the detected RAID superblock is
+		 * within some existing partition (for example RAID on
+		 * the last partition).
+		 */
+		blkid_probe_chain_reset_vals(pr, chn);
+		return 1;
+	}
+
+	/*
+	 * The RAID device could be partitioned. The problem are RAID1 devices
+	 * where the partition table is visible from underlaying devices. We
+	 * have to ignore such partition tables.
+	 */
+	if (sb && sb->usage == BLKID_USAGE_RAID)
+		pr->prob_flags |= BLKID_PARTS_IGNORE_PT;
+
 	return 0;
 }
 
>From 7d6d95ac9b5c84e8ff234c6bdef930d03f1e0577 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak at redhat.com>
Date: Fri, 30 Apr 2010 15:16:05 +0200
Subject: [PATCH 5/7] blkid: improve RAIDs and tiny devices probing

Signed-off-by: Karel Zak <kzak at redhat.com>
---
 misc-utils/blkid.c |   37 +++++++++++++++++++------------------
 1 files changed, 19 insertions(+), 18 deletions(-)


diff -up util-linux-ng-2.17.2/misc-utils/blkid.c.kzak util-linux-ng-2.17.2/misc-utils/blkid.c
--- util-linux-ng-2.17.2/misc-utils/blkid.c.kzak	2010-05-03 13:19:04.000000000 +0200
+++ util-linux-ng-2.17.2/misc-utils/blkid.c	2010-05-03 13:22:49.000000000 +0200
@@ -423,33 +423,34 @@ static int lowprobe_device(blkid_probe p
 
 	if (fstat(fd, &st))
 		goto done;
-	/*
-	 * partitions probing
-	 */
-	blkid_probe_enable_superblocks(pr, 0);	/* enabled by default ;-( */
 
 	blkid_probe_enable_partitions(pr, 1);
-	rc = blkid_do_fullprobe(pr);
-	blkid_probe_enable_partitions(pr, 0);
 
-	if (rc < 0)
-		goto done;	/* -1 = error, 1 = nothing, 0 = succes */
-
-	/*
-	 * Don't probe for FS/RAIDs on small devices
-	 */
-	if (rc || S_ISCHR(st.st_mode) ||
-	    blkid_probe_get_size(pr) > 1024 * 1440) {
+	if (!S_ISCHR(st.st_mode) && blkid_probe_get_size(pr) <= 1024 * 1440) {
 		/*
-		 * filesystems/RAIDs probing
+		 * check if the small disk is partitioned, if yes then
+		 * don't probe for filesystems.
 		 */
-		blkid_probe_enable_superblocks(pr, 1);
+		blkid_probe_enable_superblocks(pr, 0);
 
-		rc = blkid_do_safeprobe(pr);
+		rc = blkid_do_fullprobe(pr);
 		if (rc < 0)
-			goto done;
+			goto done;	/* -1 = error, 1 = nothing, 0 = succes */
+
+		if (blkid_probe_lookup_value(pr, "PTTYPE", NULL, NULL) == 0)
+			/* partition table detected */
+			goto print_vals;
+
+		/* small whole-disk is unpartitioned, probe for filesystems only */
+		blkid_probe_enable_partitions(pr, 0);
 	}
 
+	blkid_probe_enable_superblocks(pr, 1);
+
+	rc = blkid_do_safeprobe(pr);
+	if (rc < 0)
+		goto done;
+print_vals:
 	nvals = blkid_probe_numof_values(pr);
 
 	if (output & OUTPUT_DEVICE_ONLY) {


>From c6088bbd63f21ce586b3c3c3d894642f4f008355 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak at redhat.com>
Date: Fri, 30 Apr 2010 15:25:41 +0200
Subject: [PATCH 6/7] libblkid: reset superblocks result after error

Signed-off-by: Karel Zak <kzak at redhat.com>
---
 shlibs/blkid/src/superblocks/superblocks.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff -up util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c
--- util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c.kzak	2010-05-03 13:21:25.000000000 +0200
+++ util-linux-ng-2.17.2/shlibs/blkid/src/superblocks/superblocks.c	2010-05-03 13:23:38.000000000 +0200
@@ -426,8 +426,10 @@ static int superblocks_probe(blkid_probe
 		/* final check by probing function */
 		if (id->probefunc) {
 			DBG(DEBUG_LOWPROBE, printf("\tcall probefunc()\n"));
-			if (id->probefunc(pr, mag) != 0)
+			if (id->probefunc(pr, mag) != 0) {
+				blkid_probe_chain_reset_vals(pr, chn);
 				continue;
+			}
 		}
 
 		/* all cheks passed */


>From b4cd0e971dee03eac044a2d28f78fe638a04d8c5 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak at redhat.com>
Date: Mon, 3 May 2010 11:20:52 +0200
Subject: [PATCH 7/7] tests: add blkid tests for RAID1

Signed-off-by: Karel Zak <kzak at redhat.com>
---
 tests/expected/blkid/md-raid1-part  |   58 ++++++++++++++++++++++
 tests/expected/blkid/md-raid1-whole |   58 ++++++++++++++++++++++
 tests/functions.sh                  |    2 +-
 tests/ts/blkid/md-raid1-part        |   92 +++++++++++++++++++++++++++++++++++
 tests/ts/blkid/md-raid1-whole       |   88 +++++++++++++++++++++++++++++++++
 5 files changed, 297 insertions(+), 1 deletions(-)
 create mode 100644 tests/expected/blkid/md-raid1-part
 create mode 100644 tests/expected/blkid/md-raid1-whole
 create mode 100755 tests/ts/blkid/md-raid1-part
 create mode 100755 tests/ts/blkid/md-raid1-whole

diff -up util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-part.kzak util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-part
--- util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-part.kzak	2010-05-03 13:24:30.000000000 +0200
+++ util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-part	2010-05-03 13:24:30.000000000 +0200
@@ -0,0 +1,58 @@
+Create partitions
+Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
+
+Changes will remain in memory only, until you decide to write them.
+After that, of course, the previous content won't be recoverable.
+
+Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
+
+WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
+         switch off the mode (command 'c') and change display units to
+         sectors (command 'u').
+
+Command (m for help): DOS Compatibility flag is not set
+
+Command (m for help): Changing display/entry units to sectors
+
+Command (m for help): Command action
+   e   extended
+   p   primary partition (1-4)
+Partition number (1-4): First sector (2048-104447, default 2048): Using default value 2048
+Last sector, +sectors or +size{K,M,G} (2048-104447, default 104447): 
+Command (m for help): Command action
+   e   extended
+   p   primary partition (1-4)
+Partition number (1-4): First sector (53248-104447, default 53248): Using default value 53248
+Last sector, +sectors or +size{K,M,G} (53248-104447, default 104447): Using default value 104447
+
+Command (m for help): 
+Disk /dev/sdb: 53 MB, 53477376 bytes
+32 heads, 32 sectors/track, 102 cylinders, total 104448 sectors
+Units = sectors of 1 * 512 = 512 bytes
+Sector size (logical/physical): 512 bytes / 512 bytes
+I/O size (minimum/optimal): 512 bytes / 32768 bytes
+
+
+   Device Boot      Start         End      Blocks   Id  System
+/dev/sdb1            2048       53247       25600   83  Linux
+/dev/sdb2           53248      104447       25600   83  Linux
+
+Command (m for help): The partition table has been altered!
+
+Calling ioctl() to re-read partition table.
+Syncing disks.
+Create RAID1 device
+Probe whole-disk
+ID_PART_TABLE_TYPE=dos
+Probe first RAID member
+ID_FS_TYPE=linux_raid_member
+ID_FS_USAGE=raid
+
+
+ID_FS_VERSION=0.90.0
+Probe second RAID member
+ID_FS_TYPE=linux_raid_member
+ID_FS_USAGE=raid
+
+
+ID_FS_VERSION=0.90.0
diff -up util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-whole.kzak util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-whole
--- util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-whole.kzak	2010-05-03 13:24:30.000000000 +0200
+++ util-linux-ng-2.17.2/tests/expected/blkid/md-raid1-whole	2010-05-03 13:24:30.000000000 +0200
@@ -0,0 +1,58 @@
+Initialize devices
+Create RAID device
+Create partitions on RAID device
+Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
+
+Changes will remain in memory only, until you decide to write them.
+After that, of course, the previous content won't be recoverable.
+
+Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
+
+WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
+         switch off the mode (command 'c') and change display units to
+         sectors (command 'u').
+
+Command (m for help): DOS Compatibility flag is not set
+
+Command (m for help): Changing display/entry units to sectors
+
+Command (m for help): Command action
+   e   extended
+   p   primary partition (1-4)
+Partition number (1-4): First sector (2048-102271, default 2048): Using default value 2048
+Last sector, +sectors or +size{K,M,G} (2048-102271, default 102271): 
+Command (m for help): Command action
+   e   extended
+   p   primary partition (1-4)
+Partition number (1-4): First sector (22528-102271, default 22528): Using default value 22528
+Last sector, +sectors or +size{K,M,G} (22528-102271, default 102271): 
+Command (m for help): 
+Disk /dev/md8: 52 MB, 52363264 bytes
+2 heads, 4 sectors/track, 12784 cylinders, total 102272 sectors
+Units = sectors of 1 * 512 = 512 bytes
+Sector size (logical/physical): 512 bytes / 512 bytes
+I/O size (minimum/optimal): 512 bytes / 512 bytes
+
+
+    Device Boot      Start         End      Blocks   Id  System
+/dev/md8p1            2048       22527       10240   83  Linux
+/dev/md8p2           22528       43007       10240   83  Linux
+
+Command (m for help): The partition table has been altered!
+
+Calling ioctl() to re-read partition table.
+Syncing disks.
+Probe first RAID member
+ID_FS_TYPE=linux_raid_member
+ID_FS_USAGE=raid
+
+
+ID_FS_VERSION=0.90.0
+Probe second RAID member
+ID_FS_TYPE=linux_raid_member
+ID_FS_USAGE=raid
+
+
+ID_FS_VERSION=0.90.0
+Stop RAID device
+Deinitialize devices
diff -up util-linux-ng-2.17.2/tests/functions.sh.kzak util-linux-ng-2.17.2/tests/functions.sh
--- util-linux-ng-2.17.2/tests/functions.sh.kzak	2010-03-18 23:11:23.000000000 +0100
+++ util-linux-ng-2.17.2/tests/functions.sh	2010-05-03 13:24:30.000000000 +0200
@@ -256,7 +256,7 @@ function ts_image_init {
 
 function ts_device_init {
 	local img=$(ts_image_init $1 $2)
-	local dev=$($TS_CMD_LOSETUP -s -f "$img")
+	local dev=$($TS_CMD_LOSETUP --show -f "$img")
 
 	if [ -z "$dev" ]; then
 		ts_device_deinit $dev
diff -up util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-part.kzak util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-part
--- util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-part.kzak	2010-05-03 13:24:30.000000000 +0200
+++ util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-part	2010-05-03 13:24:30.000000000 +0200
@@ -0,0 +1,92 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2010 Karel Zak <kzak at redhat.com>
+#
+# This file is part of util-linux-ng.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="$(dirname $0)/../.."
+TS_DESC="MD raid1 (last partition)"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+ts_skip_nonroot
+
+modprobe --dry-run --quiet scsi_debug
+[ "$?" == 0 ] || ts_skip "missing scsi_debug module"
+[ -x /sbin/mdadm ] || ts_skip "missing mdadm"
+
+rmmod scsi_debug &> /dev/null
+modprobe scsi_debug dev_size_mb=51 sector_size=512
+[ "$?" == 0 ] || ts_die "Cannot init device"
+
+sleep 3
+
+DEVNAME=$(grep scsi_debug /sys/block/*/device/model | awk -F '/' '{print $4}')
+[ "x${DEVNAME}" == "x" ] && ts_die "Cannot found device"
+
+DEVICE="/dev/${DEVNAME}"
+
+ts_log "Create partitions"
+$TS_CMD_FDISK ${DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+c
+u
+n
+p
+1
+
++25M
+n
+p
+2
+
+
+p
+w
+q
+EOF
+
+sleep 3
+MD_DEVNAME=md8
+MD_DEVICE=/dev/${MD_DEVNAME}
+
+###exit 1
+
+ts_log "Create RAID1 device"
+/sbin/mdadm -q -S ${MD_DEVICE} &> /dev/null
+/sbin/mdadm -q --create ${MD_DEVICE} --metadata=0.90 --chunk=64 --level=1 \
+	    --raid-devices=2 ${DEVICE}1 ${DEVICE}2 >> $TS_OUTPUT 2>&1
+
+sleep 3
+
+ts_log "Probe whole-disk"
+$TS_CMD_BLKID -p -o udev ${DEVICE} 2>&1 | sort >> $TS_OUTPUT
+
+ts_log "Probe first RAID member"
+$TS_CMD_BLKID -p -o udev ${DEVICE}1 2>&1 | sort >> $TS_OUTPUT
+
+ts_log "Probe second RAID member"
+$TS_CMD_BLKID -p -o udev ${DEVICE}2 2>&1 | sort >> $TS_OUTPUT
+
+/sbin/mdadm -q -S ${MD_DEVICE} >> $TS_OUTPUT 2>&1
+
+sleep 3
+rmmod scsi_debug
+
+# remove disk ID and generated UUIDs
+sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT
+sed -i -e 's/Building a new.*//g' $TS_OUTPUT
+sed -i -e 's/ID_FS_UUID.*//g' $TS_OUTPUT
+
+ts_finalize
diff -up util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-whole.kzak util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-whole
--- util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-whole.kzak	2010-05-03 13:24:30.000000000 +0200
+++ util-linux-ng-2.17.2/tests/ts/blkid/md-raid1-whole	2010-05-03 13:24:30.000000000 +0200
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+#
+# Copyright (C) 2010 Karel Zak <kzak at redhat.com>
+#
+# This file is part of util-linux-ng.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="$(dirname $0)/../.."
+TS_DESC="MD raid1 (whole-disks)"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+ts_skip_nonroot
+[ -x /sbin/mdadm ] || ts_skip "missing mdadm"
+
+set -o pipefail
+
+ts_log "Initialize devices"
+IMGNAME="${TS_OUTDIR}/${TS_TESTNAME}"
+
+DEVICE1=$(ts_device_init 50 ${IMGNAME}1.img)
+[ "$?" == 0 ] || ts_die "Cannot init device1"
+
+DEVICE2=$(ts_device_init 50 ${IMGNAME}2.img)
+[ "$?" == 0 ] || ts_die "Cannot init device2" $DEVICE1
+
+MD_DEVNAME=md8
+MD_DEVICE=/dev/${MD_DEVNAME}
+
+/sbin/mdadm -q -S ${MD_DEVICE} &> /dev/null
+
+ts_log "Create RAID device"
+/sbin/mdadm -q --create ${MD_DEVICE} --metadata=0.90 --chunk=64 --level=1 \
+	    --raid-devices=2 ${DEVICE1} ${DEVICE2} >> $TS_OUTPUT 2>&1
+
+ts_log "Create partitions on RAID device"
+$TS_CMD_FDISK ${MD_DEVICE} >> $TS_OUTPUT 2>&1 <<EOF
+c
+u
+n
+p
+1
+
++10M
+n
+p
+2
+
++10M
+p
+w
+q
+EOF
+
+sleep 3
+
+ts_log "Probe first RAID member"
+$TS_CMD_BLKID -p -o udev $DEVICE1 2>&1 | sort >> $TS_OUTPUT
+
+ts_log "Probe second RAID member"
+$TS_CMD_BLKID -p -o udev $DEVICE1 2>&1 | sort >> $TS_OUTPUT
+
+ts_log "Stop RAID device"
+/sbin/mdadm -q -S ${MD_DEVICE} >> $TS_OUTPUT 2>&1
+
+sleep 3
+
+ts_log "Deinitialize devices"
+ts_device_deinit $DEVICE1
+ts_device_deinit $DEVICE2
+
+# remove disk ID and generated UUIDs
+sed -i -e 's/Disk identifier:.*//g' $TS_OUTPUT
+sed -i -e 's/Building a new.*//g' $TS_OUTPUT
+sed -i -e 's/ID_FS_UUID.*//g' $TS_OUTPUT
+
+ts_finalize


Index: util-linux-ng.spec
===================================================================
RCS file: /cvs/pkgs/rpms/util-linux-ng/F-13/util-linux-ng.spec,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -p -r1.82 -r1.83
--- util-linux-ng.spec	12 Apr 2010 13:19:23 -0000	1.82
+++ util-linux-ng.spec	4 May 2010 09:06:38 -0000	1.83
@@ -2,7 +2,7 @@
 Summary: A collection of basic system utilities
 Name: util-linux-ng
 Version: 2.17.2
-Release: 3%{?dist}
+Release: 4%{?dist}
 License: GPLv2 and GPLv2+ and GPLv3+ and LGPLv2+ and BSD with advertising and Public Domain
 Group: System Environment/Base
 URL: ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng
@@ -110,6 +110,10 @@ Patch8: util-linux-ng-2.15-ipcs-32bit.pa
 Patch9: util-linux-ng-2.17-blkid-usec.patch
 # 580296 - "rtcwake" does miss the "off" option
 Patch10: util-linux-ng-2.17-rtcwake-off.patch
+# 588668 - F13: don't probe for RAIDs on CD-ROMs
+Patch11: util-linux-ng-2.17-blkid-cdrom.patch
+# 543749 - After upgrade from Fedora 11, RAID-1 mdraid assembles incorrectly 
+Patch12: util-linux-ng-2.17-blkid-raid.patch
 
 %description
 The util-linux-ng package contains a large variety of low-level system
@@ -205,6 +209,8 @@ cp %{SOURCE8} %{SOURCE9} .
 %patch8 -p1
 %patch9 -p1
 %patch10 -p1
+%patch11 -p1
+%patch12 -p1
 
 %build
 unset LINGUAS || :
@@ -724,6 +730,10 @@ fi
 
 
 %changelog
+* Tue May  4 2010 Karel Zak <kzak at redhat.com> 2.17.2-4
+- #588668 - F13: don't probe for RAIDs on CD-ROMs
+- #543749 - After upgrade from Fedora 11, RAID-1 mdraid assembles incorrectly 
+
 * Mon Apr 12 2010 Karel Zak <kzak at redhat.com> 2.17.2-3
 - fix #581252 - remounting tmpfs fails because of hidden rootcontext=
 



More information about the scm-commits mailing list