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