]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/mtio.h
libarchive: merge from vendor branch
[FreeBSD/FreeBSD.git] / sys / sys / mtio.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986, 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
32 #ifndef _SYS_MTIO_H_
33 #define _SYS_MTIO_H_
34
35 #ifndef _KERNEL
36 #include <sys/types.h>
37 #endif
38 #include <sys/ioccom.h>
39
40 /*
41  * Structures and definitions for mag tape io control commands
42  */
43
44 /* structure for MTIOCTOP - mag tape op command */
45 struct mtop {
46         short   mt_op;          /* operations defined below */
47         int32_t mt_count;       /* how many of them */
48 };
49
50 /* operations */
51 #define MTWEOF          0       /* write an end-of-file record */
52 #define MTFSF           1       /* forward space file */
53 #define MTBSF           2       /* backward space file */
54 #define MTFSR           3       /* forward space record */
55 #define MTBSR           4       /* backward space record */
56 #define MTREW           5       /* rewind */
57 #define MTOFFL          6       /* rewind and put the drive offline */
58 #define MTNOP           7       /* no operation, sets status only */
59 #define MTCACHE         8       /* enable controller cache */
60 #define MTNOCACHE       9       /* disable controller cache */
61
62 #if defined(__FreeBSD__)
63 /* Set block size for device. If device is a variable size dev          */
64 /* a non zero parameter will change the device to a fixed block size    */
65 /* device with block size set to that of the parameter passed in.       */
66 /* Resetting the block size to 0 will restore the device to a variable  */
67 /* block size device. */
68
69 #define MTSETBSIZ       10
70
71 /* Set density values for device. Sets the value for the opened mode only. */
72
73 #define MTSETDNSTY      11
74
75 #define MTERASE         12      /* erase to EOM */
76 #define MTEOD           13      /* Space to EOM */
77 #define MTCOMP          14      /* select compression mode 0=off, 1=def */
78 #define MTRETENS        15      /* re-tension tape */
79 #define MTWSS           16      /* write setmark(s) */
80 #define MTFSS           17      /* forward space setmark */
81 #define MTBSS           18      /* backward space setmark */
82 #define MTLOAD          19      /* load tape in drive */
83 #define MTWEOFI         20      /* write an end-of-file record without waiting*/
84
85 #define MT_COMP_ENABLE          0xffffffff
86 #define MT_COMP_DISABLED        0xfffffffe
87 #define MT_COMP_UNSUPP          0xfffffffd
88
89 /*
90  * Values in mt_dsreg that say what the device is doing
91  */
92 #define MTIO_DSREG_NIL  0       /* Unknown */
93 #define MTIO_DSREG_REST 1       /* Doing Nothing */
94 #define MTIO_DSREG_RBSY 2       /* Communicating with tape (but no motion) */
95 #define MTIO_DSREG_WR   20      /* Writing */
96 #define MTIO_DSREG_FMK  21      /* Writing Filemarks */
97 #define MTIO_DSREG_ZER  22      /* Erasing */
98 #define MTIO_DSREG_RD   30      /* Reading */
99 #define MTIO_DSREG_FWD  40      /* Spacing Forward */
100 #define MTIO_DSREG_REV  41      /* Spacing Reverse */
101 #define MTIO_DSREG_POS  42      /* Hardware Positioning (direction unknown) */
102 #define MTIO_DSREG_REW  43      /* Rewinding */
103 #define MTIO_DSREG_TEN  44      /* Retensioning */
104 #define MTIO_DSREG_UNL  45      /* Unloading */
105 #define MTIO_DSREG_LD   46      /* Loading */
106
107 #endif  /* __FreeBSD__ */
108
109 /* structure for MTIOCGET - mag tape get status command */
110
111 struct mtget {
112         short   mt_type;        /* type of magtape device */
113 /* the following two registers are grossly device dependent */
114         short   mt_dsreg;       /* ``drive status'' register */
115         short   mt_erreg;       /* ``error'' register */
116 /* end device-dependent registers */
117         /*
118          * Note that the residual count, while maintained, may be
119          * be nonsense because the size of the residual may (greatly)
120          * exceed 32 K-bytes. Use the MTIOCERRSTAT ioctl to get a
121          * more accurate count.
122          */
123         short   mt_resid;       /* residual count */
124 #if defined (__FreeBSD__)
125         int32_t mt_blksiz;      /* presently operating blocksize */
126         int32_t mt_density;     /* presently operating density */
127         u_int32_t mt_comp;      /* presently operating compression */
128         int32_t mt_blksiz0;     /* blocksize for mode 0 */
129         int32_t mt_blksiz1;     /* blocksize for mode 1 */
130         int32_t mt_blksiz2;     /* blocksize for mode 2 */
131         int32_t mt_blksiz3;     /* blocksize for mode 3 */
132         int32_t mt_density0;    /* density for mode 0 */
133         int32_t mt_density1;    /* density for mode 1 */
134         int32_t mt_density2;    /* density for mode 2 */
135         int32_t mt_density3;    /* density for mode 3 */
136 /* the following are not yet implemented */
137         u_int32_t mt_comp0;     /* compression type for mode 0 */
138         u_int32_t mt_comp1;     /* compression type for mode 1 */
139         u_int32_t mt_comp2;     /* compression type for mode 2 */
140         u_int32_t mt_comp3;     /* compression type for mode 3 */
141 /* end not yet implemented */
142 #endif
143         int32_t mt_fileno;      /* relative file number of current position */
144         int32_t mt_blkno;       /* relative block number of current position */
145 };
146
147 /* structure for MTIOCERRSTAT - tape get error status command */
148 /* really only supported for SCSI tapes right now */
149 struct scsi_tape_errors {
150         /*
151          * These are latched from the last command that had a SCSI
152          * Check Condition noted for these operations. The act
153          * of issuing an MTIOCERRSTAT unlatches and clears them.
154          */
155         u_int8_t io_sense[32];  /* Last Sense Data For Data I/O */
156         int32_t io_resid;       /* residual count from last Data I/O */
157         u_int8_t io_cdb[16];    /* Command that Caused the Last Data Sense */
158         u_int8_t ctl_sense[32]; /* Last Sense Data For Control I/O */
159         int32_t ctl_resid;      /* residual count from last Control I/O */
160         u_int8_t ctl_cdb[16];   /* Command that Caused the Last Control Sense */
161         /*
162          * These are the read and write cumulative error counters.
163          * (how to reset cumulative error counters is not yet defined).
164          * (not implemented as yet but space is being reserved for them)
165          */
166         struct {
167                 u_int32_t retries;      /* total # retries performed */
168                 u_int32_t corrected;    /* total # corrections performed */
169                 u_int32_t processed;    /* total # corrections successful */
170                 u_int32_t failures;     /* total # corrections/retries failed */
171                 u_int64_t nbytes;       /* total # bytes processed */
172         } wterr, rderr;
173 };
174
175 union mterrstat {
176         struct scsi_tape_errors scsi_errstat;
177         char _reserved_padding[256];
178 };
179
180 struct mtrblim {
181         uint32_t granularity;
182         uint32_t min_block_length;
183         uint32_t max_block_length;
184 };
185
186 typedef enum {
187         MT_LOCATE_DEST_OBJECT   = 0x00,
188         MT_LOCATE_DEST_FILE     = 0x01,
189         MT_LOCATE_DEST_SET      = 0x02,
190         MT_LOCATE_DEST_EOD      = 0x03
191 } mt_locate_dest_type;
192
193 typedef enum {
194         MT_LOCATE_BAM_IMPLICIT  = 0x00,
195         MT_LOCATE_BAM_EXPLICIT  = 0x01
196 } mt_locate_bam;
197
198 typedef enum {
199         MT_LOCATE_FLAG_IMMED            = 0x01,
200         MT_LOCATE_FLAG_CHANGE_PART      = 0x02
201 } mt_locate_flags;
202
203 struct mtlocate {
204         mt_locate_flags         flags;
205         mt_locate_dest_type     dest_type;
206         mt_locate_bam           block_address_mode;
207         int64_t                 partition;
208         uint64_t                logical_id;
209         uint8_t                 reserved[64];
210 };
211
212 typedef enum {
213         MT_EXT_GET_NONE,
214         MT_EXT_GET_OK,
215         MT_EXT_GET_NEED_MORE_SPACE,
216         MT_EXT_GET_ERROR
217 } mt_ext_get_status;
218
219 struct mtextget {
220         uint32_t                alloc_len;
221         char                    *status_xml;
222         uint32_t                fill_len;
223         mt_ext_get_status       status;
224         char                    error_str[128];
225         uint8_t                 reserved[64];
226 };
227
228 #define MT_EXT_GET_ROOT_NAME            "mtextget"
229 #define MT_DENSITY_ROOT_NAME            "mtdensity"
230 #define MT_MEDIA_DENSITY_NAME           "media_density"
231 #define MT_DENSITY_REPORT_NAME          "density_report"
232 #define MT_MEDIUM_TYPE_REPORT_NAME      "medium_type_report"
233 #define MT_MEDIA_REPORT_NAME            "media_report"
234 #define MT_DENSITY_ENTRY_NAME           "density_entry"
235
236 #define MT_DENS_WRITE_OK                0x80
237 #define MT_DENS_DUP                     0x40
238 #define MT_DENS_DEFLT                   0x20
239
240 #define MT_PARAM_FIXED_STR_LEN  32
241 union mt_param_value {
242         int64_t         value_signed;
243         uint64_t        value_unsigned;
244         char            *value_var_str;
245         char            value_fixed_str[MT_PARAM_FIXED_STR_LEN];
246         uint8_t         reserved[64];
247 };
248
249 typedef enum {
250         MT_PARAM_SET_NONE,
251         MT_PARAM_SET_SIGNED,
252         MT_PARAM_SET_UNSIGNED,
253         MT_PARAM_SET_VAR_STR,
254         MT_PARAM_SET_FIXED_STR
255 } mt_param_set_type;
256
257 typedef enum {
258         MT_PARAM_STATUS_NONE,
259         MT_PARAM_STATUS_OK,
260         MT_PARAM_STATUS_ERROR
261 } mt_param_set_status;
262
263 #define MT_PARAM_VALUE_NAME_LEN 64
264 struct mtparamset {
265         char                    value_name[MT_PARAM_VALUE_NAME_LEN];
266         mt_param_set_type       value_type;
267         int                     value_len;
268         union mt_param_value    value;
269         mt_param_set_status     status;
270         char                    error_str[128];
271 };
272
273 #define MT_PARAM_ROOT_NAME      "mtparamget"
274 #define MT_PROTECTION_NAME      "protection"
275
276 /*
277  * Set a list of parameters.
278  */
279 struct mtsetlist {
280         int num_params;
281         int param_len;
282         struct mtparamset *params;
283 };
284
285 /*
286  * Constants for mt_type byte.  These are the same
287  * for controllers compatible with the types listed.
288  */
289 #define MT_ISTS         0x01            /* TS-11 */
290 #define MT_ISHT         0x02            /* TM03 Massbus: TE16, TU45, TU77 */
291 #define MT_ISTM         0x03            /* TM11/TE10 Unibus */
292 #define MT_ISMT         0x04            /* TM78/TU78 Massbus */
293 #define MT_ISUT         0x05            /* SI TU-45 emulation on Unibus */
294 #define MT_ISCPC        0x06            /* SUN */
295 #define MT_ISAR         0x07            /* SUN */
296 #define MT_ISTMSCP      0x08            /* DEC TMSCP protocol (TU81, TK50) */
297 #define MT_ISCY         0x09            /* CCI Cipher */
298 #define MT_ISCT         0x0a            /* HP 1/4 tape */
299 #define MT_ISFHP        0x0b            /* HP 7980 1/2 tape */
300 #define MT_ISEXABYTE    0x0c            /* Exabyte */
301 #define MT_ISEXA8200    0x0c            /* Exabyte EXB-8200 */
302 #define MT_ISEXA8500    0x0d            /* Exabyte EXB-8500 */
303 #define MT_ISVIPER1     0x0e            /* Archive Viper-150 */
304 #define MT_ISPYTHON     0x0f            /* Archive Python (DAT) */
305 #define MT_ISHPDAT      0x10            /* HP 35450A DAT drive */
306 #define MT_ISMFOUR      0x11            /* M4 Data 1/2 9track drive */
307 #define MT_ISTK50       0x12            /* DEC SCSI TK50 */
308 #define MT_ISMT02       0x13            /* Emulex MT02 SCSI tape controller */
309
310 /* mag tape io control commands */
311 #define MTIOCTOP        _IOW('m', 1, struct mtop)       /* do a mag tape op */
312 #define MTIOCGET        _IOR('m', 2, struct mtget)      /* get tape status */
313 /* these two do not appear to be used anywhere */
314 #define MTIOCIEOT       _IO('m', 3)                     /* ignore EOT error */
315 #define MTIOCEEOT       _IO('m', 4)                     /* enable EOT error */
316 /*
317  * When more SCSI-3 SSC (streaming device) devices are out there
318  * that support the full 32 byte type 2 structure, we'll have to
319  * rethink these ioctls to support all the entities they haul into
320  * the picture (64 bit blocks, logical file record numbers, etc..).
321  */
322 #define MTIOCRDSPOS     _IOR('m', 5, u_int32_t) /* get logical blk addr */
323 #define MTIOCRDHPOS     _IOR('m', 6, u_int32_t) /* get hardware blk addr */
324 #define MTIOCSLOCATE    _IOW('m', 5, u_int32_t) /* seek to logical blk addr */
325 #define MTIOCHLOCATE    _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */
326 #define MTIOCERRSTAT    _IOR('m', 7, union mterrstat)   /* get tape errors */
327
328 /*
329  * Set EOT model- argument is number of filemarks to end a tape with.
330  * Note that not all possible values will be accepted.
331  */
332 #define MTIOCSETEOTMODEL        _IOW('m', 8, u_int32_t)
333 /* Get current EOT model */
334 #define MTIOCGETEOTMODEL        _IOR('m', 8, u_int32_t)
335
336 #define MTIOCRBLIM      _IOR('m', 9, struct mtrblim)    /* get block limits */
337 #define MTIOCEXTLOCATE  _IOW('m', 10, struct mtlocate)  /* seek to position */
338 #define MTIOCEXTGET     _IOWR('m', 11, struct mtextget) /* get tape status */
339 #define MTIOCPARAMGET   _IOWR('m', 12, struct mtextget) /* get tape params */
340 #define MTIOCPARAMSET   _IOWR('m', 13, struct mtparamset) /* set tape params */
341 #define MTIOCSETLIST    _IOWR('m', 14, struct mtsetlist) /* set N params */
342
343 #ifndef _KERNEL
344 #define DEFTAPE "/dev/nsa0"
345 #endif
346
347 #endif /* !_SYS_MTIO_H_ */