Annotation of cci/usr/src/bin/mt.c, revision 1.1.1.1

1.1       root        1: static char *sccsid = "@(#)mt.c        4.8 (Berkeley) 83/05/08";
                      2: /*
                      3:  * mt --
                      4:  *   magnetic tape manipulation program
                      5:  */
                      6: #include <stdio.h>
                      7: #include <ctype.h>
                      8: #include <sys/types.h>
                      9: #include <sys/mtio.h>
                     10: #include <sys/ioctl.h>
                     11: #include <vba/cipher.h>
                     12: 
                     13: #define        equal(s1,s2)    (strcmp(s1, s2) == 0)
                     14: 
                     15: struct commands {
                     16:        char *c_name;
                     17:        int c_code;
                     18:        int c_ronly;
                     19: } com[] = {
                     20:        { "weof",       MTWEOF, 0 },
                     21:        { "eof",        MTWEOF, 0 },
                     22:        { "fsf",        MTFSF,  1 },
                     23:        { "bsf",        MTBSF,  1 },
                     24:        { "fsr",        MTFSR,  1 },
                     25:        { "bsr",        MTBSR,  1 },
                     26:        { "rewind",     MTREW,  1 },
                     27:        { "offline",    MTOFFL, 1 },
                     28:        { "rewoffl",    MTOFFL, 1 },
                     29:        { "status",     MTNOP,  1 },
                     30:        { 0 }
                     31: };
                     32: 
                     33: int mtfd;
                     34: struct mtop mt_com;
                     35: struct mtget mt_status;
                     36: char *tape;
                     37: 
                     38: main(argc, argv)
                     39: char **argv;
                     40: {
                     41:        char line[80], *getenv();
                     42:        register char *cp;
                     43:        register struct commands *comp;
                     44: 
                     45:        if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) {
                     46:                argc -= 2;
                     47:                tape = argv[2];
                     48:                argv += 2;
                     49:        } else
                     50:                if ((tape = getenv("TAPE")) == NULL)
                     51:                        tape = DEFTAPE;
                     52:        if (argc < 2) {
                     53:                fprintf(stderr, "usage: mt [ -f device ] command [ count ]\n");
                     54:                exit(1);
                     55:        }
                     56:        cp = argv[1];
                     57:        for (comp = com; comp->c_name != NULL; comp++)
                     58:                if (strncmp(cp, comp->c_name, strlen(cp)) == 0)
                     59:                        break;
                     60:        if (comp->c_name == NULL) exit(1);
                     61:        if ((mtfd = open(tape, comp->c_ronly ? 0 : 2)) < 0) {
                     62:                perror(tape);
                     63:                exit(1);
                     64:        }
                     65:        if (comp->c_code != MTNOP) {
                     66:                mt_com.mt_op = comp->c_code;
                     67:                mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1);
                     68:                if (mt_com.mt_count < 0) {
                     69:                        fprintf(stderr, "mt: negative repeat count\n");
                     70:                        exit(1);
                     71:                }
                     72:                if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) {
                     73:                        fprintf(stderr, "%s %s %d ", tape, comp->c_name,
                     74:                                mt_com.mt_count);
                     75:                        perror("failed");
                     76:                        exit(2);
                     77:                }
                     78:        } 
                     79:        else {
                     80:                if (ioctl(mtfd, MTIOCGET, (char *)&mt_status) < 0) {
                     81:                        perror("mt");
                     82:                        exit(2);
                     83:                }
                     84:                status(&mt_status);
                     85:        }
                     86: }
                     87: 
                     88: #define t_type         MT_ISCY
                     89: #define t_name         TapeMaster
                     90: 
                     91: /*
                     92:  * Interpret the status buffer returned
                     93:  */
                     94: status(bp)
                     95: register struct mtget *bp;
                     96: {
                     97: 
                     98:        if (t_type != bp->mt_type) {
                     99:                fprintf(stderr,"unknown tape drive type (%d)\n", bp->mt_type);
                    100:                exit(0);
                    101:        }
                    102:        printf("Cipher tape drive, residual=%x\n", bp->mt_resid);
                    103:        printf("control: %x\n", bp->mt_dsreg); 
                    104:        printf("status: %x\n", bp->mt_erreg); 
                    105:        printstatus(bp->mt_erreg); 
                    106: }
                    107: 
                    108: printstatus(value)
                    109: register unsigned short value;
                    110: {
                    111:        if((value & (CS_OL | CS_RDY)) != (CS_OL | CS_RDY)) {
                    112:                printf("Drive is not online\n");
                    113:        }
                    114:        if (value & CS_FM) printf("<Filemark Detected> ");
                    115:        if (value & CS_OL) printf("<On line> ");
                    116:        if (value & CS_LP) printf("<Load point> ");
                    117:        if (value & CS_EOT) printf("<End of Tape> ");
                    118:        if (value & CS_RDY)  printf("<Ready> ");
                    119:        if (value & CS_FB) printf("<Formatter Busy> ");
                    120:        if (value & CS_P)  printf("<Write protected> ");
                    121:        if (value & CS_CR)  printf("<Operation Retry> ");
                    122:        printf("\n");
                    123:        switch(value & CS_ERm) {
                    124:        case ER_TIMOUT:
                    125:        case ER_TIMOUT1:
                    126:        case ER_TIMOUT2:
                    127:        case ER_TIMOUT3:
                    128:        case ER_TIMOUT4:
                    129:                printf("Drive timed out during transfer\n");
                    130:        case ER_NEX:    
                    131:                printf("Controller referenced non-existant system memory\n");
                    132:        case ER_DIAG:
                    133:        case ER_JUMPER:
                    134:                printf("Controller micro diagnostics failed\n");
                    135:        case ER_HARD:
                    136:                printf("Unrecoverble media error\n");
                    137:        case ER_STROBE:
                    138:                printf("Unsatisfactory media found\n");
                    139:        case ER_FIFO:
                    140:                printf("FIFO error\n");
                    141:        case ER_NOTRDY:
                    142:                printf("Drive is not ready\n");
                    143:        case ER_PROT:
                    144:                printf("Tape is write protected\n");
                    145:        case ER_CHKSUM:
                    146:                printf("Checksum error in controller proms\n");
                    147:        case ER_PARITY:
                    148:                printf("Unrecoverable tape parity error\n");
                    149:        case ER_BLANK:
                    150:                printf("Blank tape found where data was expected\n");
                    151:        case ER_HDWERR:
                    152:                printf("Unrecoverble hardware error\n");
                    153:        default:
                    154:                return;
                    155:        }
                    156: }
                    157: 
                    158:        
                    159: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.