xref: /freebsd/share/man/man4/mtio.4 (revision 315ee00f)
1.\" Copyright (c) 1996
2.\"	Mike Pritchard <mpp@FreeBSD.org>.  All rights reserved.
3.\"
4.\" Copyright (c) 1983, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)mtio.4	8.1 (Berkeley) 6/5/93
32.\"
33.Dd February 12, 2015
34.Dt MTIO 4
35.Os
36.Sh NAME
37.Nm mtio
38.Nd FreeBSD magtape interface
39.Sh DESCRIPTION
40The special files
41named
42.Pa /dev/[en]sa*
43refer to SCSI tape drives,
44which may be attached to the system.
45.Pa /dev/sa*.ctl
46are control devices that can be used to issue ioctls to the SCSI
47tape driver to set parameters that are required to last beyond the
48unmounting of a tape.
49.Pp
50The rewind devices automatically rewind
51when the last requested read, write or seek has finished, or the end of the tape
52has been reached.
53The letter
54.Ql n
55is prepended to
56the name of the no-rewind devices.
57The letter
58.Ql e
59is prepended to the name of the eject devices.
60.Pp
61Tapes can be written with either fixed length records or variable length
62records.
63See
64.Xr sa 4
65for more information.
66Two filemarks mark the end of a tape, and
67one filemark marks the end of a tape file.
68If the tape is not to be rewound it is positioned with the
69head in between the two tape marks, where the next write
70will over write the second end-of-file marker.
71.Pp
72All of the magtape devices may be manipulated with the
73.Xr mt 1
74command.
75.Pp
76A number of
77.Xr ioctl 2
78operations are available
79on raw magnetic tape.
80The following definitions are from
81.In sys/mtio.h :
82.Bd  -literal
83#ifndef	_SYS_MTIO_H_
84#define	_SYS_MTIO_H_
85
86#ifndef _KERNEL
87#include <sys/types.h>
88#endif
89#include <sys/ioccom.h>
90
91/*
92 * Structures and definitions for mag tape io control commands
93 */
94
95/* structure for MTIOCTOP - mag tape op command */
96struct mtop {
97	short	mt_op;		/* operations defined below */
98	int32_t	mt_count;	/* how many of them */
99};
100
101/* operations */
102#define MTWEOF		0	/* write an end-of-file record */
103#define MTFSF		1	/* forward space file */
104#define MTBSF		2	/* backward space file */
105#define MTFSR		3	/* forward space record */
106#define MTBSR		4	/* backward space record */
107#define MTREW		5	/* rewind */
108#define MTOFFL		6	/* rewind and put the drive offline */
109#define MTNOP		7	/* no operation, sets status only */
110#define MTCACHE		8	/* enable controller cache */
111#define MTNOCACHE	9	/* disable controller cache */
112
113#if defined(__FreeBSD__)
114/* Set block size for device. If device is a variable size dev		*/
115/* a non zero parameter will change the device to a fixed block size	*/
116/* device with block size set to that of the parameter passed in.	*/
117/* Resetting the block size to 0 will restore the device to a variable	*/
118/* block size device. */
119
120#define MTSETBSIZ	10
121
122/* Set density values for device. Sets the value for the opened mode only. */
123
124#define MTSETDNSTY	11
125
126#define MTERASE		12	/* erase to EOM */
127#define MTEOD		13	/* Space to EOM */
128#define MTCOMP		14	/* select compression mode 0=off, 1=def */
129#define MTRETENS	15	/* re-tension tape */
130#define MTWSS		16	/* write setmark(s) */
131#define MTFSS		17	/* forward space setmark */
132#define MTBSS		18	/* backward space setmark */
133#define MTLOAD		19	/* load tape in drive */
134#define MTWEOFI		20	/* write an end-of-file record without waiting*/
135
136#define MT_COMP_ENABLE		0xffffffff
137#define MT_COMP_DISABLED	0xfffffffe
138#define MT_COMP_UNSUPP		0xfffffffd
139
140/*
141 * Values in mt_dsreg that say what the device is doing
142 */
143#define	MTIO_DSREG_NIL	0	/* Unknown */
144#define	MTIO_DSREG_REST	1	/* Doing Nothing */
145#define	MTIO_DSREG_RBSY	2	/* Communicating with tape (but no motion) */
146#define	MTIO_DSREG_WR	20	/* Writing */
147#define	MTIO_DSREG_FMK	21	/* Writing Filemarks */
148#define	MTIO_DSREG_ZER	22	/* Erasing */
149#define	MTIO_DSREG_RD	30	/* Reading */
150#define	MTIO_DSREG_FWD	40	/* Spacing Forward */
151#define	MTIO_DSREG_REV	41	/* Spacing Reverse */
152#define	MTIO_DSREG_POS	42	/* Hardware Positioning (direction unknown) */
153#define	MTIO_DSREG_REW	43	/* Rewinding */
154#define	MTIO_DSREG_TEN	44	/* Retensioning */
155#define	MTIO_DSREG_UNL	45	/* Unloading */
156#define	MTIO_DSREG_LD	46	/* Loading */
157
158#endif	/* __FreeBSD__ */
159
160/* structure for MTIOCGET - mag tape get status command */
161
162struct mtget {
163	short	mt_type;	/* type of magtape device */
164/* the following two registers are grossly device dependent */
165	short	mt_dsreg;	/* ``drive status'' register */
166	short	mt_erreg;	/* ``error'' register */
167/* end device-dependent registers */
168	/*
169	 * Note that the residual count, while maintained, may be
170	 * be nonsense because the size of the residual may (greatly)
171	 * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a
172	 * more accurate count.
173	 */
174	short	mt_resid;	/* residual count */
175#if defined (__FreeBSD__)
176	int32_t mt_blksiz;	/* presently operating blocksize */
177	int32_t mt_density;	/* presently operating density */
178	uint32_t mt_comp;	/* presently operating compression */
179	int32_t mt_blksiz0;	/* blocksize for mode 0 */
180	int32_t mt_blksiz1;	/* blocksize for mode 1 */
181	int32_t mt_blksiz2;	/* blocksize for mode 2 */
182	int32_t mt_blksiz3;	/* blocksize for mode 3 */
183	int32_t mt_density0;	/* density for mode 0 */
184	int32_t mt_density1;	/* density for mode 1 */
185	int32_t mt_density2;	/* density for mode 2 */
186	int32_t mt_density3;	/* density for mode 3 */
187/* the following are not yet implemented */
188	uint32_t mt_comp0;	/* compression type for mode 0 */
189	uint32_t mt_comp1;	/* compression type for mode 1 */
190	uint32_t mt_comp2;	/* compression type for mode 2 */
191	uint32_t mt_comp3;	/* compression type for mode 3 */
192/* end not yet implemented */
193#endif
194	int32_t	mt_fileno;	/* relative file number of current position */
195	int32_t	mt_blkno;	/* relative block number of current position */
196};
197
198/* structure for MTIOCERRSTAT - tape get error status command */
199/* really only supported for SCSI tapes right now */
200struct scsi_tape_errors {
201	/*
202	 * These are latched from the last command that had a SCSI
203	 * Check Condition noted for these operations. The act
204	 * of issuing an MTIOCERRSTAT unlatches and clears them.
205	 */
206	uint8_t io_sense[32];	/* Last Sense Data For Data I/O */
207	int32_t io_resid;	/* residual count from last Data I/O */
208	uint8_t io_cdb[16];	/* Command that Caused the Last Data Sense */
209	uint8_t ctl_sense[32];	/* Last Sense Data For Control I/O */
210	int32_t ctl_resid;	/* residual count from last Control I/O */
211	uint8_t ctl_cdb[16];	/* Command that Caused the Last Control Sense */
212	/*
213	 * These are the read and write cumulative error counters.
214	 * (how to reset cumulative error counters is not yet defined).
215	 * (not implemented as yet but space is being reserved for them)
216	 */
217	struct {
218		uint32_t retries;	/* total # retries performed */
219		uint32_t corrected;	/* total # corrections performed */
220		uint32_t processed;	/* total # corrections successful */
221		uint32_t failures;	/* total # corrections/retries failed */
222		uint64_t nbytes;	/* total # bytes processed */
223	} wterr, rderr;
224};
225
226union mterrstat {
227	struct scsi_tape_errors scsi_errstat;
228	char _reserved_padding[256];
229};
230
231struct mtrblim {
232	uint32_t granularity;
233	uint32_t min_block_length;
234	uint32_t max_block_length;
235};
236
237typedef enum {
238	MT_LOCATE_DEST_OBJECT	= 0x00,
239	MT_LOCATE_DEST_FILE	= 0x01,
240	MT_LOCATE_DEST_SET	= 0x02,
241	MT_LOCATE_DEST_EOD	= 0x03
242} mt_locate_dest_type;
243
244typedef enum {
245	MT_LOCATE_BAM_IMPLICIT	= 0x00,
246	MT_LOCATE_BAM_EXPLICIT	= 0x01
247} mt_locate_bam;
248
249typedef enum {
250	MT_LOCATE_FLAG_IMMED		= 0x01,
251	MT_LOCATE_FLAG_CHANGE_PART	= 0x02
252} mt_locate_flags;
253
254struct mtlocate {
255	mt_locate_flags		flags;
256	mt_locate_dest_type 	dest_type;
257	mt_locate_bam		block_address_mode;
258	int64_t			partition;
259	uint64_t		logical_id;
260	uint8_t			reserved[64];
261};
262
263typedef enum {
264	MT_EXT_GET_NONE,
265	MT_EXT_GET_OK,
266	MT_EXT_GET_NEED_MORE_SPACE,
267	MT_EXT_GET_ERROR
268} mt_ext_get_status;
269
270struct mtextget {
271	uint32_t		alloc_len;
272	char			*status_xml;
273	uint32_t		fill_len;
274	mt_ext_get_status	status;
275	char			error_str[128];
276	uint8_t			reserved[64];
277};
278
279#define	MT_EXT_GET_ROOT_NAME		"mtextget"
280#define	MT_DENSITY_ROOT_NAME		"mtdensity"
281#define	MT_MEDIA_DENSITY_NAME		"media_density"
282#define	MT_DENSITY_REPORT_NAME		"density_report"
283#define	MT_MEDIUM_TYPE_REPORT_NAME	"medium_type_report"
284#define	MT_MEDIA_REPORT_NAME		"media_report"
285#define	MT_DENSITY_ENTRY_NAME		"density_entry"
286
287#define	MT_DENS_WRITE_OK		0x80
288#define	MT_DENS_DUP			0x40
289#define	MT_DENS_DEFLT			0x20
290
291
292#define	MT_PARAM_FIXED_STR_LEN	32
293union mt_param_value {
294	int64_t		value_signed;
295	uint64_t	value_unsigned;
296	char		*value_var_str;
297	char		value_fixed_str[MT_PARAM_FIXED_STR_LEN];
298	uint8_t		reserved[64];
299};
300
301typedef enum {
302	MT_PARAM_SET_NONE,
303	MT_PARAM_SET_SIGNED,
304	MT_PARAM_SET_UNSIGNED,
305	MT_PARAM_SET_VAR_STR,
306	MT_PARAM_SET_FIXED_STR
307} mt_param_set_type;
308
309typedef enum {
310	MT_PARAM_STATUS_NONE,
311	MT_PARAM_STATUS_OK,
312	MT_PARAM_STATUS_ERROR
313} mt_param_set_status;
314
315#define	MT_PARAM_VALUE_NAME_LEN	64
316struct mtparamset {
317	char			value_name[MT_PARAM_VALUE_NAME_LEN];
318	mt_param_set_type	value_type;
319	int			value_len;
320	union mt_param_value	value;
321	mt_param_set_status	status;
322	char			error_str[128];
323};
324
325#define	MT_PARAM_ROOT_NAME	"mtparamget"
326#define	MT_PROTECTION_NAME	"protection"
327
328/*
329 * Set a list of parameters.
330 */
331struct mtsetlist {
332	int num_params;
333	int param_len;
334	struct mtparamset *params;
335};
336
337/*
338 * Constants for mt_type byte.  These are the same
339 * for controllers compatible with the types listed.
340 */
341#define	MT_ISTS		0x01		/* TS-11 */
342#define	MT_ISHT		0x02		/* TM03 Massbus: TE16, TU45, TU77 */
343#define	MT_ISTM		0x03		/* TM11/TE10 Unibus */
344#define	MT_ISMT		0x04		/* TM78/TU78 Massbus */
345#define	MT_ISUT		0x05		/* SI TU-45 emulation on Unibus */
346#define	MT_ISCPC	0x06		/* SUN */
347#define	MT_ISAR		0x07		/* SUN */
348#define	MT_ISTMSCP	0x08		/* DEC TMSCP protocol (TU81, TK50) */
349#define MT_ISCY		0x09		/* CCI Cipher */
350#define MT_ISCT		0x0a		/* HP 1/4 tape */
351#define MT_ISFHP	0x0b		/* HP 7980 1/2 tape */
352#define MT_ISEXABYTE	0x0c		/* Exabyte */
353#define MT_ISEXA8200	0x0c		/* Exabyte EXB-8200 */
354#define MT_ISEXA8500	0x0d		/* Exabyte EXB-8500 */
355#define MT_ISVIPER1	0x0e		/* Archive Viper-150 */
356#define MT_ISPYTHON	0x0f		/* Archive Python (DAT) */
357#define MT_ISHPDAT	0x10		/* HP 35450A DAT drive */
358#define MT_ISMFOUR	0x11		/* M4 Data 1/2 9track drive */
359#define MT_ISTK50	0x12		/* DEC SCSI TK50 */
360#define MT_ISMT02	0x13		/* Emulex MT02 SCSI tape controller */
361
362/* mag tape io control commands */
363#define	MTIOCTOP	_IOW('m', 1, struct mtop)	/* do a mag tape op */
364#define	MTIOCGET	_IOR('m', 2, struct mtget)	/* get tape status */
365/* these two do not appear to be used anywhere */
366#define MTIOCIEOT	_IO('m', 3)			/* ignore EOT error */
367#define MTIOCEEOT	_IO('m', 4)			/* enable EOT error */
368/*
369 * When more SCSI-3 SSC (streaming device) devices are out there
370 * that support the full 32 byte type 2 structure, we'll have to
371 * rethink these ioctls to support all the entities they haul into
372 * the picture (64 bit blocks, logical file record numbers, etc..).
373 */
374#define	MTIOCRDSPOS	_IOR('m', 5, uint32_t)	/* get logical blk addr */
375#define	MTIOCRDHPOS	_IOR('m', 6, uint32_t)	/* get hardware blk addr */
376#define	MTIOCSLOCATE	_IOW('m', 5, uint32_t)	/* seek to logical blk addr */
377#define	MTIOCHLOCATE	_IOW('m', 6, uint32_t)	/* seek to hardware blk addr */
378#define	MTIOCERRSTAT	_IOR('m', 7, union mterrstat)	/* get tape errors */
379/*
380 * Set EOT model- argument is number of filemarks to end a tape with.
381 * Note that not all possible values will be accepted.
382 */
383#define	MTIOCSETEOTMODEL	_IOW('m', 8, uint32_t)
384/* Get current EOT model */
385#define	MTIOCGETEOTMODEL	_IOR('m', 8, uint32_t)
386#define	MTIOCRBLIM	_IOR('m', 9, struct mtrblim)    /* get block limits */
387#define	MTIOCEXTLOCATE	_IOW('m', 10, struct mtlocate)  /* seek to position */
388#define	MTIOCEXTGET	_IOWR('m', 11, struct mtextget) /* get tape status */
389#define	MTIOCPARAMGET	_IOWR('m', 12, struct mtextget) /* get tape params */
390#define	MTIOCPARAMSET	_IOWR('m', 13, struct mtparamset) /* set tape params */
391#define	MTIOCSETLIST	_IOWR('m', 14, struct mtsetlist) /* set N params */
392
393#ifndef _KERNEL
394#define	DEFTAPE	"/dev/nsa0"
395#endif
396
397#endif /* !_SYS_MTIO_H_ */
398.Ed
399.Sh FILES
400.Bl -tag -width /dev/[en]sa* -compact
401.It Pa /dev/[en]sa*
402.El
403.Sh SEE ALSO
404.Xr mt 1 ,
405.Xr tar 1 ,
406.Xr sa 4
407.Sh HISTORY
408The
409.Nm
410manual appeared in
411.Bx 4.2 .
412An i386 version first appeared in
413.Fx 2.2 .
414