|
|
Power 6/32 Unix version 1.2b
static char *sccsid = "@(#)mt.c 4.8 (Berkeley) 83/05/08";
/*
* mt --
* magnetic tape manipulation program
*/
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/mtio.h>
#include <sys/ioctl.h>
#include <vba/cipher.h>
#define equal(s1,s2) (strcmp(s1, s2) == 0)
struct commands {
char *c_name;
int c_code;
int c_ronly;
} com[] = {
{ "weof", MTWEOF, 0 },
{ "eof", MTWEOF, 0 },
{ "fsf", MTFSF, 1 },
{ "bsf", MTBSF, 1 },
{ "fsr", MTFSR, 1 },
{ "bsr", MTBSR, 1 },
{ "rewind", MTREW, 1 },
{ "offline", MTOFFL, 1 },
{ "rewoffl", MTOFFL, 1 },
{ "status", MTNOP, 1 },
{ 0 }
};
int mtfd;
struct mtop mt_com;
struct mtget mt_status;
char *tape;
main(argc, argv)
char **argv;
{
char line[80], *getenv();
register char *cp;
register struct commands *comp;
if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) {
argc -= 2;
tape = argv[2];
argv += 2;
} else
if ((tape = getenv("TAPE")) == NULL)
tape = DEFTAPE;
if (argc < 2) {
fprintf(stderr, "usage: mt [ -f device ] command [ count ]\n");
exit(1);
}
cp = argv[1];
for (comp = com; comp->c_name != NULL; comp++)
if (strncmp(cp, comp->c_name, strlen(cp)) == 0)
break;
if (comp->c_name == NULL) exit(1);
if ((mtfd = open(tape, comp->c_ronly ? 0 : 2)) < 0) {
perror(tape);
exit(1);
}
if (comp->c_code != MTNOP) {
mt_com.mt_op = comp->c_code;
mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1);
if (mt_com.mt_count < 0) {
fprintf(stderr, "mt: negative repeat count\n");
exit(1);
}
if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) {
fprintf(stderr, "%s %s %d ", tape, comp->c_name,
mt_com.mt_count);
perror("failed");
exit(2);
}
}
else {
if (ioctl(mtfd, MTIOCGET, (char *)&mt_status) < 0) {
perror("mt");
exit(2);
}
status(&mt_status);
}
}
#define t_type MT_ISCY
#define t_name TapeMaster
/*
* Interpret the status buffer returned
*/
status(bp)
register struct mtget *bp;
{
if (t_type != bp->mt_type) {
fprintf(stderr,"unknown tape drive type (%d)\n", bp->mt_type);
exit(0);
}
printf("Cipher tape drive, residual=%x\n", bp->mt_resid);
printf("control: %x\n", bp->mt_dsreg);
printf("status: %x\n", bp->mt_erreg);
printstatus(bp->mt_erreg);
}
printstatus(value)
register unsigned short value;
{
if((value & (CS_OL | CS_RDY)) != (CS_OL | CS_RDY)) {
printf("Drive is not online\n");
}
if (value & CS_FM) printf("<Filemark Detected> ");
if (value & CS_OL) printf("<On line> ");
if (value & CS_LP) printf("<Load point> ");
if (value & CS_EOT) printf("<End of Tape> ");
if (value & CS_RDY) printf("<Ready> ");
if (value & CS_FB) printf("<Formatter Busy> ");
if (value & CS_P) printf("<Write protected> ");
if (value & CS_CR) printf("<Operation Retry> ");
printf("\n");
switch(value & CS_ERm) {
case ER_TIMOUT:
case ER_TIMOUT1:
case ER_TIMOUT2:
case ER_TIMOUT3:
case ER_TIMOUT4:
printf("Drive timed out during transfer\n");
case ER_NEX:
printf("Controller referenced non-existant system memory\n");
case ER_DIAG:
case ER_JUMPER:
printf("Controller micro diagnostics failed\n");
case ER_HARD:
printf("Unrecoverble media error\n");
case ER_STROBE:
printf("Unsatisfactory media found\n");
case ER_FIFO:
printf("FIFO error\n");
case ER_NOTRDY:
printf("Drive is not ready\n");
case ER_PROT:
printf("Tape is write protected\n");
case ER_CHKSUM:
printf("Checksum error in controller proms\n");
case ER_PARITY:
printf("Unrecoverable tape parity error\n");
case ER_BLANK:
printf("Blank tape found where data was expected\n");
case ER_HDWERR:
printf("Unrecoverble hardware error\n");
default:
return;
}
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.