diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2010-10-05 14:34:55 +0200 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2010-10-05 14:34:55 +0200 |
commit | ea88774a922c734afd751a59d8102bfa4806a1a6 (patch) | |
tree | 2486db5063a0b81bdad396f69f25e9fcbf3b9e41 /extras/cdrom_id | |
parent | 0bd77e2acd0dc58c6eba16bb3c4c01865d090855 (diff) |
cdrom_id: Try reading the medium if all MMC commands fail
Reportedly, some "when I'm grown up I want to be a CD drive" fake USB CD sticks
like the IronKey neither support the SCSI "GET CONFIGURATION" nor the older
(pre-MMC2) "READ DISC INFORMATION" command. In that case, check if we can read
data from the drive, and assume that we have a CD-ROM medium if it succeeds.
Diffstat (limited to 'extras/cdrom_id')
-rw-r--r-- | extras/cdrom_id/cdrom_id.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/extras/cdrom_id/cdrom_id.c b/extras/cdrom_id/cdrom_id.c index 0153af6633..f65f04f9dc 100644 --- a/extras/cdrom_id/cdrom_id.c +++ b/extras/cdrom_id/cdrom_id.c @@ -350,6 +350,34 @@ static int feature_profiles(struct udev *udev, const unsigned char *profiles, si return 0; } +static int cd_profiles_broken_mmc(struct udev *udev, int fd) +{ + struct scsi_cmd sc; + unsigned char buffer[16 * 2048]; + int err; + + /* we land here if both the standard and the old MMC commands failed; + * this might happen on broken wanna-be-CD USB drives like the IronKey. + * As a last resort, try to read data to see whether it has a medium. + */ + scsi_cmd_init(udev, &sc, buffer, sizeof(buffer)); + scsi_cmd_set(udev, &sc, 0, 0x28); + scsi_cmd_set(udev, &sc, 5, 0); + scsi_cmd_set(udev, &sc, 8, 16); + scsi_cmd_set(udev, &sc, 9, 0); + err = scsi_cmd_run(udev, &sc, fd, buffer, sizeof(buffer)); + if ((err != 0)) { + info(udev, "READ DATA failed, assuming no medium\n"); + return -1; + } + + /* that's all we can claim if we can read data */ + info(udev, "READ DATA succeeded, assuming CD-ROM medium\n"); + cd_media = 1; + cd_media_cd_rom = 1; + return 0; +} + static int cd_profiles_old_mmc(struct udev *udev, int fd) { struct scsi_cmd sc; @@ -364,8 +392,8 @@ static int cd_profiles_old_mmc(struct udev *udev, int fd) err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header)); if ((err != 0)) { info_scsi_cmd_err(udev, "READ DISC INFORMATION", err); - info(udev, "no current profile, assuming no media\n"); - return -1; + info(udev, "no current profile, probing readability of medium\n"); + return cd_profiles_broken_mmc(udev, fd); }; cd_media = 1; |