]> err.no Git - util-linux/commitdiff
libblkid: avoid probing CDs for RAID
authorM.S.Colclough <m.s.colclough@bham.ac.uk>
Wed, 31 Mar 2010 16:11:00 +0000 (18:11 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 31 Mar 2010 16:12:47 +0000 (18:12 +0200)
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@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@bham.ac.uk>
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/probe.c
shlibs/blkid/src/superblocks/superblocks.c

index 02777a8ea667abdd3e96b08a952741edf008bdc0..121ac502ccf67637326cc93a38fc263875fdc227 100644 (file)
@@ -108,6 +108,7 @@ AC_CHECK_HEADERS(
        linux/tiocl.h \
        linux/version.h \
        linux/falloc.h \
+       linux/cdrom.h \
        fcntl.h \
        locale.h \
        stdint.h \
index db5da5e80d853875a21926e3db043b9e3671aae2..b15c7f9b731af7647730bebd558ffe9db1d36555 100644 (file)
@@ -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_DEV                (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);
 
index ab1c8d5806caeaff807d58389d1c7e1cb395a666..3c6e6948a4ee1e11f65c00388312df7e393c774e 100644 (file)
@@ -77,6 +77,9 @@
 #include <fcntl.h>
 #include <ctype.h>
 #include <sys/types.h>
+#ifdef HAVE_LINUX_CDROM_H
+#include <linux/cdrom.h>
+#endif
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
@@ -545,6 +548,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 +581,7 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
 
        pr->flags &= ~BLKID_PRIVATE_FD;
        pr->flags &= ~BLKID_TINY_DEV;
+       pr->flags &= ~BLKID_CDROM_DEV;
        pr->fd = fd;
        pr->off = off;
        pr->size = 0;
@@ -619,6 +631,10 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
        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,
index 05668e1e2fc736e7434ddeffc046851968bdef54..9c71597e1d5b3ca51d143f9f89fe0fce9f1371b8 100644 (file)
@@ -343,6 +343,11 @@ static int superblocks_probe(blkid_probe pr, struct blkid_chain *chn)
                    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 */