Subject: bin/921:
To: None <gnats-admin@NetBSD.ORG>
From: Olaf Seibert <rhialto@polder.ubc.kun.nl>
List: netbsd-bugs
Date: 03/29/1995 04:35:05
>Number:         921
>Category:       bin
>Synopsis:       
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 29 04:35:03 1995
>Originator:     Olaf Seibert
>Organization:
___ Olaf 'Rhialto' Seibert      D787B44DFC896063 4CBB95A5BD1DAA96 
\X/ There are no lemurs in this post    rhialto@polder.ubc.kun.nl
>Release:        1.0A
>Environment:
	
System: NetBSD polder.ubc.kun.nl 1.0A NetBSD 1.0A (TESTPOLDER) #1: Mon Mar 27 18:12:34 MET DST 1995 rhialto@polder.ubc.kun.nl:/home/users/rhialto/cpp/nobackup-netbsd/src/sys/arch/i386/compile/TESTPOLDER i386


>Description:

The mt command did not allow setting the recording density and block sizes.
Nor did it show those values. mt status does not even recognize the tape
device type 7 as set in /usr/src/scsi/st.c.

>How-To-Repeat:

mt -f /dev/st0 status

>Fix:
	
I include my modified version of mt below, including updated manual page.
It adds mt blocksize, mt density, and extends mt status.

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	mt.c
#	mt.1
#
echo x - mt.c
sed 's/^X//' >mt.c << 'END-of-mt.c'
X/*	$NetBSD: mt.c,v 1.5 1995/03/21 06:57:47 cgd Exp $	*/
X
X/*
X * Copyright (c) 1980, 1993
X *	The Regents of the University of California.  All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X *    must display the following acknowledgement:
X *	This product includes software developed by the University of
X *	California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X *    may be used to endorse or promote products derived from this software
X *    without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#ifndef lint
Xstatic char copyright[] =
X"@(#) Copyright (c) 1980, 1993\n\
X	The Regents of the University of California.  All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
X#if 0
Xstatic char sccsid[] = "@(#)mt.c	8.1 (Berkeley) 6/6/93";
X#else
Xstatic char rcsid[] = "$NetBSD: mt.c,v 1.5 1995/03/21 06:57:47 cgd Exp $";
X#endif
X#endif /* not lint */
X
X/*
X * mt --
X *   magnetic tape manipulation program
X */
X#include <sys/types.h>
X#include <sys/ioctl.h>
X#include <sys/mtio.h>
X#include <fcntl.h>
X#include <err.h>
X#include <stdlib.h>
X#include <stdio.h>
X#include <ctype.h>
X#include <string.h>
X
Xstruct commands {
X	char *c_name;
X	int c_code;
X	int c_ronly;
X} com[] = {
X	{ "blocksize",	MTSETBSIZ, 1 },
X	{ "bsf",	MTBSF,	1 },
X	{ "bsr",	MTBSR,	1 },
X	{ "density",	MTSETDNSTY, 1 },
X	{ "eof",	MTWEOF,	0 },
X	{ "eom",	MTEOM,	1 },
X	{ "erase",	MTERASE, 0 },
X	{ "fsf",	MTFSF,	1 },
X	{ "fsr",	MTFSR,	1 },
X	{ "offline",	MTOFFL,	1 },
X	{ "rewind",	MTREW,	1 },
X	{ "rewoffl",	MTOFFL,	1 },
X	{ "status",	MTNOP,	1 },
X	{ "retension",	MTRETEN, 1 },
X	{ "weof",	MTWEOF,	0 },
X	{ NULL }
X};
X
Xvoid printreg __P((char *, u_int, char *));
Xvoid status __P((struct mtget *));
Xvoid usage __P((void));
X
Xint
Xmain(argc, argv)
X	int argc;
X	char *argv[];
X{
X	register struct commands *comp;
X	struct mtget mt_status;
X	struct mtop mt_com;
X	int ch, len, mtfd;
X	char *p, *tape;
X
X	if ((tape = getenv("TAPE")) == NULL)
X		tape = DEFTAPE;
X
X	while ((ch = getopt(argc, argv, "f:t:")) != -1)
X		switch (ch) {
X		case 'f':
X		case 't':
X			tape = optarg;
X			break;
X		case '?':
X		default:
X			usage();
X		}
X	argc -= optind;
X	argv += optind;
X
X	if (argc < 1 || argc > 2)
X		usage();
X
X	len = strlen(p = *argv++);
X	for (comp = com;; comp++) {
X		if (comp->c_name == NULL)
X			errx(1, "%s: unknown command", p);
X		if (strncmp(p, comp->c_name, len) == 0)
X			break;
X	}
X	if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0)
X		err(1, "%s", tape);
X	if (comp->c_code != MTNOP) {
X		mt_com.mt_op = comp->c_code;
X		if (*argv) {
X			mt_com.mt_count = strtol(*argv, &p, 10);
X			if (mt_com.mt_count <= 0 || *p)
X				errx(1, "%s: illegal count", *argv);
X		}
X		else
X			mt_com.mt_count = 1;
X		if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0)
X			err(1, "%s: %s", tape, comp->c_name);
X	} else {
X		if (ioctl(mtfd, MTIOCGET, &mt_status) < 0)
X			err(1, "ioctl MTIOCGET");
X		status(&mt_status);
X	}
X	exit (0);
X	/* NOTREACHED */
X}
X
X#ifdef vax
X#include <vax/mba/mtreg.h>
X#include <vax/mba/htreg.h>
X
X#include <vax/uba/utreg.h>
X#include <vax/uba/tmreg.h>
X#undef b_repcnt		/* argh */
X#include <vax/uba/tsreg.h>
X#endif
X
X#ifdef sun
X#include <sundev/tmreg.h>
X#include <sundev/arreg.h>
X#endif
X
X#ifdef tahoe
X#include <tahoe/vba/cyreg.h>
X#endif
X
Xstruct tape_desc {
X	short	t_type;		/* type of magtape device */
X	char	*t_name;	/* printing name */
X	char	*t_dsbits;	/* "drive status" register */
X	char	*t_erbits;	/* "error" register */
X} tapes[] = {
X#ifdef vax
X	{ MT_ISTS,	"ts11",		0,		TSXS0_BITS },
X	{ MT_ISHT,	"tm03",		HTDS_BITS,	HTER_BITS },
X	{ MT_ISTM,	"tm11",		0,		TMER_BITS },
X	{ MT_ISMT,	"tu78",		MTDS_BITS,	0 },
X	{ MT_ISUT,	"tu45",		UTDS_BITS,	UTER_BITS },
X#endif
X#ifdef sun
X	{ MT_ISCPC,	"TapeMaster",	TMS_BITS,	0 },
X	{ MT_ISAR,	"Archive",	ARCH_CTRL_BITS,	ARCH_BITS },
X#endif
X#ifdef tahoe
X	{ MT_ISCY,	"cipher",	CYS_BITS,	CYCW_BITS },
X#endif
X	{ 0x7,		"SCSI tape",	"76543210",	"76543210" },
X	{ 0 }
X};
X
X/*
X * Interpret the status buffer returned
X */
Xvoid
Xstatus(bp)
X	register struct mtget *bp;
X{
X	register struct tape_desc *mt;
X
X	for (mt = tapes;; mt++) {
X		if (mt->t_type == 0) {
X			(void)printf("%d: unknown tape drive type\n",
X			    bp->mt_type);
X			return;
X		}
X		if (mt->t_type == bp->mt_type)
X			break;
X	}
X	(void)printf("%s tape drive, residual=%d\n", mt->t_name, bp->mt_resid);
X	printreg("ds", bp->mt_dsreg, mt->t_dsbits);
X	printreg("\ner", bp->mt_erreg, mt->t_erbits);
X	(void)putchar('\n');
X	(void)printf("blocksize: %ld (%ld, %ld, %ld, %ld)\n",
X		bp->mt_blksiz, bp->mt_mblksiz[0], bp->mt_mblksiz[1],
X		bp->mt_mblksiz[2], bp->mt_mblksiz[3]);
X	(void)printf("density: %ld (%ld, %ld, %ld, %ld)\n",
X		bp->mt_density, bp->mt_mdensity[0], bp->mt_mdensity[1],
X		bp->mt_mdensity[2], bp->mt_mdensity[3]);
X}
X
X/*
X * Print a register a la the %b format of the kernel's printf.
X */
Xvoid
Xprintreg(s, v, bits)
X	char *s;
X	register u_int v;
X	register char *bits;
X{
X	register int i, any = 0;
X	register char c;
X
X	if (bits && *bits == 8)
X		printf("%s=%o", s, v);
X	else
X		printf("%s=%x", s, v);
X	bits++;
X	if (v && bits) {
X		putchar('<');
X		while (i = *bits++) {
X			if (v & (1 << (i-1))) {
X				if (any)
X					putchar(',');
X				any = 1;
X				for (; (c = *bits) > 32; bits++)
X					putchar(c);
X			} else
X				for (; *bits > 32; bits++)
X					;
X		}
X		putchar('>');
X	}
X}
X
Xvoid
Xusage()
X{
X	(void)fprintf(stderr, "usage: mt [-f device] command [ count ]\n");
X	exit(1);
X}
END-of-mt.c
echo x - mt.1
sed 's/^X//' >mt.1 << 'END-of-mt.1'
X.\"	$NetBSD: mt.1,v 1.4 1995/03/21 06:57:46 cgd Exp $
X.\"
X.\" Copyright (c) 1981, 1990, 1993
X.\"	The Regents of the University of California.  All rights reserved.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" 3. All advertising materials mentioning features or use of this software
X.\"    must display the following acknowledgement:
X.\"	This product includes software developed by the University of
X.\"	California, Berkeley and its contributors.
X.\" 4. Neither the name of the University nor the names of its contributors
X.\"    may be used to endorse or promote products derived from this software
X.\"    without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\"	@(#)mt.1	8.1 (Berkeley) 6/6/93
X.\"
X.Dd June 6, 1993
X.Dt MT 1
X.Os BSD 4
X.Sh NAME
X.Nm mt
X.Nd magnetic tape manipulating program
X.Sh SYNOPSIS
X.Nm mt
X.Op Fl f Ar tapename
X.Ar command
X.Op Ar count
X.Sh DESCRIPTION
X.Nm Mt
Xis used to give commands to a magnetic tape drive.
XBy default
X.Nm mt
Xperforms the requested operation once.  Operations
Xmay be performed multiple times by specifying
X.Ar count  .
XNote
Xthat
X.Ar tapename
Xmust reference a raw (not block) tape device.
X.Pp
XThe available commands are listed below.  Only as many
Xcharacters as are required to uniquely identify a command
Xneed be specified.
X.Bl -tag -width "eof, weof"
X.It Cm eof , weof
XWrite
X.Ar count
Xend-of-file marks at the current position on the tape.
X.It Cm fsf
XForward space
X.Ar count
Xfiles.
X.It Cm fsr
XForward space
X.Ar count
Xrecords.
X.It Cm bsf
XBack space
X.Ar count
Xfiles.
X.It Cm bsr
XBack space
X.Ar count
Xrecords.
X.It Cm rewind
XRewind the tape
X(Count is ignored).
X.It Cm offline , rewoffl
XRewind the tape and place the tape unit off-line
X(Count is ignored).
X.It Cm status
XPrint status information about the tape unit.
X.It Cm retension
XRetensions the tape (if this operation is supported by the tape unit).
X.It Cm erase
XErases the tape (if this operation is supported by the tape unit).
X.It Cm eom
XForward space to the end of the media.
X.It Cm blocksize
XSet the tape blocksize to
X.Ar count
Xbytes.
X.It Cm density
XSet the tape density code to
X.Ar count ,
Xaccording to the scsi2 spec (for scsi tapes). Taken from
X.Pa /usr/src/sys/scsi/scsi_tape.h :
X
X.Bd -literal
Xfrom the scsi2 spec
XValue Tracks Density(bpi) Code Type  Reference     Note
X0x1     9       800       NRZI  R    X3.22-1983    2
X0x2     9      1600       PE    R    X3.39-1986    2
X0x3     9      6250       GCR   R    X3.54-1986    2
X0x5    4/9     8000       GCR   C    X3.136-1986   1
X0x6     9      3200       PE    R    X3.157-1987   2
X0x7     4      6400       IMFM  C    X3.116-1986   1
X0x8     4      8000       GCR   CS   X3.158-1986   1
X0x9    18     37871       GCR   C    X3B5/87-099   2
X0xA    22      6667       MFM   C    X3B5/86-199   1
X0xB     4      1600       PE    C    X3.56-1986    1
X0xC    24     12690       GCR   C    HI-TC1        1,5
X0xD    24     25380       GCR   C    HI-TC2        1,5
X0xF    15     10000       GCR   C    QIC-120       1,5
X0x10   18     10000       GCR   C    QIC-150       1,5
X0x11   26     16000       GCR   C    QIC-320(525?) 1,5
X0x12   30     51667       RLL   C    QIC-1350      1,5
X0x13    1     61000       DDS   CS    X3B5/88-185A 4
X0x14    1     43245       RLL   CS    X3.202-1991  4
X0x15    1     45434       RLL   CS    ECMA TC17    4
X0x16   48     10000       MFM   C     X3.193-1990  1
X0x17   48     42500       MFM   C     X3B5/91-174  1
X
Xwhere Code means:
XNRZI Non Return to Zero, change on ones
XGCR  Group Code Recording
XPE   Phase Encoded
XIMFM Inverted Modified Frequency Modulation
XMFM  Modified Frequency Modulation
XDDS  Dat Data Storage
XRLL  Run Length Encoding
X
Xwhere Type means:
XR    Reel-to-Reel
XC    Cartridge
XCS   cassette
X
Xwhere Notes means:
X1    Serial Recorded
X2    Parallel Recorded
X3    Old format know as QIC-11
X4    Helical Scan
X5    Not ANSI standard, rather industry standard.
X************************************************/
X
X#define	HALFINCH_800	0x01
X#define	HALFINCH_1600	0x02
X#define	HALFINCH_6250	0x03
X#define	QIC_11		0x04	/* from Archive 150S Theory of Op. XXX	*/
X#define QIC_24		0x05	/* may be bad, works for CIPHER ST150S XXX */
X#define QIC_120		0x0f
X#define QIC_150		0x10
X#define QIC_320		0x11
X#define QIC_525		0x11
X#define QIC_1320	0x12
X#define DDS		0x13
X#define DAT_1		0x13
X.Ed
X.El
X.Pp
XIf a tape name is not specified, and the environment variable
X.Ev TAPE
Xdoes not exist;
X.Nm mt
Xuses the device
X.Pa /dev/rmt12 .
X.Pp
X.Nm Mt
Xreturns a 0 exit status when the operation(s) were successful,
X1 if the command was unrecognized, and 2 if an operation failed.
X.Sh ENVIRONMENT
XIf the following environment variable exists, it is utilized by
X.Nm mt .
X.Bl -tag -width Fl
X.It Ev TAPE
X.Nm Mt
Xchecks the
X.Ev TAPE
Xenvironment variable if the
Xargument
X.Ar tapename
Xis not given.
X.Sh FILES
X.Bl -tag -width /dev/rmt* -compact
X.It Pa /dev/rmt*
XRaw magnetic tape interface
X.El
X.Sh SEE ALSO
X.\".Xr mtio 4 ,
X.Xr dd 1 ,
X.Xr ioctl 2 ,
X.Xr environ 7
X.Sh HISTORY
XThe
X.Nm mt
Xcommand appeared in
X.Bx 4.3 .
X.\" mt.1: mtio(4) missing
END-of-mt.1
exit

>Audit-Trail:
>Unformatted:


Enable setting of tape density and block size on SCSI tapes.
change-request