]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: check for medium on CDMROMs probing
authorKarel Zak <kzak@redhat.com>
Tue, 7 Jan 2020 15:48:34 +0000 (16:48 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 7 Jan 2020 15:48:34 +0000 (16:48 +0100)
The commit 39f5af25982d8b0244000e92a9d0e0e6557d0e17 introduces
O_NONBLOCK to avoid the tray close on open(). The side effect is that
open() is successful when there is no medium.

This is usually no problem for standard tools because the next read()
will fail. Unfortunately, libblkid ignores I/O errors for (and only
for) CDROMs to support some crazy hybrid data+audio disks. The final
result is many I/O errors in system log when O_NONBLOCK is enabled.

This patch add CDROM_DRIVE_STATUS to stop probing when there is no
disk or when the tray is open.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1787973
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/probe.c
misc-utils/blkid.c

index f6dd5573d5dd6ccef2fbf7042b12c30ea1509c43..871cd9bf21aafa8a53594ac207e8aea39c131793 100644 (file)
@@ -945,6 +945,14 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
            blkid_probe_is_wholedisk(pr) &&
            ioctl(fd, CDROM_GET_CAPABILITY, NULL) >= 0) {
 
+# ifdef CDROM_DRIVE_STATUS
+               switch (ioctl(fd, CDROM_DRIVE_STATUS, 0)) {
+               case CDS_TRAY_OPEN:
+               case CDS_NO_DISC:
+                       errno = ENOMEDIUM;
+                       goto err;
+               }
+# endif
                pr->flags |= BLKID_FL_CDROM_DEV;
                cdrom_size_correction(pr);
        }
index 0df9f6b6f29e986618d471e5dbdf1cf82d631179..88a90578b030b1658860ed5fedadeefd3a3c11da 100644 (file)
@@ -504,8 +504,12 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
                warn(_("error: %s"), devname);
                return BLKID_EXIT_NOTFOUND;
        }
-       if (blkid_probe_set_device(pr, fd, ctl->offset, ctl->size))
+       errno = 0;
+       if (blkid_probe_set_device(pr, fd, ctl->offset, ctl->size)) {
+               if (errno)
+                       warn(_("error: %s"), devname);
                goto done;
+       }
 
        if (ctl->lowprobe_topology)
                rc = lowprobe_topology(pr);