|
|
1.1 ! root 1: static char *sccsid = "@(#)mt.c 4.2 (Berkeley) 81/07/05"; ! 2: ! 3: /* ! 4: * mt ! 5: */ ! 6: ! 7: #include <stdio.h> ! 8: #include <ctype.h> ! 9: #include <sys/types.h> ! 10: #include <sys/mtio.h> ! 11: #include <sys/ioctl.h> ! 12: ! 13: struct commands { ! 14: char *c_name; ! 15: int c_code; ! 16: int c_ronly; ! 17: } com[] = { ! 18: "eof", MTWEOF, 0, ! 19: "fsf", MTFSF, 1, ! 20: "bsf", MTBSF, 1, ! 21: "fsr", MTFSR, 1, ! 22: "bsr", MTBSR, 1, ! 23: "rewind", MTREW, 1, ! 24: "offline", MTOFFL, 1, ! 25: "reset", MTRST, 1, ! 26: 0,0 ! 27: }; ! 28: ! 29: int mtfd; ! 30: struct mtop mt_com; ! 31: char *tape; ! 32: ! 33: main(argc, argv) ! 34: char **argv; ! 35: { ! 36: char line[80], *getenv(); ! 37: register char *cp; ! 38: register struct commands *comp; ! 39: ! 40: if (argc < 2) { ! 41: fprintf(stderr, "usage: mt [ -t tape ] command [ count ]\n"); ! 42: exit(1); ! 43: } ! 44: if ((strcmp(argv[1], "-t") == 0) && argc > 2) { ! 45: argc -= 2; ! 46: tape = argv[2]; ! 47: argv += 2; ! 48: } else ! 49: if ((tape = getenv("TAPE")) == NULL) ! 50: tape = "/dev/nrmt1"; ! 51: cp = argv[1]; ! 52: for (comp = com; comp->c_name != NULL; comp++) ! 53: if (strncmp(cp, comp->c_name, strlen(cp)) == 0) ! 54: break; ! 55: if (comp->c_name == NULL) { ! 56: fprintf(stderr, "mt: don't grok \"%s\"\n", cp); ! 57: exit(1); ! 58: } ! 59: if ((mtfd = open(tape, comp->c_ronly ? 0 : 2)) < 0) { ! 60: perror(tape); ! 61: exit(1); ! 62: } ! 63: mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1); ! 64: mt_com.mt_op = comp->c_code; ! 65: if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) { ! 66: fprintf(stderr, "%s %d ", comp->c_name, mt_com.mt_count); ! 67: perror("failed"); ! 68: } ! 69: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.