19 #include <linux/kernel.h>
20 #include <linux/errno.h>
21 #include <linux/string.h>
22 #include <linux/module.h>
24 #include <linux/capability.h>
26 #include <linux/cdrom.h>
28 #include <linux/slab.h>
30 #include <asm/uaccess.h>
32 #include <scsi/scsi.h>
37 unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
53 static int sg_get_version(
int __user *
p)
55 static const int sg_version_num = 30527;
84 static int sg_get_reserved_size(
struct request_queue *q,
int __user *p)
86 unsigned val =
min(q->sg_reserved_size, queue_max_sectors(q) << 9);
91 static int sg_set_reserved_size(
struct request_queue *q,
int __user *p)
100 if (size > (queue_max_sectors(q) << 9))
101 size = queue_max_sectors(q) << 9;
103 q->sg_reserved_size =
size;
111 static int sg_emulated_host(
struct request_queue *q,
int __user *p)
235 rq->cmd_type = REQ_TYPE_BLOCK_PC;
239 rq->timeout = q->sg_timeout;
241 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
242 if (rq->timeout < BLK_MIN_SG_TIMEOUT)
243 rq->timeout = BLK_MIN_SG_TIMEOUT;
256 hdr->
status = rq->errors & 0xff;
264 hdr->
resid = rq->resid_len;
267 if (rq->sense_len && hdr->
sbp) {
284 static int sg_io(
struct request_queue *q,
struct gendisk *bd_disk,
288 int writing = 0, ret = 0;
295 if (hdr->
cmd_len > BLK_MAX_CDB)
298 if (hdr->
dxfer_len > (queue_max_hw_sectors(q) << 9))
317 if (blk_fill_sghdr_rq(q, rq, hdr, mode)) {
344 iov = (
struct iovec *) sg_iov;
347 if (iov_data_len + iov[i].
iov_len < iov_data_len) {
374 memset(sense, 0,
sizeof(sense));
389 return blk_complete_sghdr_rq(rq, hdr, bio);
428 #define OMAX_SB_LEN 16
430 struct scsi_ioctl_command __user *sic)
445 if (
get_user(out_len, &sic->outlen))
452 bytes =
max(in_len, out_len);
468 rq->cmd_len = cmdlen;
502 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
511 memset(sense, 0,
sizeof(sense));
514 rq->cmd_type = REQ_TYPE_BLOCK_PC;
519 err = rq->errors & 0xff;
521 if (rq->sense_len && rq->sense) {
540 static int __blk_send_generic(
struct request_queue *q,
struct gendisk *bd_disk,
547 rq->cmd_type = REQ_TYPE_BLOCK_PC;
548 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
558 static inline int blk_send_start_stop(
struct request_queue *q,
559 struct gendisk *bd_disk,
int data)
565 unsigned int cmd,
void __user *
arg)
577 err = sg_get_version(arg);
580 err = scsi_get_idlun(q, arg);
583 err = scsi_get_bus(q, arg);
586 err = sg_set_timeout(q, arg);
589 err = sg_get_timeout(q);
592 err = sg_get_reserved_size(q, arg);
595 err = sg_set_reserved_size(q, arg);
598 err = sg_emulated_host(q, arg);
606 err = sg_io(q, bd_disk, &hdr, mode);
622 memset(&hdr, 0,
sizeof(hdr));
654 err = sg_io(q, bd_disk, &hdr, mode);
681 err = blk_send_start_stop(q, bd_disk, 0x03);
684 err = blk_send_start_stop(q, bd_disk, 0x02);
729 "%s: sending ioctl %x to a partition!\n",
current->comm, cmd);
736 unsigned int cmd,
void __user *
arg)
748 static int __init blk_scsi_ioctl_init(
void)
750 blk_set_cmd_filter_defaults(&blk_default_cmd_filter);