1 // SPDX-License-Identifier: GPL-2.0-only
4 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 08/23/2000
5 * - get rid of some verify_areas and use __copy*user and __get/put_user
6 * for the ones that remain
8 #include <linux/module.h>
9 #include <linux/blkdev.h>
10 #include <linux/interrupt.h>
11 #include <linux/errno.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
15 #include <linux/string.h>
16 #include <linux/uaccess.h>
17 #include <linux/cdrom.h>
19 #include <scsi/scsi.h>
20 #include <scsi/scsi_cmnd.h>
21 #include <scsi/scsi_device.h>
22 #include <scsi/scsi_eh.h>
23 #include <scsi/scsi_host.h>
24 #include <scsi/scsi_ioctl.h>
26 #include <scsi/scsi_dbg.h>
28 #include "scsi_logging.h"
30 #define NORMAL_RETRIES 5
31 #define IOCTL_NORMAL_TIMEOUT (10 * HZ)
33 #define MAX_BUF PAGE_SIZE
36 * ioctl_probe -- return host identification
37 * @host: host to identify
38 * @buffer: userspace buffer for identification
40 * Return an identifying string at @buffer, if @buffer is non-NULL, filling
41 * to the length stored at * (int *) @buffer.
43 static int ioctl_probe(struct Scsi_Host *host, void __user *buffer)
45 unsigned int len, slen;
49 if (get_user(len, (unsigned int __user *) buffer))
52 if (host->hostt->info)
53 string = host->hostt->info(host);
55 string = host->hostt->name;
57 slen = strlen(string);
60 if (copy_to_user(buffer, string, len))
67 static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
68 int timeout, int retries)
71 struct scsi_sense_hdr sshdr;
72 const struct scsi_exec_args exec_args = {
76 SCSI_LOG_IOCTL(1, sdev_printk(KERN_INFO, sdev,
77 "Trying ioctl with scsi command %d\n", *cmd));
79 result = scsi_execute_cmd(sdev, cmd, REQ_OP_DRV_IN, NULL, 0, timeout,
82 SCSI_LOG_IOCTL(2, sdev_printk(KERN_INFO, sdev,
83 "Ioctl returned 0x%x\n", result));
87 if (scsi_sense_valid(&sshdr)) {
88 switch (sshdr.sense_key) {
90 if (cmd[0] == ALLOW_MEDIUM_REMOVAL)
93 sdev_printk(KERN_INFO, sdev,
94 "ioctl_internal_command: "
96 "asc=0x%x ascq=0x%x\n",
97 sshdr.asc, sshdr.ascq);
99 case NOT_READY: /* This happens if there is no disc in drive */
104 if (sdev->removable) {
106 result = 0; /* This is no longer considered an error */
109 fallthrough; /* for non-removable media */
111 sdev_printk(KERN_INFO, sdev,
112 "ioctl_internal_command return code = %x\n",
114 scsi_print_sense_hdr(sdev, NULL, &sshdr);
119 SCSI_LOG_IOCTL(2, sdev_printk(KERN_INFO, sdev,
120 "IOCTL Releasing command\n"));
124 int scsi_set_medium_removal(struct scsi_device *sdev, char state)
126 char scsi_cmd[MAX_COMMAND_SIZE];
129 if (!sdev->removable || !sdev->lockable)
132 scsi_cmd[0] = ALLOW_MEDIUM_REMOVAL;
139 ret = ioctl_internal_command(sdev, scsi_cmd,
140 IOCTL_NORMAL_TIMEOUT, NORMAL_RETRIES);
142 sdev->locked = (state == SCSI_REMOVAL_PREVENT);
145 EXPORT_SYMBOL(scsi_set_medium_removal);
148 * The scsi_ioctl_get_pci() function places into arg the value
149 * pci_dev::slot_name (8 characters) for the PCI device (if any).
150 * Returns: 0 on success
151 * -ENXIO if there isn't a PCI device pointer
152 * (could be because the SCSI driver hasn't been
153 * updated yet, or because it isn't a SCSI
155 * any copy_to_user() error on failure there
157 static int scsi_ioctl_get_pci(struct scsi_device *sdev, void __user *arg)
159 struct device *dev = scsi_get_device(sdev->host);
165 name = dev_name(dev);
167 /* compatibility with old ioctl which only returned
169 return copy_to_user(arg, name, min(strlen(name), (size_t)20))
173 static int sg_get_version(int __user *p)
175 static const int sg_version_num = 30527;
176 return put_user(sg_version_num, p);
179 static int sg_set_timeout(struct scsi_device *sdev, int __user *p)
181 int timeout, err = get_user(timeout, p);
184 sdev->sg_timeout = clock_t_to_jiffies(timeout);
189 static int sg_get_reserved_size(struct scsi_device *sdev, int __user *p)
191 int val = min(sdev->sg_reserved_size,
192 queue_max_bytes(sdev->request_queue));
194 return put_user(val, p);
197 static int sg_set_reserved_size(struct scsi_device *sdev, int __user *p)
199 int size, err = get_user(size, p);
207 sdev->sg_reserved_size = min_t(unsigned int, size,
208 queue_max_bytes(sdev->request_queue));
213 * will always return that we are ATAPI even for a real SCSI drive, I'm not
214 * so sure this is worth doing anything about (why would you care??)
216 static int sg_emulated_host(struct request_queue *q, int __user *p)
218 return put_user(1, p);
221 static int scsi_get_idlun(struct scsi_device *sdev, void __user *argp)
223 struct scsi_idlun v = {
224 .dev_id = (sdev->id & 0xff) +
225 ((sdev->lun & 0xff) << 8) +
226 ((sdev->channel & 0xff) << 16) +
227 ((sdev->host->host_no & 0xff) << 24),
228 .host_unique_id = sdev->host->unique_id
230 if (copy_to_user(argp, &v, sizeof(struct scsi_idlun)))
235 static int scsi_send_start_stop(struct scsi_device *sdev, int data)
237 u8 cdb[MAX_COMMAND_SIZE] = { };
241 return ioctl_internal_command(sdev, cdb, START_STOP_TIMEOUT,
246 * Check if the given command is allowed.
248 * Only a subset of commands are allowed for unprivileged users. Commands used
249 * to format the media, update the firmware, etc. are not permitted.
251 bool scsi_cmd_allowed(unsigned char *cmd, bool open_for_write)
253 /* root can do any command. */
254 if (capable(CAP_SYS_RAWIO))
257 /* Anybody who can open the device can do a read-safe command */
259 /* Basic read-only commands */
260 case TEST_UNIT_READY:
267 case READ_DEFECT_DATA:
268 case READ_CAPACITY: /* also GPCMD_READ_CDVD_CAPACITY */
275 case GPCMD_VERIFY_10:
278 case SERVICE_ACTION_IN_16:
279 case RECEIVE_DIAGNOSTIC:
280 case MAINTENANCE_IN: /* also GPCMD_SEND_KEY, which is a write command */
281 case GPCMD_READ_BUFFER_CAPACITY:
282 /* Audio CD commands */
284 case GPCMD_PLAY_AUDIO_10:
285 case GPCMD_PLAY_AUDIO_MSF:
286 case GPCMD_PLAY_AUDIO_TI:
287 case GPCMD_PAUSE_RESUME:
288 /* CD/DVD data reading */
290 case GPCMD_READ_CD_MSF:
291 case GPCMD_READ_DISC_INFO:
292 case GPCMD_READ_DVD_STRUCTURE:
293 case GPCMD_READ_HEADER:
294 case GPCMD_READ_TRACK_RZONE_INFO:
295 case GPCMD_READ_SUBCHANNEL:
296 case GPCMD_READ_TOC_PMA_ATIP:
297 case GPCMD_REPORT_KEY:
299 case GPCMD_GET_CONFIGURATION:
300 case GPCMD_READ_FORMAT_CAPACITIES:
301 case GPCMD_GET_EVENT_STATUS_NOTIFICATION:
302 case GPCMD_GET_PERFORMANCE:
304 case GPCMD_STOP_PLAY_SCAN:
308 /* Basic writing commands */
313 case WRITE_VERIFY_12:
321 case GPCMD_MODE_SELECT_10:
325 case GPCMD_CLOSE_TRACK:
326 case GPCMD_FLUSH_CACHE:
327 case GPCMD_FORMAT_UNIT:
328 case GPCMD_REPAIR_RZONE_TRACK:
329 case GPCMD_RESERVE_RZONE_TRACK:
330 case GPCMD_SEND_DVD_STRUCTURE:
331 case GPCMD_SEND_EVENT:
333 case GPCMD_SEND_CUE_SHEET:
334 case GPCMD_SET_SPEED:
335 case GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
336 case GPCMD_LOAD_UNLOAD:
337 case GPCMD_SET_STREAMING:
338 case GPCMD_SET_READ_AHEAD:
341 return open_for_write;
346 EXPORT_SYMBOL(scsi_cmd_allowed);
348 static int scsi_fill_sghdr_rq(struct scsi_device *sdev, struct request *rq,
349 struct sg_io_hdr *hdr, bool open_for_write)
351 struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
353 if (hdr->cmd_len < 6)
355 if (copy_from_user(scmd->cmnd, hdr->cmdp, hdr->cmd_len))
357 if (!scsi_cmd_allowed(scmd->cmnd, open_for_write))
359 scmd->cmd_len = hdr->cmd_len;
361 rq->timeout = msecs_to_jiffies(hdr->timeout);
363 rq->timeout = sdev->sg_timeout;
365 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
366 if (rq->timeout < BLK_MIN_SG_TIMEOUT)
367 rq->timeout = BLK_MIN_SG_TIMEOUT;
372 static int scsi_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
375 struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(rq);
379 * fill in all the output members
381 hdr->status = scmd->result & 0xff;
382 hdr->masked_status = sg_status_byte(scmd->result);
383 hdr->msg_status = COMMAND_COMPLETE;
384 hdr->host_status = host_byte(scmd->result);
385 hdr->driver_status = 0;
386 if (scsi_status_is_check_condition(hdr->status))
387 hdr->driver_status = DRIVER_SENSE;
389 if (hdr->masked_status || hdr->host_status || hdr->driver_status)
390 hdr->info |= SG_INFO_CHECK;
391 hdr->resid = scmd->resid_len;
394 if (scmd->sense_len && hdr->sbp) {
395 int len = min((unsigned int) hdr->mx_sb_len, scmd->sense_len);
397 if (!copy_to_user(hdr->sbp, scmd->sense_buffer, len))
398 hdr->sb_len_wr = len;
403 r = blk_rq_unmap_user(bio);
410 static int sg_io(struct scsi_device *sdev, struct sg_io_hdr *hdr,
413 unsigned long start_time;
418 struct scsi_cmnd *scmd;
421 if (hdr->interface_id != 'S')
424 if (hdr->dxfer_len > (queue_max_hw_sectors(sdev->request_queue) << 9))
428 switch (hdr->dxfer_direction) {
431 case SG_DXFER_TO_DEV:
434 case SG_DXFER_TO_FROM_DEV:
435 case SG_DXFER_FROM_DEV:
438 if (hdr->flags & SG_FLAG_Q_AT_HEAD)
441 rq = scsi_alloc_request(sdev->request_queue, writing ?
442 REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
445 scmd = blk_mq_rq_to_pdu(rq);
447 if (hdr->cmd_len > sizeof(scmd->cmnd)) {
449 goto out_put_request;
452 ret = scsi_fill_sghdr_rq(sdev, rq, hdr, open_for_write);
454 goto out_put_request;
456 ret = blk_rq_map_user_io(rq, NULL, hdr->dxferp, hdr->dxfer_len,
457 GFP_KERNEL, hdr->iovec_count && hdr->dxfer_len,
458 hdr->iovec_count, 0, rq_data_dir(rq));
460 goto out_put_request;
465 start_time = jiffies;
467 blk_execute_rq(rq, at_head);
469 hdr->duration = jiffies_to_msecs(jiffies - start_time);
471 ret = scsi_complete_sghdr_rq(rq, hdr, bio);
474 blk_mq_free_request(rq);
479 * sg_scsi_ioctl -- handle deprecated SCSI_IOCTL_SEND_COMMAND ioctl
480 * @q: request queue to send scsi commands down
481 * @open_for_write: is the file / block device opened for writing?
482 * @sic: userspace structure describing the command to perform
484 * Send down the scsi command described by @sic to the device below
485 * the request queue @q.
488 * - This interface is deprecated - users should use the SG_IO
489 * interface instead, as this is a more flexible approach to
490 * performing SCSI commands on a device.
491 * - The SCSI command length is determined by examining the 1st byte
492 * of the given command. There is no way to override this.
493 * - Data transfers are limited to PAGE_SIZE
494 * - The length (x + y) must be at least OMAX_SB_LEN bytes long to
495 * accommodate the sense buffer when an error occurs.
496 * The sense buffer is truncated to OMAX_SB_LEN (16) bytes so that
497 * old code will not be surprised.
498 * - If a Unix error occurs (e.g. ENOMEM) then the user will receive
499 * a negative return and the Unix error code in 'errno'.
500 * If the SCSI command succeeds then 0 is returned.
501 * Positive numbers returned are the compacted SCSI error codes (4
502 * bytes in one int) where the lowest byte is the SCSI status.
504 static int sg_scsi_ioctl(struct request_queue *q, bool open_for_write,
505 struct scsi_ioctl_command __user *sic)
509 unsigned int in_len, out_len, bytes, opcode, cmdlen;
510 struct scsi_cmnd *scmd;
517 * get in an out lengths, verify they don't exceed a page worth of data
519 if (get_user(in_len, &sic->inlen))
521 if (get_user(out_len, &sic->outlen))
523 if (in_len > PAGE_SIZE || out_len > PAGE_SIZE)
525 if (get_user(opcode, &sic->data[0]))
528 bytes = max(in_len, out_len);
530 buffer = kzalloc(bytes, GFP_NOIO | GFP_USER | __GFP_NOWARN);
536 rq = scsi_alloc_request(q, in_len ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
539 goto error_free_buffer;
541 scmd = blk_mq_rq_to_pdu(rq);
543 cmdlen = COMMAND_SIZE(opcode);
546 * get command and data to send to device, if any
549 scmd->cmd_len = cmdlen;
550 if (copy_from_user(scmd->cmnd, sic->data, cmdlen))
553 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
557 if (!scsi_cmd_allowed(scmd->cmnd, open_for_write))
560 /* default. possible overridden later */
564 case SEND_DIAGNOSTIC:
566 rq->timeout = FORMAT_UNIT_TIMEOUT;
570 rq->timeout = START_STOP_TIMEOUT;
573 rq->timeout = MOVE_MEDIUM_TIMEOUT;
575 case READ_ELEMENT_STATUS:
576 rq->timeout = READ_ELEMENT_STATUS_TIMEOUT;
578 case READ_DEFECT_DATA:
579 rq->timeout = READ_DEFECT_DATA_TIMEOUT;
583 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
588 err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
593 blk_execute_rq(rq, false);
595 err = scmd->result & 0xff; /* only 8 bit SCSI status */
597 if (scmd->sense_len && scmd->sense_buffer) {
598 /* limit sense len for backward compatibility */
599 if (copy_to_user(sic->data, scmd->sense_buffer,
600 min(scmd->sense_len, 16U)))
604 if (copy_to_user(sic->data, buffer, out_len))
609 blk_mq_free_request(rq);
617 int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp)
620 if (in_compat_syscall()) {
621 struct compat_sg_io_hdr hdr32 = {
622 .interface_id = hdr->interface_id,
623 .dxfer_direction = hdr->dxfer_direction,
624 .cmd_len = hdr->cmd_len,
625 .mx_sb_len = hdr->mx_sb_len,
626 .iovec_count = hdr->iovec_count,
627 .dxfer_len = hdr->dxfer_len,
628 .dxferp = (uintptr_t)hdr->dxferp,
629 .cmdp = (uintptr_t)hdr->cmdp,
630 .sbp = (uintptr_t)hdr->sbp,
631 .timeout = hdr->timeout,
633 .pack_id = hdr->pack_id,
634 .usr_ptr = (uintptr_t)hdr->usr_ptr,
635 .status = hdr->status,
636 .masked_status = hdr->masked_status,
637 .msg_status = hdr->msg_status,
638 .sb_len_wr = hdr->sb_len_wr,
639 .host_status = hdr->host_status,
640 .driver_status = hdr->driver_status,
642 .duration = hdr->duration,
646 if (copy_to_user(argp, &hdr32, sizeof(hdr32)))
653 if (copy_to_user(argp, hdr, sizeof(*hdr)))
658 EXPORT_SYMBOL(put_sg_io_hdr);
660 int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp)
663 struct compat_sg_io_hdr hdr32;
665 if (in_compat_syscall()) {
666 if (copy_from_user(&hdr32, argp, sizeof(hdr32)))
669 *hdr = (struct sg_io_hdr) {
670 .interface_id = hdr32.interface_id,
671 .dxfer_direction = hdr32.dxfer_direction,
672 .cmd_len = hdr32.cmd_len,
673 .mx_sb_len = hdr32.mx_sb_len,
674 .iovec_count = hdr32.iovec_count,
675 .dxfer_len = hdr32.dxfer_len,
676 .dxferp = compat_ptr(hdr32.dxferp),
677 .cmdp = compat_ptr(hdr32.cmdp),
678 .sbp = compat_ptr(hdr32.sbp),
679 .timeout = hdr32.timeout,
680 .flags = hdr32.flags,
681 .pack_id = hdr32.pack_id,
682 .usr_ptr = compat_ptr(hdr32.usr_ptr),
683 .status = hdr32.status,
684 .masked_status = hdr32.masked_status,
685 .msg_status = hdr32.msg_status,
686 .sb_len_wr = hdr32.sb_len_wr,
687 .host_status = hdr32.host_status,
688 .driver_status = hdr32.driver_status,
689 .resid = hdr32.resid,
690 .duration = hdr32.duration,
698 if (copy_from_user(hdr, argp, sizeof(*hdr)))
703 EXPORT_SYMBOL(get_sg_io_hdr);
706 struct compat_cdrom_generic_command {
707 unsigned char cmd[CDROM_PACKET_SIZE];
708 compat_caddr_t buffer;
709 compat_uint_t buflen;
711 compat_caddr_t sense;
712 unsigned char data_direction;
713 unsigned char pad[3];
715 compat_int_t timeout;
716 compat_caddr_t unused;
720 static int scsi_get_cdrom_generic_arg(struct cdrom_generic_command *cgc,
721 const void __user *arg)
724 if (in_compat_syscall()) {
725 struct compat_cdrom_generic_command cgc32;
727 if (copy_from_user(&cgc32, arg, sizeof(cgc32)))
730 *cgc = (struct cdrom_generic_command) {
731 .buffer = compat_ptr(cgc32.buffer),
732 .buflen = cgc32.buflen,
734 .sense = compat_ptr(cgc32.sense),
735 .data_direction = cgc32.data_direction,
736 .quiet = cgc32.quiet,
737 .timeout = cgc32.timeout,
738 .unused = compat_ptr(cgc32.unused),
740 memcpy(&cgc->cmd, &cgc32.cmd, CDROM_PACKET_SIZE);
744 if (copy_from_user(cgc, arg, sizeof(*cgc)))
750 static int scsi_put_cdrom_generic_arg(const struct cdrom_generic_command *cgc,
754 if (in_compat_syscall()) {
755 struct compat_cdrom_generic_command cgc32 = {
756 .buffer = (uintptr_t)(cgc->buffer),
757 .buflen = cgc->buflen,
759 .sense = (uintptr_t)(cgc->sense),
760 .data_direction = cgc->data_direction,
762 .timeout = cgc->timeout,
763 .unused = (uintptr_t)(cgc->unused),
765 memcpy(&cgc32.cmd, &cgc->cmd, CDROM_PACKET_SIZE);
767 if (copy_to_user(arg, &cgc32, sizeof(cgc32)))
773 if (copy_to_user(arg, cgc, sizeof(*cgc)))
779 static int scsi_cdrom_send_packet(struct scsi_device *sdev, bool open_for_write,
782 struct cdrom_generic_command cgc;
783 struct sg_io_hdr hdr;
786 err = scsi_get_cdrom_generic_arg(&cgc, arg);
790 cgc.timeout = clock_t_to_jiffies(cgc.timeout);
791 memset(&hdr, 0, sizeof(hdr));
792 hdr.interface_id = 'S';
793 hdr.cmd_len = sizeof(cgc.cmd);
794 hdr.dxfer_len = cgc.buflen;
795 switch (cgc.data_direction) {
796 case CGC_DATA_UNKNOWN:
797 hdr.dxfer_direction = SG_DXFER_UNKNOWN;
800 hdr.dxfer_direction = SG_DXFER_TO_DEV;
803 hdr.dxfer_direction = SG_DXFER_FROM_DEV;
806 hdr.dxfer_direction = SG_DXFER_NONE;
812 hdr.dxferp = cgc.buffer;
815 hdr.mx_sb_len = sizeof(struct request_sense);
816 hdr.timeout = jiffies_to_msecs(cgc.timeout);
817 hdr.cmdp = ((struct cdrom_generic_command __user *) arg)->cmd;
818 hdr.cmd_len = sizeof(cgc.cmd);
820 err = sg_io(sdev, &hdr, open_for_write);
828 cgc.buflen = hdr.resid;
829 if (scsi_put_cdrom_generic_arg(&cgc, arg))
835 static int scsi_ioctl_sg_io(struct scsi_device *sdev, bool open_for_write,
838 struct sg_io_hdr hdr;
841 error = get_sg_io_hdr(&hdr, argp);
844 error = sg_io(sdev, &hdr, open_for_write);
845 if (error == -EFAULT)
847 if (put_sg_io_hdr(&hdr, argp))
853 * scsi_ioctl - Dispatch ioctl to scsi device
854 * @sdev: scsi device receiving ioctl
855 * @open_for_write: is the file / block device opened for writing?
856 * @cmd: which ioctl is it
857 * @arg: data associated with ioctl
859 * Description: The scsi_ioctl() function differs from most ioctls in that it
860 * does not take a major/minor number as the dev field. Rather, it takes
861 * a pointer to a &struct scsi_device.
863 int scsi_ioctl(struct scsi_device *sdev, bool open_for_write, int cmd,
866 struct request_queue *q = sdev->request_queue;
867 struct scsi_sense_hdr sense_hdr;
869 /* Check for deprecated ioctls ... all the ioctls which don't
870 * follow the new unique numbering scheme are deprecated */
872 case SCSI_IOCTL_SEND_COMMAND:
873 case SCSI_IOCTL_TEST_UNIT_READY:
874 case SCSI_IOCTL_BENCHMARK_COMMAND:
875 case SCSI_IOCTL_SYNC:
876 case SCSI_IOCTL_START_UNIT:
877 case SCSI_IOCTL_STOP_UNIT:
878 printk(KERN_WARNING "program %s is using a deprecated SCSI "
879 "ioctl, please convert it to SG_IO\n", current->comm);
886 case SG_GET_VERSION_NUM:
887 return sg_get_version(arg);
889 return sg_set_timeout(sdev, arg);
891 return jiffies_to_clock_t(sdev->sg_timeout);
892 case SG_GET_RESERVED_SIZE:
893 return sg_get_reserved_size(sdev, arg);
894 case SG_SET_RESERVED_SIZE:
895 return sg_set_reserved_size(sdev, arg);
896 case SG_EMULATED_HOST:
897 return sg_emulated_host(q, arg);
899 return scsi_ioctl_sg_io(sdev, open_for_write, arg);
900 case SCSI_IOCTL_SEND_COMMAND:
901 return sg_scsi_ioctl(q, open_for_write, arg);
902 case CDROM_SEND_PACKET:
903 return scsi_cdrom_send_packet(sdev, open_for_write, arg);
905 return scsi_send_start_stop(sdev, 3);
907 return scsi_send_start_stop(sdev, 2);
908 case SCSI_IOCTL_GET_IDLUN:
909 return scsi_get_idlun(sdev, arg);
910 case SCSI_IOCTL_GET_BUS_NUMBER:
911 return put_user(sdev->host->host_no, (int __user *)arg);
912 case SCSI_IOCTL_PROBE_HOST:
913 return ioctl_probe(sdev->host, arg);
914 case SCSI_IOCTL_DOORLOCK:
915 return scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT);
916 case SCSI_IOCTL_DOORUNLOCK:
917 return scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW);
918 case SCSI_IOCTL_TEST_UNIT_READY:
919 return scsi_test_unit_ready(sdev, IOCTL_NORMAL_TIMEOUT,
920 NORMAL_RETRIES, &sense_hdr);
921 case SCSI_IOCTL_START_UNIT:
922 return scsi_send_start_stop(sdev, 1);
923 case SCSI_IOCTL_STOP_UNIT:
924 return scsi_send_start_stop(sdev, 0);
925 case SCSI_IOCTL_GET_PCI:
926 return scsi_ioctl_get_pci(sdev, arg);
928 return scsi_ioctl_reset(sdev, arg);
932 if (in_compat_syscall()) {
933 if (!sdev->host->hostt->compat_ioctl)
935 return sdev->host->hostt->compat_ioctl(sdev, cmd, arg);
938 if (!sdev->host->hostt->ioctl)
940 return sdev->host->hostt->ioctl(sdev, cmd, arg);
942 EXPORT_SYMBOL(scsi_ioctl);
945 * We can process a reset even when a device isn't fully operable.
947 int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev, int cmd,
950 if (cmd == SG_SCSI_RESET && ndelay) {
951 if (scsi_host_in_recovery(sdev->host))
954 if (!scsi_block_when_processing_errors(sdev))
960 EXPORT_SYMBOL_GPL(scsi_ioctl_block_when_processing_errors);