xref: /freebsd/usr.bin/mt/mt.c (revision 6ff6d951ade3f3379932df7f878ef3ea272cfc59)
1 /*
2  * Copyright (c) 1980, 1993
3  *	The Regents of the University of California.  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 static const char copyright[] =
36 "@(#) Copyright (c) 1980, 1993\n\
37 	The Regents of the University of California.  All rights reserved.\n";
38 #endif /* not lint */
39 
40 #ifndef lint
41 #if 0
42 static char sccsid[] = "@(#)mt.c	8.2 (Berkeley) 5/4/95";
43 #endif
44 #endif /* not lint */
45 
46 #include <sys/cdefs.h>
47 __FBSDID("$FreeBSD$");
48 
49 /*
50  * mt --
51  *   magnetic tape manipulation program
52  */
53 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #include <sys/mtio.h>
56 
57 #include <ctype.h>
58 #include <err.h>
59 #include <fcntl.h>
60 #include <stdio.h>
61 #include <stdlib.h>
62 #include <string.h>
63 #include <unistd.h>
64 
65 /* the appropriate sections of <sys/mtio.h> are also #ifdef'd for FreeBSD */
66 /* c_flags */
67 #define NEED_2ARGS	0x01
68 #define ZERO_ALLOWED	0x02
69 #define IS_DENSITY	0x04
70 #define DISABLE_THIS	0x08
71 #define IS_COMP		0x10
72 
73 #ifndef TRUE
74 #define TRUE 1
75 #endif
76 #ifndef FALSE
77 #define FALSE 0
78 #endif
79 
80 struct commands {
81 	const char *c_name;
82 	int c_code;
83 	int c_ronly;
84 	int c_flags;
85 } com[] = {
86 	{ "bsf",	MTBSF,	1, 0 },
87 	{ "bsr",	MTBSR,	1, 0 },
88 	/* XXX FreeBSD considered "eof" dangerous, since it's being
89 	   confused with "eom" (and is an alias for "weof" anyway) */
90 	{ "eof",	MTWEOF, 0, DISABLE_THIS },
91 	{ "fsf",	MTFSF,	1, 0 },
92 	{ "fsr",	MTFSR,	1, 0 },
93 	{ "offline",	MTOFFL,	1, 0 },
94 	{ "rewind",	MTREW,	1, 0 },
95 	{ "rewoffl",	MTOFFL,	1, 0 },
96 	{ "status",	MTNOP,	1, 0 },
97 	{ "weof",	MTWEOF,	0, ZERO_ALLOWED },
98 	{ "erase",	MTERASE, 0, ZERO_ALLOWED},
99 	{ "blocksize",	MTSETBSIZ, 0, NEED_2ARGS|ZERO_ALLOWED },
100 	{ "density",	MTSETDNSTY, 0, NEED_2ARGS|ZERO_ALLOWED|IS_DENSITY },
101 	{ "eom",	MTEOD, 1, 0 },
102 	{ "eod",	MTEOD, 1, 0 },
103 	{ "smk",	MTWSS, 0, 0 },
104 	{ "wss",	MTWSS, 0, 0 },
105 	{ "fss",	MTFSS, 1, 0 },
106 	{ "bss",	MTBSS, 1, 0 },
107 	{ "comp",	MTCOMP, 0, NEED_2ARGS|ZERO_ALLOWED|IS_COMP },
108 	{ "retension",	MTRETENS, 1, 0 },
109 	{ "rdhpos",     MTIOCRDHPOS,  0, 0 },
110 	{ "rdspos",     MTIOCRDSPOS,  0, 0 },
111 	{ "sethpos",    MTIOCHLOCATE, 0, NEED_2ARGS|ZERO_ALLOWED },
112 	{ "setspos",    MTIOCSLOCATE, 0, NEED_2ARGS|ZERO_ALLOWED },
113 	{ "errstat",	MTIOCERRSTAT, 0, 0 },
114 	{ "setmodel",	MTIOCSETEOTMODEL, 0, NEED_2ARGS|ZERO_ALLOWED },
115 	{ "seteotmodel",	MTIOCSETEOTMODEL, 0, NEED_2ARGS|ZERO_ALLOWED },
116 	{ "getmodel",	MTIOCGETEOTMODEL, 0, 0 },
117 	{ "geteotmodel",	MTIOCGETEOTMODEL, 0, 0 },
118 	{ NULL, 0, 0, 0 }
119 };
120 
121 const char *getblksiz(int);
122 void printreg(const char *, u_int, const char *);
123 void status(struct mtget *);
124 void usage(void);
125 void st_status (struct mtget *);
126 int stringtodens (const char *s);
127 const char *denstostring (int d);
128 int denstobp(int d, int bpi);
129 u_int32_t stringtocomp(const char *s);
130 const char *comptostring(u_int32_t comp);
131 void warn_eof(void);
132 
133 int
134 main(int argc, char *argv[])
135 {
136 	struct commands *comp;
137 	struct mtget mt_status;
138 	struct mtop mt_com;
139 	int ch, len, mtfd;
140 	const char *p, *tape;
141 
142 	if ((tape = getenv("TAPE")) == NULL)
143 		tape = DEFTAPE;
144 
145 	while ((ch = getopt(argc, argv, "f:t:")) != -1)
146 		switch(ch) {
147 		case 'f':
148 		case 't':
149 			tape = optarg;
150 			break;
151 		case '?':
152 		default:
153 			usage();
154 		}
155 	argc -= optind;
156 	argv += optind;
157 
158 	if (argc < 1 || argc > 2)
159 		usage();
160 
161 	len = strlen(p = *argv++);
162 	for (comp = com;; comp++) {
163 		if (comp->c_name == NULL)
164 			errx(1, "%s: unknown command", p);
165 		if (strncmp(p, comp->c_name, len) == 0)
166 			break;
167 	}
168 	if((comp->c_flags & NEED_2ARGS) && argc != 2)
169 		usage();
170 	if(comp->c_flags & DISABLE_THIS) {
171 		warn_eof();
172 	}
173 	if ((mtfd = open(tape, comp->c_ronly ? O_RDONLY : O_RDWR)) < 0)
174 		err(1, "%s", tape);
175 	if (comp->c_code != MTNOP) {
176 		mt_com.mt_op = comp->c_code;
177 		if (*argv) {
178 			if (!isdigit(**argv) &&
179 			    (comp->c_flags & IS_DENSITY)) {
180 				const char *dcanon;
181 				mt_com.mt_count = stringtodens(*argv);
182 				if (mt_com.mt_count == 0)
183 					errx(1, "%s: unknown density", *argv);
184 				dcanon = denstostring(mt_com.mt_count);
185 				if (strcmp(dcanon, *argv) != 0)
186 					printf(
187 					"Using \"%s\" as an alias for %s\n",
188 					       *argv, dcanon);
189 				p = "";
190 			} else if (!isdigit(**argv) &&
191 				   (comp->c_flags & IS_COMP)) {
192 
193 				mt_com.mt_count = stringtocomp(*argv);
194 				if ((u_int32_t)mt_com.mt_count == 0xf0f0f0f0)
195 					errx(1, "%s: unknown compression",
196 					     *argv);
197 				p = "";
198 			} else {
199 				char *q;
200 				/* allow for hex numbers; useful for density */
201 				mt_com.mt_count = strtol(*argv, &q, 0);
202 				p = q;
203 			}
204 			if ((mt_com.mt_count <=
205 			    ((comp->c_flags & ZERO_ALLOWED)? -1: 0)
206 			    && ((comp->c_flags & IS_COMP) == 0)
207 			    ) || *p)
208 				errx(1, "%s: illegal count", *argv);
209 		}
210 		else
211 			mt_com.mt_count = 1;
212 		switch (comp->c_code) {
213 		case MTIOCERRSTAT:
214 		{
215 			unsigned int i;
216 			union mterrstat umn;
217 			struct scsi_tape_errors *s = &umn.scsi_errstat;
218 
219 			if (ioctl(mtfd, comp->c_code, (caddr_t)&umn) < 0)
220 				err(2, "%s", tape);
221 			(void)printf("Last I/O Residual: %u\n", s->io_resid);
222 			(void)printf(" Last I/O Command:");
223 			for (i = 0; i < sizeof (s->io_cdb); i++)
224 				(void)printf(" %02X", s->io_cdb[i]);
225 			(void)printf("\n");
226 			(void)printf("   Last I/O Sense:\n\n\t");
227 			for (i = 0; i < sizeof (s->io_sense); i++) {
228 				(void)printf(" %02X", s->io_sense[i]);
229 				if (((i + 1) & 0xf) == 0) {
230 					(void)printf("\n\t");
231 				}
232 			}
233 			(void)printf("\n");
234 			(void)printf("Last Control Residual: %u\n",
235 			    s->ctl_resid);
236 			(void)printf(" Last Control Command:");
237 			for (i = 0; i < sizeof (s->ctl_cdb); i++)
238 				(void)printf(" %02X", s->ctl_cdb[i]);
239 			(void)printf("\n");
240 			(void)printf("   Last Control Sense:\n\n\t");
241 			for (i = 0; i < sizeof (s->ctl_sense); i++) {
242 				(void)printf(" %02X", s->ctl_sense[i]);
243 				if (((i + 1) & 0xf) == 0) {
244 					(void)printf("\n\t");
245 				}
246 			}
247 			(void)printf("\n\n");
248 			exit(0);
249 			/* NOTREACHED */
250 		}
251 		case MTIOCRDHPOS:
252 		case MTIOCRDSPOS:
253 		{
254 			u_int32_t block;
255 			if (ioctl(mtfd, comp->c_code, (caddr_t)&block) < 0)
256 				err(2, "%s", tape);
257 			(void)printf("%s: %s block location %u\n", tape,
258 			    (comp->c_code == MTIOCRDHPOS)? "hardware" :
259 			    "logical", block);
260 			exit(0);
261 			/* NOTREACHED */
262 		}
263 		case MTIOCSLOCATE:
264 		case MTIOCHLOCATE:
265 		{
266 			u_int32_t block = (u_int32_t)mt_com.mt_count;
267 			if (ioctl(mtfd, comp->c_code, (caddr_t)&block) < 0)
268 				err(2, "%s", tape);
269 			exit(0);
270 			/* NOTREACHED */
271 		}
272 		case MTIOCGETEOTMODEL:
273 		{
274 			u_int32_t om;
275 			if (ioctl(mtfd, MTIOCGETEOTMODEL, (caddr_t)&om) < 0)
276 				err(2, "%s", tape);
277 			(void)printf("%s: the model is %u filemar%s at EOT\n",
278 			    tape, om, (om > 1)? "ks" : "k");
279 			exit(0);
280 			/* NOTREACHED */
281 		}
282 		case MTIOCSETEOTMODEL:
283 		{
284 			u_int32_t om, nm = (u_int32_t)mt_com.mt_count;
285 			if (ioctl(mtfd, MTIOCGETEOTMODEL, (caddr_t)&om) < 0)
286 				err(2, "%s", tape);
287 			if (ioctl(mtfd, comp->c_code, (caddr_t)&nm) < 0)
288 				err(2, "%s", tape);
289 			(void)printf("%s: old model was %u filemar%s at EOT\n",
290 			    tape, om, (om > 1)? "ks" : "k");
291 			(void)printf("%s: new model  is %u filemar%s at EOT\n",
292 			    tape, nm, (nm > 1)? "ks" : "k");
293 			exit(0);
294 			/* NOTREACHED */
295 		}
296 		default:
297 			break;
298 		}
299 		if (ioctl(mtfd, MTIOCTOP, &mt_com) < 0)
300 			err(1, "%s: %s", tape, comp->c_name);
301 	} else {
302 		if (ioctl(mtfd, MTIOCGET, &mt_status) < 0)
303 			err(1, NULL);
304 		status(&mt_status);
305 	}
306 	exit(0);
307 	/* NOTREACHED */
308 }
309 
310 struct tape_desc {
311 	short	t_type;		/* type of magtape device */
312 	const char *t_name;	/* printing name */
313 	const char *t_dsbits;	/* "drive status" register */
314 	const char *t_erbits;	/* "error" register */
315 } tapes[] = {
316 	{ MT_ISAR,	"SCSI tape drive", 0,		0 },
317 	{ 0, NULL, 0, 0 }
318 };
319 
320 /*
321  * Interpret the status buffer returned
322  */
323 void
324 status(struct mtget *bp)
325 {
326 	struct tape_desc *mt;
327 
328 	for (mt = tapes;; mt++) {
329 		if (mt->t_type == 0) {
330 			(void)printf("%d: unknown tape drive type\n",
331 			    bp->mt_type);
332 			return;
333 		}
334 		if (mt->t_type == bp->mt_type)
335 			break;
336 	}
337 	if(mt->t_type == MT_ISAR)
338 		st_status(bp);
339 	else {
340 		(void)printf("%s tape drive, residual=%d\n",
341 		    mt->t_name, bp->mt_resid);
342 		printreg("ds", (unsigned short)bp->mt_dsreg, mt->t_dsbits);
343 		printreg("\ner", (unsigned short)bp->mt_erreg, mt->t_erbits);
344 		(void)putchar('\n');
345 	}
346 }
347 
348 /*
349  * Print a register a la the %b format of the kernel's printf.
350  */
351 void
352 printreg(const char *s, u_int v, const char *bits)
353 {
354 	int i, any = 0;
355 	char c;
356 
357 	if (bits && *bits == 8)
358 		printf("%s=%o", s, v);
359 	else
360 		printf("%s=%x", s, v);
361 	if (!bits)
362 		return;
363 	bits++;
364 	if (v && bits) {
365 		putchar('<');
366 		while ((i = *bits++)) {
367 			if (v & (1 << (i-1))) {
368 				if (any)
369 					putchar(',');
370 				any = 1;
371 				for (; (c = *bits) > 32; bits++)
372 					putchar(c);
373 			} else
374 				for (; *bits > 32; bits++)
375 					;
376 		}
377 		putchar('>');
378 	}
379 }
380 
381 void
382 usage(void)
383 {
384 	(void)fprintf(stderr, "usage: mt [-f device] command [count]\n");
385 	exit(1);
386 }
387 
388 struct densities {
389 	int dens;
390 	int bpmm;
391 	int bpi;
392 	const char *name;
393 } dens[] = {
394 	/*
395 	 * Taken from T10 Project 997D
396 	 * SCSI-3 Stream Device Commands (SSC)
397 	 * Revision 11, 4-Nov-97
398 	 */
399 	/*Num.  bpmm    bpi     Reference     */
400 	{ 0x1,	32,	800,	"X3.22-1983" },
401 	{ 0x2,	63,	1600,	"X3.39-1986" },
402 	{ 0x3,	246,	6250,	"X3.54-1986" },
403 	{ 0x5,	315,	8000,	"X3.136-1986" },
404 	{ 0x6,	126,	3200,	"X3.157-1987" },
405 	{ 0x7,	252,	6400,	"X3.116-1986" },
406 	{ 0x8,	315,	8000,	"X3.158-1987" },
407 	{ 0x9,	491,	37871,	"X3.180" },
408 	{ 0xA,	262,	6667,	"X3B5/86-199" },
409 	{ 0xB,	63,	1600,	"X3.56-1986" },
410 	{ 0xC,	500,	12690,	"HI-TC1" },
411 	{ 0xD,	999,	25380,	"HI-TC2" },
412 	{ 0xF,	394,	10000,	"QIC-120" },
413 	{ 0x10,	394,	10000,	"QIC-150" },
414 	{ 0x11,	630,	16000,	"QIC-320" },
415 	{ 0x12,	2034,	51667,	"QIC-1350" },
416 	{ 0x13,	2400,	61000,	"X3B5/88-185A" },
417 	{ 0x14,	1703,	43245,	"X3.202-1991" },
418 	{ 0x15,	1789,	45434,	"ECMA TC17" },
419 	{ 0x16,	394,	10000,	"X3.193-1990" },
420 	{ 0x17,	1673,	42500,	"X3B5/91-174" },
421 	{ 0x18,	1673,	42500,	"X3B5/92-50" },
422 	{ 0x19, 2460,   62500,  "DLTapeIII" },
423 	{ 0x1A, 3214,   81633,  "DLTapeIV(20GB)" },
424 	{ 0x1B, 3383,   85937,  "DLTapeIV(35GB)" },
425 	{ 0x1C, 1654,	42000,	"QIC-385M" },
426 	{ 0x1D,	1512,	38400,	"QIC-410M" },
427 	{ 0x1E, 1385,	36000,	"QIC-1000C" },
428 	{ 0x1F,	2666,	67733,	"QIC-2100C" },
429 	{ 0x20, 2666,	67733,	"QIC-6GB(M)" },
430 	{ 0x21,	2666,	67733,	"QIC-20GB(C)" },
431 	{ 0x22,	1600,	40640,	"QIC-2GB(C)" },
432 	{ 0x23, 2666,	67733,	"QIC-875M" },
433 	{ 0x24,	2400,	61000,	"DDS-2" },
434 	{ 0x25,	3816,	97000,	"DDS-3" },
435 	{ 0x26,	3816,	97000,	"DDS-4" },
436 	{ 0x27,	3056,	77611,	"Mammoth" },
437 	{ 0x28,	1491,	37871,	"X3.224" },
438 	{ 0x41, 3868,   98250,  "DLTapeIV(40GB)" },
439 	{ 0x48, 5236,   133000, "SDLTapeI(110)" },
440 	{ 0x49, 7598,   193000, "SDLTapeI(160)" },
441 	{ 0, 0, 0, NULL }
442 };
443 
444 struct compression_types {
445 	u_int32_t	comp_number;
446 	const char 	*name;
447 } comp_types[] = {
448 	{ 0x00, "none" },
449 	{ 0x00, "off" },
450 	{ 0x10, "IDRC" },
451 	{ 0x20, "DCLZ" },
452 	{ 0xffffffff, "enable" },
453 	{ 0xffffffff, "on" },
454 	{ 0xf0f0f0f0, NULL}
455 };
456 
457 const char *
458 denstostring(int d)
459 {
460 	static char buf[20];
461 	struct densities *sd;
462 
463 	/* densities 0 and 0x7f are handled as special cases */
464 	if (d == 0)
465 		return "default";
466 	if (d == 0x7f)
467 		return "same";
468 	for (sd = dens; sd->dens; sd++)
469 		if (sd->dens == d)
470 			break;
471 	if (sd->dens == 0)
472 		sprintf(buf, "0x%02x", d);
473 	else
474 		sprintf(buf, "0x%02x:%s", d, sd->name);
475 	return buf;
476 }
477 
478 /*
479  * Given a specific density number, return either the bits per inch or bits
480  * per millimeter for the given density.
481  */
482 int
483 denstobp(int d, int bpi)
484 {
485 	struct densities *sd;
486 
487 	for (sd = dens; sd->dens; sd++)
488 		if (sd->dens == d)
489 			break;
490 	if (sd->dens == 0)
491 		return(0);
492 	else {
493 		if (bpi)
494 			return(sd->bpi);
495 		else
496 			return(sd->bpmm);
497 	}
498 }
499 
500 int
501 stringtodens(const char *s)
502 {
503 	struct densities *sd;
504 	size_t l = strlen(s);
505 
506 	for (sd = dens; sd->dens; sd++)
507 		if (strncasecmp(sd->name, s, l) == 0)
508 			break;
509 	return sd->dens;
510 }
511 
512 
513 const char *
514 getblksiz(int bs)
515 {
516 	static char buf[25];
517 	if (bs == 0)
518 		return "variable";
519 	else {
520 		sprintf(buf, "%d bytes", bs);
521 		return buf;
522 	}
523 }
524 
525 const char *
526 comptostring(u_int32_t comp)
527 {
528 	static char buf[20];
529 	struct compression_types *ct;
530 
531 	if (comp == MT_COMP_DISABLED)
532 		return "disabled";
533 	else if (comp == MT_COMP_UNSUPP)
534 		return "unsupported";
535 
536 	for (ct = comp_types; ct->name; ct++)
537 		if (ct->comp_number == comp)
538 			break;
539 
540 	if (ct->comp_number == 0xf0f0f0f0) {
541 		sprintf(buf, "0x%x", comp);
542 		return(buf);
543 	} else
544 		return(ct->name);
545 }
546 
547 u_int32_t
548 stringtocomp(const char *s)
549 {
550 	struct compression_types *ct;
551 	size_t l = strlen(s);
552 
553 	for (ct = comp_types; ct->name; ct++)
554 		if (strncasecmp(ct->name, s, l) == 0)
555 			break;
556 
557 	return(ct->comp_number);
558 }
559 
560 void
561 st_status(struct mtget *bp)
562 {
563 	printf("Mode      Density              Blocksize      bpi      "
564 	       "Compression\n"
565 	       "Current:  %-17s    %-12s   %-7d  %s\n"
566 	       "---------available modes---------\n"
567 	       "0:        %-17s    %-12s   %-7d  %s\n"
568 	       "1:        %-17s    %-12s   %-7d  %s\n"
569 	       "2:        %-17s    %-12s   %-7d  %s\n"
570 	       "3:        %-17s    %-12s   %-7d  %s\n",
571 	       denstostring(bp->mt_density), getblksiz(bp->mt_blksiz),
572 	       denstobp(bp->mt_density, TRUE), comptostring(bp->mt_comp),
573 	       denstostring(bp->mt_density0), getblksiz(bp->mt_blksiz0),
574 	       denstobp(bp->mt_density0, TRUE), comptostring(bp->mt_comp0),
575 	       denstostring(bp->mt_density1), getblksiz(bp->mt_blksiz1),
576 	       denstobp(bp->mt_density1, TRUE), comptostring(bp->mt_comp1),
577 	       denstostring(bp->mt_density2), getblksiz(bp->mt_blksiz2),
578 	       denstobp(bp->mt_density2, TRUE), comptostring(bp->mt_comp2),
579 	       denstostring(bp->mt_density3), getblksiz(bp->mt_blksiz3),
580 	       denstobp(bp->mt_density3, TRUE), comptostring(bp->mt_comp3));
581 
582 	if (bp->mt_dsreg != MTIO_DSREG_NIL) {
583 		auto char foo[32];
584 		const char sfmt[] = "Current Driver State: %s.\n";
585 		printf("---------------------------------\n");
586 		switch (bp->mt_dsreg) {
587 		case MTIO_DSREG_REST:
588 			printf(sfmt, "at rest");
589 			break;
590 		case MTIO_DSREG_RBSY:
591 			printf(sfmt, "Communicating with drive");
592 			break;
593 		case MTIO_DSREG_WR:
594 			printf(sfmt, "Writing");
595 			break;
596 		case MTIO_DSREG_FMK:
597 			printf(sfmt, "Writing Filemarks");
598 			break;
599 		case MTIO_DSREG_ZER:
600 			printf(sfmt, "Erasing");
601 			break;
602 		case MTIO_DSREG_RD:
603 			printf(sfmt, "Reading");
604 			break;
605 		case MTIO_DSREG_FWD:
606 			printf(sfmt, "Spacing Forward");
607 			break;
608 		case MTIO_DSREG_REV:
609 			printf(sfmt, "Spacing Reverse");
610 			break;
611 		case MTIO_DSREG_POS:
612 			printf(sfmt,
613 			    "Hardware Positioning (direction unknown)");
614 			break;
615 		case MTIO_DSREG_REW:
616 			printf(sfmt, "Rewinding");
617 			break;
618 		case MTIO_DSREG_TEN:
619 			printf(sfmt, "Retensioning");
620 			break;
621 		case MTIO_DSREG_UNL:
622 			printf(sfmt, "Unloading");
623 			break;
624 		case MTIO_DSREG_LD:
625 			printf(sfmt, "Loading");
626 			break;
627 		default:
628 			(void) sprintf(foo, "Unknown state 0x%x", bp->mt_dsreg);
629 			printf(sfmt, foo);
630 			break;
631 		}
632 	}
633 	if (bp->mt_resid == 0 && bp->mt_fileno == (daddr_t) -1 &&
634 	    bp->mt_blkno == (daddr_t) -1)
635 		return;
636 	printf("---------------------------------\n");
637 	printf("File Number: %d\tRecord Number: %d\tResidual Count %d\n",
638 	    bp->mt_fileno, bp->mt_blkno, bp->mt_resid);
639 }
640 
641 void
642 warn_eof(void)
643 {
644 	fprintf(stderr,
645 		"The \"eof\" command has been disabled.\n"
646 		"Use \"weof\" if you really want to write end-of-file marks,\n"
647 		"or \"eom\" if you rather want to skip to the end of "
648 		"recorded medium.\n");
649 	exit(1);
650 }
651