SCSI Pass-Through Programmer's Guide
Opening the SPT device file
Open() is used to open the SPT device file after it has been created via mknod(). The file is
opened as an ordinary disc file. The device file is actually a “sharable” file, so it is possible to
have multiple opens from multiple processes. The application program could also create
child processes via fork() and can issue many parallel SCSI commands to the device that is
opened. But, it should be noted that the capability to use fork() on SPT device files is a recent
enhancement to MPE/iX and requires the corresponding patch to be installed. For details on
this enhancement, please refer the section “Recent Enhancements”.
The device file is closed using close() after use. Close() is done via the filenum returned by
open(). The device file can be purged using the unlink call.
Issuing SCSI commands
SPT I/O is achieved by using ioctl() calls. Making the ioctl() call is very simple:
r = ioctl(fd, SIOC_IO, &command);
SIOC_IO specifies a SCSI Pass through request. The “&command” passes the address of the
variable (a structure) which contains the SCSI command (called as the Command Data Bytes
– CDB) and related information:
struct sctl_io command;
The sctl_io structure is defined in the “sys/scsi.h” file. This definition is exactly as it appears
in the HP-UX “sys/scsi.h” file. There is a data_xfer field which is returned by the low level
I/O layers to tell the actual number of bytes transferred. Typically, the initialization
resembles:
memset(command, 0, sizeof(struct sctl_io));
command.flags = SCTL_READ;
command.cdb_length = 6;
command.cdb[0] = CMDtest_unit_ready;
command.cdb[4] = sizeof(struct inquiry_2);
command.data = buf;
command.data_length = 64*1024;
command.max_msecs = timeout;
sctl_io flags and commands supported are defined in sys/scsi.h. sctl_io.data is the buffer
where the command output is returned. A detailed description of ioctl and the data structures
involved is beyond the scope of this document. Please
click here for a more detailed
explanation. All SCSI commands are described as part of the SCSI Standards documents
available at http:www.t10.org.
- 8 -