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

Defined functions

main defined in line 40; never used
printreg defined in line 163; used 2 times
status defined in line 142; used 1 times
  • in line 88

Defined variables

com defined in line 21; used 1 times
  • in line 59
mt_com defined in line 36; used 5 times
mt_status defined in line 37; used 2 times
mtfd defined in line 35; used 3 times
sccsid defined in line 2; never used
tape defined in line 38; used 6 times
tapes defined in line 119; used 1 times

Defined struct's

commands defined in line 17; used 2 times
  • in line 45(2)
tape_desc defined in line 114; used 2 times
  • in line 145(2)

Defined macros

equal defined in line 15; used 2 times
  • in line 47(2)
Last modified: 1983-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 987
Valid CSS Valid XHTML 1.0 Strict