* [PATCH] user_space_eject: unlock door before issuing CDROMEJECT command
@ 2013-06-06 8:47 Aaron Lu
2013-06-13 11:29 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Aaron Lu @ 2013-06-06 8:47 UTC (permalink / raw)
To: Karel Zak, Michal Luscon; +Cc: SCSI development list, Aaron Lu
Hi Karel & Michal,
Not sure if I should send this to you, please kindly forward it to other
people if they should take care of this instead, thanks.
Note that this is a patch for user space tool eject, but since it also
has something to do with the SCSI driver, the SCSI mailing list is CC-ed
in case people there think it should be solved in another way.
Here is the patch.
>From d4202374d620bf72953a0b59f108521f94cefbd6 Mon Sep 17 00:00:00 2001
From: Aaron Lu <aaron.lu@intel.com>
Date: Thu, 6 Jun 2013 16:28:37 +0800
Subject: [PATCH] eject: unlock door before issuing CDROMEJECT command
If user has inserted a disc into the drive, the drive will normally be
locked. When using eject command to eject the drive, we need to unlock
the door first, or the CDROMEJECT command will fail.
Though the 2nd attmpt to eject the drive with eject_scsi will succeed,
it actually does two things: first to unlock the door and then to eject
the tray, both with the SG_IO ioctl. The problem is, Linux SCSI driver
keeps track of if a device is in locked state or not, if we go with
SG_IO to do the unlocking, the driver will not be aware of the unlocking
and would think the drive is locked while actually it has already been
unlocked by the first SG_IO command.
Fix this by issuing a unlock door command before the CDROMEJECT command
in cdrom_eject. Prior to this fix, the following output is expected when
there is a disc inside:
[aaron@aaronlu util-linux-2.22.2]$ eject -v /dev/sr0
eject: device name is `/dev/sr0'
eject: /dev/sr0: mounted on /run/media/aaron/CD_ROM
eject: /dev/sr0: is whole-disk device
eject: /dev/sr0: is removable device
eject: /run/media/aaron/CD_ROM: unmounting
eject: /dev/sr0: trying to eject using CD-ROM eject command
eject: CD-ROM eject command failed
eject: /dev/sr0: trying to eject using SCSI commands
eject: SCSI eject succeeded
After this fix, the following output is expected:
[aaron@aaronlu util-linux-2.22.2]$ ./eject -v /dev/sr0
lt-eject: device name is `/dev/sr0'
lt-eject: /dev/sr0: mounted on /run/media/aaron/CD_ROM
lt-eject: /dev/sr0: is whole-disk device
lt-eject: /dev/sr0: is removable device
lt-eject: /run/media/aaron/CD_ROM: unmounting
lt-eject: /dev/sr0: trying to eject using CD-ROM eject command
lt-eject: CD-ROM eject command succeeded
And the SCSI device's locked state is correct now.
Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
sys-utils/eject.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index 6d0da18..72e2cb1 100644
--- a/sys-utils/eject.c
+++ b/sys-utils/eject.c
@@ -398,6 +398,9 @@ static void close_tray(int fd)
static int eject_cdrom(int fd)
{
#if defined(CDROMEJECT)
+ int ret = ioctl(fd, CDROM_LOCKDOOR, 0);
+ if (ret < 0)
+ return 0;
return ioctl(fd, CDROMEJECT) >= 0;
#elif defined(CDIOCEJECT)
return ioctl(fd, CDIOCEJECT) >= 0;
--
1.8.3.3.gfada522
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-13 11:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-06 8:47 [PATCH] user_space_eject: unlock door before issuing CDROMEJECT command Aaron Lu
2013-06-13 11:29 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).