mt.c revision 41913
11590Srgrimes/* 21590Srgrimes * Copyright (c) 1980, 1993 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 3. All advertising materials mentioning features or use of this software 141590Srgrimes * must display the following acknowledgement: 151590Srgrimes * This product includes software developed by the University of 161590Srgrimes * California, Berkeley and its contributors. 171590Srgrimes * 4. Neither the name of the University nor the names of its contributors 181590Srgrimes * may be used to endorse or promote products derived from this software 191590Srgrimes * without specific prior written permission. 201590Srgrimes * 211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311590Srgrimes * SUCH DAMAGE. 321590Srgrimes */ 331590Srgrimes 341590Srgrimes#ifndef lint 3527752Scharnierstatic const char copyright[] = 361590Srgrimes"@(#) Copyright (c) 1980, 1993\n\ 371590Srgrimes The Regents of the University of California. All rights reserved.\n"; 381590Srgrimes#endif /* not lint */ 391590Srgrimes 401590Srgrimes#ifndef lint 4127752Scharnier#if 0 4223693Speterstatic char sccsid[] = "@(#)mt.c 8.2 (Berkeley) 5/4/95"; 4327752Scharnier#endif 4427752Scharnierstatic const char rcsid[] = 4541913Smjacob "$Id: mt.c,v 1.16 1998/10/03 10:58:54 dfr Exp $"; 461590Srgrimes#endif /* not lint */ 471590Srgrimes 481590Srgrimes/* 491590Srgrimes * mt -- 501590Srgrimes * magnetic tape manipulation program 511590Srgrimes */ 521590Srgrimes#include <sys/types.h> 531590Srgrimes#include <sys/ioctl.h> 541590Srgrimes#include <sys/mtio.h> 5523693Speter 5623693Speter#include <ctype.h> 5727752Scharnier#include <err.h> 581590Srgrimes#include <fcntl.h> 5923693Speter#include <stdio.h> 601590Srgrimes#include <stdlib.h> 611590Srgrimes#include <string.h> 6223693Speter#include <unistd.h> 631590Srgrimes 647913Sjoerg/* the appropriate sections of <sys/mtio.h> are also #ifdef'd for FreeBSD */ 657913Sjoerg#if defined(__FreeBSD__) 667913Sjoerg/* c_flags */ 677913Sjoerg#define NEED_2ARGS 0x01 687929Sjoerg#define ZERO_ALLOWED 0x02 697929Sjoerg#define IS_DENSITY 0x04 709541Sjoerg#define DISABLE_THIS 0x08 7139260Sgibbs#define IS_COMP 0x10 727913Sjoerg#endif /* defined(__FreeBSD__) */ 737913Sjoerg 7439260Sgibbs#ifndef TRUE 7539260Sgibbs#define TRUE 1 7639260Sgibbs#endif 7739260Sgibbs#ifndef FALSE 7839260Sgibbs#define FALSE 0 7939260Sgibbs#endif 8039260Sgibbs 811590Srgrimesstruct commands { 821590Srgrimes char *c_name; 831590Srgrimes int c_code; 841590Srgrimes int c_ronly; 857913Sjoerg#if defined(__FreeBSD__) 867913Sjoerg int c_flags; 877913Sjoerg#endif /* defined(__FreeBSD__) */ 881590Srgrimes} com[] = { 891590Srgrimes { "bsf", MTBSF, 1 }, 901590Srgrimes { "bsr", MTBSR, 1 }, 919541Sjoerg#if defined(__FreeBSD__) 929541Sjoerg /* XXX FreeBSD considered "eof" dangerous, since it's being 939541Sjoerg confused with "eom" (and is an alias for "weof" anyway) */ 949541Sjoerg { "eof", MTWEOF, 0, DISABLE_THIS }, 959541Sjoerg#else 969541Sjoerg { "eof", MTWEOF, 0 }, 979541Sjoerg#endif 981590Srgrimes { "fsf", MTFSF, 1 }, 991590Srgrimes { "fsr", MTFSR, 1 }, 1001590Srgrimes { "offline", MTOFFL, 1 }, 1011590Srgrimes { "rewind", MTREW, 1 }, 1021590Srgrimes { "rewoffl", MTOFFL, 1 }, 1031590Srgrimes { "status", MTNOP, 1 }, 10441913Smjacob#if defined(__FreeBSD__) 10541913Smjacob { "weof", MTWEOF, 0, ZERO_ALLOWED }, 10641913Smjacob#else 1071590Srgrimes { "weof", MTWEOF, 0 }, 10841913Smjacob#endif 1097913Sjoerg#if defined(__FreeBSD__) 11039260Sgibbs { "erase", MTERASE, 0, ZERO_ALLOWED}, 1117913Sjoerg { "blocksize", MTSETBSIZ, 0, NEED_2ARGS|ZERO_ALLOWED }, 1127929Sjoerg { "density", MTSETDNSTY, 0, NEED_2ARGS|ZERO_ALLOWED|IS_DENSITY }, 1137913Sjoerg { "eom", MTEOD, 1 }, 11428492Sjoerg { "eod", MTEOD, 1 }, 11539260Sgibbs { "comp", MTCOMP, 0, NEED_2ARGS|ZERO_ALLOWED|IS_COMP }, 11613401Sjoerg { "retension", MTRETENS, 1 }, 11741913Smjacob { "rdhpos", MTIOCRDHPOS, 0 }, 11841913Smjacob { "rdspos", MTIOCRDSPOS, 0 }, 11941913Smjacob { "sethpos", MTIOCHLOCATE, 0, NEED_2ARGS|ZERO_ALLOWED }, 12041913Smjacob { "setspos", MTIOCSLOCATE, 0, NEED_2ARGS|ZERO_ALLOWED }, 1217913Sjoerg#endif /* defined(__FreeBSD__) */ 1221590Srgrimes { NULL } 1231590Srgrimes}; 1241590Srgrimes 1251590Srgrimesvoid printreg __P((char *, u_int, char *)); 1261590Srgrimesvoid status __P((struct mtget *)); 1271590Srgrimesvoid usage __P((void)); 1287913Sjoerg#if defined (__FreeBSD__) 1297913Sjoergvoid st_status (struct mtget *); 1307929Sjoergint stringtodens (const char *s); 1317929Sjoergconst char *denstostring (int d); 13239260Sgibbsint denstobp(int d, int bpi); 13339260Sgibbsu_int32_t stringtocomp(const char *s); 13439260Sgibbsconst char * comptostring(u_int32_t comp); 1359541Sjoergvoid warn_eof __P((void)); 1367913Sjoerg#endif /* defined (__FreeBSD__) */ 1371590Srgrimes 1381590Srgrimesint 1391590Srgrimesmain(argc, argv) 1401590Srgrimes int argc; 1411590Srgrimes char *argv[]; 1421590Srgrimes{ 1431590Srgrimes register struct commands *comp; 1441590Srgrimes struct mtget mt_status; 1451590Srgrimes struct mtop mt_com; 1461590Srgrimes int ch, len, mtfd; 1471590Srgrimes char *p, *tape; 1481590Srgrimes 1491590Srgrimes if ((tape = getenv("TAPE")) == NULL) 1501590Srgrimes tape = DEFTAPE; 1511590Srgrimes 15224360Simp while ((ch = getopt(argc, argv, "f:t:")) != -1) 1531590Srgrimes switch(ch) { 1541590Srgrimes case 'f': 1551590Srgrimes case 't': 1561590Srgrimes tape = optarg; 1571590Srgrimes break; 1581590Srgrimes case '?': 1591590Srgrimes default: 1601590Srgrimes usage(); 1611590Srgrimes } 1621590Srgrimes argc -= optind; 1631590Srgrimes argv += optind; 1641590Srgrimes 1651590Srgrimes if (argc < 1 || argc > 2) 1661590Srgrimes usage(); 1671590Srgrimes 1681590Srgrimes len = strlen(p = *argv++); 1691590Srgrimes for (comp = com;; comp++) { 1701590Srgrimes if (comp->c_name == NULL) 17127752Scharnier errx(1, "%s: unknown command", p); 1721590Srgrimes if (strncmp(p, comp->c_name, len) == 0) 1731590Srgrimes break; 1741590Srgrimes } 1757913Sjoerg#if defined(__FreeBSD__) 1767913Sjoerg if((comp->c_flags & NEED_2ARGS) && argc != 2) 1777913Sjoerg usage(); 1789541Sjoerg if(comp->c_flags & DISABLE_THIS) { 1799541Sjoerg warn_eof(); 1809541Sjoerg } 1817913Sjoerg#endif /* defined(__FreeBSD__) */ 1821590Srgrimes if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0) 18327752Scharnier err(1, "%s", tape); 1841590Srgrimes if (comp->c_code != MTNOP) { 1851590Srgrimes mt_com.mt_op = comp->c_code; 1861590Srgrimes if (*argv) { 1877913Sjoerg#if defined (__FreeBSD__) 1887929Sjoerg if (!isdigit(**argv) && 1897929Sjoerg comp->c_flags & IS_DENSITY) { 1907929Sjoerg const char *dcanon; 1917929Sjoerg mt_com.mt_count = stringtodens(*argv); 1927929Sjoerg if (mt_com.mt_count == 0) 19327752Scharnier errx(1, "%s: unknown density", *argv); 1947929Sjoerg dcanon = denstostring(mt_com.mt_count); 1957929Sjoerg if (strcmp(dcanon, *argv) != 0) 1967929Sjoerg printf( 1977929Sjoerg "Using \"%s\" as an alias for %s\n", 1987929Sjoerg *argv, dcanon); 1997929Sjoerg p = ""; 20039260Sgibbs } else if (!isdigit(**argv) && 20139260Sgibbs comp->c_flags & IS_COMP) { 20239260Sgibbs 20339260Sgibbs mt_com.mt_count = stringtocomp(*argv); 20439260Sgibbs if ((u_int32_t)mt_com.mt_count == 0xf0f0f0f0) 20539260Sgibbs errx(1, "%s: unknown compression", 20639260Sgibbs *argv); 20739260Sgibbs p = ""; 2087929Sjoerg } else 2097929Sjoerg /* allow for hex numbers; useful for density */ 2107929Sjoerg mt_com.mt_count = strtol(*argv, &p, 0); 2117913Sjoerg#else 2121590Srgrimes mt_com.mt_count = strtol(*argv, &p, 10); 2137913Sjoerg#endif /* defined(__FreeBSD__) */ 2147913Sjoerg if (mt_com.mt_count <= 2157913Sjoerg#if defined (__FreeBSD__) 2167913Sjoerg ((comp->c_flags & ZERO_ALLOWED)? -1: 0) 21739260Sgibbs && ((comp->c_flags & IS_COMP) == 0) 2187913Sjoerg#else 2197913Sjoerg 0 2207913Sjoerg#endif /* defined (__FreeBSD__) */ 2217913Sjoerg || *p) 22227752Scharnier errx(1, "%s: illegal count", *argv); 2231590Srgrimes } 2241590Srgrimes else 2251590Srgrimes mt_com.mt_count = 1; 22641913Smjacob#if defined(__FreeBSD__) 22741913Smjacob switch (comp->c_code) { 22841913Smjacob case MTIOCRDHPOS: 22941913Smjacob case MTIOCRDSPOS: 23041913Smjacob if (ioctl(mtfd, comp->c_code, &mt_com.mt_count) < 0) 23141913Smjacob err(2, "%s", tape); 23241913Smjacob printf("%s: %s block location %u\n", tape, 23341913Smjacob (comp->c_code == MTIOCRDHPOS)? "hardware" : 23441913Smjacob "logical", (unsigned int) mt_com.mt_count); 23541913Smjacob exit (0); 23641913Smjacob /* NOTREACHED */ 23741913Smjacob case MTIOCSLOCATE: 23841913Smjacob case MTIOCHLOCATE: 23941913Smjacob if (ioctl(mtfd, comp->c_code, &mt_com.mt_count) < 0) 24041913Smjacob err(2, "%s", tape); 24141913Smjacob exit (0); 24241913Smjacob /* NOTREACHED */ 24341913Smjacob default: 24441913Smjacob break; 24541913Smjacob } 24641913Smjacob#endif 2471590Srgrimes if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) 24827752Scharnier err(1, "%s: %s", tape, comp->c_name); 2491590Srgrimes } else { 2501590Srgrimes if (ioctl(mtfd, MTIOCGET, &mt_status) < 0) 25127752Scharnier err(1, NULL); 2521590Srgrimes status(&mt_status); 2531590Srgrimes } 2541590Srgrimes exit (0); 2551590Srgrimes /* NOTREACHED */ 2561590Srgrimes} 2571590Srgrimes 2581590Srgrimes#ifdef vax 2591590Srgrimes#include <vax/mba/mtreg.h> 2601590Srgrimes#include <vax/mba/htreg.h> 2611590Srgrimes 2621590Srgrimes#include <vax/uba/utreg.h> 2631590Srgrimes#include <vax/uba/tmreg.h> 2641590Srgrimes#undef b_repcnt /* argh */ 2651590Srgrimes#include <vax/uba/tsreg.h> 2661590Srgrimes#endif 2671590Srgrimes 2681590Srgrimes#ifdef sun 2691590Srgrimes#include <sundev/tmreg.h> 2701590Srgrimes#include <sundev/arreg.h> 2711590Srgrimes#endif 2721590Srgrimes 2731590Srgrimes#ifdef tahoe 2741590Srgrimes#include <tahoe/vba/cyreg.h> 2751590Srgrimes#endif 2761590Srgrimes 27739913Sdfr#if defined(__FreeBSD__) && defined(__i386__) 27814176Sjoerg#include <machine/wtio.h> 27914176Sjoerg#endif 28014176Sjoerg 2811590Srgrimesstruct tape_desc { 2821590Srgrimes short t_type; /* type of magtape device */ 2831590Srgrimes char *t_name; /* printing name */ 2841590Srgrimes char *t_dsbits; /* "drive status" register */ 2851590Srgrimes char *t_erbits; /* "error" register */ 2861590Srgrimes} tapes[] = { 2871590Srgrimes#ifdef vax 2881590Srgrimes { MT_ISTS, "ts11", 0, TSXS0_BITS }, 2891590Srgrimes { MT_ISHT, "tm03", HTDS_BITS, HTER_BITS }, 2901590Srgrimes { MT_ISTM, "tm11", 0, TMER_BITS }, 2911590Srgrimes { MT_ISMT, "tu78", MTDS_BITS, 0 }, 2921590Srgrimes { MT_ISUT, "tu45", UTDS_BITS, UTER_BITS }, 2931590Srgrimes#endif 2941590Srgrimes#ifdef sun 2951590Srgrimes { MT_ISCPC, "TapeMaster", TMS_BITS, 0 }, 2961590Srgrimes { MT_ISAR, "Archive", ARCH_CTRL_BITS, ARCH_BITS }, 2971590Srgrimes#endif 2981590Srgrimes#ifdef tahoe 2991590Srgrimes { MT_ISCY, "cipher", CYS_BITS, CYCW_BITS }, 3001590Srgrimes#endif 3017913Sjoerg#if defined (__FreeBSD__) 3027913Sjoerg /* 30314176Sjoerg * XXX This is weird. The st driver reports the tape drive 3047913Sjoerg * as 0x7 (MT_ISAR - Sun/Archive compatible); the wt driver 3057913Sjoerg * either reports MT_ISVIPER1 for an Archive tape, or 0x11 3067913Sjoerg * (MT_ISMFOUR) for other tapes. 3077913Sjoerg * XXX for the wt driver, rely on it behaving like a "standard" 3087913Sjoerg * magtape driver. 3097913Sjoerg */ 3107913Sjoerg { MT_ISAR, "SCSI tape drive", 0, 0 }, 31139913Sdfr#if defined (__i386__) 31214176Sjoerg { MT_ISVIPER1, "Archive Viper", WTDS_BITS, WTER_BITS }, 31314176Sjoerg { MT_ISMFOUR, "Wangtek", WTDS_BITS, WTER_BITS }, 31439913Sdfr#endif 3157913Sjoerg#endif /* defined (__FreeBSD__) */ 3161590Srgrimes { 0 } 3171590Srgrimes}; 3181590Srgrimes 3191590Srgrimes/* 3201590Srgrimes * Interpret the status buffer returned 3211590Srgrimes */ 3221590Srgrimesvoid 3231590Srgrimesstatus(bp) 3241590Srgrimes register struct mtget *bp; 3251590Srgrimes{ 3261590Srgrimes register struct tape_desc *mt; 3271590Srgrimes 3281590Srgrimes for (mt = tapes;; mt++) { 3291590Srgrimes if (mt->t_type == 0) { 3301590Srgrimes (void)printf("%d: unknown tape drive type\n", 3311590Srgrimes bp->mt_type); 3321590Srgrimes return; 3331590Srgrimes } 3341590Srgrimes if (mt->t_type == bp->mt_type) 3351590Srgrimes break; 3361590Srgrimes } 3377913Sjoerg#if defined (__FreeBSD__) 3387913Sjoerg if(mt->t_type == MT_ISAR) 3397913Sjoerg st_status(bp); 3407913Sjoerg else { 3417913Sjoerg#endif /* defined (__FreeBSD__) */ 3421590Srgrimes (void)printf("%s tape drive, residual=%d\n", mt->t_name, bp->mt_resid); 34314176Sjoerg printreg("ds", (unsigned short)bp->mt_dsreg, mt->t_dsbits); 34414176Sjoerg printreg("\ner", (unsigned short)bp->mt_erreg, mt->t_erbits); 3451590Srgrimes (void)putchar('\n'); 3467913Sjoerg#if defined (__FreeBSD__) 3477913Sjoerg } 3487913Sjoerg#endif /* defined (__FreeBSD__) */ 3491590Srgrimes} 3501590Srgrimes 3511590Srgrimes/* 3521590Srgrimes * Print a register a la the %b format of the kernel's printf. 3531590Srgrimes */ 3541590Srgrimesvoid 3551590Srgrimesprintreg(s, v, bits) 3561590Srgrimes char *s; 3571590Srgrimes register u_int v; 3581590Srgrimes register char *bits; 3591590Srgrimes{ 3601590Srgrimes register int i, any = 0; 3611590Srgrimes register char c; 3621590Srgrimes 3631590Srgrimes if (bits && *bits == 8) 3641590Srgrimes printf("%s=%o", s, v); 3651590Srgrimes else 3661590Srgrimes printf("%s=%x", s, v); 36711608Sbde if (!bits) 36811608Sbde return; 3691590Srgrimes bits++; 3701590Srgrimes if (v && bits) { 3711590Srgrimes putchar('<'); 37227752Scharnier while ((i = *bits++)) { 3731590Srgrimes if (v & (1 << (i-1))) { 3741590Srgrimes if (any) 3751590Srgrimes putchar(','); 3761590Srgrimes any = 1; 3771590Srgrimes for (; (c = *bits) > 32; bits++) 3781590Srgrimes putchar(c); 3791590Srgrimes } else 3801590Srgrimes for (; *bits > 32; bits++) 3811590Srgrimes ; 3821590Srgrimes } 3831590Srgrimes putchar('>'); 3841590Srgrimes } 3851590Srgrimes} 3861590Srgrimes 3871590Srgrimesvoid 3881590Srgrimesusage() 3891590Srgrimes{ 3901590Srgrimes (void)fprintf(stderr, "usage: mt [-f device] command [ count ]\n"); 3911590Srgrimes exit(1); 3921590Srgrimes} 3931590Srgrimes 3947913Sjoerg#if defined (__FreeBSD__) 3957913Sjoerg 3967913Sjoergstruct densities { 3977913Sjoerg int dens; 39839260Sgibbs int bpmm; 39939260Sgibbs int bpi; 4007913Sjoerg const char *name; 40139260Sgibbs} dens[] = { 40239260Sgibbs /* 40339260Sgibbs * Taken from T10 Project 997D 40439260Sgibbs * SCSI-3 Stream Device Commands (SSC) 40539260Sgibbs * Revision 11, 4-Nov-97 40639260Sgibbs */ 40739260Sgibbs /*Num. bpmm bpi Reference */ 40839260Sgibbs { 0x1, 32, 800, "X3.22-1983" }, 40939260Sgibbs { 0x2, 63, 1600, "X3.39-1986" }, 41039260Sgibbs { 0x3, 246, 6250, "X3.54-1986" }, 41139260Sgibbs { 0x5, 315, 8000, "X3.136-1986" }, 41239260Sgibbs { 0x6, 126, 3200, "X3.157-1987" }, 41339260Sgibbs { 0x7, 252, 6400, "X3.116-1986" }, 41439260Sgibbs { 0x8, 315, 8000, "X3.158-1987" }, 41539260Sgibbs { 0x9, 491, 37871, "X3.180" }, 41639260Sgibbs { 0xA, 262, 6667, "X3B5/86-199" }, 41739260Sgibbs { 0xB, 63, 1600, "X3.56-1986" }, 41839260Sgibbs { 0xC, 500, 12690, "HI-TC1" }, 41939260Sgibbs { 0xD, 999, 25380, "HI-TC2" }, 42039260Sgibbs { 0xF, 394, 10000, "QIC-120" }, 42139260Sgibbs { 0x10, 394, 10000, "QIC-150" }, 42239260Sgibbs { 0x11, 630, 16000, "QIC-320" }, 42339260Sgibbs { 0x12, 2034, 51667, "QIC-1350" }, 42439260Sgibbs { 0x13, 2400, 61000, "X3B5/88-185A" }, 42539260Sgibbs { 0x14, 1703, 43245, "X3.202-1991" }, 42639260Sgibbs { 0x15, 1789, 45434, "ECMA TC17" }, 42739260Sgibbs { 0x16, 394, 10000, "X3.193-1990" }, 42839260Sgibbs { 0x17, 1673, 42500, "X3B5/91-174" }, 42939260Sgibbs { 0x18, 1673, 42500, "X3B5/92-50" }, 43039260Sgibbs { 0x1C, 1654, 42000, "QIC-385M" }, 43139260Sgibbs { 0x1D, 1512, 38400, "QIC-410M" }, 43239260Sgibbs { 0x1E, 1385, 36000, "QIC-1000C" }, 43339260Sgibbs { 0x1F, 2666, 67733, "QIC-2100C" }, 43439260Sgibbs { 0x20, 2666, 67733, "QIC-6GB(M)" }, 43539260Sgibbs { 0x21, 2666, 67733, "QIC-20GB(C)" }, 43639260Sgibbs { 0x22, 1600, 40640, "QIC-2GB(C)" }, 43739260Sgibbs { 0x23, 2666, 67733, "QIC-875M" }, 43839260Sgibbs { 0x24, 2400, 61000, "DDS-2" }, 43939260Sgibbs { 0x25, 3816, 97000, "DDS-3" }, 44039260Sgibbs { 0x26, 3816, 97000, "DDS-4" }, 44139260Sgibbs { 0x27, 3056, 77611, "Mammoth" }, 44239260Sgibbs { 0x28, 1491, 37871, "X3.224" }, 44339260Sgibbs { 0, 0, 0, NULL } 4447913Sjoerg}; 4457913Sjoerg 44639260Sgibbsstruct compression_types { 44739260Sgibbs u_int32_t comp_number; 44839260Sgibbs const char *name; 44939260Sgibbs} comp_types[] = { 45039260Sgibbs { 0x00, "none" }, 45139260Sgibbs { 0x00, "off" }, 45239260Sgibbs { 0x10, "IDRC" }, 45339260Sgibbs { 0x20, "DCLZ" }, 45439260Sgibbs { 0xffffffff, "enable" }, 45539260Sgibbs { 0xffffffff, "on" }, 45639260Sgibbs { 0xf0f0f0f0, NULL} 45739260Sgibbs}; 45839260Sgibbs 4597913Sjoergconst char * 4607929Sjoergdenstostring(int d) 4617913Sjoerg{ 4627913Sjoerg static char buf[20]; 4637913Sjoerg struct densities *sd; 4647913Sjoerg 4657913Sjoerg for (sd = dens; sd->dens; sd++) 4667913Sjoerg if (sd->dens == d) 4677913Sjoerg break; 4687913Sjoerg if (sd->dens == 0) { 4697929Sjoerg sprintf(buf, "0x%02x", d); 4707913Sjoerg return buf; 4717929Sjoerg } else 4727913Sjoerg return sd->name; 4737913Sjoerg} 4747913Sjoerg 47539260Sgibbs/* 47639260Sgibbs * Given a specific density number, return either the bits per inch or bits 47739260Sgibbs * per millimeter for the given density. 47839260Sgibbs */ 4797929Sjoergint 48039260Sgibbsdenstobp(int d, int bpi) 48139260Sgibbs{ 48239260Sgibbs struct densities *sd; 48339260Sgibbs 48439260Sgibbs for (sd = dens; sd->dens; sd++) 48539260Sgibbs if (sd->dens == d) 48639260Sgibbs break; 48739260Sgibbs if (sd->dens == 0) 48839260Sgibbs return(0); 48939260Sgibbs else { 49039260Sgibbs if (bpi) 49139260Sgibbs return(sd->bpi); 49239260Sgibbs else 49339260Sgibbs return(sd->bpmm); 49439260Sgibbs } 49539260Sgibbs} 49639260Sgibbs 49739260Sgibbsint 4987929Sjoergstringtodens(const char *s) 4997929Sjoerg{ 5007929Sjoerg struct densities *sd; 5017929Sjoerg size_t l = strlen(s); 5027929Sjoerg 5037929Sjoerg for (sd = dens; sd->dens; sd++) 5047929Sjoerg if (strncasecmp(sd->name, s, l) == 0) 5057929Sjoerg break; 5067929Sjoerg return sd->dens; 5077929Sjoerg} 5087929Sjoerg 5097929Sjoerg 5107913Sjoergconst char * 5117913Sjoerggetblksiz(int bs) 5127913Sjoerg{ 5137913Sjoerg static char buf[25]; 5147913Sjoerg if (bs == 0) 5157913Sjoerg return "variable"; 5167913Sjoerg else { 51739260Sgibbs sprintf(buf, "%d bytes", bs); 5187913Sjoerg return buf; 5197913Sjoerg } 5207913Sjoerg} 5217913Sjoerg 52239260Sgibbsconst char * 52339260Sgibbscomptostring(u_int32_t comp) 52439260Sgibbs{ 52539260Sgibbs static char buf[20]; 52639260Sgibbs struct compression_types *ct; 5277913Sjoerg 52839260Sgibbs if (comp == MT_COMP_DISABLED) 52939260Sgibbs return "disabled"; 53039260Sgibbs else if (comp == MT_COMP_UNSUPP) 53139260Sgibbs return "unsupported"; 53239260Sgibbs 53339260Sgibbs for (ct = comp_types; ct->name; ct++) 53439260Sgibbs if (ct->comp_number == comp) 53539260Sgibbs break; 53639260Sgibbs 53739260Sgibbs if (ct->comp_number == 0xf0f0f0f0) { 53839260Sgibbs sprintf(buf, "0x%2x", comp); 53939260Sgibbs return(buf); 54039260Sgibbs } else 54139260Sgibbs return(ct->name); 54239260Sgibbs} 54339260Sgibbs 54439260Sgibbsu_int32_t 54539260Sgibbsstringtocomp(const char *s) 54639260Sgibbs{ 54739260Sgibbs struct compression_types *ct; 54839260Sgibbs size_t l = strlen(s); 54939260Sgibbs 55039260Sgibbs for (ct = comp_types; ct->name; ct++) 55139260Sgibbs if (strncasecmp(ct->name, s, l) == 0) 55239260Sgibbs break; 55339260Sgibbs 55439260Sgibbs return(ct->comp_number); 55539260Sgibbs} 55639260Sgibbs 5577913Sjoergvoid 5587913Sjoergst_status(struct mtget *bp) 5597913Sjoerg{ 56039260Sgibbs printf("Mode Density Blocksize bpi " 56139260Sgibbs "Compression\n" 56239260Sgibbs "Current: %-12s %-12s %-7d %s\n" 56339260Sgibbs "---------available modes---------\n" 56439260Sgibbs "0: %-12s %-12s %-7d %s\n" 56539260Sgibbs "1: %-12s %-12s %-7d %s\n" 56639260Sgibbs "2: %-12s %-12s %-7d %s\n" 56739260Sgibbs "3: %-12s %-12s %-7d %s\n", 56839260Sgibbs denstostring(bp->mt_density), getblksiz(bp->mt_blksiz), 56939260Sgibbs denstobp(bp->mt_density, TRUE), comptostring(bp->mt_comp), 57039260Sgibbs denstostring(bp->mt_density0), getblksiz(bp->mt_blksiz0), 57139260Sgibbs denstobp(bp->mt_density0, TRUE), comptostring(bp->mt_comp0), 57239260Sgibbs denstostring(bp->mt_density1), getblksiz(bp->mt_blksiz1), 57339260Sgibbs denstobp(bp->mt_density1, TRUE), comptostring(bp->mt_comp1), 57439260Sgibbs denstostring(bp->mt_density2), getblksiz(bp->mt_blksiz2), 57539260Sgibbs denstobp(bp->mt_density2, TRUE), comptostring(bp->mt_comp2), 57639260Sgibbs denstostring(bp->mt_density3), getblksiz(bp->mt_blksiz3), 57739260Sgibbs denstobp(bp->mt_density3, TRUE), comptostring(bp->mt_comp3)); 5787913Sjoerg} 5797913Sjoerg 5809541Sjoergvoid 5819541Sjoergwarn_eof(void) 5829541Sjoerg{ 5839541Sjoerg fprintf(stderr, 5849541Sjoerg "The \"eof\" command has been disabled.\n" 5859541Sjoerg "Use \"weof\" if you really want to write end-of-file marks,\n" 5869541Sjoerg "or \"eom\" if you rather want to skip to the end of " 5879541Sjoerg "recorded medium.\n"); 5889541Sjoerg exit(1); 5899541Sjoerg} 5909541Sjoerg 5917913Sjoerg#endif /* defined (__FreeBSD__) */ 592