mt.7 (2010 09)

m
mt(7) mt(7)
When a file open for reading (only) is closed and the no-rewind bit is not set, the tape is rewound. If the
no-rewind bit is set, the behaviour depends on the style mode. For AT&T-style devices, the tape is posi-
tioned after the EOF following the data just read (unless already at BOT or Filemark). For Berkeley-
style devices, the tape is not repositioned in any way.
Each read(2) or write (2) call reads or writes the next record on the tape. For writes, the record has the
same length as the buffer given (within the limits of the hardware).
During a read, the record size is passed back as the number of bytes read, up to the buffer size specified.
Since the minimum read length on a tape device is a complete record (to the next record mark), the
number of bytes ignored (for records longer than the buffer size specified) is available in the
mt_resid
field of the mtget structure via the
MTIOCGET call of ioctl (2). Current restrictions require tape device
application programs to use 2-byte alignment for buffer locations and I/O sizes. To allow for more
stringent future restrictions (4-byte aligned, etc.) and to maximize performance, page alignment is sug-
gested. For example, if the target buffer is contained within a structure, care must be taken that struc-
ture elements before the buffer allow the target buffer to begin on an even address. If need be, placing a
filler integer before the target buffer will insure its location on a 4-byte boundary.
The ascending hierarchy of tape marks is defined as follows: record mark, filemark (EOF), setmark and
EOD (End of Data). Not all devices support all types of tape marks but the positioning within the hierar-
chy holds true. Each type of mark is typically used to contain one or more of the lesser marks.
When spacing over a number of a particular type of tape mark, hierarchically superior marks (except
EOD) do not terminate tape motion and are included in the count. For instance, MTFSR can be used to
pass over record marks and filemarks.
Reading an EOF mark is returned as a successful zero-length read; that is, the data count returned is
zero and the tape is positioned after the EOF, enabling the next read to return the next record.
DDS devices also support setmarks, which are used to delineate a group (set) of files. Reading a setmark
is also returned as a zero-length read. Filemarks, setmarks and EOD can be distinguished by unique bits
in the
mt_gstat field.
Spacing operations (back or forward space, setmark, file or record) position past the object being spaced
to in the direction of motion. For example, back-spacing a file leaves the tape positioned before the file
mark; forward-spacing a file leaves the tape positioned after the file mark. This is consistent with stan-
dard tape usage.
lseek (2) type seeks on a magnetic tape device are ignored. Instead, the ioctl (2) operations below can be
used to position the tape and determine its status.
The header file
<sys/mtio.h> has useful information for tape handling.
Macros to Decode Options
The minor number of the device ID (
dev_t) of persistent tape device special files no longer encode the
tape device options (such as, density, style of access and so on). Hence the macros given below, that are
defined in <sys/mtio.h> header file do not interpret the options correctly for persistent (agile) DSFs.
The macros are:
M_INSTANCE(dev) M_TARGET(dev)
M_LUN(dev) M_BERKELEY(dev)
M_NO_REWIND(dev) M_USER_CONFIG(dev)
M_INDEX(dev) M_INDEX_PUT(dev,index)
M_DFLT_DENSITY(dev) M_DFLT_DENSITY_PUT(dev,density)
M_TRANSPARENT_MODE(dev) M_PROP_TBL_ACCESS(dev)
These macros continue to work on the legacy DSFs as before.
Applications should use the method described below to decode the tape device options from persistent
device files.
libIO(3X) API
io_dev_to_options is used to decode the device options from the persistent device
files as given below:
#include <libIO.h>
#include <sys/_inttypes.h>
#include <fcntl.h>
Note:
libIO calls should be within calls to io_init() and io_end(). Refer to libIO(3X) manpage
for more details. Applications have to link with libIO library to access these APIs.
HP-UX 11i Version 3: September 2010 3 Hewlett-Packard Company 3