SCSI_IOCTL_SEND_COMMAND

The Linux SCSI Generic (sg) HOWTO
Prev | Chapter 8. Ioctl()s | Next

# 8.26. SCSI_IOCTL_SEND_COMMAND

SCSI_IOCTL_SEND_COMMAND 0x1. This ioctl() also offers a "pass through" SCSI command capability which is a subset of what is offered by the sg driver.

The structure that we are passed should look like:

       struct sdata {
        unsigned int inlen;     [i] Length of data written to device
        unsigned int outlen;    [i] Length of data read from device
        unsigned char cmd[x];   [i] SCSI command (6 <= x <= 16)
                                [o] Data read from device starts here
                                [o] On error, sense buffer starts here
        unsigned char wdata[y]; [i] Data written to device starts here
       };

Notes:

- The SCSI command length is determined by examining the 1st byte of the given command [1] . There is no way to override this.

- Data transfers are limited to PAGE_SIZE (4K on i386, 8K on alpha).

- The length (x + y) must be at least OMAX_SB_LEN bytes long to accommodate the sense buffer when an error occurs. The sense buffer is truncated to OMAX_SB_LEN (16) bytes so that old code will not be surprised.

- If a Unix error occurs (e.g. ENOMEM) then the user will receive a negative return and the Unix error code in 'errno'. If the SCSI command succeeds then 0 is returned. Positive numbers returned are the compacted SCSI error codes (4 bytes in one int) where the lowest byte is the SCSI status. See the drivers/scsi/scsi.h file for more information on this.

### Notes

[1] | Here is the mapping from the SCSI opcode "group" (top 3 bits of opcode) to the assumed length (in lk 2.4.15):
    unsigned char scsi_command_size[8] =
    {
            6, 10, 10, 12,
            16, 12, 10, 10
    };
The assumed length of group 4 commands changed from 12 to 16 in lk 2.4.15 reflecting support for 16 byte SCSI commands being added to the kernel.

Prev | Home | Next
SCSI_IOCTL_PROBE_HOST | Up | Direct and Mmap-ed IO