summaryrefslogtreecommitdiffstats
path: root/sys-utils/eject.c
diff options
context:
space:
mode:
authorAaron Lu2013-06-06 10:28:37 +0200
committerKarel Zak2013-06-13 13:28:04 +0200
commit12272030e563201e0b06732d8a87d8cea7157a04 (patch)
treef804cfb480e4fd9569f2304be396b46100b26eff /sys-utils/eject.c
parentagetty: use O_NONBLOCK only for serial lines with CLOCAL (diff)
downloadkernel-qcow2-util-linux-12272030e563201e0b06732d8a87d8cea7157a04.tar.gz
kernel-qcow2-util-linux-12272030e563201e0b06732d8a87d8cea7157a04.tar.xz
kernel-qcow2-util-linux-12272030e563201e0b06732d8a87d8cea7157a04.zip
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>
Diffstat (limited to 'sys-utils/eject.c')
-rw-r--r--sys-utils/eject.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index a5b56565d..4ec69e729 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;