Skip to content

Commit

Permalink
[PATCH] block: Cleanup CDROMEJECT ioctl
Browse files Browse the repository at this point in the history
This is just a basic cleanup. No change in functionality.

Signed-off-by: Ben Collins <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
benmcollins authored and Linus Torvalds committed Dec 20, 2005
1 parent 931b11b commit f98d2df
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions block/scsi_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,37 @@ static int sg_scsi_ioctl(struct file *file, request_queue_t *q,
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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f98d2df

Please sign in to comment.