MT(7) — HP-UX
NAME
mt − magnetic tape interface and controls
DESCRIPTION
The files /dev/mt/∗ and /dev/rmt/∗ refer to specific tape drives; the behavior of the specific unit is specified in the major and minor numbers of the device special file which describes the tape unit.
The following naming convention is recommended for tape devices, and serves to connect most of the mode flags with the device name:
/dev/{r}mt/(c#d)#[hml]{n}
where r indicates a raw device, c#d indicates the controller number (which is optionally specified by the system administrator), # is the device number, hml indicates the density (h (high) for 6250 bpi, m (medium) for 1600 bpi, and l (low density) for 800 bpi), and n indicates no rewind on close. For example, /dev/rmt/2mn is raw device 2 at 1600 bpi with no rewind. Blocked mag tapes are used only for special situations and are supported only in some implementations. See HARDWARE DEPENDENCIES below for details. The selection of controller and unit numbers is system dependent, and is discussed in the appropriate System Administrator’s Guide.
The operation of a tape drive is controlled by mode flags, which are usually encoded as bits in the minor number of the device special file.
no-rewind Unless this mode is requested, the tape is automatically rewound upon close. When a rewind on close is not desired, the n flag should be used in the device name.
style When this mode is requested, the tape drive behaves as on Berkeley systems; when not requested, the drive behaves as on AT&T UNIX operating systems. The details are described below. The ioctl operations described below work in both modes on raw tapes only. The mt(1) tape movement utility requires that the Berkeley mode be specified.
density This may be used to select the density of the tape being written. Possible values that may be selected may include 6250, 1600, and 800 bpi, depending on the capabilities of the specific tape drive. This corresponds to the h, m and l flags in the recommended device name.
Refer to the System Administrator Manual for your computer for more specific details of how to select the modes for a given device.
The special files associated with a raw tape interface are named rmt/∗. Unless otherwise stated, the following discussion refers to raw magnetic tapes.
When opened for reading or writing, the tape is assumed to be positioned as desired.
When a file opened for writing is closed, two consecutive EOF marks are written if, and only if, one or more writes to the file have occurred. The tape is rewound unless the no-rewind mode has been specified, in which case the tape is positioned before the second EOF just written.
When a file open only for reading is closed, and the no-rewind bit is not set, the tape is rewound. If the no-rewind bit is set, the behavior depends on the style mode. For AT&T-style devices, the tape is positioned after the EOF following the data just read. For Berkeley-style devices, the tape is not re-positioned in any way.
Each read or write call reads or writes the next record on the tape. In the write case 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. The number of bytes ignored is available in the mt_resid field of the mtget structure via the MTIOCGET call of ioctl. The buffer and size may have implementation dependent alignment restrictions.
Reading an EOF mark is returned as a zero-length read, i.e., the data count returned will be zero, and the tape is positioned after the EOF, so that the next read will return the next record.
Seeks on a raw magnetic tape device are ignored. Instead, the ioctl operations below can be used to position the tape and determine its status.
The following is included from <sys/mtio.h> and describes the possible operations:
/* mag tape I/O control requests */
#defineMTIOCTOP _IOW(m,1,struct mtop) /* do mag tape op */
#defineMTIOCGET _IOR(m,2,struct mtget) /* get tape status */
/* structure for MTIOCTOP - mag tape op request */
structmtop {
| short | mt_op; | /* operations defined below */ | ||
| daddr_t | mt_count; | /* how many of them */ |
};
/* operations */
| #define MTWEOF | 0 | /* write end-of-file record */ |
| #define MTFSF | 1 | /* forward space file */ |
| #define MTBSF | 2 | /* backward space file */ |
| #define MTFSR | 3 | /* forward space record */ |
| #define MTBSR | 4 | /* backward space record */ |
| #define MTREW | 5 | /* rewind */ |
| #define MTOFFL | 6 | /* rewind, put drive offline */ |
| #define MTNOP | 7 | /* no-op, may set status */ |
/* structure for MTIOCGET - mag tape get status command */
structmtget {
| long | mt_type; | ||
| long | mt_resid; |
/* The following two registers are device dependent */
| long | mt_dsreg1; | ||
| long | mt_dsreg2; |
/* The following is a device independent status word */
| long | mt_gstat; | ||
| long | mt_erreg; |
/* The following are used only when block devices are supported */
| daddr_t | mt_fileno; | ||
| daddr_t | mt_blkno; |
};
/*
* Constants for mt_type; the first three are historical
*/
| #define MT_ISTS | 01 |
| #define MT_ISHT | 02 |
| #define MT_ISTM | 03 |
| #define MT_IS7970E | 04 |
| #define MT_ISSTREAM | 05 |
HARDWARE DEPENDENCIES
Series 200, 300, and 500:
Block magnetic tape is not supported.
Series 800:
The MTNOP operation does not set the device independent status word.
The files /dev/mt/∗ refer to block magnetic tapes. They should only be used for system installation or for treating a pre-written mag tape as a read-only block file system. A read-only block tape can best be created with dd(1) using raw mode and a record size of 512 bytes.
Although the size of records on a block tape is always 512 bytes, the block I/O system deals with block sizes that are a multiple of DEV_BSIZE (param.h) with the tape driver making the translation. For this reason, if a user is attempting to write 512 bytes in block mode, the block I/O system will attempt to pre-read from the block tape prior to merging in the new data and writing it to the tape. Since a pre-read of a blank tape or a tape of unknown format will terminate with an error, it is strongly suggested that dd(1) be used to create the tape as described above, and that block magnetic tape be used only for seeking and reading. Alternatively, always writing a byte count which is an even multiple of BLKDEV_IOSIZE (param.h) bytes will avoid the hazards of a block pre-read.
A tape treated as a block-special device consists of several 512-byte records terminated by an EOF.
The system makes it possible to treat a pre-written block tape like an ordinary file, with the exception that writing in the "middle" of a file truncates the file at that point. Seeks have their usual meaning and it is possible to read or write a byte at a time.
The efficient use of streaming tape drives with large internal buffers and immediate-reporting require the following end-of-tape procedures:
All writes near the EOT foil (which is not on the recording surface) will complete without error if actually written to the tape. When the tape drive determines the foil has been passed, subsequent writes will not occur and an error will be returned.
Since some applications require the writing of a trailer for multiple tape operations, a user request for mag tape status, which will reflect the EOT condition, signals the driver to drop all write barriers. Caution must be exercised in order to keep the tape on the reel.
When reading near the end-of-tape, the user will not be made aware of the EOT foil marker. Instead, the typical double EOF marks or a pre-arranged trailer will signal the logical end-of-tape.
The EOT description above applies in the default case when immediate-reporting mode is allowed in the minor. When it is specifically dis-allowed in the minor, the EOT operation attempts to emulate compatibility-mode on other HP-UX machines. In this mode, the write that encounters the EOT foil returns an error with the tape automatically backing up over that record. The read that encounters the EOT foil returns an error.
Since there are differences in EOT sensing among various types of mag tape drives because of the physical placement of sensors, any application (such as multiple tape cpio(1) backups) requiring that data be continued from the EOT area of one tape to another tape must be restricted. Therefore, the tape drive type and mode should be the same for the creation and reading of the tapes.
The following macros are defined in <sys/mtio.h> for decoding the generic status of the tape drive (returned in the mt_gstat field):
| GMT_EOF(x) | /* At an EOF mark */ |
| GMT_BOT(x) | /* At beginning of tape */ |
| GMT_EOT(x) | /* At end of tape */ |
| GMT_WR_PROT(x) | /* Tape is write protected */ |
| GMT_ONLINE(x) | /* Drive is online */ |
| GMT_D_6250(x) | /* Density is 6520 bpi */ |
| GMT_D_1600(x) | /* Density is 1600 bpi */ |
| GMT_D_800(x) | /* Density is 800 bpi */ |
| GMT_DR_OPEN(x) | /* Drive door is open */ |
| GMT_IM_REP_EN(x) | /* Immediate reporting on */ |
(which means that the drive will report completion immediately)
FILES
/dev/mt/∗
/dev/rmt/∗
AUTHOR
Mt was developed by HP, and the University of California, Berkeley.
BUGS
It is impossible to write a program that will leave a tape positioned at the beginning on an AT&T−style raw device with the no-rewind bit set, because closing the device file upon the program’s termination will reposition the tape after the first EOF mark.
SEE ALSO
Hewlett-Packard Company — Version B.1, April 12, 1993