1 /* vi: set sw=4 ts=4: */
3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
6 //usage:#define mt_trivial_usage
7 //usage: "[-f device] opcode value"
8 //usage:#define mt_full_usage "\n\n"
9 //usage: "Control magnetic tape drive operation\n"
11 //usage: "Available Opcodes:\n"
13 //usage: "bsf bsfm bsr bss datacompression drvbuffer eof eom erase\n"
14 //usage: "fsf fsfm fsr fss load lock mkpart nop offline ras1 ras2\n"
15 //usage: "ras3 reset retension rewind rewoffline seek setblk setdensity\n"
16 //usage: "setpart tell unload unlock weof wset"
21 /* missing: eod/seod, stoptions, stwrthreshold, densities */
22 static const short opcode_value
[] = {
59 static const char opcode_name
[] ALIGN1
=
64 "datacompression" "\0"
95 int mt_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
96 int mt_main(int argc UNUSED_PARAM
, char **argv
)
98 const char *file
= "/dev/tape";
100 struct mtpos position
;
107 if (strcmp(argv
[1], "-f") == 0) {
108 if (!argv
[2] || !argv
[3])
114 idx
= index_in_strings(opcode_name
, argv
[1]);
117 bb_error_msg_and_die("unrecognized opcode %s", argv
[1]);
119 op
.mt_op
= opcode_value
[idx
];
121 op
.mt_count
= xatoi_positive(argv
[2]);
123 op
.mt_count
= 1; /* One, not zero, right? */
125 switch (opcode_value
[idx
]) {
138 fd
= xopen(file
, mode
);
140 switch (opcode_value
[idx
]) {
142 ioctl_or_perror_and_die(fd
, MTIOCPOS
, &position
, "%s", file
);
143 printf("At block %d\n", (int) position
.mt_blkno
);
147 ioctl_or_perror_and_die(fd
, MTIOCTOP
, &op
, "%s", file
);