xref: /freebsd/share/man/man4/mtio.4 (revision 871c940b716e3c02657a891d2884d249751a746b)
1c2466934SMike Pritchard.\" Copyright (c) 1996
2c2466934SMike Pritchard.\"	Mike Pritchard <mpp@FreeBSD.org>.  All rights reserved.
3c2466934SMike Pritchard.\"
4c2466934SMike Pritchard.\" Copyright (c) 1983, 1991, 1993
5c2466934SMike Pritchard.\"	The Regents of the University of California.  All rights reserved.
6c2466934SMike Pritchard.\"
7c2466934SMike Pritchard.\" Redistribution and use in source and binary forms, with or without
8c2466934SMike Pritchard.\" modification, are permitted provided that the following conditions
9c2466934SMike Pritchard.\" are met:
10c2466934SMike Pritchard.\" 1. Redistributions of source code must retain the above copyright
11c2466934SMike Pritchard.\"    notice, this list of conditions and the following disclaimer.
12c2466934SMike Pritchard.\" 2. Redistributions in binary form must reproduce the above copyright
13c2466934SMike Pritchard.\"    notice, this list of conditions and the following disclaimer in the
14c2466934SMike Pritchard.\"    documentation and/or other materials provided with the distribution.
15c2466934SMike Pritchard.\" 3. All advertising materials mentioning features or use of this software
16c2466934SMike Pritchard.\"    must display the following acknowledgement:
17c2466934SMike Pritchard.\"	This product includes software developed by the University of
18c2466934SMike Pritchard.\"	California, Berkeley and its contributors.
19c2466934SMike Pritchard.\" 4. Neither the name of the University nor the names of its contributors
20c2466934SMike Pritchard.\"    may be used to endorse or promote products derived from this software
21c2466934SMike Pritchard.\"    without specific prior written permission.
22c2466934SMike Pritchard.\"
23c2466934SMike Pritchard.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24c2466934SMike Pritchard.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25c2466934SMike Pritchard.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26c2466934SMike Pritchard.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27c2466934SMike Pritchard.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28c2466934SMike Pritchard.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29c2466934SMike Pritchard.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30c2466934SMike Pritchard.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31c2466934SMike Pritchard.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32c2466934SMike Pritchard.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33c2466934SMike Pritchard.\" SUCH DAMAGE.
34c2466934SMike Pritchard.\"
35c2466934SMike Pritchard.\"     @(#)mtio.4	8.1 (Berkeley) 6/5/93
367f3dea24SPeter Wemm.\" $FreeBSD$
37c2466934SMike Pritchard.\"
38*871c940bSSergey Kandaurov.Dd November 11, 2011
39474fc32bSAlexey Zelkin.Dt MTIO 4
403d45e180SRuslan Ermilov.Os
41c2466934SMike Pritchard.Sh NAME
42c2466934SMike Pritchard.Nm mtio
43eb083802SRuslan Ermilov.Nd FreeBSD magtape interface
44c2466934SMike Pritchard.Sh DESCRIPTION
45c2466934SMike PritchardThe special files
46c2466934SMike Pritchardnamed
47095a0a15SPeter Pentchev.Pa /dev/[n]sa*
48c2466934SMike Pritchardrefer to SCSI tape drives,
49c2466934SMike Pritchardwhich may be attached to the system.
50095a0a15SPeter Pentchev.Pa /dev/[n]sa*.ctl
51c2466934SMike Pritchardare control devices that can be used to issue ioctls to the SCSI
52c2466934SMike Pritchardtape driver to set parameters that are required to last beyond the
53c2466934SMike Pritchardunmounting of a tape.
54c2466934SMike Pritchard.Pp
55c2466934SMike PritchardThe rewind devices automatically rewind
56c2466934SMike Pritchardwhen the last requested read, write or seek has finished, or the end of the tape
576d249eeeSSheldon Hearnhas been reached.
586d249eeeSSheldon HearnThe letter
59c2466934SMike Pritchard.Ql n
60c2466934SMike Pritchardis usually prepended to
61c2466934SMike Pritchardthe name of the no-rewind devices.
62c2466934SMike Pritchard.Pp
63c2466934SMike PritchardTapes can be written with either fixed length records or variable length
645203edcdSRuslan Ermilovrecords.
655203edcdSRuslan ErmilovSee
660a36ae36SMatt Jacob.Xr sa 4
67b5e7e999SRuslan Ermilovfor more information.
68b5e7e999SRuslan ErmilovTwo end-of-file markers mark the end of a tape, and
69c2466934SMike Pritchardone end-of-file marker marks the end of a tape file.
70c2466934SMike PritchardIf the tape is not to be rewound it is positioned with the
71c2466934SMike Pritchardhead in between the two tape marks, where the next write
72c2466934SMike Pritchardwill over write the second end-of-file marker.
73c2466934SMike Pritchard.Pp
74c2466934SMike PritchardAll of the magtape devices may be manipulated with the
75c2466934SMike Pritchard.Xr mt 1
76c2466934SMike Pritchardcommand.
77c2466934SMike Pritchard.Pp
78c2466934SMike PritchardA number of
79c2466934SMike Pritchard.Xr ioctl 2
80c2466934SMike Pritchardoperations are available
81c2466934SMike Pritchardon raw magnetic tape.
82c2466934SMike PritchardThe following definitions are from
83fe08efe6SRuslan Ermilov.In sys/mtio.h :
84c2466934SMike Pritchard.Bd  -literal
85f5ead386SBruce Evans#ifndef	_SYS_MTIO_H_
86f5ead386SBruce Evans#define	_SYS_MTIO_H_
87f5ead386SBruce Evans
88f5ead386SBruce Evans#ifndef _KERNEL
89f5ead386SBruce Evans#include <sys/types.h>
90f5ead386SBruce Evans#endif
91f5ead386SBruce Evans#include <sys/ioccom.h>
92f5ead386SBruce Evans
93c2466934SMike Pritchard/*
94c2466934SMike Pritchard * Structures and definitions for mag tape io control commands
95c2466934SMike Pritchard */
96c2466934SMike Pritchard
97c2466934SMike Pritchard/* structure for MTIOCTOP - mag tape op command */
98c2466934SMike Pritchardstruct mtop {
99c2466934SMike Pritchard	short	mt_op;		/* operations defined below */
100*871c940bSSergey Kandaurov	int32_t	mt_count;	/* how many of them */
101c2466934SMike Pritchard};
102c2466934SMike Pritchard
103c2466934SMike Pritchard/* operations */
104c2466934SMike Pritchard#define MTWEOF		0	/* write an end-of-file record */
105c2466934SMike Pritchard#define MTFSF		1	/* forward space file */
106c2466934SMike Pritchard#define MTBSF		2	/* backward space file */
107c2466934SMike Pritchard#define MTFSR		3	/* forward space record */
108c2466934SMike Pritchard#define MTBSR		4	/* backward space record */
109c2466934SMike Pritchard#define MTREW		5	/* rewind */
110c2466934SMike Pritchard#define MTOFFL		6	/* rewind and put the drive offline */
111c2466934SMike Pritchard#define MTNOP		7	/* no operation, sets status only */
112c2466934SMike Pritchard#define MTCACHE		8	/* enable controller cache */
113c2466934SMike Pritchard#define MTNOCACHE	9	/* disable controller cache */
114c2466934SMike Pritchard
115c2466934SMike Pritchard#if defined(__FreeBSD__)
116c2466934SMike Pritchard/* Set block size for device. If device is a variable size dev		*/
117c2466934SMike Pritchard/* a non zero parameter will change the device to a fixed block size	*/
118c2466934SMike Pritchard/* device with block size set to that of the parameter passed in.	*/
119c2466934SMike Pritchard/* Resetting the block size to 0 will restore the device to a variable	*/
120c2466934SMike Pritchard/* block size device. */
121c2466934SMike Pritchard
122c2466934SMike Pritchard#define MTSETBSIZ	10
123c2466934SMike Pritchard
124f5ead386SBruce Evans/* Set density values for device. Sets the value for the opened mode only. */
125c2466934SMike Pritchard
126c2466934SMike Pritchard#define MTSETDNSTY	11
127c2466934SMike Pritchard
128c2466934SMike Pritchard#define MTERASE		12	/* erase to EOM */
129c2466934SMike Pritchard#define MTEOD		13	/* Space to EOM */
130c2466934SMike Pritchard#define MTCOMP		14	/* select compression mode 0=off, 1=def */
131c2466934SMike Pritchard#define MTRETENS	15	/* re-tension tape */
1320a36ae36SMatt Jacob#define MTWSS		16	/* write setmark(s) */
1330a36ae36SMatt Jacob#define MTFSS		17	/* forward space setmark */
1340a36ae36SMatt Jacob#define MTBSS		18	/* backward space setmark */
1350a36ae36SMatt Jacob
1360a36ae36SMatt Jacob#define MT_COMP_ENABLE		0xffffffff
1370a36ae36SMatt Jacob#define MT_COMP_DISABLED	0xfffffffe
1380a36ae36SMatt Jacob#define MT_COMP_UNSUPP		0xfffffffd
1390a36ae36SMatt Jacob
1400a36ae36SMatt Jacob/*
1410a36ae36SMatt Jacob * Values in mt_dsreg that say what the device is doing
1420a36ae36SMatt Jacob */
1430a36ae36SMatt Jacob#define	MTIO_DSREG_NIL	0	/* Unknown */
1440a36ae36SMatt Jacob#define	MTIO_DSREG_REST	1	/* Doing Nothing */
1450a36ae36SMatt Jacob#define	MTIO_DSREG_RBSY	2	/* Communicating with tape (but no motion) */
1460a36ae36SMatt Jacob#define	MTIO_DSREG_WR	20	/* Writing */
1470a36ae36SMatt Jacob#define	MTIO_DSREG_FMK	21	/* Writing Filemarks */
1480a36ae36SMatt Jacob#define	MTIO_DSREG_ZER	22	/* Erasing */
1490a36ae36SMatt Jacob#define	MTIO_DSREG_RD	30	/* Reading */
1500a36ae36SMatt Jacob#define	MTIO_DSREG_FWD	40	/* Spacing Forward */
1510a36ae36SMatt Jacob#define	MTIO_DSREG_REV	41	/* Spacing Reverse */
1520a36ae36SMatt Jacob#define	MTIO_DSREG_POS	42	/* Hardware Positioning (direction unknown) */
1530a36ae36SMatt Jacob#define	MTIO_DSREG_REW	43	/* Rewinding */
1540a36ae36SMatt Jacob#define	MTIO_DSREG_TEN	44	/* Retensioning */
1550a36ae36SMatt Jacob#define	MTIO_DSREG_UNL	45	/* Unloading */
156f5ead386SBruce Evans#define	MTIO_DSREG_LD	46	/* Loading */
157c2466934SMike Pritchard
158f5ead386SBruce Evans#endif	/* __FreeBSD__ */
159c2466934SMike Pritchard
160c2466934SMike Pritchard/* structure for MTIOCGET - mag tape get status command */
161c2466934SMike Pritchard
162c2466934SMike Pritchardstruct mtget {
163c2466934SMike Pritchard	short	mt_type;	/* type of magtape device */
164c2466934SMike Pritchard/* the following two registers are grossly device dependent */
165c2466934SMike Pritchard	short	mt_dsreg;	/* ``drive status'' register */
166c2466934SMike Pritchard	short	mt_erreg;	/* ``error'' register */
167c2466934SMike Pritchard/* end device-dependent registers */
168*871c940bSSergey Kandaurov	/*
169*871c940bSSergey Kandaurov	 * Note that the residual count, while maintained, may be
170*871c940bSSergey Kandaurov	 * be nonsense because the size of the residual may (greatly)
171*871c940bSSergey Kandaurov	 * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a
172*871c940bSSergey Kandaurov	 * more accurate count.
173*871c940bSSergey Kandaurov	 */
174c2466934SMike Pritchard	short	mt_resid;	/* residual count */
175c2466934SMike Pritchard#if defined (__FreeBSD__)
176*871c940bSSergey Kandaurov	int32_t mt_blksiz;	/* presently operating blocksize */
177*871c940bSSergey Kandaurov	int32_t mt_density;	/* presently operating density */
178f5ead386SBruce Evans	u_int32_t mt_comp;	/* presently operating compression */
179*871c940bSSergey Kandaurov	int32_t mt_blksiz0;	/* blocksize for mode 0 */
180*871c940bSSergey Kandaurov	int32_t mt_blksiz1;	/* blocksize for mode 1 */
181*871c940bSSergey Kandaurov	int32_t mt_blksiz2;	/* blocksize for mode 2 */
182*871c940bSSergey Kandaurov	int32_t mt_blksiz3;	/* blocksize for mode 3 */
183*871c940bSSergey Kandaurov	int32_t mt_density0;	/* density for mode 0 */
184*871c940bSSergey Kandaurov	int32_t mt_density1;	/* density for mode 1 */
185*871c940bSSergey Kandaurov	int32_t mt_density2;	/* density for mode 2 */
186*871c940bSSergey Kandaurov	int32_t mt_density3;	/* density for mode 3 */
187c2466934SMike Pritchard/* the following are not yet implemented */
188f5ead386SBruce Evans	u_int32_t mt_comp0;	/* compression type for mode 0 */
189f5ead386SBruce Evans	u_int32_t mt_comp1;	/* compression type for mode 1 */
190f5ead386SBruce Evans	u_int32_t mt_comp2;	/* compression type for mode 2 */
191f5ead386SBruce Evans	u_int32_t mt_comp3;	/* compression type for mode 3 */
1920a36ae36SMatt Jacob/* end not yet implemented */
193c2466934SMike Pritchard#endif
194*871c940bSSergey Kandaurov	int32_t	mt_fileno;	/* relative file number of current position */
195*871c940bSSergey Kandaurov	int32_t	mt_blkno;	/* relative block number of current position */
196c2466934SMike Pritchard};
197c2466934SMike Pritchard
1980a36ae36SMatt Jacob/* structure for MTIOCERRSTAT - tape get error status command */
1990a36ae36SMatt Jacob/* really only supported for SCSI tapes right now */
2000a36ae36SMatt Jacobstruct scsi_tape_errors {
2010a36ae36SMatt Jacob	/*
2020a36ae36SMatt Jacob	 * These are latched from the last command that had a SCSI
2030a36ae36SMatt Jacob	 * Check Condition noted for these operations. The act
2040a36ae36SMatt Jacob	 * of issuing an MTIOCERRSTAT unlatches and clears them.
2050a36ae36SMatt Jacob	 */
2060a36ae36SMatt Jacob	u_int8_t io_sense[32];	/* Last Sense Data For Data I/O */
207*871c940bSSergey Kandaurov	int32_t io_resid;	/* residual count from last Data I/O */
2080a36ae36SMatt Jacob	u_int8_t io_cdb[16];	/* Command that Caused the Last Data Sense */
2090a36ae36SMatt Jacob	u_int8_t ctl_sense[32];	/* Last Sense Data For Control I/O */
210*871c940bSSergey Kandaurov	int32_t ctl_resid;	/* residual count from last Control I/O */
2110a36ae36SMatt Jacob	u_int8_t ctl_cdb[16];	/* Command that Caused the Last Control Sense */
2120a36ae36SMatt Jacob	/*
2130a36ae36SMatt Jacob	 * These are the read and write cumulative error counters.
2140a36ae36SMatt Jacob	 * (how to reset cumulative error counters is not yet defined).
2150a36ae36SMatt Jacob	 * (not implemented as yet but space is being reserved for them)
2160a36ae36SMatt Jacob	 */
2170a36ae36SMatt Jacob	struct {
2180a36ae36SMatt Jacob		u_int32_t retries;	/* total # retries performed */
2190a36ae36SMatt Jacob		u_int32_t corrected;	/* total # corrections performed */
220f87717faSMike Pritchard		u_int32_t processed;	/* total # corrections successful */
2210a36ae36SMatt Jacob		u_int32_t failures;	/* total # corrections/retries failed */
2220a36ae36SMatt Jacob		u_int64_t nbytes;	/* total # bytes processed */
2230a36ae36SMatt Jacob	} wterr, rderr;
2240a36ae36SMatt Jacob};
2250a36ae36SMatt Jacob
2260a36ae36SMatt Jacobunion mterrstat {
2270a36ae36SMatt Jacob	struct scsi_tape_errors scsi_errstat;
2280a36ae36SMatt Jacob	char _reserved_padding[256];
2290a36ae36SMatt Jacob};
230f5ead386SBruce Evans
231c2466934SMike Pritchard/*
232c2466934SMike Pritchard * Constants for mt_type byte.  These are the same
233c2466934SMike Pritchard * for controllers compatible with the types listed.
234c2466934SMike Pritchard */
235c2466934SMike Pritchard#define	MT_ISTS		0x01		/* TS-11 */
236c2466934SMike Pritchard#define	MT_ISHT		0x02		/* TM03 Massbus: TE16, TU45, TU77 */
237c2466934SMike Pritchard#define	MT_ISTM		0x03		/* TM11/TE10 Unibus */
238c2466934SMike Pritchard#define	MT_ISMT		0x04		/* TM78/TU78 Massbus */
239c2466934SMike Pritchard#define	MT_ISUT		0x05		/* SI TU-45 emulation on Unibus */
240c2466934SMike Pritchard#define	MT_ISCPC	0x06		/* SUN */
241c2466934SMike Pritchard#define	MT_ISAR		0x07		/* SUN */
242c2466934SMike Pritchard#define	MT_ISTMSCP	0x08		/* DEC TMSCP protocol (TU81, TK50) */
243c2466934SMike Pritchard#define MT_ISCY		0x09		/* CCI Cipher */
244c2466934SMike Pritchard#define MT_ISCT		0x0a		/* HP 1/4 tape */
245c2466934SMike Pritchard#define MT_ISFHP	0x0b		/* HP 7980 1/2 tape */
246c2466934SMike Pritchard#define MT_ISEXABYTE	0x0c		/* Exabyte */
247c2466934SMike Pritchard#define MT_ISEXA8200	0x0c		/* Exabyte EXB-8200 */
248c2466934SMike Pritchard#define MT_ISEXA8500	0x0d		/* Exabyte EXB-8500 */
249c2466934SMike Pritchard#define MT_ISVIPER1	0x0e		/* Archive Viper-150 */
250c2466934SMike Pritchard#define MT_ISPYTHON	0x0f		/* Archive Python (DAT) */
251c2466934SMike Pritchard#define MT_ISHPDAT	0x10		/* HP 35450A DAT drive */
252c2466934SMike Pritchard#define MT_ISMFOUR	0x11		/* M4 Data 1/2 9track drive */
253c2466934SMike Pritchard#define MT_ISTK50	0x12		/* DEC SCSI TK50 */
254c2466934SMike Pritchard#define MT_ISMT02	0x13		/* Emulex MT02 SCSI tape controller */
255c2466934SMike Pritchard
256c2466934SMike Pritchard/* mag tape io control commands */
257c2466934SMike Pritchard#define	MTIOCTOP	_IOW('m', 1, struct mtop)	/* do a mag tape op */
258c2466934SMike Pritchard#define	MTIOCGET	_IOR('m', 2, struct mtget)	/* get tape status */
2590a36ae36SMatt Jacob/* these two do not appear to be used anywhere */
260c2466934SMike Pritchard#define MTIOCIEOT	_IO('m', 3)			/* ignore EOT error */
261c2466934SMike Pritchard#define MTIOCEEOT	_IO('m', 4)			/* enable EOT error */
2620a36ae36SMatt Jacob/*
2630a36ae36SMatt Jacob * When more SCSI-3 SSC (streaming device) devices are out there
2640a36ae36SMatt Jacob * that support the full 32 byte type 2 structure, we'll have to
2650a36ae36SMatt Jacob * rethink these ioctls to support all the entities they haul into
2660a36ae36SMatt Jacob * the picture (64 bit blocks, logical file record numbers, etc..).
2670a36ae36SMatt Jacob */
2680a36ae36SMatt Jacob#define	MTIOCRDSPOS	_IOR('m', 5, u_int32_t)	/* get logical blk addr */
2690a36ae36SMatt Jacob#define	MTIOCRDHPOS	_IOR('m', 6, u_int32_t)	/* get hardware blk addr */
2700a36ae36SMatt Jacob#define	MTIOCSLOCATE	_IOW('m', 5, u_int32_t)	/* seek to logical blk addr */
2710a36ae36SMatt Jacob#define	MTIOCHLOCATE	_IOW('m', 6, u_int32_t)	/* seek to hardware blk addr */
2720a36ae36SMatt Jacob#define	MTIOCERRSTAT	_IOR('m', 7, union mterrstat)	/* get tape errors */
273f5ead386SBruce Evans/*
274f5ead386SBruce Evans * Set EOT model- argument is number of filemarks to end a tape with.
275f5ead386SBruce Evans * Note that not all possible values will be accepted.
276f5ead386SBruce Evans */
277f5ead386SBruce Evans#define	MTIOCSETEOTMODEL	_IOW('m', 8, u_int32_t)
278f5ead386SBruce Evans/* Get current EOT model */
279f5ead386SBruce Evans#define	MTIOCGETEOTMODEL	_IOR('m', 8, u_int32_t)
280c2466934SMike Pritchard
281f5ead386SBruce Evans#ifndef _KERNEL
282095a0a15SPeter Pentchev#define	DEFTAPE	"/dev/nsa0"
283c2466934SMike Pritchard#endif
284c2466934SMike Pritchard
285f5ead386SBruce Evans#endif /* !_SYS_MTIO_H_ */
286c2466934SMike Pritchard.Ed
287c2466934SMike Pritchard.Sh FILES
288095a0a15SPeter Pentchev.Bl -tag -width /dev/[n]sa* -compact
289095a0a15SPeter Pentchev.It Pa /dev/[n]sa*
290c2466934SMike Pritchard.El
291c2466934SMike Pritchard.Sh SEE ALSO
292c2466934SMike Pritchard.Xr mt 1 ,
293c2466934SMike Pritchard.Xr tar 1 ,
2948904de15SWarner Losh.Xr ast 4 ,
295d08c353bSNeil Blakey-Milner.Xr sa 4
296c2466934SMike Pritchard.Sh HISTORY
297c2466934SMike PritchardThe
2984b66483fSRuslan Ermilov.Nm
299c2466934SMike Pritchardmanual appeared in
300c2466934SMike Pritchard.Bx 4.2 .
301400d45a3SMike PritchardAn i386 version first appeared in
302400d45a3SMike Pritchard.Fx 2.2 .
303c2466934SMike Pritchard.Sh BUGS
304c2466934SMike PritchardThe status should be returned in a device independent format.
305c2466934SMike Pritchard.Pp
306c2466934SMike PritchardThe special file naming should be redone in a more consistent and
307c2466934SMike Pritchardunderstandable manner.
308