The behaviour of eject/lock_door ioctl is not consistent, so add some check 
before scsi_cmd_ioctl.

Signed-off-by: Dave Young <[EMAIL PROTECTED]> 

---
drivers/cdrom/cdrom.c |   42 ++++++++++++++++++++++++++++++++++++------
1 file changed, 36 insertions(+), 6 deletions(-)

diff -upr linux/drivers/cdrom/cdrom.c linux.new/drivers/cdrom/cdrom.c
--- linux/drivers/cdrom/cdrom.c 2008-01-04 15:06:50.000000000 +0800
+++ linux.new/drivers/cdrom/cdrom.c     2008-01-04 15:05:06.000000000 +0800
@@ -2236,6 +2236,15 @@ static int cdrom_ioctl_multisession(stru
        return 0;
 }
 
+static int cdrom_eject_check(struct cdrom_device_info *cdi)
+{
+       if (!CDROM_CAN(CDC_OPEN_TRAY))
+               return -ENOSYS;
+       if (cdi->use_count != 1 || keeplocked)
+               return -EBUSY;
+       return 0;
+}
+
 static int cdrom_ioctl_eject(struct cdrom_device_info *cdi)
 {
        cdinfo(CD_DO_IOCTL, "entering CDROMEJECT\n");
@@ -2392,22 +2401,31 @@ static int cdrom_ioctl_reset(struct cdro
        return cdi->ops->reset(cdi);
 }
 
-static int cdrom_ioctl_lock_door(struct cdrom_device_info *cdi,
+static int cdrom_lock_door_check(struct cdrom_device_info *cdi,
                unsigned long arg)
 {
-       cdinfo(CD_DO_IOCTL, "%socking door.\n", arg ? "L" : "Unl");
-
        if (!CDROM_CAN(CDC_LOCK))
                return -EDRIVE_CANT_DO_THIS;
-
-       keeplocked = arg ? 1 : 0;
-
        /*
         * Don't unlock the door on multiple opens by default, but allow
         * root to do so.
         */
        if (cdi->use_count != 1 && !arg && !capable(CAP_SYS_ADMIN))
                return -EBUSY;
+
+       return 0;
+}
+
+
+static int cdrom_ioctl_lock_door(struct cdrom_device_info *cdi,
+               unsigned long arg)
+{
+       cdinfo(CD_DO_IOCTL, "%socking door.\n", arg ? "L" : "Unl");
+
+       /*
+        * cdrom_lock_door_check is done in cdrom_ioctl.
+        */
+       keeplocked = arg ? 1 : 0;
        return cdi->ops->lock_door(cdi, arg);
 }
 
@@ -2701,6 +2719,18 @@ int cdrom_ioctl(struct file * file, stru
        int ret;
        struct gendisk *disk = ip->i_bdev->bd_disk;
 
+       if (cmd == CDROMEJECT) {
+               ret = cdrom_eject_check(cdi);
+               if (ret)
+                       return ret;
+       }
+
+       if (cmd == CDROM_LOCKDOOR) {
+               ret = cdrom_lock_door_check(cdi, arg);
+               if (ret)
+                       return ret;
+       }
+
        /*
         * Try the generic SCSI command ioctl's first.
         */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to