Commit | Line | Data |
---|---|---|
e7e6e844 NW |
1 | /* |
2 | * Copyright (c) 1980 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | char copyright[] = | |
36 | "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ | |
37 | All rights reserved.\n"; | |
38 | #endif /* not lint */ | |
39 | ||
40 | #ifndef lint | |
41 | static char sccsid[] = "@(#)mt.c 5.6 (Berkeley) 6/6/91"; | |
42 | #endif /* not lint */ | |
43 | ||
44 | /* | |
45 | * mt -- | |
46 | * magnetic tape manipulation program | |
47 | */ | |
48 | #include <sys/types.h> | |
49 | #include <sys/ioctl.h> | |
50 | #include <sys/mtio.h> | |
51 | #include <fcntl.h> | |
52 | #include <stdio.h> | |
53 | #include <ctype.h> | |
54 | ||
55 | #define equal(s1,s2) (strcmp(s1, s2) == 0) | |
56 | ||
57 | struct commands { | |
58 | char *c_name; | |
59 | int c_code; | |
60 | int c_ronly; | |
61 | } com[] = { | |
62 | { "weof", MTWEOF, 0 }, | |
63 | { "eof", MTWEOF, 0 }, | |
64 | { "fsf", MTFSF, 1 }, | |
65 | { "bsf", MTBSF, 1 }, | |
66 | { "fsr", MTFSR, 1 }, | |
67 | { "bsr", MTBSR, 1 }, | |
68 | { "rewind", MTREW, 1 }, | |
69 | { "offline", MTOFFL, 1 }, | |
70 | { "rewoffl", MTOFFL, 1 }, | |
71 | { "status", MTNOP, 1 }, | |
72 | { "blocksize", MTSETBSIZ, 0 }, | |
0269d546 | 73 | { "density", MTSETDNSTY, 0 }, |
e7e6e844 NW |
74 | { 0 } |
75 | }; | |
76 | ||
77 | int mtfd; | |
78 | struct mtop mt_com; | |
79 | struct mtget mt_status; | |
80 | char *tape; | |
81 | ||
82 | main(argc, argv) | |
83 | char **argv; | |
84 | { | |
85 | void usage(); | |
86 | char line[80], *getenv(); | |
87 | register char *cp; | |
88 | register struct commands *comp; | |
89 | ||
90 | if (argc > 2 && (equal(argv[1], "-t") || equal(argv[1], "-f"))) { | |
91 | argc -= 2; | |
92 | tape = argv[2]; | |
93 | argv += 2; | |
94 | } else | |
95 | if ((tape = getenv("TAPE")) == NULL) | |
96 | tape = DEFTAPE; | |
97 | if (argc < 2) { | |
98 | usage(); | |
99 | exit(1); | |
100 | } | |
101 | cp = argv[1]; | |
102 | if ((strncmp(cp, "blocksize", strlen(cp)) == 0) && argc < 3 ) { | |
103 | usage(); | |
104 | exit(1); | |
105 | } | |
0269d546 | 106 | if ((strncmp(cp, "density", strlen(cp)) == 0) && argc < 3 ) { |
e7e6e844 NW |
107 | usage(); |
108 | exit(1); | |
109 | } | |
110 | for (comp = com; comp->c_name != NULL; comp++) | |
111 | if (strncmp(cp, comp->c_name, strlen(cp)) == 0) | |
112 | break; | |
113 | if (comp->c_name == NULL) { | |
8f5872cc | 114 | fprintf(stderr, "st: don't grok \"%s\"\n", cp); |
e7e6e844 NW |
115 | usage(); |
116 | exit(1); | |
117 | } | |
118 | if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0) { | |
119 | perror(tape); | |
120 | exit(1); | |
121 | } | |
122 | if (comp->c_code != MTNOP) { | |
123 | mt_com.mt_op = comp->c_code; | |
124 | mt_com.mt_count = (argc > 2 ? atoi(argv[2]) : 1); | |
125 | if (mt_com.mt_count < 0) { | |
8f5872cc | 126 | fprintf(stderr, "st: negative repeat count\n"); |
e7e6e844 NW |
127 | exit(1); |
128 | } | |
129 | if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0) { | |
130 | fprintf(stderr, "%s %s %d ", tape, comp->c_name, | |
131 | mt_com.mt_count); | |
132 | perror("failed"); | |
133 | exit(2); | |
134 | } | |
135 | } else { | |
136 | if (ioctl(mtfd, MTIOCGET, (char *)&mt_status) < 0) { | |
8f5872cc | 137 | perror("st"); |
e7e6e844 NW |
138 | exit(2); |
139 | } | |
140 | status(&mt_status); | |
141 | } | |
142 | } | |
143 | ||
144 | #ifdef vax | |
145 | #include <vaxmba/mtreg.h> | |
146 | #include <vaxmba/htreg.h> | |
147 | ||
148 | #include <vaxuba/utreg.h> | |
149 | #include <vaxuba/tmreg.h> | |
150 | #undef b_repcnt /* argh */ | |
151 | #include <vaxuba/tsreg.h> | |
152 | #endif | |
153 | ||
154 | #ifdef sun | |
155 | #include <sundev/tmreg.h> | |
156 | #include <sundev/arreg.h> | |
157 | #endif | |
158 | ||
159 | #ifdef tahoe | |
160 | #include <tahoe/vba/cyreg.h> | |
161 | #endif | |
162 | ||
163 | struct tape_desc { | |
164 | short t_type; /* type of magtape device */ | |
165 | char *t_name; /* printing name */ | |
166 | char *t_dsbits; /* "drive status" register */ | |
167 | char *t_erbits; /* "error" register */ | |
168 | } tapes[] = { | |
169 | #ifdef vax | |
170 | { MT_ISTS, "ts11", 0, TSXS0_BITS }, | |
171 | { MT_ISHT, "tm03", HTDS_BITS, HTER_BITS }, | |
172 | { MT_ISTM, "tm11", 0, TMER_BITS }, | |
173 | { MT_ISMT, "tu78", MTDS_BITS, 0 }, | |
174 | { MT_ISUT, "tu45", UTDS_BITS, UTER_BITS }, | |
175 | #endif | |
176 | #if defined(sun) | |
177 | { MT_ISCPC, "TapeMaster", TMS_BITS, 0 }, | |
178 | { MT_ISAR, "Archive", ARCH_CTRL_BITS, ARCH_BITS }, | |
179 | #endif | |
180 | #ifdef tahoe | |
181 | { MT_ISCY, "cipher", CYS_BITS, CYCW_BITS }, | |
182 | #endif | |
183 | #if defined (__386BSD__) | |
184 | { MT_ISAR, "Archive/Tandberg?", 0, 0 }, | |
185 | #endif | |
186 | { 0 } | |
187 | }; | |
188 | ||
189 | /* | |
190 | * Interpret the status buffer returned | |
191 | */ | |
192 | status(bp) | |
193 | register struct mtget *bp; | |
194 | { | |
195 | register struct tape_desc *mt; | |
196 | ||
8f5872cc RG |
197 | printf("Present Mode: Density = 0x%02x, Blocksize = %d bytes\n", |
198 | bp->mt_density, bp->mt_blksiz); | |
199 | printf("---------available modes----------\n"); | |
200 | printf("Mode 0: Density = 0x%02x, Blocksize = %d bytes\n", | |
201 | bp->mt_density0, bp->mt_blksiz0); | |
202 | printf("Mode 1: Density = 0x%02x, Blocksize = %d bytes\n", | |
203 | bp->mt_density1, bp->mt_blksiz1); | |
204 | printf("Mode 2: Density = 0x%02x, Blocksize = %d bytes\n", | |
205 | bp->mt_density2, bp->mt_blksiz2); | |
206 | printf("Mode 3: Density = 0x%02x, Blocksize = %d bytes\n", | |
207 | bp->mt_density3, bp->mt_blksiz3); | |
208 | ||
209 | #ifdef NOTYET | |
210 | printf("tape drive: residual=%d\n", | |
211 | bp->mt_resid); | |
e7e6e844 NW |
212 | printreg("ds", bp->mt_dsreg, mt->t_dsbits); |
213 | printreg("\ner", bp->mt_erreg, mt->t_erbits); | |
214 | putchar('\n'); | |
8f5872cc | 215 | #endif |
e7e6e844 NW |
216 | } |
217 | ||
218 | /* | |
219 | * Print a register a la the %b format of the kernel's printf | |
220 | */ | |
221 | printreg(s, v, bits) | |
222 | char *s; | |
223 | register char *bits; | |
224 | register unsigned short v; | |
225 | { | |
226 | register int i, any = 0; | |
227 | register char c; | |
228 | ||
229 | if (bits && *bits == 8) | |
230 | printf("%s=%o", s, v); | |
231 | else | |
232 | printf("%s=%x", s, v); | |
233 | bits++; | |
234 | if (v && bits) { | |
235 | putchar('<'); | |
236 | while (i = *bits++) { | |
237 | if (v & (1 << (i-1))) { | |
238 | if (any) | |
239 | putchar(','); | |
240 | any = 1; | |
241 | for (; (c = *bits) > 32; bits++) | |
242 | putchar(c); | |
243 | } else | |
244 | for (; *bits > 32; bits++) | |
245 | ; | |
246 | } | |
247 | putchar('>'); | |
248 | } | |
249 | } | |
250 | void usage() { | |
251 | register struct commands *comp; | |
252 | ||
253 | fprintf(stderr, "Usage: st [ -f tape ] command [ count ] \n"); | |
254 | fprintf(stderr, " Where command is one of:\n"); | |
255 | for (comp=com; comp->c_name != NULL; comp++) { | |
256 | fprintf(stderr, " %s\n", comp->c_name); | |
257 | } | |
258 | fprintf(stderr,"Note that the count argument is required\n"); | |
259 | fprintf(stderr, "with the \"blocksize\" , and the density setting commands.\n"); | |
260 | fprintf(stderr, "Note that the count argument is a base 10 number\n"); | |
261 | } |