Return to BSD News archive
Newsgroups: comp.os.386bsd.bugs Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!saimiri.primate.wisc.edu!usenet.coe.montana.edu!nate From: nate@cs.montana.edu (Nate Williams) Subject: FWD:hacked version of mt (called st) for beating up scsi tape drives. Message-ID: <1993May26.185312.539@coe.montana.edu> Sender: usenet@coe.montana.edu (USENET News System) Organization: CS Date: Wed, 26 May 1993 18:53:12 GMT Lines: 547 ---------------- From: Julian Elischer <julian@jules.dialix.oz.au> # 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: # # /usr/src/sbin/st # /usr/src/sbin/st/Makefile # /usr/src/sbin/st/st.1 # /usr/src/sbin/st/st.c # echo c - /usr/src/sbin/st mkdir /usr/src/sbin/st > /dev/null 2>&1 echo x - /usr/src/sbin/st/Makefile sed 's/^X//' >/usr/src/sbin/st/Makefile << 'END-of-/usr/src/sbin/st/Makefile' X# @(#)Makefile 5.4 (Berkeley) 6/5/91 X XPROG= st XMAN8= st.0 X X.include <bsd.prog.mk> END-of-/usr/src/sbin/st/Makefile echo x - /usr/src/sbin/st/st.1 sed 's/^X//' >/usr/src/sbin/st/st.1 << 'END-of-/usr/src/sbin/st/st.1' X.\" Copyright (c) 1981, 1990 The Regents of the University of California. X.\" All rights reserved. X.\" 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 6.7 (Berkeley) 7/28/91 X.\" X.Dd July 28, 1991 X.Dt ST 1 X.Os BSD 4 X.Sh NAME X.Nm st X.Nd magnetic tape manipulating program X.Sh SYNOPSIS X.Nm st X.Op Fl f Ar tapename X.Ar command X.Op Ar count X.Sh DESCRIPTION X.Nm St Xis used to give commands to a magnetic tape drive. XBy default X.Nm st 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 blocksize XSets the block size characteristics of the device to value specified in X.Ar count. XA 0 means variable sized blocks, and anything else means fixed block, Xwith blocksize as that of X.Ar count. X.It Cm high_dnsty XSet the default high density minor device X.Ar count Xdensity code as specified by the SCSI II specification. Valid values Xare from 0 to 0x17. X.It Cm medium_dnsty XSet the default medium density minor device X.Ar count Xdensity code as specified by the SCSI II specification. Valid values Xare from 0 to 0x17. X.It Cm low_dnsty XSet the default low density minor device X.Ar count Xdensity code as specified by the SCSI II specification. Valid values Xare from 0 to 0x17. X.It The different density codes are as follows: X0x0 default for device X.br X0xE reserved for ECMA X.br X XValue Tracks Density(bpi) Code Type Reference Note X.br X0x1 9 800 NRZI R X3.22-1983 2 X.br X0x2 9 1600 PE R X3.39-1986 2 X.br X0x3 9 6250 GCR R X3.54-1986 2 X.br X0x5 4/9 8000 GCR C X3.136-1986 1 X.br X0x6 9 3200 PE R X3.157-1987 2 X.br X0x7 4 6400 IMFM C X3.116-1986 1 X.br X0x8 4 8000 GCR CS X3.158-1986 1 X.br X0x9 18 37871 GCR C X3B5/87-099 2 X.br X0xA 22 6667 MFM C X3B5/86-199 1 X.br X0xB 4 1600 PE C X3.56-1986 1 X.br X0xC 24 12690 GCR C HI-TC1 1,5 X.br X0xD 24 25380 GCR C HI-TC2 1,5 X.br X0xF 15 10000 GCR C QIC-120 1,5 X.br X0x10 18 10000 GCR C QIC-150 1,5 X.br X0x11 26 16000 GCR C QIC-320(525?) 1,5 X.br X0x12 30 51667 RLL C QIC-1350 1,5 X.br X0x13 1 61000 DDS CS X3B5/88-185A 4 X.br X0x14 1 43245 RLL CS X3.202-1991 4 X.br X0x15 1 45434 RLL CS ECMA TC17 4 X.br X0x16 48 10000 MFM C X3.193-1990 1 X.br X0x17 48 42500 MFM C X3B5/91-174 1 X.br X Xwhere Code means: X.br XNRZI Non Return to Zero, change on ones X.br XGCR Group Code Recording X.br XPE Phase Encoded X.br XIMFM Inverted Modified Frequency Modulation X.br XMFM Modified Frequency Modulation X.br XDDS Dat Data Storage X.br XRLL Run Length Encoding X.br X Xwhere Type means: X.br XR Real-to-Real X.br XC Cartridge X.br XCS cassette X.br X Xwhere Notes means: X.br X1 Serial Recorded X.br X2 Parallel Recorded X.br X3 Old format know as QIC-11 X.br X4 Helical Scan X.br X5 Not ANSI standard, rather industry standard. X.br X X.It Cm status XPrint status information about the tape unit. X.El X.Pp XIf a tape name is not specified, and the environment variable X.Ev TAPE Xdoes not exist; X.Nm st Xuses the device X.Pa /dev/rmt12 . X.Pp X.Nm St 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 st . X.Bl -tag -width Fl X.It Ev TAPE X.Nm St 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 st Xcommand appeared in 386BSD 0.1. X X.\" mt.1: mtio(4) missing END-of-/usr/src/sbin/st/st.1 echo x - /usr/src/sbin/st/st.c sed 's/^X//' >/usr/src/sbin/st/st.c << 'END-of-/usr/src/sbin/st/st.c' X/* X * Copyright (c) 1980 The Regents of the University of California. X * 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 Xchar copyright[] = X"@(#) Copyright (c) 1980 The Regents of the University of California.\n\ X All rights reserved.\n"; X#endif /* not lint */ X X#ifndef lint Xstatic char sccsid[] = "@(#)mt.c 5.6 (Berkeley) 6/6/91"; 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 <stdio.h> X#include <ctype.h> X X#define equal(s1,s2) (strcmp(s1, s2) == 0) X Xstruct commands { X char *c_name; X int c_code; X int c_ronly; X} com[] = { X { "weof", MTWEOF, 0 }, X { "eof", MTWEOF, 0 }, X { "fsf", MTFSF, 1 }, X { "bsf", MTBSF, 1 }, X { "fsr", MTFSR, 1 }, X { "bsr", MTBSR, 1 }, X { "rewind", MTREW, 1 }, X { "offline", MTOFFL, 1 }, X { "rewoffl", MTOFFL, 1 }, X { "status", MTNOP, 1 }, X { "blocksize", MTSETBSIZ, 0 }, X { "high_dnsty", MTSETHDNSTY, 0 }, X { "medium_dnsty", MTSETMDNSTY, 0 }, X { "low_dnsty", MTSETLDNSTY, 0 }, X { 0 } X}; X Xint mtfd; Xstruct mtop mt_com; Xstruct mtget mt_status; Xchar *tape; X Xmain(argc, argv) X char **argv; X{ X void usage(); X char line[80], *getenv(); X register char *cp; X register struct commands *comp; X X if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) { X argc -= 2; X tape = argv[2]; X argv += 2; X } else X if ((tape = getenv("TAPE")) == NULL) X tape = DEFTAPE; X if (argc < 2) { X usage(); X exit(1); X } X cp = argv[1]; X if ((strncmp(cp, "blocksize", strlen(cp)) == 0) && argc < 3 ) { X usage(); X exit(1); X } X if ((strncmp(cp, "high_dnsty", strlen(cp)) == 0) && argc < 3 ) { X usage(); X exit(1); X } X if ((strncmp(cp, "medium_dnsty", strlen(cp)) == 0) && argc < 3 ) { X usage(); X exit(1); X } X if ((strncmp(cp, "low_dnsty", strlen(cp)) == 0) && argc < 3 ) { X usage(); X exit(1); X } X for (comp = com; comp->c_name != NULL; comp++) X if (strncmp(cp, comp->c_name, strlen(cp)) == 0) X break; X if (comp->c_name == NULL) { X fprintf(stderr, "mt: don't grok \"%s\"\n", cp); X usage(); X exit(1); X } X if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0) { X perror(tape); X exit(1); X } X if (comp->c_code != MTNOP) { X mt_com.mt_op = comp->c_code; X mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1); X if (mt_com.mt_count < 0) { X fprintf(stderr, "mt: negative repeat count\n"); X exit(1); X } X if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) { X fprintf(stderr, "%s %s %d ", tape, comp->c_name, X mt_com.mt_count); X perror("failed"); X exit(2); X } X } else { X if (ioctl(mtfd, MTIOCGET, (char *)&mt_status) < 0) { X perror("mt"); X exit(2); X } X status(&mt_status); X } X} X X#ifdef vax X#include <vaxmba/mtreg.h> X#include <vaxmba/htreg.h> X X#include <vaxuba/utreg.h> X#include <vaxuba/tmreg.h> X#undef b_repcnt /* argh */ X#include <vaxuba/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#if defined(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#if defined (__386BSD__) X { MT_ISAR, "Archive/Tandberg?", 0, 0 }, X#endif X { 0 } X}; X X/* X * Interpret the status buffer returned X */ Xstatus(bp) X register struct mtget *bp; X{ X register struct tape_desc *mt; X X for (mt = tapes; mt->t_type; mt++) X if (mt->t_type == bp->mt_type) X break; X if (mt->t_type == 0) { X printf("unknown tape drive type (%d)\n", bp->mt_type); X return; X } X printf("%s tape drive, residual=%d, blocksize=%d\n", X mt->t_name, bp->mt_resid, bp->mt_bsiz); X printf("Density: high = %d (0x%x), medium = %d (0x%x), low = %d (0x%x)\n", X bp->mt_dns_high, bp->mt_dns_high, bp->mt_dns_medium, X bp->mt_dns_medium, bp->mt_dns_low, bp->mt_dns_low); X printreg("ds", bp->mt_dsreg, mt->t_dsbits); X printreg("\ner", bp->mt_erreg, mt->t_erbits); X putchar('\n'); X} X X/* X * Print a register a la the %b format of the kernel's printf X */ Xprintreg(s, v, bits) X char *s; X register char *bits; X register unsigned short v; 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} Xvoid usage() { X register struct commands *comp; X X fprintf(stderr, "Usage: st [ -f tape ] command [ count ] \n"); X fprintf(stderr, " Where command is one of:\n"); X for (comp=com; comp->c_name != NULL; comp++) { X fprintf(stderr, " %s\n", comp->c_name); X } X fprintf(stderr,"Note that the count argument is required\n"); X fprintf(stderr, "with the \"blocksize\" , and the density setting commands.\n"); X fprintf(stderr, "Note that the count argument is a base 10 number\n"); X} END-of-/usr/src/sbin/st/st.c exit -- osynw@terra.oscs.montana.edu | Still trying to find a good reason for nate@cs.montana.edu | these 'computer' things. Personally, work #: (406) 994-4836 | I don't think they'll catch on - home #: (406) 586-0579 | Don Hammerstrom