|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: char copyright[] = ! 22: "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ ! 23: All rights reserved.\n"; ! 24: #endif /* not lint */ ! 25: ! 26: #ifndef lint ! 27: static char sccsid[] = "@(#)mt.c 5.4 (Berkeley) 6/1/90"; ! 28: #endif /* not lint */ ! 29: ! 30: /* ! 31: * mt -- ! 32: * magnetic tape manipulation program ! 33: */ ! 34: #include <stdio.h> ! 35: #include <ctype.h> ! 36: #include <sys/types.h> ! 37: #include <sys/mtio.h> ! 38: #include <sys/ioctl.h> ! 39: ! 40: #define equal(s1,s2) (strcmp(s1, s2) == 0) ! 41: ! 42: struct commands { ! 43: char *c_name; ! 44: int c_code; ! 45: int c_ronly; ! 46: } com[] = { ! 47: { "weof", MTWEOF, 0 }, ! 48: { "eof", MTWEOF, 0 }, ! 49: { "fsf", MTFSF, 1 }, ! 50: { "bsf", MTBSF, 1 }, ! 51: { "fsr", MTFSR, 1 }, ! 52: { "bsr", MTBSR, 1 }, ! 53: { "rewind", MTREW, 1 }, ! 54: { "offline", MTOFFL, 1 }, ! 55: { "rewoffl", MTOFFL, 1 }, ! 56: { "status", MTNOP, 1 }, ! 57: { 0 } ! 58: }; ! 59: ! 60: int mtfd; ! 61: struct mtop mt_com; ! 62: struct mtget mt_status; ! 63: char *tape; ! 64: ! 65: main(argc, argv) ! 66: char **argv; ! 67: { ! 68: char line[80], *getenv(); ! 69: register char *cp; ! 70: register struct commands *comp; ! 71: ! 72: if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) { ! 73: argc -= 2; ! 74: tape = argv[2]; ! 75: argv += 2; ! 76: } else ! 77: if ((tape = getenv("TAPE")) == NULL) ! 78: tape = DEFTAPE; ! 79: if (argc < 2) { ! 80: fprintf(stderr, "usage: mt [ -f device ] command [ count ]\n"); ! 81: exit(1); ! 82: } ! 83: cp = argv[1]; ! 84: for (comp = com; comp->c_name != NULL; comp++) ! 85: if (strncmp(cp, comp->c_name, strlen(cp)) == 0) ! 86: break; ! 87: if (comp->c_name == NULL) { ! 88: fprintf(stderr, "mt: don't grok \"%s\"\n", cp); ! 89: exit(1); ! 90: } ! 91: if ((mtfd = open(tape, comp->c_ronly ? 0 : 2)) < 0) { ! 92: perror(tape); ! 93: exit(1); ! 94: } ! 95: if (comp->c_code != MTNOP) { ! 96: mt_com.mt_op = comp->c_code; ! 97: mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1); ! 98: if (mt_com.mt_count < 0) { ! 99: fprintf(stderr, "mt: negative repeat count\n"); ! 100: exit(1); ! 101: } ! 102: if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) { ! 103: fprintf(stderr, "%s %s %d ", tape, comp->c_name, ! 104: mt_com.mt_count); ! 105: perror("failed"); ! 106: exit(2); ! 107: } ! 108: } else { ! 109: if (ioctl(mtfd, MTIOCGET, (char *)&mt_status) < 0) { ! 110: perror("mt"); ! 111: exit(2); ! 112: } ! 113: status(&mt_status); ! 114: } ! 115: } ! 116: ! 117: #ifdef vax ! 118: #include <vaxmba/mtreg.h> ! 119: #include <vaxmba/htreg.h> ! 120: ! 121: #include <vaxuba/utreg.h> ! 122: #include <vaxuba/tmreg.h> ! 123: #undef b_repcnt /* argh */ ! 124: #include <vaxuba/tsreg.h> ! 125: #endif ! 126: ! 127: #ifdef sun ! 128: #include <sundev/tmreg.h> ! 129: #include <sundev/arreg.h> ! 130: #endif ! 131: ! 132: #ifdef tahoe ! 133: #include <tahoevba/cyreg.h> ! 134: #endif ! 135: ! 136: struct tape_desc { ! 137: short t_type; /* type of magtape device */ ! 138: char *t_name; /* printing name */ ! 139: char *t_dsbits; /* "drive status" register */ ! 140: char *t_erbits; /* "error" register */ ! 141: } tapes[] = { ! 142: #ifdef vax ! 143: { MT_ISTS, "ts11", 0, TSXS0_BITS }, ! 144: { MT_ISHT, "tm03", HTDS_BITS, HTER_BITS }, ! 145: { MT_ISTM, "tm11", 0, TMER_BITS }, ! 146: { MT_ISMT, "tu78", MTDS_BITS, 0 }, ! 147: { MT_ISUT, "tu45", UTDS_BITS, UTER_BITS }, ! 148: #endif ! 149: #ifdef sun ! 150: { MT_ISCPC, "TapeMaster", TMS_BITS, 0 }, ! 151: { MT_ISAR, "Archive", ARCH_CTRL_BITS, ARCH_BITS }, ! 152: #endif ! 153: #ifdef tahoe ! 154: { MT_ISCY, "cipher", CYS_BITS, CYCW_BITS }, ! 155: #endif ! 156: { 0 } ! 157: }; ! 158: ! 159: /* ! 160: * Interpret the status buffer returned ! 161: */ ! 162: status(bp) ! 163: register struct mtget *bp; ! 164: { ! 165: register struct tape_desc *mt; ! 166: ! 167: for (mt = tapes; mt->t_type; mt++) ! 168: if (mt->t_type == bp->mt_type) ! 169: break; ! 170: if (mt->t_type == 0) { ! 171: printf("unknown tape drive type (%d)\n", bp->mt_type); ! 172: return; ! 173: } ! 174: printf("%s tape drive, residual=%d\n", mt->t_name, bp->mt_resid); ! 175: printreg("ds", bp->mt_dsreg, mt->t_dsbits); ! 176: printreg("\ner", bp->mt_erreg, mt->t_erbits); ! 177: putchar('\n'); ! 178: } ! 179: ! 180: /* ! 181: * Print a register a la the %b format of the kernel's printf ! 182: */ ! 183: printreg(s, v, bits) ! 184: char *s; ! 185: register char *bits; ! 186: register unsigned short v; ! 187: { ! 188: register int i, any = 0; ! 189: register char c; ! 190: ! 191: if (bits && *bits == 8) ! 192: printf("%s=%o", s, v); ! 193: else ! 194: printf("%s=%x", s, v); ! 195: bits++; ! 196: if (v && bits) { ! 197: putchar('<'); ! 198: while (i = *bits++) { ! 199: if (v & (1 << (i-1))) { ! 200: if (any) ! 201: putchar(','); ! 202: any = 1; ! 203: for (; (c = *bits) > 32; bits++) ! 204: putchar(c); ! 205: } else ! 206: for (; *bits > 32; bits++) ! 207: ; ! 208: } ! 209: putchar('>'); ! 210: } ! 211: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.