Services for Unix 3.0 and Tape Drives

Operating System
Services for Unix 3.0 Technical Note

Abstract

This paper explains what is new in the last release of the Interix tape tools (Services for UNIX 3.0).

On This Page

Interix and Tape Drives Interix and Tape Drives
For More Information For More Information

Interix and Tape Drives

Here is what is new in the last release of the Interix tape tools (Services for UNIX 3.0):

  • Tar and pax automatically determines the correct block size to use when reading a tape. It is no longer necessary to know the block size of a tape before you can untar it.

  • We now support hardware data compression. The mt setcmp command is used to turn this feature on and off.

  • The mt analyze command will scan a tape, finding all of the files, blocks and tape marks. You can use this command to determine the block size of an existing tape.

How To Read a UNIX Tar Tape

The new version of tar automatically determines the correct block size to use when reading a tape, but only if the tape drive is set to variable length block mode. To read a UNIX tar tape, use the following procedure:

  1. Insert the tape into the tape drive.

  2. Set the tape drive to variable length block mode, as follows:

mt setblk 0

**N.B.** Use the **-f tape***x* option to **mt** if more than one tape drive is connected, where *x* is the tape drive on which you want to work.
  1. Read the tape using tar:

tar xvf /dev/tape0

How To Write a UNIX Tar Tape

To write a UNIX tar tape that can be easily read on any UNIX system, including old System V systems, write the tape using a block size of 512 bytes as described in the following procedure:

  1. Insert the tape into the tape drive.

  2. Set the tape drive block size to 512 bytes:

$ mt setblk 512

  1. Write the tape using tar:

$ tar cvf /dev/tape0 ...

Note that small tape blocks are inefficient. If you want to be more efficient and modern, then write your tar archive with a block size of 10240. The following procedure will achieve this:

  1. Insert the tape into the tape drive.

  2. Set the tape drive to variable length block mode,

$ mt setblk 0

  1. Write the tape using tar. Note that tar defaults to a block size of 10240:

$ tar cvf /dev/tape0 ...

One more caveat: If you are writing the tape using a tape drive that supports hardware data compression, and you will later be reading the tape using a drive that does not support hardware data compression, then you should turn compression off before writing the tape. Do this:

$ mt setcmp 0

before issuing the tar command.

N.B. For streaming tape drives (drives that use DC300, DC600, or DC6250 tapes) you do not have a fixed blocking factor and thus any block size will work that is a multiple of 512 bytes.

Tape Block Sizes: The Inside Story

This discussion applies to non-streaming tape drives.

When people encounter problems reading tapes, the problem most often involves mismatched block sizes. For this reason, it is useful to understand how tape block sizes work.

When a tape is written, the data is written as a sequence of blocks, with an interblock gap in between each block.

When you write a tape, the actual size of the blocks written on the tape is determined by two factors:

  1. The first factor is the block size specified on the tar, pax or dd command line.

  2. The second factor is whether the tape drive is set to variable length or fixed length block mode.

On BSD-style UNIX systems, the tape drive is normally set to variable length block mode, which means that each call to the write() system call results in exactly one block being written to the tape. On such systems, the block size specified on the tar or dd command lines is the size of the blocks that are written to the tape.

On System V-style UNIX systems, the tape drive is normally set to fixed length block mode. This means that the tape device driver splits up each write() request into a series of fixed length blocks, often of length 512 bytes. On such systems, the block size specified on the tar or dd command line has no effect on the block size used when writing the tape, except that the tar or dd block size must be an integer multiple of the tape device block size.

On Interix, you can set the tape drive to variable length block mode using

mt setblk 0

You can set the tape drive to fixed length block mode using a block size of (for example) 512 bytes by using

mt setblk 512 

When a tape is read, the success or failure of the read operation is determined by three factors:

  1. The first factor is the size of the tape blocks to be read.

  2. The second factor is the size of the buffer into which the data is to be read.

  3. The third factor is whether the tape drive is set to variable length or fixed length block mode.

In variable length block mode, exactly one tape block is read by each read() request. The read buffer must be at least as large as the block to be read, or the read operation will fail.

If the tape drive is set to fixed length block mode with a block length of N, then each block that is read must be exactly N bytes long. The read() request will fill the buffer with as many blocks as will fit, and again the request will fail if the buffer is smaller than a block.

This means you can't successfully read a tape when you are in fixed length block mode unless you know the block size that the tape was written with. That is why we recommend you set the tape drive to variable length block mode when reading a tape using tar or pax: in variable length block mode, tar can automatically determine the block size, which means that you don't have to.

There may be circumstances where you want to determine the block size of a UNIX tape of uncertain provenance. You can do this with the following sequence of commands:

mt rewind
mt setblk 0
mt analyse

The mt analyse command will scan the tape, printing out a message for each block and each tape mark that is found. If the tape contains more than one file or tar archive, separated by tape marks, then mt analyse will find them all.

Hardware Data Compression

If your tape drive supports hardware data compression, then you can turn compression on using:

mt setcmp 1

and you can turn it off using:

mt setcmp 0 

You don't normally need to worry about this when reading a tape, because the tape drive firmware will detect hardware data compression, and automatically decompress the data.

However, if you are writing a tape that will later be read using a tape drive that does not support hardware data compression, then you will want to turn compression off before writing the tape.

Trouble Shooting, and How To Get Help

If nothing you try works, try the following command:

mt status

If this command succeeds, it prints information about the tape drive, including the current blocking factor as set by mt setblk. If this command fails, then you can't access the tape using Interix at all until the underlying problem is resolved.

If you need help from Softway to read or write a tape, then please follow this procedure:

  1. Insert the tape you are having problems with into the tape drive.

  2. Type:

    mt rewind
      mt status >status 2>&1
      mt setblk 0
      mt analyse >analysis 2>&1 
  3. Send email to Support, including the following information:

    • The contents of the status file.

    • The contents of the analysis file.

    • The brand and model number of the tape drive connected to your Services for Unix system.

    • The brand and model number of the tape media.

    • The sequence of commands that you typed to the Interix shell while attempting to read or write the tape, and the messages that you got back.

    • If you are attempting to exchange data with a UNIX system, then tell us:

      • The brand and version number of the UNIX operating system. Output from uname -a would be appropriate.

      • The brand and model number of the tape drive on the UNIX system with which you want to exchange data.

      • The sequence of commands that you typed to the UNIX system while attempting to read or write the tape, and the messages that you got back.

      • The name of the tape device that you were using on the UNIX system.

      • If you used mt, tapecntl or an equivalent command to set tape drive parameters, then include this information.

      • If the UNIX system has an mt, tapecntl or equivalent command which is capable of displaying the current tape drive parameters, then issue the command and include the output.

For More Information

For more information about Interix, see the Interix Web site at:
https://www.microsoft.com/windows2000/interix.