[PATCH] libblkid: Avoid probing CDs for RAID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Mark Colclough <m.s.colclough@xxxxxxxxxx>
---
 shlibs/blkid/src/blkidP.h                  |    2 ++
 shlibs/blkid/src/probe.c                   |   12 ++++++++++++
 shlibs/blkid/src/superblocks/superblocks.c |    4 ++--
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h
index db5da5e..71293f7 100644
--- a/shlibs/blkid/src/blkidP.h
+++ b/shlibs/blkid/src/blkidP.h
@@ -208,6 +208,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		(1 << 3)	/* is a CD/DVD drive */

 /*
  * Evaluation methods (for blkid_eval_* API)
@@ -369,6 +370,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 --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c
index ab1c8d5..e747b08 100644
--- a/shlibs/blkid/src/probe.c
+++ b/shlibs/blkid/src/probe.c
@@ -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);
+}
+
 /**
  * blkid_probe_set_device:
  * @pr: probe
@@ -619,6 +628,9 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
 	if (pr->size <= 1440 * 1024 && !S_ISCHR(pr->mode))
 		pr->flags |= BLKID_TINY_DEV;

+	if (ioctl(fd, CDROM_GET_CAPABILITY, NULL) >= 0)
+		pr->flags |= BLKID_CDROM;
+	
 	return 0;
 err:
 	DBG(DEBUG_LOWPROBE,
diff --git a/shlibs/blkid/src/superblocks/superblocks.c b/shlibs/blkid/src/superblocks/superblocks.c
index 05668e1..5a52d4e 100644
--- a/shlibs/blkid/src/superblocks/superblocks.c
+++ b/shlibs/blkid/src/superblocks/superblocks.c
@@ -338,9 +338,9 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)

 		mag = id->magics ? &id->magics[0] : NULL;

-		/* don't probe for RAIDs, swap or journal on floppies */
+		/* 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_tiny(pr) || blkid_probe_is_cdrom(pr)))
 			continue;

 		DBG(DEBUG_LOWPROBE, printf("[%d] %s:\n", i, id->name));
--
1.6.6.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux