1 /* vi: set sw=4 ts=4: */
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
6 //config: bool "mt (2.7 kb)"
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 //applet:IF_MT(APPLET(mt, BB_DIR_BIN, BB_SUID_DROP))
15 //kbuild:lib-$(CONFIG_MT) += mt.o
17 //usage:#define mt_trivial_usage
18 //usage: "[-f DEVICE] OPCODE VALUE"
19 //usage:#define mt_full_usage "\n\n"
20 //usage: "Control magnetic tape drive operation\n"
24 //usage: "bsf bsfm bsr bss datacompression drvbuffer eof eom erase\n"
25 //usage: "fsf fsfm fsr fss load lock mkpart nop offline ras1 ras2\n"
26 //usage: "ras3 reset retension rewind rewoffline seek setblk setdensity\n"
27 //usage: "setpart tell unload unlock weof wset"
32 /* missing: eod/seod, stoptions, stwrthreshold, densities */
33 static const short opcode_value
[] ALIGN2
= {
70 static const char opcode_name
[] ALIGN1
=
75 "datacompression" "\0"
106 int mt_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
107 int mt_main(int argc UNUSED_PARAM
, char **argv
)
109 const char *file
= "/dev/tape";
111 struct mtpos position
;
118 if (strcmp(argv
[1], "-f") == 0) {
119 if (!argv
[2] || !argv
[3])
125 idx
= index_in_strings(opcode_name
, argv
[1]);
128 bb_error_msg_and_die("unrecognized opcode %s", argv
[1]);
130 op
.mt_op
= opcode_value
[idx
];
132 op
.mt_count
= xatoi_positive(argv
[2]);
134 op
.mt_count
= 1; /* One, not zero, right? */
136 switch (opcode_value
[idx
]) {
149 fd
= xopen(file
, mode
);
151 switch (opcode_value
[idx
]) {
153 ioctl_or_perror_and_die(fd
, MTIOCPOS
, &position
, "%s", file
);
154 printf("At block %d\n", (int) position
.mt_blkno
);
158 ioctl_or_perror_and_die(fd
, MTIOCTOP
, &op
, "%s", file
);