SCSItape User's Manual
SCSItape
Tape Basics
User's Manual
Device Names
Device Behavior
Tape Control
Usage Examples
Programmer's Manual
Glossary
Valid HTML 4.0!
Device Names
For each physical SCSI tape device it finds, the SCSItape driver creates a number of logical device names. The device names follow the usual BeOS (R4) naming convention, starting with a string of the form /dev/tape/scsi/[B]/[T]/[L]/[P], where [B], [T] and [L] are integers identifying the SCSI bus number, device address and logical unit of the physical device, respectively. [P] selects a logical partition on a medium in the drive.

For a tape drive on bus 0, with SCSI address 2 and LUN 0, the driver creates the following names:
/dev/tape/scsi/0/2/0/0 /dev/tape/scsi/0/2/0/1
/dev/tape/scsi/0/2/0/0n /dev/tape/scsi/0/2/0/1n
/dev/tape/scsi/0/2/0/0nb /dev/tape/scsi/0/2/0/1nb
/dev/tape/scsi/0/2/0/0u /dev/tape/scsi/0/2/0/1u
/dev/tape/scsi/0/2/0/0un /dev/tape/scsi/0/2/0/1un
/dev/tape/scsi/0/2/0/0unb /dev/tape/scsi/0/2/0/1unb
The various components of the device name indicate options which distinguish the behavior of the logical devices:

0, 1 - Partition ID
The number starting the device name identifies the logical partition accessed by the device. Currently the number of supported partitions is hard-wired in the driver.

u - Uncompressed Format
The presence of the letter u means that the corresponding logical device will not perform any data compression when writing. During read operations, compressed data will be processed normally (provided that the tape drive supports data compression).

If the u is absent, the driver will attempt to use the drive's default data compression algorithm when writing.

n - No Auto-Rewind
If the letter n is not present in the logical device name, the driver will automatically rewind the tape when the device is closed.

If the letter n is present, the tape will not be rewound after closing the device; the exact behavior depends on the style option and is explained below.

b - Berkeley-Style Device
This option can only be specified for non-auto-rewind devices. It determines whether the tape operates in AT&T or Berkeley style. When the letter b is absent, AT&T style is used, otherwise Berkeley style.
^ Device Behavior
Tape behavior can be mysterious at times. This section tries to explain it and to give some tips on using the various possible options. Note that this is just an overview; all the nasty details are explained in the Programmer's Manual.

Reading a Tape
When reading, it is important that the block size expected by the reader matches the lengths of the blocks written to the tape. The tape drive can only read entire records, and length mismatches can cause data to be lost. The driver's block size should always be set either to zero (variable sized blocks, which however may not be supported by the drive) or to the same block size used to write the tape. The block size of the reading program should be equal to that of the writing program. Block sizes should be chosen large enough to allow the reading program to keep up with the data coming from the tape; this avoids repeated stopping and restarting of the tape, which takes time and can wear out the tape and drive faster than if the tape is kept streaming.

If the driver encounters a filemark or setmark, it signals an end-of-file condition to the reading program; if it encounters either end-of-data or end-of-medium, it signals an error. The latter condition indicates that the program has attempted to read beyond the end of recorded data.

When the user program closes the tape device, the tape may be rewound or repositioned, depending on the logical device used. There are three different styles of behavior, as explained above:

  • An auto-rewind device will rewind the tape to BOT after being closed.
  • An AT&T-style no-auto-rewind device moves the tape forward past the next filemark on the tape, unless the tape is already positioned after a filemark (or at BOT). This is useful when working with programs like tar, which do not rely on filemarks to detect an end-of-file condition. By using the AT&T-style device, you can ensure that the tape will always be positioned after the filemark at the end of the file just read.
  • A Berkeley-style no-auto-rewind device does not perform any tape movement when it is closed. Berkeley-style behavior is useful for reading tapes record-by-record, using programs like dd.
Writing a Tape
When writing, the lengths of records can be chosen by one of two methods:
  • When the drive is in variable-block mode (block size is zero), each write() operation causes one record to be created. The length of the record is the number of bytes transferred. In this mode, the writing program should ensure a consistent block length; if it cannot do so, it may be advisable to pipe its output through dd for reblocking.
  • When the drive's block size is fixed, each write() creates an integral number of records. The number of bytes transferred may be smaller than requested because of rounding to the block size. The user program should be prepared for this case.
If the tape is to be read by a different program or even on a different system, it is important to use consistent block lengths. It may be advisable not to use data compression if the tape must be readable on a different drive.

To avoid loss of data when the end of the medium is reached, tape drives implement an early warning mechanism which signals to the driver when it is nearing the physical end of the tape. This condition is also called the logical end of tape. During normal operation, the driver refuses to write data after it has passed this point; user programs can override this barrier at their own peril (as described in the Programmer's Manual). The definition of the early-warning condition depends on the drive mechanism; if data is written past logical end of tape, it may not be readable on another drive. It is usually not a good idea to try writing beyond the early-warning point. It doesn't gain much, it may be slow (typical drives switch off the buffering mechanism after this point), and if the physical end of tape is reached while writing, data will be irrevocably lost.[1]

When the user program closes a logical device which was opened for writing, one or more filemarks may be placed on the tape to indicate the end of the file just written. The exact behavior depends on the operations performed by the user program, and on the drive mechanism:

  • If the user program wrote at least one record, and if it has not repositioned the tape after writing:
    • If the drive is a QIC device, one filemark is written.
    • Otherwise, two filemarks are written.
    If an auto-rewind device was used, the tape is rewound; otherwise it is positioned after the first filemark just written.
  • Otherwise, the behavior is the same as after reading from tape. (In this case, the program is responsible for writing the filemark(s) indicating end-of-file.)
The first case (automatic writing of filemarks) is the most common one.

^ Tape Control
The SCSItape driver implements a standard set of ioctl() commands to control the tape device. These can either be used by a program calling the driver, or from the command line via the mt utility.

The device to be controlled must be specified to mt in one of the following ways:

  • By command-line option: -f <device> or -t <device>.
  • As the value of the environment variable $TAPE.
  • Using the default, /dev/tape/scsi/0/2/0/0.
The mt program takes one or two command-line arguments (in addition to a -f or -t option):
  • A command, which indicates what kind of operation is to be performed.
  • An optional count, which is an argument to some of the commands. If this argument is not present, a default of 1 is assumed.
The following commands are recognized (brackets indicate possible abbreviations):
status
Prints a short status report (medium density, block size etc.).
weof
Writes <count> filemarks to the tape.
wss
Writes <count> setmarks to the tape.
fsr
(Forward Space Record) Moves the tape forward past the next <count> records, filemarks and/or setmarks.
bsr
(Backward Space Record) Moves the tape backward past the previous <count> records, filemarks and/or setmarks.
fsf
(Forward Space Filemark) Moves the tape forward past the next <count> filemarks and/or setmarks.
bsf
(Backward Space Filemark) Moves the tape backward past the previous <count> filemarks and/or setmarks.
fss
(Forward Space Setmark) Moves the tape forward past the next <count> setmarks.
bss
(Backward Space Setmark) Moves the tape backward past the previous <count> setmarks.
eod
Moves the tape to the end of recorded data; the next write will append to the tape.
rew[ind]
Rewinds the tape.
offl[ine] or eject
Rewinds the tape and puts the drive off-line, allowing the medium to be removed.
reten[sion]
Applies the correct tension to the tape. (Usually by winding the tape all the way forward to physical end of tape, then rewinding.) This action should be performed with new media, or with ones that haven't been used recently.
erase
Erases all data on the tape.
setblk
Sets the current block size to <count>. A value of zero selects variable-block mode, which is preferred.
NOTES:
  • When spacing across records, each filemark or setmark encountered counts as a single record. When spacing across filemarks, each setmark encountered counts as a single filemark.
  • When spacing forward, after the command completes the tape is positioned after the last record, filemark or setmark encountered. When spacing backward, the tape is positioned before the last record, filemark or setmark encountered.
  • Not all drive mechanisms support setmarks.
  • Some of these operations (notably spacing and erasing) can take a very long time. On QIC drives, spacing operations may take hours.
^ Usage Examples
Using mt to find the device status:
/boot/home % mt status
/dev/tape/scsi/0/2/0/0 is on-line.
Device supports data compression.
Current density is 0x13 (DDS-1).
Current block size is 0.
	
Backing up a directory to tape using tar:
/boot/home % tar cvf /dev/tape/scsi/0/2/0/0 SampleMedia
SampleMedia/
SampleMedia/images/
SampleMedia/images/Be Logo 1
SampleMedia/midi/
SampleMedia/midi/BeBoxBeBop.mid
SampleMedia/sound/
SampleMedia/sound/RU.N+
	
Displaying the contents of the backed-up tape. Note that we are using a no-rewind device; when the command returns, the tape is positioned after the end of the archive:
/boot/home % tar tf /dev/tape/scsi/0/2/0/0n
SampleMedia/
SampleMedia/images/
SampleMedia/images/Be Logo 1
SampleMedia/midi/
SampleMedia/midi/BeBoxBeBop.mid
SampleMedia/sound/
SampleMedia/sound/RU.N+
	
Writing a single file to tape using dd:
/boot/home % dd bs=10k < Kim > /dev/tape/scsi/0/2/0/0n
56+1 records in
56+1 records out
	
Positioning the tape at the start of the file just written; the image below shows what's going on.
/boot/home % mt -t /dev/tape/scsi/0/2/0/0n bsf 2
/boot/home % mt -t /dev/tape/scsi/0/2/0/0n fsf 1
	
Effect of tape positioning

Reading the first block of the file:

/boot/home % dd bs=10k count=1 < /dev/tape/scsi/0/2/0/0n |\
             head -20
                  1901

                  KIM
           by Rudyard Kipling

                   1


     "Oh ye who tread the Narrow Way
      By Tophet-flare to Judgement Day,
      Be gentle when the heathen pray
      To Buddha at Kamakura!"


He sat, in defiance of municipal orders,
astride the gun Zam-Zammah on her brick platform
opposite the old Ajaib-Gher- the Wonder House,
as the natives call the Lahore Museum. Who hold
Zam-Zammah, that "fire-breathing dragon," hold
the Punjab, for the great green-bronze piece is
1+0 records in
0+0 records out
	
Rewinding and ejecting the cartridge:
/boot/home % mt offline
	

[1] Not to speak of mechanical problems, like the tape coming off the reel.


Copyright © 1998 Jens Kilian. This file may be distributed under the conditions of the GNU General Public License.
$Id: User.html,v 1.8 1998/11/29 17:20:19 jjk Exp $