Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 2 | #include "internal.h" |
| 3 | #include <stdio.h> |
| 4 | #include <sys/mtio.h> |
| 5 | #include <sys/fcntl.h> |
| 6 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 7 | struct mt_opcodes { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 8 | char *name; |
| 9 | short value; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | /* missing: eod/seod, stoptions, stwrthreshold, densities */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 13 | static const struct mt_opcodes opcodes[] = { |
| 14 | {"bsf", MTBSF}, |
| 15 | {"bsfm", MTBSFM}, |
| 16 | {"bsr", MTBSR}, |
| 17 | {"bss", MTBSS}, |
| 18 | {"datacompression", MTCOMPRESSION}, |
| 19 | {"eom", MTEOM}, |
| 20 | {"erase", MTERASE}, |
| 21 | {"fsf", MTFSF}, |
| 22 | {"fsfm", MTFSFM}, |
| 23 | {"fsr", MTFSR}, |
| 24 | {"fss", MTFSS}, |
| 25 | {"load", MTLOAD}, |
| 26 | {"lock", MTLOCK}, |
| 27 | {"mkpart", MTMKPART}, |
| 28 | {"nop", MTNOP}, |
| 29 | {"offline", MTOFFL}, |
| 30 | {"rewoffline", MTOFFL}, |
| 31 | {"ras1", MTRAS1}, |
| 32 | {"ras2", MTRAS2}, |
| 33 | {"ras3", MTRAS3}, |
| 34 | {"reset", MTRESET}, |
| 35 | {"retension", MTRETEN}, |
| 36 | {"rew", MTREW}, |
| 37 | {"seek", MTSEEK}, |
| 38 | {"setblk", MTSETBLK}, |
| 39 | {"setdensity", MTSETDENSITY}, |
| 40 | {"drvbuffer", MTSETDRVBUFFER}, |
| 41 | {"setpart", MTSETPART}, |
| 42 | {"tell", MTTELL}, |
| 43 | {"wset", MTWSM}, |
| 44 | {"unload", MTUNLOAD}, |
| 45 | {"unlock", MTUNLOCK}, |
| 46 | {"eof", MTWEOF}, |
| 47 | {"weof", MTWEOF}, |
| 48 | {0, 0} |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 51 | extern int mt_main(int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 52 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 53 | const char *file = "/dev/tape"; |
| 54 | const struct mt_opcodes *code = opcodes; |
| 55 | struct mtop op; |
| 56 | int fd; |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 57 | |
Erik Andersen | 499f65f | 2000-05-16 20:07:38 +0000 | [diff] [blame] | 58 | if ((argc != 2 && argc != 3) && **(argv + 1) != '-') { |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 59 | usage(mt_usage); |
| 60 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 61 | |
| 62 | if (strcmp(argv[1], "-f") == 0) { |
| 63 | if (argc < 4) { |
| 64 | usage(mt_usage); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 65 | } |
| 66 | file = argv[2]; |
| 67 | argv += 2; |
| 68 | argc -= 2; |
| 69 | } |
| 70 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 71 | while (code->name != 0) { |
| 72 | if (strcmp(code->name, argv[1]) == 0) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 73 | break; |
| 74 | code++; |
| 75 | } |
| 76 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 77 | if (code->name == 0) { |
Matt Kraai | d537a95 | 2000-07-14 01:51:25 +0000 | [diff] [blame] | 78 | errorMsg("unrecognized opcode %s.\n", argv[1]); |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 79 | exit (FALSE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | op.mt_op = code->value; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 83 | if (argc >= 3) |
| 84 | op.mt_count = atoi(argv[2]); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 85 | else |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 86 | op.mt_count = 1; /* One, not zero, right? */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 87 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 88 | if ((fd = open(file, O_RDONLY, 0)) < 0) { |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 89 | perror(file); |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 90 | exit (FALSE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 93 | if (ioctl(fd, MTIOCTOP, &op) != 0) { |
Eric Andersen | b0e9a70 | 1999-10-18 22:28:26 +0000 | [diff] [blame] | 94 | perror(file); |
Erik Andersen | 5e1189e | 2000-04-15 16:34:54 +0000 | [diff] [blame] | 95 | exit (FALSE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Eric Andersen | b610615 | 2000-06-19 17:25:40 +0000 | [diff] [blame] | 98 | return (TRUE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 99 | } |