HP-UX Reference (11i v2 04/09) - 7 Device (Special) Files, 9 General Information, Index (vol 10)
s
scsi_disk(7) scsi_disk(7)
NAME
scsi_disk - SCSI direct access device driver (sdisk)
DESCRIPTION
This section describes the interface for access of SCSI disk, CD-ROM, and optical disk devices through
the character special device driver.
SCSI direct access devices store a sequence of data blocks. Each direct access device has a specific device
size consisting of a number of data blocks and a logical block size. All data blocks have the same logical
block size. Since I/O operations must have a size that is an integral number of blocks, one logical block
size is the smallest possible I/O quantity. The device block size can be determined through use of the
DIOC_DESCRIBE
, DIOC_CAPACITY
, and SIOC_CAPACITY
ioctls (see disk(7) and scsi (7);
SIOC_CAPACITY
is not supported on disc3). A direct access device that is not ready for use, whether
due to no media installed or another reason, is interpreted to mean the device has zero size. An
open()
call to such a device succeeds, but subsequent
read() and write() calls fail.
The ioctl (2) manpage explains how the operations and arguments are used. Note, the arg used is com-
monly the address of the parameter cited in the particular ioctl
#define statement. See the EXAM-
PLES section for sample code.
To improve performance, many SCSI disk devices have caches, which can be used for both read and write
operations. Read cache use, called "read ahead", causes the disk drive to read data in anticipation of read
requests. Read ahead is only apparent to users in the increased performance that it produces. Write
cache use is called "immediate reporting". Immediate reporting increases I/O performance by reporting a
completed write status before the data being written is actually committed to media. If the subsequent
physical write operation does not complete successfully, data may be lost. Physical write failures due to
media defects are largely eliminated by use of automatic sparing in disk drives. Power failure between
immediate reporting and media commit can result in cached data being lost. However, the period of time
between these events is typically relatively small, making such losses unlikely. The
SIOC_GET_IR ioctl
can be used to determine if immediate-reporting functionality is currently being used by the device. The
value 1 indicates immediate reporting is enabled. The value zero indicates immediate reporting is dis-
abled. The SIOC_SET_IR ioctl can be used to enable or disable immediate reporting. A zero value dis-
ables immediate reporting. The value 1 enables immediate reporting.
The
SIOC_SYNC_CACHE ioctl can be used to force data cached in the device to media.
Most SCSI removable media disk devices support "prevent" and "allow" media-removal commands. To
avoid data corruption and data accessibility problems, media removal is prevented for the entire duration
a removable media disk device is open. Because media removal is not supported, the
SIOC_MEDIUM_CHANGED
ioctl is not supported.
The header file
<sys/scsi.h> has useful information for direct access device control, including the fol-
lowing:
/* ioctl support for SCSI disk devices */
#define SIOC_GET_IR _IOR(’S’, 14, int)
#define SIOC_SET_IR _IOW(’S’, 15, int)
#define SIOC_SYNC_CACHE -IOW(’S’, 70, int)
The SIOC_FORMAT ioctl reformats the entire media surface. Exclusive access to the device, obtained
through use of the DIOC_EXCLUSIVE ioctl (see disk (7)), is required prior to reformatting to ensure that
other applications are not affected. The fmt_optn field can be used to select the desired media
geometry. Only one media geometry is supported on most devices. The value zero should be used for
these devices. The value zero can also be used to select the default geometry on devices that support mul-
tiple media geometries. The interleave field can be used to specify sector interleaving. The value zero
specifies that an appropriate default interleave should be used.
EXAMPLES
The following sample code shows how to use ioctls that affect
scsi_disk.
#include <stdio.h>
#include <fcntl.h>
#include <sys/errno.h>
#include <sys/diskio.h>
#include <sys/scsi.h>
Describe (dfd)
int dfd;
HP-UX 11i Version 2: September 2004 − 1 − Hewlett-Packard Company Section 7−−141