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