blob: 7168ef7ac79a07c160518c0848751fb225734ca3 [file] [log] [blame]
Eric Andersencc8ed391999-10-05 16:24:54 +00001#include "internal.h"
2#include <stdio.h>
3#include <sys/mtio.h>
4#include <sys/fcntl.h>
5
Eric Andersene77ae3a1999-10-19 20:03:34 +00006static const char mt_usage[] = "mt [-f device] opcode value\n";
Eric Andersencc8ed391999-10-05 16:24:54 +00007
8struct mt_opcodes {
9 char * name;
10 short value;
11};
12
13/* missing: eod/seod, stoptions, stwrthreshold, densities */
14static 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 }
50};
51
52extern int
Eric Andersenb0e9a701999-10-18 22:28:26 +000053mt_main(int argc, char** argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000054{
55 const char * file = "/dev/tape";
56 const struct mt_opcodes * code = opcodes;
57 struct mtop op;
58 int fd;
59
60 if ( strcmp(argv[1], "-f") == 0 ) {
61 if ( argc < 4 ) {
Eric Andersenb0e9a701999-10-18 22:28:26 +000062 usage (mt_usage);
Eric Andersencc8ed391999-10-05 16:24:54 +000063 }
64 file = argv[2];
65 argv += 2;
66 argc -= 2;
67 }
68
69 while ( code->name != 0 ) {
70 if ( strcmp(code->name, argv[1]) == 0 )
71 break;
72 code++;
73 }
74
75 if ( code->name == 0 ) {
76 fprintf(stderr, "mt: unrecognized opcode %s.\n", argv[1]);
Eric Andersenb0e9a701999-10-18 22:28:26 +000077 return( FALSE);
Eric Andersencc8ed391999-10-05 16:24:54 +000078 }
79
80 op.mt_op = code->value;
81 if ( argc >= 3 )
82 op.mt_count = atoi(argv[2]);
83 else
84 op.mt_count = 1; /* One, not zero, right? */
85
86 if ( (fd = open(file, O_RDONLY, 0)) < 0 ) {
Eric Andersenb0e9a701999-10-18 22:28:26 +000087 perror(file);
88 return( FALSE);
Eric Andersencc8ed391999-10-05 16:24:54 +000089 }
90
91 if ( ioctl(fd, MTIOCTOP, &op) != 0 ) {
Eric Andersenb0e9a701999-10-18 22:28:26 +000092 perror(file);
93 return( FALSE);
Eric Andersencc8ed391999-10-05 16:24:54 +000094 }
95
Eric Andersenb0e9a701999-10-18 22:28:26 +000096 return( TRUE);
Eric Andersencc8ed391999-10-05 16:24:54 +000097}