Linux Hotplug development
 help / color / mirror / Atom feed
From: Mike Brudevold <mike@brudevold.com>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] cdrom_id: Fix empty drive detection for drives with an active
Date: Sat, 17 Apr 2010 16:26:42 +0000	[thread overview]
Message-ID: <o2x8911efe41004170926v32b8f421sffbd1a976a9b8f03@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3227 bytes --]

My CD-RW drive experiences a problem in that it automatically closes
after opening if there is media in the drive.  This only happens if
there was media in the drive when it was last closed (an empty drive
stays open).  From what I can tell, this behavior is affected by the
ID_CDROM_MEDIA variable.

This is the output of cdrom_id:

$ /lib/udev/cdrom_id -d /dev/sr1
main: probing: '/dev/sr1'
cd_media_compat: CDROM_DRIVE_STATUS != CDS_DISC_OK
cd_inquiry: INQUIRY: [LITE-ON ][LTR-52327S      ][QS58]
cd_profiles: GET CONFIGURATION: size of features buffer 0x00b4
cd_profiles: GET CONFIGURATION: feature 'profiles', with 4 entries
feature_profiles: profile 0x0a cd_rw
feature_profiles: profile 0x09 cd_r
feature_profiles: profile 0x08 cd_rom
feature_profiles: profile 0x02 <ignored>
cd_profiles: GET CONFIGURATION: feature 0x0001 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0002 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0003 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0010 <ignored>, with 0x08 bytes
cd_profiles: GET CONFIGURATION: feature 0x001d <ignored>, with 0x00 bytes
cd_profiles: GET CONFIGURATION: feature 0x001e <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0020 <ignored>, with 0x0c bytes
cd_profiles: GET CONFIGURATION: feature 0x0021 <ignored>, with 0x08 bytes
cd_profiles: GET CONFIGURATION: feature 0x0023 <ignored>, with 0x00 bytes
cd_profiles: GET CONFIGURATION: feature 0x0024 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0026 <ignored>, with 0x00 bytes
cd_profiles: GET CONFIGURATION: feature 0x0027 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0028 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x002d <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x002e <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0100 <ignored>, with 0x00 bytes
cd_profiles: GET CONFIGURATION: feature 0x0101 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0103 <ignored>, with 0x04 bytes
cd_profiles: GET CONFIGURATION: feature 0x0105 <ignored>, with 0x00 bytes
cd_profiles: current profile 0x02
cd_profiles: profile 0x02 <ignored>
info_scsi_cmd_err: READ DISC INFORMATION failed with SK=2h/ASC=3Ah/ACQ=00h
ID_CDROM=1
ID_CDROM_CD=1
ID_CDROM_CD_R=1
ID_CDROM_CD_RW=1
ID_CDROM_MRW=1
ID_CDROM_MRW_W=1
ID_CDROM_MEDIA=1

I attached a patch that only sets ID_CDROM_MEDIA if the "READ DISC
INFORMATION" command is successful.  With this patch, the drive no
longer automatically closes.

I am not sure if the location that I moved it to is the best, because
I don't exactly understand this section of code:

/* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */
if (!cd_media_cd_rom && (header[2] & 3) < 4)
       cd_media_state = media_status[header[2] & 3];

First of all, ((header[2] & 3) < 4) is by definition always true, so
I'm not sure what it is checking.  But if somehow this is a valid
check, perhaps we should set cd_media in here.

I have tested this patch with my cd-rw drive and dvd drive (blank
media, normal media, and no media were all tested), and all seems
well.

Mike

[-- Attachment #2: 0001-cdrom_id-Fix-empty-drive-detection-for-drives-with-a.patch --]
[-- Type: text/x-patch, Size: 919 bytes --]

From c074a888f235a74c64ce5ffad1b65a00002ac287 Mon Sep 17 00:00:00 2001
From: Mike Brudevold <mike@brudevold.com>
Date: Sat, 17 Apr 2010 11:00:44 -0500
Subject: [PATCH] cdrom_id: Fix empty drive detection for drives with an active profile when empty.

---
 extras/cdrom_id/cdrom_id.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/extras/cdrom_id/cdrom_id.c b/extras/cdrom_id/cdrom_id.c
index da2785e..2910378 100644
--- a/extras/cdrom_id/cdrom_id.c
+++ b/extras/cdrom_id/cdrom_id.c
@@ -401,8 +401,6 @@ static int cd_profiles(struct udev *udev, int fd)
 		return -1;
 	}
 
-	cd_media = 1;
-
 	switch (cur_profile) {
 	case 0x03:
 	case 0x04:
@@ -509,6 +507,8 @@ static int cd_media_info(struct udev *udev, int fd)
 		return -1;
 	};
 
+	cd_media = 1;
+
 	info(udev, "disk type %02x\n", header[8]);
 
 	/* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */
-- 
1.7.0.4


             reply	other threads:[~2010-04-17 16:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-17 16:26 Mike Brudevold [this message]
2010-04-17 17:37 ` [PATCH] cdrom_id: Fix empty drive detection for drives with an Kay Sievers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=o2x8911efe41004170926v32b8f421sffbd1a976a9b8f03@mail.gmail.com \
    --to=mike@brudevold.com \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox