Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 3570a34 | 2000-09-25 21:45:58 +0000 | [diff] [blame] | 2 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 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 | |
Eric Andersen | 1eec89d | 2000-09-05 18:21:53 +0000 | [diff] [blame] | 58 | if (argc < 2) { |
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) { |
Mark Whitley | f57c944 | 2000-12-07 19:56:48 +0000 | [diff] [blame] | 78 | error_msg("unrecognized opcode %s.\n", argv[1]); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 79 | return EXIT_FAILURE; |
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 | |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame^] | 88 | if ((fd = open(file, O_RDONLY, 0)) < 0) |
| 89 | perror_msg_and_die("%s", file); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 90 | |
Matt Kraai | a9819b2 | 2000-12-22 01:48:07 +0000 | [diff] [blame^] | 91 | if (ioctl(fd, MTIOCTOP, &op) != 0) |
| 92 | perror_msg_and_die("%s", file); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 93 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 94 | return EXIT_SUCCESS; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 95 | } |