MTIO(4) — DEVICES AND NETWORK INTERFACES
NAME
mtio − general magnetic tape interface
SYNOPSIS
#include <sys/ioctl.h>
#include <sys/mtio.h>
DESCRIPTION
Both 1/2” and 1/4” magnetic tape drives share the same general interface, no matter what hardware is involved. The remainder of this section discusses the common features of this interface.
The “cooked” magnetic tape device files read and write magnetic tape in 2048 byte blocks (the 2048 is actually BLKDEV_IOSIZE in <sys/param.h>). The name of such a device file might be /dev/mt0. The final component of the name is composed of a name that represents the type of device the file refers to, and the unit number of that device.
These files are rewound when closed; the “no-rewind” versions of these files are not. The name of “no-rewind” device files include the letter n at the beginning of the final component of the name; the “no-rewind” version of /dev/mt0 would be /dev/nmt0. When a 1/2” tape file, open for writing or just written, is closed, two tape marks are written; if the tape is not to be rewound it is positioned with the head between the two tapemarks. When a 1/4” tape file, (due to a bug, only if) just written, is closed, only one end of file mark is written because of the inability to overwrite data on a 1/4” tape; see below.
The files discussed above are useful when you want to access the tape in a way compatible with ordinary files. This interface requires that all blocks be 2048 bytes long, and does not permit special operations (such as spacing the tape forward or backward) to be performed. When using foreign tapes, and especially when reading or writing long records, the “raw” interface is appropriate. The name of “raw” device files include the letter r before the device type; the “raw” version of /dev/mt0 would be /dev/rmt0, and the “raw” version of /dev/nmt0 would be /dev/nrmt0. Each read(2V) or write(2V) call reads or writes the next record on the tape. In the write case the record has the same length as the buffer given. During a read, the record size is passed back as the number of bytes read, provided it is no greater than the buffer size. In “raw” tape I/O, seeks are ignored. A zero byte count is returned when a tape mark is read, but another read will fetch the first record of the new tape file.
1/4” tapes are not able to back up and always write fixed sized blocks. Since they cannot back up, they cannot support backward space file and backward space record. Since they always write fixed sized blocks, the size of transfers using the “raw” interface must be a multiple of the underlying blocksize, usually 512 bytes.
1/4” tapes also have an unusual tape format. They have parallel tracks, but only record information on one track at a time, switching to another track near the physical end of the medium. They erase all the tracks at once while writing the first track. Therefore, they cannot, in general, overwrite previously written data. If the old data were not on the first track, it would not be erased before being overwritten, and the result would be unreadable.
A number of additional ioctl operations are available on “raw” devices. The following definitions are from <sys/mtio.h>:
/∗
∗ Structures and definitions for mag tape I/O control commands
∗/
/∗ structure for MTIOCTOP - mag tape op command ∗/
structmtop{
shortmt_op;/∗ operations defined below ∗/
daddr_tmt_count;/∗ how many of them ∗/
};
/∗ operations ∗/
#defineMTWEOF0/∗ write an end-of-file record ∗/
#defineMTFSF1/∗ forward space file ∗/
#defineMTBSF2/∗ backward space file ∗/
#defineMTFSR3/∗ forward space record ∗/
#defineMTBSR4/∗ backward space record ∗/
#defineMTREW5/∗ rewind ∗/
#defineMTOFFL6/∗ rewind and put the drive offline ∗/
#defineMTNOP7/∗ no operation, sets status only ∗/
#defineMTRETEN8/∗ retension the tape ∗/
#defineMTERASE9/∗ erase the entire tape ∗/
#defineMTEOM10/∗ position to end of media (SCSI only) ∗/
/∗ structure for MTIOCGET - mag tape get status command ∗/
structmtget{
shortmt_type;/∗ type of magtape device ∗/
/∗ the following two registers are grossly device dependent ∗/
shortmt_dsreg;/∗ “drive status” register ∗/
shortmt_erreg;/∗ “error” register ∗/
/∗ end device-dependent registers ∗/
shortmt_resid;/∗ residual count ∗/
/∗ the following two are not yet implemented ∗/
daddr_tmt_fileno;/∗ file number of current position ∗/
daddr_tmt_blkno;/∗ block number of current position ∗/
/∗ end not yet implemented ∗/
};
/∗
∗ Constants for mt_type byte
∗/
#defineMT_ISTS0x01/∗ vax: unibus ts-11 ∗/
#defineMT_ISHT0x02/∗ vax: massbus tu77, etc ∗/
#defineMT_ISTM0x03/∗ vax: unibus tm-11 ∗/
#defineMT_ISMT0x04/∗ vax: massbus tu78 ∗/
#defineMT_ISUT0x05/∗ vax: unibus gcr ∗/
#defineMT_ISCPC0x06/∗ sun: Multibus tapemaster ∗/
#defineMT_ISAR0x07/∗ sun: Multibus archive ∗/
#defineMT_ISSC0x08/∗ sun: SCSI archive ∗/
#defineMT_ISXY0x09/∗ sun: Xylogics 472 ∗/
#defineMT_ISSYSGEN0x0a/∗ sun: SCSI Sysgen ∗/
#defineMT_ISMT020x0b/∗ sun: SCSI Emulex MT02 ∗/
#defineMT_ISCCS0x0c/∗ sun: SCSI generic (unknown) CCS ∗/
/∗ mag tape io control commands ∗/
#defineMTIOCTOP_IOW(m, 1, struct mtop)/∗ do a mag tape op ∗/
#defineMTIOCGET_IOR(m, 2, struct mtget)/∗ get tape status ∗/
#ifndef KERNEL
#defineDEFTAPE“/dev/rmt12”
#endif
SEE ALSO
mt(1), tar(1), read(2V), write(2V), ar(4S), tm(4S), st(4S), xt(4S)
Sun Release 4.0 — Last change: 24 November 1987