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