MT(4)
NAME
magtape − magnetic tape interface and controls
HP-UX COMPATIBILITY
Level: Magnetic Tape Support -- HP-UX/RUN ONLY
Origin: UCB and HP
DESCRIPTION
The files /dev/mt∗ and /dev/rmt∗ refer to specific tape drives; the behavior of the specific unit is specified by several bits in the least significant digit of the minor number in the mknod(1M) command.
There are three bits controlling the operation of the tape drive. These bits are usually encoded into the minor number of mknod(8). Refer to the System Administrator Manual for your computer for details.
rewind When this bit is cleared, the tape is automatically rewound upon close. This is normally done for units numbered 0-3 and 8-11.
mode When this bit is set, the tape drive behaves like the Berkeley tape drivers; when clear the driver behaves like System III. The details are described below. The ioctl operations described below work in both modes on raw tapes only.
density When cleared, the tape drive is run at 1600 bpi; when set it is run at 800 bpi. The 800 bpi drives are usually numbered 0-7, and 1600 bpi are usually numbered 8-15.
When opened for reading or writing, the tape is assumed to be positioned as desired.
When a file is opened for writing and then closed, a double end-of-file (double tape mark) is written. If the device has the rewind bit set, the tape is rewound; otherwise, the tape is positioned before the second EOF just written.
When a read-only file is closed and the rewind bit is set, the tape is rewound. If the rewind bit is not set, the behavior depends on the mode bit. For System III compatibility, the tape is positioned after the EOF following the data just read. For Berkeley compatibility, the tape is not re-positioned in any way.
The EOF is returned as a zero-length read.
By judiciously choosing mt files, it is possible to read and write multi-file tapes.
A tape treated as a block device consists of several 512 byte records terminated by an EOF. To the extent possible, the system makes it possible to treat the tape like any other file. Seeks have their usual meaning and it is possible to read or write a byte at a time (although very inadvisable).
The mt files discussed above are useful when it is desired to access the tape in a way compatible with ordinary files. When foreign tapes are to be dealt with, and especially when long records are to be read or written, the raw interface is appropriate. The raw interface is described below.
The special files associated with a raw tape interface are named rmt∗. 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.
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. In raw tape I/O, the buffer and size may have implementation dependent alignment restrictions. Seeks are ignored, instead the ioctl operations described below are available. An EOF is returned as a zero-length read, with the tape positioned after the EOF, so that the next read will return the next record.
Using Ioctl With Magnetic Tape
The ioctl system call can be used to manipulate magnetic tapes; refer to the include file /usr/include/sys/mtio.h for a description of the possible operations.
The following code fragment shows how an ioctl call might be used to perform several mag tape operations:
#include <sys/types.h>
#include <sys/mtio.h>
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
int fd;
struct mtop top;
/∗ open mag tape device file ∗/
top.mt_count = 1;
switch(∗argv[1]) {
case ′1′:/∗ write an eof ∗/
top.mt_op = MTWEOF;
break;
case ′2′:/∗ rewind the tape ∗/
top.mt_op = MTREW;
break;
case ′3′:/∗ backspace record ∗/
top.mt_op = MTBSR;
break;
default:
fprintf(stderr, "Unknown option: %s0, argv[1]);
exit(1);
break;
}
fd = ioctl(fd, MTIOCTOP, &top);
}
This program accepts one argument which selects the operation to perform. The structure template mtop is defined in sys/mtio.h, and contains two parameters defining the operation to perform (mt_op) and how many operations to perform (mt_count). All constants used above (plus many others not used) are defined in sys/mtio.h.
HARDWARE DEPENDENCIES
Series 200:
Block magnetic tape is not supported.
The density bit cannot select 800 bpi; 800 bpi is not supported.
The settings of the mode, rewind, and density bits are reflected in the minor numbers used to create the special file names (see mkdev(8)).
Series 500:
Block magnetic tape is not supported.
The density bit cannot select 800 bpi; 800 bpi is not supported.
FILES
/dev/mt∗
/dev/rmt∗
SEE ALSO
intro(4), mkdev(1M), mknod(1M), and the HP-UX System Administrator Manual included with your system.
Hewlett-Packard — last mod. May 11, 2021