HP-UX Reference (11i v3 07/02) - 7 Device (Special) Files, 9 General Information, Index (vol 10)

d
disk(7) disk(7)
Character-special access
Character-special device files access disks without buffering and support the direct transmission of data
between the disk and the user’s read or write buffer. Disk access through the character special file inter-
face causes all physical I/O operations to be completed before control returns from the call. A single read or
write operation up to MAXPHYS bytes (typically 64 Kbytes or 256 Kbytes) results in exactly one disk opera-
tion. Requests larger than this are broken up automatically by the operating system. Since large I/O
operations via character-special files avoid block buffer cache handling and result in fewer disk operations,
they are typically more efficient than similar block-special file operations.
There may be implementation-dependent restrictions on the alignment of the user buffer in memory for
character special file read() and write()
calls. Also, each read and write operation must begin and
end on a logical block boundary and must be a whole number of logical blocks in size. The logical block size
is a hardware-dependent value that can be queried with the
DIOC_DESCRIBE_EXT
and
DIOC_DESCRIBE
ioctl calls, which are described below.
In addition to reading and writing data, the character-special file interface can be used to obtain device
specific information and to perform special operations. These operations are controlled through use of ioctl
calls. Details related to these ioctls are contained in
<sys/diskio.h>.
The
DIOC_DESCRIBE_EXT
and DIOC_DESCRIBE ioctl can be used to obtain device specific
identification information. The information returned includes the disk’s model identification, the disk inter-
face type, maximum offset address, device type, and the disk’s logical block size.
The
DIOC_CAPACITY ioctl can be used to obtain the capacity of a disk device in
DEV_BSIZE units.
(
DEV_BSIZE is defined in <sys/param.h>
).
The
DIOC_EXCLUSIVE ioctl can be used to obtain and release exclusive access to a disk device. Exclusive
access is required for some special operations, such as media reformatting, and may be desirable in other
circumstances. The value one specifies that exclusive access is requested. The value zero specifies the
exclusive access should be released. Exclusive access causes other open requests to fail. Exclusive access
can only be granted when the device is not currently opened in block-mode and there is only one open file
table entry for that disk device (the one accessible to the exclusive access requester).
ERRORS
The following errors can be returned by a disk device driver call:
[EACCES] Required permission is denied for the the device or operation.
[EIO] I/O error (e.g., media defect or device communication problem).
[EINVAL] From an
open() call: the device is not a disk device. For other calls: Invalid
request or parameter. Note that for legacy, 32-bit access, this error can result when
the size of the device overflows the argument of the
DIOC_DESCRIBE
or
DIOC_CAPACITY ioctls.
[ENXIO] If resulting from an open() call, this indicates there is no device at the specified
address. For other calls, this indicates the specified address is out of range or the dev-
ice can no longer be accessed.
WARNINGS
The interaction of block-special and character-special file access to the same
BLKDEV_IOSIZE-sized block
is not specified, and in general is unpredictable.
On some systems, having both a mounted file system and a block special file open on the same device can
cause unpredictable results; this should be avoided if possible. This is because it may be possible for some
files to have private buffers in some systems.
Although disk devices have historically had small (typically 512-byte) block sizes, some disk devices (such as
optical disks and disk arrays) have relatively large block sizes. Applications using direct raw disk access
should use
ioctl() calls to determine appropriate I/O operation sizes and alignments.
Any disk with removable media (for example, floppy or CD-ROM) containing a mounted file system should
not be removed prior to being unmounted. Removal of disk media containing mounted file systems is likely
to result in file system errors and system panics.
AUTHOR
disk was developed by HP and AT&T.
40 Hewlett-Packard Company 2 HP-UX 11i Version 3: February 2007