sg_io_hdr
field |
in
or out |
type |
different |
brief
description including differences between implementations |
interface_id |
in |
int |
guard field. Current
implementations only accept " (int)'S' ". If not set, the sg driver
sets errno to ENOSYS
while the block layer sets it to EINVAL |
|
dxfer_direction |
in |
(-ve) int |
minor |
direction of data transfer.
SG_DXFER_NONE and friends are defined as negative integers so the sg
driver can discriminate between sg_io_hdr instances and those of
sg_header. This nuance is irrelevant to non-sg driver usage of SG_IO.
See below. |
cmd_len |
in |
unsigned char |
limits command length to 255
bytes. No SCSI commands (even variable length ones in OSD) are this
long (yet) |
|
max_sb_len |
in |
unsigned char |
maximum number of bytes of sense
data that the driver can output via the sbp pointer |
|
iovec_count |
in |
unsigned short |
yes |
if not sg driver and greater
than zero then the SG_IO ioctl fails with errno set to EOPNOTSUPP; sg
driver treats dxferp as a pointer to an array struct sg_iovec when this
field is greater than zero |
dxfer_len |
in |
unsigned int |
minor |
number of bytes of data to
transfer to or from the device. Upper limit for block devices related
to /sys/block/<device>/queue/max_sectors_kb |
dxferp | in [*in or *out] |
void * |
minor |
pointer to (user space) data to
transfer to (if reading from device) or transfer from (if writing to
device). Further level of indirection in the sg driver when iovec_count
is greater than 0 . |
cmdp | in [*in] |
unsigned char * |
pointer to SCSI command. The
SG_IO ioctl in the sg drive fails with errno set to EMSGSIZE if
cmdp is NULL and EFAULT if it is invalid; the block layer sets errno to
EFAULT in both cases. |
|
sbp |
in [*out] |
unsigned char * |
pointer to user data area where
no more than max_sb_len bytes of sense data from the device will be
written if the SCSI status is CHECK CONDITION. |
|
timeout |
in |
unsigned int |
yes (if = 0) |
time in milliseconds that the
SCSI mid-level will wait for a response. If that timer expires
before the command finishes, then the command may be aborted, the
device (and maybe others on the same interconnect) may be reset
depending on error
handler settings. Dangerous stuff, the SG_IO ioctl has no control
(through this interface) of exactly what happens. In the sg driver a
timeout value of 0 means 0 milliseconds, in the block layer (currently)
it means 60 seconds. |
flags |
in |
unsigned int |
yes |
Block layer SG_IO ioctl ignores
this field; the sg driver uses it to request special services like
direct IO or mmap-ed transfers. It is a bit mask. |
pack_id |
in -> out |
int |
unused (for user space program
tag) |
|
usr_ptr |
in -> out |
void * |
unused (for user space pointer
tag) |
|
status |
out |
unsigned char |
SCSI command status, zero
implies GOOD |
|
masked_status |
out |
unsigned char |
Logically: masked_status == ((status & 0x3e) >> 1). Old linux SCSI subsystem usage, deprecated. | |
msg_status |
out |
unsigned char |
SCSI parallel interface (SPI)
message status (very
old, deprecated) |
|
sb_len_wr |
out |
unsigned char |
actual length of sense data (in
bytes) output via sbp pointer. |
|
host_status |
out |
unsigned short |
error reported by the initiator
(port). These are the "DID_*" error codes in scsi.h |
|
driver_status |
out |
unsigned short |
bit mask: error and suggestion reported by the low level driver (LLD). These are the "DRIVER_*" error codes in scsi.h | |
resid |
out |
int |
(dxfer_len - number_of_bytes_actually_transferred). Typically only set when there is a shortened DMA transfer from the device. Not necessarily an error. Older LLDs always yield zero. | |
duration |
out |
unsigned int |
number of milliseconds that
elapsed between when the command was injected into the SCSI mid level
and the corresponding "done" callback was invoked. Roughly the duration
of the SCSI command in milliseconds. |
|
info |
out |
unsigned int |
minor |
bit mask indicating what was
done (or not) and whether any error was detected. Block layer SG_IO
ioctl only sets SG_INFO_CHECK if an error was detected |
open()
flags |
sg notes |
sd notes |
st notes |
cdrom notes |
Comments |
<none> or O_RDONLY |
1, 2 |
3,4 |
3,5 |
3,6 |
best to add O_NONBLOCK. For a
device with removable media (e.g. tape drive) that depends on whether
the drive or its media is being accessed. |
O_RDONLY | O_NONBLOCK |
1,7 |
3 |
3,13 |
3 |
recommended when SCSI commands
are recognized as reading information from the device |
O_RDWR |
2 |
4,8,9 |
5,8,9 |
6,8,9 |
again, could be better to add O_NONBLOCK |
O_RDWR | O_NONBLOCK |
7 |
8,9 |
8,9,13 |
8,9 |
recommended when arbitrary
(including vendor specific) SCSI commands are to be sent |
<< interaction with
O_EXCL>> |
10 |
11 |
12 |
11 |
only use when sure that no other
application may want to access the device (or partition). A surprising
number of applications do "poke around" devices. |
<< interaction with
O_DIRECT>> |
- |
--> |
- |
--> |
requires sector alignment on
data transfers (ignored by sg and st) |
SCSI
command |
(draft)
standard |
sg
driver requires |
block
layer SG_IO requires (except st) |
Comments |
BLANK |
MMC-4 |
O_RDWR | O_RDWR | |
CLOSE TRACK/SESSION |
MMC-4 |
O_RDWR | O_RDWR | |
ERASE |
MMC-4 |
O_RDWR | O_RDWR | |
FLUSH CACHE |
SBC-3, MMC-4 |
O_RDWR | O_RDWR | Really SYNCHRONIZE CACHE command |
FORMAT UNIT |
SBC-3, MMC-4 |
O_RDWR | O_RDWR | default command timeout may not
be long enough |
GET CONFIGURATION |
MMC-4 |
O_RDWR | O_RDONLY | reads CD/DVD metadata |
GET EVENT STATUS NOTIFICATION |
MMC-4 |
O_RDWR | O_RDONLY | |
GET PERFORMANCE |
MMC-4 | O_RDWR | O_RDONLY | |
INQUIRY |
SPC-4 |
O_RDONLY |
O_RDONLY |
All SCSI devices should respond
to this command |
LOAD UNLOAD MEDIUM |
MMC-4 |
O_RDWR | O_RDWR | MEDIUM may be replaced by CD,
DVD or nothing |
LOG SELECT |
SPC-4 |
O_RDWR | O_RDWR | used to change logging or clear
logged data |
LOG SENSE |
SPC-4 |
O_RDONLY | O_RDONLY | used to fetch logged data |
MAINTENANCE COMMAND IN |
SPC-4 |
O_RDONLY |
CAP_SYS_RAWIO |
various "REPORT ..." commands
such as REPORT SUPPORTED OPERATION CODES in here |
MODE SELECT (6+10) |
SPC-4 |
O_RDWR | O_RDWR | Used to change SCSI device
metadata |
MODE SENSE (6+10) |
SPC-4 |
O_RDONLY | O_RDONLY | Used to read SCSI device metadata |
PAUSE RESUME | MMC-4 | O_RDWR | O_RDONLY | |
PLAY AUDIO (10) |
MMC-4 |
O_RDWR | O_RDONLY | |
PLAY AUDIO MSF |
MMC-4 |
O_RDWR | O_RDONLY | |
PLAY AUDIO TI |
?? |
O_RDWR | O_RDONLY | opcode 0x48, unassigned to
any spec in SPC-4 |
PLAY CD | MMC-2 |
O_RDWR | O_RDONLY | old, now SPARE IN in SPC-4 |
PREVENT ALLOW MEDIUM REMOVAL |
SPC-4, MMC-4 |
O_RDWR | O_RDWR | sd, st and cdrom drivers use
this internally |
READ (6+10+12+16) |
SBC-3 |
O_RDONLY | O_RDONLY | READ(16) requires O_RDWR with
the sg driver before lk2.6.11 |
READ BUFFER |
SPC-4 |
O_RDONLY | O_RDONLY | |
READ BUFFER CAPACITY |
MMC-4 |
O_RDWR | O_RDONLY | |
READ CAPACITY(10) |
SBC-3, MMC-4 |
O_RDONLY | O_RDONLY | |
READ CAPACITY(16) |
SBC-3, MMC-4 |
O_RDONLY |
CAP_SYS_RAWIO |
within SERVICE ACTION IN
command. Needed for RAIDs larger than 2 TB |
READ CD |
MMC-4 |
O_RDWR | O_RDONLY | |
READ CD MSF |
MMC-4 |
O_RDWR | O_RDONLY | |
READ CDVD CAPACITY |
SBC-3, MMC-4 |
O_RDONLY | O_RDONLY | Strange (old ?) name from
cdrom.h . Actually is READ CAPACITY. |
READ DEFECT (10) |
SBC-3 |
O_RDWR |
O_RDONLY | |
READ DISC INFO |
MMC-4 |
O_RDWR | O_RDONLY | |
READ DVD STRUCTURE |
MMC-4 |
O_RDWR | O_RDONLY | |
READ FORMAT CAPACITIES |
MMC-4 |
O_RDWR | O_RDONLY | |
READ HEADER |
MMC-2 |
O_RDWR | O_RDONLY | |
READ LONG (10) |
SBC-3 |
O_RDONLY | O_RDONLY | but not READ LONG (16) |
READ SUB-CHANNEL |
MMC-4 |
O_RDWR | O_RDONLY | |
READ TOC/PMA/ATIP |
MMC-4 |
O_RDWR | O_RDONLY | |
READ TRACK (RZONE) INFO |
MMC-4 |
O_RDWR | O_RDONLY | In MMC-4 called READ TRACK INFO |
RECEIVE DIAGNOSTIC |
SPC-4 |
O_RDONLY | CAP_SYS_RAWIO | the SES command set uses this
command a lot. An SES device is only accessible via an sg device node |
REPAIR (RZONE) TRACK |
MMC-4 | O_RDWR | O_RDWR | |
REPORT KEY |
MMC-4 |
O_RDWR | O_RDONLY | |
REPORT LUNS |
SPC-4 |
O_RDONLY | CAP_SYS_RAWIO | mandatory since SPC-3 |
REQUEST SENSE |
SPC-4 |
O_RDONLY | O_RDONLY | has uses other than those
displaced by autosense |
RESERVE (RZONE) TRACK |
MMC-4 |
O_RDWR | O_RDWR | |
SCAN |
MMC-4 |
O_RDWR | O_RDONLY | |
SEEK |
MMC-4 | O_RDWR | O_RDONLY | |
SEND CUE SHEET |
MMC-4 |
O_RDWR | O_RDWR | |
SEND DVD STRUCTURE |
MMC-4 |
O_RDWR | O_RDWR | |
[SEND EVENT] |
MMC-2 |
O_RDWR | cdrom.h associates opcode 0xa2
but MMC-2 uses opcode 0x5d ?? |
|
SEND KEY |
MMC-4 |
O_RDWR | O_RDWR | |
SEND OPC INFORMATION |
MMC-4 |
O_RDWR | O_RDWR | |
SERVICE ACTION IN |
SPC-4, SBC-3 |
O_RDONLY | CAP_SYS_RAWIO | READ CAPACITY (16) service
action in here |
SET CD SPEED |
MMC-4 |
O_RDWR | O_RDWR | cdrom.h calls this SET SPEED |
SET STREAMING |
MMC-4 |
O_RDWR | O_RDWR | |
START STOP UNIT |
SBC-3, MMC-4 |
O_RDWR | O_RDONLY | hmm |
STOP PLAY/SCAN |
MMC-4 | O_RDWR | O_RDONLY | |
SYNCHRONIZE CACHE | SBC-3, MMC-4 |
O_RDWR | O_RDWR | cdrom.h calls this FLUSH CACHE |
TEST UNIT READY |
SPC-4 |
O_RDONLY | O_RDONLY | All SCSI devices should respond to this command |
VERIFY (10+16) |
SBC-3, MMC-4 |
O_RDWR | O_RDONLY | |
WRITE (6+10+12+16) | SBC-3 |
O_RDWR | O_RDWR | |
WRITE LONG (10+16) |
SBC-3 |
O_RDWR | O_RDWR | |
WRITE VERIFY (10+16) |
SBC-3, MMC-4 |
O_RDWR | O_RDWR | only WRITE VERIFY(10) is in MMC-4 |
Return to main page.
Last updated: 26th July 2008