1 /* vi: set sw=4 ts=4: */
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 //config: mt is used to control tape devices. You can use the mt utility
10 //config: to advance or rewind a tape past a specified number of archive
11 //config: files on the tape.
13 //usage:#define mt_trivial_usage
14 //usage: "[-f device] opcode value"
15 //usage:#define mt_full_usage "\n\n"
16 //usage: "Control magnetic tape drive operation\n"
18 //usage: "Available Opcodes:\n"
20 //usage: "bsf bsfm bsr bss datacompression drvbuffer eof eom erase\n"
21 //usage: "fsf fsfm fsr fss load lock mkpart nop offline ras1 ras2\n"
22 //usage: "ras3 reset retension rewind rewoffline seek setblk setdensity\n"
23 //usage: "setpart tell unload unlock weof wset"
28 /* missing: eod/seod, stoptions, stwrthreshold, densities */
29 static const short opcode_value[] = {
66 static const char opcode_name[] ALIGN1 =
71 "datacompression" "\0"
102 int mt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
103 int mt_main(int argc UNUSED_PARAM, char **argv)
105 const char *file = "/dev/tape";
107 struct mtpos position;
114 if (strcmp(argv[1], "-f") == 0) {
115 if (!argv[2] || !argv[3])
121 idx = index_in_strings(opcode_name, argv[1]);
124 bb_error_msg_and_die("unrecognized opcode %s", argv[1]);
126 op.mt_op = opcode_value[idx];
128 op.mt_count = xatoi_positive(argv[2]);
130 op.mt_count = 1; /* One, not zero, right? */
132 switch (opcode_value[idx]) {
145 fd = xopen(file, mode);
147 switch (opcode_value[idx]) {
149 ioctl_or_perror_and_die(fd, MTIOCPOS, &position, "%s", file);
150 printf("At block %d\n", (int) position.mt_blkno);
154 ioctl_or_perror_and_die(fd, MTIOCTOP, &op, "%s", file);