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