Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S

scsi_disk(7)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

scsi_disk — SCSI direct access device drivers (esdisk/sdisk)

DESCRIPTION

This section describes the interface for access of SCSI disk, CD-ROM, and optical disk devices through the character special device driver. esdisk is the default driver for direct access devices starting at HP-UX 11i Version 3. sdisk is the default driver used on HP-UX 11i Version 2 and earlier releases. It is maintained for backward compatibility.

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, SIOC_CAPACITY, DIOC_DESCRIBE_EXT, and SIOC_STORAGE_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 commonly the address of the parameter cited in the particular ioctl #define statement. See the EXAMPLES 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 disabled. The SIOC_SET_IR ioctl can be used to enable or disable immediate reporting. A zero value disables 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 following:

/* 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 multiple 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_ext(dfd) int dfd; { int ret; disk_describe_type_ext_t disk_descr; uint64_t capacity; if ((ret = ioctl (dfd, DIOC_DESCRIBE_EXT, &descr_type)) != 0) { exit(1); } printf("\nSuccessful ioctl DIOC_DESCRIBE_EXT \n"); printf(" model number: %s\n", disk_descr.model_num); printf(" interface: %d <20=scsi>\n", disk_descr.intf_type); capacity = (disk_descr.maxsva_high << 32) + disk_descr.low_lba; printf(" Capacity: %llu (blocks)\n", capacity); printf(" block size: %u (bytes)\n", disk_descr.lgblksz); printf(" Device type: %u (0=disk, 5=CD, 7=OM)\n", disk_descr.dev_type); printf(" Write Protected: %s \n", disk_descr.flags & WRITE_PROTECT_FLAG ? "yes" : "No"); } Describe (dfd) int dfd; { int ret; disk_describe_type descr_type; if ((ret = ioctl (dfd, DIOC_DESCRIBE, &descr_type)) != 0) { exit(1); } printf ("\nSuccessful ioctl DIOC_DESCRIBE \n"); printf (" model number: %s\n", descr_type.model_num); printf (" interface: %d <20=scsi>\n", descr_type.intf_type); } Exclusive (dfd) int dfd; { int ret, flag=1; if ((ret = ioctl (dfd, DIOC_EXCLUSIVE, &flag)) != 0) { exit(1); } } Enable_WOE (dfd) int dfd; { int ret, flag=1; if ((ret = ioctl (dfd, SIOC_WRITE_WOE, &flag)) != 0) { exit(1); } printf ("\nSuccessful ioctl SIOC_WRITE_WOE \n"); } main (argc, argv) int argc; char ** argv; { int ret, fd; if (argc != 2) { printf ("Usage: %s <disk_device> \n", argv[0]); exit(1); } if ((fd = open (argv[1], O_RDWR)) < 0) { exit (1); } Describe_ext(fd); Describe (fd); Exclusive (fd); Enable_WOE (fd); }

WARNINGS

Historically, disk devices have had small (typically 512 byte) block sizes; however, many newer disk devices (such as optical disks and disk arrays) have relatively large block sizes. Applications using direct raw disk access should use the DIOC_DESCRIBE, DIOC_CAPACITY, DIOC_DESCRIBE_EXT, or SIOC_CAPACITY ioctl to determine the appropriate minimum I/O size.

Media removal and insertion while a disk device is open is unsupported and unpredictable. Do not attempt to circumvent prevention of media removal. Device capacity changes resulting from such intervention may not be recognized.

Often larger I/O operation sizes are expected to be more efficient. However, SCSI disk I/O operations that are large relative to the device's cache can result in insufficient cache space for the device to maintain full-media-speed data transfer rates. This can result in decreased I/O performance relative to smaller I/O sizes.

DEPENDENCIES

Optical Disk Devices

The SIOC_VERIFY_WRITES ioctl controls the write mode. Normally written data is assumed to be correctly stored on the media. Verify-writes mode causes verification of written data to ensure that data has been correctly written. Verification can substantially reduce write performance and is not generally needed.

The SIOC_VERIFY_WRITES ioctl can be used to enable or disable write verification. A zero value disables write verification. The value 1 enables write verification. Although write verification is primarily intended for optical media, some systems may support write verification on normal disk devices.

The SIOC_VERIFY ioctl verifies that a media area contains valid data (that is, data that has been correctly written). Verified media will not cause I/O errors when reading is attempted. The media area to be verified is specified via the start_lba and block_cnt fields. Although verification is intended primarily for optical media, some systems may support verify operations on normal disk devices.

The SIOC_WRITE_WOE ioctl controls the write mode used for magneto-optical disk devices. Normally magneto-optical write operations require two physical head passes. The first pass erases the media area to be written. The second pass actually writes the data. Write-without-erase mode dramatically increases write performance by skipping the first (erase media area) pass. To ensure that the correct data results, it is essential that write-without-erase operations be performed only on media that is known to be blank (previously erased or never used). The SIOC_WRITE_WOE ioctl can be used to enable or disable write-without-erase. A zero value disables write-without-erase. The value 1 enables write-without-erase.

The SIOC_ERASE ioctl allows media areas to be explicitly erased. The media area to be erased is specified via the start_lba and block_cnt fields. Media areas erased in this manner can be written using write-without-erase mode. Note that an erased media area is different from a media area written with some data values (e.g. zeros). An erased media area should not be read. Attempting to read an erased media area generally results in an I/O error.

The SIOC_VERIFY_BLANK ioctl verifies that a media area has been erased and is suitable for being written using write-without-erase mode. The media area to be verified is specified via the start_lba and block_cnt fields.

The following optical disk device specific information is included from <sys/scsi.h>:

#define SIOC_WRITE_WOE _IOW('S', 17, int) #define SIOC_VERIFY_WRITES _IOW('S', 18, int) #define SIOC_ERASE _IOW('S', 19, struct scsi_erase) #define SIOC_VERIFY_BLANK _IOW('S', 20, struct scsi_verify) #define SIOC_VERIFY _IOW('S', 21, struct scsi_verify) /* structure for SIOC_ERASE ioctl */ struct scsi_erase { unsigned int start_lba; unsigned short block_cnt; }; /* structure for SIOC_VERIFY_BLANK and SIOC_VERIFY ioctls */ struct scsi_verify { unsigned int start_lba; unsigned short block_cnt; };

FILES

/usr/include/sys/scsi.h

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.