[PATCH] block: Cleanup CDROMEJECT ioctl
authorBen Collins <bcollins@ubuntu.com>
Mon, 19 Dec 2005 19:49:24 +0000 (11:49 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Tue, 20 Dec 2005 00:47:50 +0000 (16:47 -0800)
This is just a basic cleanup. No change in functionality.

Signed-off-by: Ben Collins <bcollins@ubuntu.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
block/scsi_ioctl.c

index 382dea7b224c61b87c354fdb425ad7b6f3e19c39..6e7db2e79f427833bb1ca06086d7ed1c81c40dfb 100644 (file)
@@ -442,11 +442,37 @@ error:
        return err;
 }
 
+
+/* Send basic block requests */
+static int __blk_send_generic(request_queue_t *q, struct gendisk *bd_disk, int cmd, int data)
+{
+       struct request *rq;
+       int err;
+
+       rq = blk_get_request(q, WRITE, __GFP_WAIT);
+       rq->flags |= REQ_BLOCK_PC;
+       rq->data = NULL;
+       rq->data_len = 0;
+       rq->timeout = BLK_DEFAULT_TIMEOUT;
+       memset(rq->cmd, 0, sizeof(rq->cmd));
+       rq->cmd[0] = cmd;
+       rq->cmd[4] = data;
+       rq->cmd_len = 6;
+       err = blk_execute_rq(q, bd_disk, rq, 0);
+       blk_put_request(rq);
+
+       return err;
+}
+
+static inline int blk_send_start_stop(request_queue_t *q, struct gendisk *bd_disk, int data)
+{
+       return __blk_send_generic(q, bd_disk, GPCMD_START_STOP_UNIT, data);
+}
+
 int scsi_cmd_ioctl(struct file *file, struct gendisk *bd_disk, unsigned int cmd, void __user *arg)
 {
        request_queue_t *q;
-       struct request *rq;
-       int close = 0, err;
+       int err;
 
        q = bd_disk->queue;
        if (!q)
@@ -564,19 +590,10 @@ int scsi_cmd_ioctl(struct file *file, struct gendisk *bd_disk, unsigned int cmd,
                        err = sg_scsi_ioctl(file, q, bd_disk, arg);
                        break;
                case CDROMCLOSETRAY:
-                       close = 1;
+                       err = blk_send_start_stop(q, bd_disk, 0x03);
+                       break;
                case CDROMEJECT:
-                       rq = blk_get_request(q, WRITE, __GFP_WAIT);
-                       rq->flags |= REQ_BLOCK_PC;
-                       rq->data = NULL;
-                       rq->data_len = 0;
-                       rq->timeout = BLK_DEFAULT_TIMEOUT;
-                       memset(rq->cmd, 0, sizeof(rq->cmd));
-                       rq->cmd[0] = GPCMD_START_STOP_UNIT;
-                       rq->cmd[4] = 0x02 + (close != 0);
-                       rq->cmd_len = 6;
-                       err = blk_execute_rq(q, bd_disk, rq, 0);
-                       blk_put_request(rq);
+                       err = blk_send_start_stop(q, bd_disk, 0x02);
                        break;
                default:
                        err = -ENOTTY;