]> git.ipfire.org Git - thirdparty/util-linux.git/commit
eject: unlock door before issuing CDROMEJECT command
authorAaron Lu <aaron.lu@intel.com>
Thu, 6 Jun 2013 08:28:37 +0000 (16:28 +0800)
committerKarel Zak <kzak@redhat.com>
Thu, 13 Jun 2013 11:28:04 +0000 (13:28 +0200)
commit12272030e563201e0b06732d8a87d8cea7157a04
treef804cfb480e4fd9569f2304be396b46100b26eff
parent714cff30fd94d7fe6c7a8c6a1b4aa6cc8abd2ca7
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