tape(7) — SPECIAL FILES AND DEVICES
NAME
tape − tape support
DESCRIPTION
Only the character (raw) interface is supported for tape drives.
The raw device nodes /dev/rmt/prefix_∗ allow the transfer of a specified number of bytes between the tape drive and a location in the user’s address space.
Tape devices may be accessed using fixed or variable block sizes. When operating in fixed mode, tapes must be accessed using buffers in multiples of the configured block size, typically 512 bytes. Exabyte tapes use 1024 bytes. Variable block mode allows records to be any size from 1 byte to the device maximum length, typically 64 KB. However, not all tape devices support variable mode or block sizes as small as 1 byte.
Attempts to access a tape in fixed mode with a block size not a multiple of the configured block size results in an error (EIO).
By default, the generic device nodes for cartridge tapes are configured for fixed block mode, and 9-track tape devices are configured for variable mode.
You can only write streaming tapes when the tape is positioned at beginning-of-tape (BOT) or end-of-data (EOD). You may not overwrite a streaming tape in the middle. To overwrite a streaming tape, you must rewind the tape before starting to write data. To append a streaming tape, you must either perform an MTEND tape ioctl operation before starting to write data or read until you reach EOD, and then close and re-open the tape for writing.
Drivers return EIO when you attempt to read past the end of data, attempt to forward space a record (MTFSR), or backward space a record (MTBSR) across an end-of-file mark.
When an end-of-file mark is encountered while reading a tape, a zero-length or partial read is returned. If a zero-length read is returned, the tape is positioned at the end-of-media side of the end-of-file mark. If a partial read is returned, the tape is positioned at the beginning-of-media side of the end-of-file mark, and the next read succeeds with zero bytes returned. After the zero-length read, additional attempts to read the tape return ENXIO.
When using the don’t-rewind-on-close device (the no-rewind device) for reading, the tape will be positioned immediately after a file mark upon close. If a file hasn’t been read all of the way to the end (encountering the file mark), the tape will be skipped forward to the file mark by the device close.
Attempting to open a write-protected tape for writing fails and return EIO.
IMPORTANT INFORMATION
When dealing with tapes that contain multiple files or images, it is important to understand how the forward-space-file (fsf) and back-space-file (bsf) commands work. These commands move the tape by counting end-of-file marks actually past over and therefore position the tape to the beginning-of-tape and end-of-medium side of the last file mark skipped, respectively.
In order to get back to the beginning of the file just read you must rewind the tape if the file is the first file on the tape. If the file is second or later on the tape, issue the back-space-file (bsf) command twice followed by a single forward-space-file (fsf) command.
IOCTL COMMANDS
Tapes support several ioctl(2) functions on the character or raw devices. These functions permit control beyond the normal open(2), close(2), read(2), and write(2) system calls. Any attempt to utilize ioctl(2) functions not listed in the following table causes an EINVAL error to be returned. This table gives an overview of the available calls and their syntax, listed alphabetically and with descriptions.
| CALL | SYNTAX |
| MTIOCTOP | ioctl (fildes, MTIOCTOP, ∗arg) struct mtop ∗arg; |
| The mtop structure and the value MTIOCTOP | |
| are defined in sys/mtio.h. | |
| Valid operation codes are: | |
| MTBSF, MTBSR, MTCEOM, MTEND, MTERA, | |
| MTFSF, MTFSR, MTNOP, MTOFFL, MTREW, | |
| MTTEN, and MTWEOF. | |
| MTIOCGET | ioctl (fildes, MTIOCGET, ∗arg) struct |
| mtget ∗arg; | |
| The mtget structure and the value MTIOCGET | |
| are defined in sys/mtio.h. | |
| MTIONOFSF | ioctl (fildes, MTIONOFSF, 0) |
| The value MTIONOFSF is defined in sys/mtio.h. |
MTIOCTOP
The mtop structure is defined in sys/mtio.h. The operation this command performs depends on the value of the mt_op and mt_count fields. The following values for the mt_op field are supported:
MTBSF
Moves the tape backward past mt_count filemarks. The tape is positioned at the beginning-of-medium side of the filemark. This function is not supported by all tape drives. If it is not supported, the operation fails, returning ENXIO. If it is supported, it will not fail if the operation is attempted before beginning-of-tape.
MTBSR
Moves the tape backward past mt_count records. For streaming tapes, the record size is always the logical block size (512 bytes default, 1024 bytes for Exabyte). This function is not supported by all tape drives. Whenever it is not supported, the operation fails, returning ENXIO.
MTCEOM
Clears the end-of-media indicator.
MTEND
Spaces forward to the end-of-data. For 9-track tapes, it spaces forward two sequential filemarks and positions the tape between them.
MTERA
Erases the tape. The tape is rewound, erased, and rewound again.
MTFSF
Moves the tape forward past mt_count filemarks. The tape is positioned at the end-of-medium side of the filemark. If this operation is attempted while the tape is positioned at end-of-data, it fails with EIO.
MTFSR
Moves the tape forward past mt_count records. For streaming tapes, the record size is always the logical block size (512 bytes default, 1024 bytes for Exabyte). This function is not supported by all tape drives. Whenever it is not supported, the operation fails, returning ENXIO.
MTNOP
No operation.
MTOFFL
Rewinds the tape and puts the drive offline. For some devices, this may just rewind the tape. Note: operations normally done during close (such as rewinding or writing filemarks) will not be attempted if the drive is put offline.
MTREW
Rewinds the tape.
MTTEN
Retensions the tape. This operation is not supported by all tape drives. Whenever it is not supported, the tape is rewound instead.
MTWEOF
Writes an end-of-file record. An end-of-file can be used only after data has been written with the write(2) system call.
MTIOCGET
Returns status information about the tape drive. The mt_type field is set to the appropriate value defined in sys/mtio.h. Bits in the mt_dsreg field are set to indicate whether the tape is write protected or if the drive is offline. Note: if there is no tape in the drive, it is considered both offline and write-protected.
MTIONOFSF
Disables the seeking to the beginning of the next file upon close when the whole file has not been read and the no-rewind device was opened in a read-only mode. This may leave the tape positioned so that attempts to append data to the tape will fail due to the behaviour of some tape devies (e.g. ARCHIVE 2150 and 2525).