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