3b8a36c10a7acf784a51200b7a980d1e8379ed72
[debian/amanda] / changer-src / scsi-defs.h
1
2 /*
3  * Copyright (c) 1998 T.Hepper
4  */
5 #ifndef WORDS_BIGENDIAN
6 #define LITTLE_ENDIAN_BITFIELDS
7 #endif
8
9 typedef enum { Input, Output } Direction_T; 
10 typedef unsigned char CDB_T[12];
11
12 #ifdef _AIX
13 typedef unsigned int PackedBit;
14 #define AIX_USE_GSC 1
15 #else
16 typedef unsigned char PackedBit;
17 #endif
18
19 #define INDEX_CHANGER 0
20 #define INDEX_TAPE 1
21 #define INDEX_TAPECTL 2
22
23 #define CHG_MAXDEV 32           /* Maximum number of devices handled by pDev */
24                                 /* Must be large to hold the result of ScanBus */
25
26 #define TAPETYPE 4
27 #define IMPORT 3
28 #define STORAGE 2
29 #define CHANGER 1
30
31 #define TAG_SIZE 36
32 #define MAXTRIES 100  /* How many tries until SCSI_TestUnitReady should return an ok */
33 /*
34  * Sense Key definitions
35 */
36 #define SENSE_NULL 0
37 #define SENSE_RECOVERED_ERROR 1
38 #define NOT_READY 2
39 #define SENSE_NOT_READY 2
40 #define SENSE_MEDIUM_ERROR 3
41 #define SENSE_HARDWARE_ERROR 4
42 #define HARDWARE_ERROR 4
43 #define ILLEGAL_REQUEST 5
44 #define SENSE_ILLEGAL_REQUEST 5
45 #define UNIT_ATTENTION 6
46 #define SENSE_UNIT_ATTENTION 6
47 #define SENSE_DATA_PROTECT 7
48 #define SENSE_BLANK_CHECK 8
49 #define SENSE_VENDOR_SPECIFIC 0x9
50 #define SENSE_ABORTED_COMMAND 0xb
51 #define SENSE_VOLUME_OVERFLOW 0xd
52 #define SENSE_CHG_ELEMENT_STATUS 0xe
53
54 #define MAX_RETRIES 100
55
56 #define INQUIRY_SIZE sizeof(SCSIInquiry_T)
57
58 /*
59  * Return values from the OS dependent part
60  * of the SCSI interface
61  *
62  * The underlaying functions must decide what to do
63  */
64 #define SCSI_ERROR -1
65 #define SCSI_OK 0
66 #define SCSI_SENSE 1
67 #define SCSI_BUSY 2
68 #define SCSI_CHECK 3
69
70
71 /*
72  *  SCSI Commands
73 */
74 #define SC_COM_TEST_UNIT_READY 0
75 #define SC_COM_REWIND 0x1
76 #define SC_COM_REQUEST_SENSE 0x3
77 #define SC_COM_IES 0x7
78 #define SC_COM_INQUIRY 0x12
79 #define SC_COM_MODE_SELECT 0x15
80 #define SC_COM_ERASE 0x19
81 #define SC_COM_MODE_SENSE 0x1A
82 #define SC_COM_UNLOAD 0x1B
83 #define SC_COM_LOCATE 0x2B
84 #define SC_COM_LOG_SELECT 0x4C
85 #define SC_COM_LOG_SENSE 0x4d
86 #define SC_MOVE_MEDIUM 0xa5
87 #define SC_COM_RES 0xb8
88 /*
89  * Define for LookupDevice
90  */
91 #define LOOKUP_NAME 1
92 #define LOOKUP_FD 2
93 #define LOOKUP_TYPE 3
94 #define LOOKUP_CONFIG 4
95 /* 
96  * Define for the return codes from SenseHandler
97  */
98 #define SENSE_ABORT -1
99 #define SENSE_IGNORE 0
100 #define SENSE_RETRY 2
101 #define SENSE_IES 3
102 #define SENSE_TAPE_NOT_ONLINE 4
103 #define SENSE_TAPE_NOT_LOADED 5
104 #define SENSE_NO 6
105 #define SENSE_TAPE_NOT_UNLOADED 7
106 #define SENSE_CHM_FULL 8
107 /*
108  * Defines for the type field in the inquiry command
109  */
110 #define TYPE_DISK 0
111 #define TYPE_TAPE 1
112 #define TYPE_PRINTER 2
113 #define TYPE_PROCESSOR 3
114 #define TYPE_WORM 4
115 #define TYPE_CDROM 5
116 #define TYPE_SCANNER 6
117 #define TYPE_OPTICAL 7
118 #define TYPE_CHANGER 8
119 #define TYPE_COMM 9
120
121 /* Defines for Tape_Status */
122 #define TAPE_ONLINE 1        /* Tape is loaded */
123 #define TAPE_BOT 2           /* Tape is at begin of tape */
124 #define TAPE_EOT 4           /* Tape is at end of tape */
125 #define TAPE_WR_PROT 8       /* Tape is write protected */
126 #define TAPE_NOT_LOADED 16   /* Tape is not loaded */
127
128 /* Defines for the function Tape_Ioctl */
129 #define IOCTL_EJECT 0
130
131 /* Defines for exit status */
132 #define WARNING 1
133 #define FATAL   2
134
135 /* macros for building scsi msb array parameter lists */
136 #ifndef B
137 #define B(s,i) ((unsigned char)((s) >> i))
138 #endif
139 #ifndef B1
140 #define B1(s)                           ((unsigned char)(s))
141 #endif
142 #define B2(s)                       B((s),8),   B1(s)
143 #define B3(s)            B((s),16), B((s),8),   B1(s)
144 #define B4(s) B((s),24), B((s),16), B((s),8),   B1(s)
145
146 /* macros for converting scsi msb array to binary */
147 #define V1(s)           (s)[0]
148 #define V2(s)         (((s)[0] << 8) | (s)[1])
149 #define V3(s)       (((((s)[0] << 8) | (s)[1]) << 8) | (s)[2])
150 #define V4(s)     (((((((s)[0] << 8) | (s)[1]) << 8) | (s)[2]) << 8) | (s)[3])
151 #define V5(s)   (((((((((s)[0] << 8) | (s)[1]) << 8) | (s)[2]) << 8) | (s)[3]) << 8) | (s)[4])
152 #define V6(s) (((((((((((s)[0] << 8) | (s)[1]) << 8) | (s)[2]) << 8) | (s)[3]) << 8) | (s)[4]) << 8) | (s)[5])
153
154 /* macros for converting binary into scsi msb array */
155 #define MSB1(s,v)                                               *(s)=B1(v)
156 #define MSB2(s,v)                                *(s)=B(v,8), (s)[1]=B1(v)
157 #define MSB3(s,v)               *(s)=B(v,16),  (s)[1]=B(v,8), (s)[2]=B1(v)
158 #define MSB4(s,v) *(s)=B(v,24),(s)[1]=B(v,16), (s)[2]=B(v,8), (s)[3]=B1(v)
159
160 #define LABEL_DB_VERSION 2
161
162 #define DEBUG_INFO 9
163 #define DEBUG_ERROR 1
164 #define DEBUG_ALL 0
165
166 #define SECTION_ALL 0
167 #define SECTION_INFO 1
168 #define SECTION_SCSI 2
169 #define SECTION_MAP_BARCODE 3
170 #define SECTION_ELEMENT 4
171 #define SECTION_BARCODE 5
172 #define SECTION_TAPE 6
173 #define SECTION_MOVE 7
174 /*----------------------------------------------------------------------------*/
175 /* Some stuff for our own configurationfile */
176 typedef struct {  /* The information we can get for any drive (configuration) */
177   int drivenum;      /* Which drive to use in the library */
178   int start;         /* Which is the first slot we may use */
179   int end;           /* The last slot we are allowed to use */
180   int cleanslot;     /* Where the cleaningcartridge stays */
181   char *scsitapedev; /* Where can we send raw SCSI commands to the tape */
182   char *device;      /* Which device is associated to the drivenum */
183   char *slotfile;    /* Where we should have our memory */   
184   char *cleanfile;   /* Where we count how many cleanings we did */
185   char *timefile;    /* Where we count the time the tape was used*/
186   char *tapestatfile;/* Where can we place some drive stats */
187   char *changerident;/* Config to use foe changer control, ovverride result from inquiry */
188   char *tapeident;   /* Same as above for the tape device */
189 }config_t; 
190
191 typedef struct {
192   int number_of_configs; /* How many different configurations are used */
193   int eject;             /* Do the drives need an eject-command */
194   int autoinv;           /* Do automaticly an inventory if an tape is not in the db or not active in the db */
195   int havebarcode;       /* Do we have an barcode reader installed */
196   char *debuglevel;      /* How many debug info to print */
197   unsigned char emubarcode;     /* Emulate the barcode feature,  used for keeping an inventory of the lib */
198   int sleep;             /* How many seconds to wait for the drive to get ready */
199   int cleanmax;          /* How many runs could be done with one cleaning tape */
200   char *device;          /* Which device is our changer */
201   char *labelfile;       /* Mapping from Barcode labels to volume labels */
202   config_t *conf;
203 }changer_t;
204
205 typedef struct {
206   char voltag[128];
207   char barcode[TAG_SIZE];
208   unsigned char valid;
209 } LabelV1_T;
210
211 typedef struct {
212   char voltag[128];              /* Tape volume label */
213   char barcode[TAG_SIZE];        /* Barcode of the tape */
214   unsigned int slot;             /* in which slot is the tape */
215   unsigned int from;             /* from where it comes, needed to move
216                                  * a tape back to the right slot from the drive
217                                  */
218
219   unsigned int LoadCount;       /* How many times has the tape been loaded */
220   unsigned int RecovError;      /* How many recovered errors */
221   unsigned int UnrecovError;    /* How man unrecoverd errors */
222   unsigned char valid;          /* Is this tape in the current magazin */
223 } LabelV2_T;
224
225 typedef enum {BARCODE_PUT, BARCODE_VOL, BARCODE_BARCODE, BARCODE_DUMP, RESET_VALID, FIND_SLOT, UPDATE_SLOT } MBCAction_T;
226 typedef struct {
227   LabelV2_T data;
228   MBCAction_T action;
229 } MBC_T;
230
231
232 /* ======================================================= */
233 /* RequestSense_T */
234 /* ======================================================= */
235 typedef struct  
236 {
237 #ifdef LITTLE_ENDIAN_BITFIELDS 
238     PackedBit     ErrorCode:7;                    /* Byte 0 Bits 0-6 */
239     PackedBit     Valid:1;                              /* Byte 0 Bit 7    */
240 #else 
241     PackedBit     Valid:1;                              /* Byte 0 Bit 7    */
242     PackedBit     ErrorCode:7;                    /* Byte 0 Bits 0-6 */
243 #endif
244     unsigned char SegmentNumber;                  /* Byte 1 */ 
245 #ifdef LITTLE_ENDIAN_BITFIELDS        
246     PackedBit     SenseKey:4;                     /* Byte 2 Bits 0-3 */
247     PackedBit     :1;                             /* Byte 2 Bit 4    */
248     PackedBit     RILI:1;                                /* Byte 2 Bit 5    */
249     PackedBit     REOM:1;                                /* Byte 2 Bit 6    */
250     PackedBit     Filemark:1;                           /* Byte 2 Bit 7    */
251 #else 
252     PackedBit     Filemark:1;                           /* Byte 2 Bit 7    */
253     PackedBit     REOM:1;                                /* Byte 2 Bit 6    */
254     PackedBit     RILI:1;                                /* Byte 2 Bit 5    */
255     PackedBit     :1;                             /* Byte 2 Bit 4    */ 
256     PackedBit     SenseKey:4;                     /* Byte 2 Bits 0-3 */
257 #endif
258     unsigned char Information[4];                 /* Bytes 3-6       */ 
259     unsigned char AdditionalSenseLength;          /* Byte 7          */   
260     unsigned char CommandSpecificInformation[4];  /* Bytes 8-11      */ 
261     unsigned char AdditionalSenseCode;            /* Byte 12         */
262     unsigned char AdditionalSenseCodeQualifier;   /* Byte 13         */ 
263     unsigned char Byte14;                          /* Byte 14         */ 
264     unsigned char Byte15;                           /* Byte 15         */ 
265     
266 } RequestSense_T;     
267
268 /* ======================================================= */
269 /* ExtendedRequestSense_T */
270 /* ======================================================= */
271 typedef struct  
272 {
273 #ifdef LITTLE_ENDIAN_BITFIELDS 
274     PackedBit     ErrorCode:7;                    /* Byte 0 Bits 0-6 */
275     PackedBit     Valid:1;                        /* Byte 0 Bit 7    */
276 #else 
277     PackedBit     Valid:1;                        /* Byte 0 Bit 7    */
278     PackedBit     ErrorCode:7;                    /* Byte 0 Bits 0-6 */
279 #endif
280     unsigned char SegmentNumber;                  /* Byte 1 */ 
281 #ifdef LITTLE_ENDIAN_BITFIELDS        
282     PackedBit     SenseKey:4;                     /* Byte 2 Bits 0-3 */
283     PackedBit     :1;                             /* Byte 2 Bit 4    */
284     PackedBit     RILI:1;                         /* Byte 2 Bit 5    */
285     PackedBit     REOM:1;                         /* Byte 2 Bit 6    */
286     PackedBit     Filemark:1;                     /* Byte 2 Bit 7    */
287 #else 
288     PackedBit     Filemark:1;                     /* Byte 2 Bit 7    */
289     PackedBit     REOM:1;                         /* Byte 2 Bit 6    */
290     PackedBit     RILI:1;                         /* Byte 2 Bit 5    */
291     PackedBit     :1;                             /* Byte 2 Bit 4    */ 
292     PackedBit     SenseKey:4;                     /* Byte 2 Bits 0-3 */
293 #endif
294     unsigned char Information[4];                 /* Bytes 3-6       */ 
295     unsigned char AdditionalSenseLength;          /* Byte 7          */   
296     unsigned char LogParameterPageCode;           /* Bytes 8         */ 
297     unsigned char LogParameterCode;               /* Bytes 9         */ 
298     unsigned char Byte10;                         /* Bytes 10        */ 
299     unsigned char UnderrunOverrunCounter;         /* Bytes 11        */ 
300     unsigned char AdditionalSenseCode;            /* Byte 12         */
301     unsigned char AdditionalSenseCodeQualifier;   /* Byte 13         */ 
302     unsigned char Byte14;                         /* Byte 14         */ 
303     unsigned char Byte15;                         /* Byte 15         */ 
304     unsigned char ReadWriteDataErrorCounter[3];   /* Byte 16-18      */ 
305 #ifdef LITTLE_ENDIAN_BITFIELDS        
306     PackedBit     LBOT:1;                         /* Byte 19 Bits 0 */
307     PackedBit     TNP:1;                          /* Byte 19 Bits 1 */
308     PackedBit     TME:1;                          /* Byte 19 Bits 2 */
309     PackedBit     ECO:1;                          /* Byte 19 Bits 3 */
310     PackedBit     ME:1;                           /* Byte 19 Bits 4 */
311     PackedBit     FPE:1;                          /* Byte 19 Bits 5 */
312     PackedBit     BPE:1;                          /* Byte 19 Bits 6 */
313     PackedBit     PF:1;                           /* Byte 19 Bits 7 */
314 #else 
315     PackedBit     PF:1;                           /* Byte 19 Bits 7 */
316     PackedBit     BPE:1;                          /* Byte 19 Bits 6 */
317     PackedBit     FPE:1;                          /* Byte 19 Bits 5 */
318     PackedBit     ME:1;                           /* Byte 19 Bits 4 */
319     PackedBit     ECO:1;                          /* Byte 19 Bits 3 */
320     PackedBit     TME:1;                          /* Byte 19 Bits 2 */
321     PackedBit     TNP:1;                          /* Byte 19 Bits 1 */
322     PackedBit     LBOT:1;                         /* Byte 19 Bits 0 */
323 #endif
324 #ifdef LITTLE_ENDIAN_BITFIELDS        
325     PackedBit     FE:1;                           /* Byte 20 Bits 0 */
326     PackedBit     SSE:1;                          /* Byte 20 Bits 1 */
327     PackedBit     WEI:1;                          /* Byte 20 Bits 2 */
328     PackedBit     URE:1;                          /* Byte 20 Bits 3 */
329     PackedBit     FMKE:1;                         /* Byte 20 Bits 4 */
330     PackedBit     WP:1;                           /* Byte 20 Bits 5 */
331     PackedBit     TMD:1;                          /* Byte 20 Bits 6 */
332     PackedBit     :1;                             /* Byte 20 Bits 7 */
333 #else 
334     PackedBit     :1;                             /* Byte 20 Bits 7 */
335     PackedBit     TMD:1;                          /* Byte 20 Bits 6 */
336     PackedBit     WP:1;                           /* Byte 20 Bits 5 */
337     PackedBit     FMKE:1;                         /* Byte 20 Bits 4 */
338     PackedBit     URE:1;                          /* Byte 20 Bits 3 */
339     PackedBit     WEI:1;                          /* Byte 20 Bits 2 */
340     PackedBit     SSE:1;                          /* Byte 20 Bits 1 */
341     PackedBit     FE:1;                           /* Byte 20 Bits 0 */
342 #endif
343 #ifdef LITTLE_ENDIAN_BITFIELDS        
344     PackedBit     WSEO:1;                         /* Byte 21 Bits 0 */
345     PackedBit     WSEB:1;                         /* Byte 21 Bits 1 */
346     PackedBit     PEOT:1;                         /* Byte 21 Bits 2 */
347     PackedBit     CLN:1;                          /* Byte 21 Bits 3 */
348     PackedBit     CLND:1;                         /* Byte 21 Bits 4 */
349     PackedBit     RRR:1;                          /* Byte 21 Bits 5 */
350     PackedBit     UCLN:1;                         /* Byte 21 Bits 6 */
351     PackedBit     :1;                             /* Byte 21 Bits 7 */
352 #else 
353     PackedBit     :1;                             /* Byte 21 Bits 7 */
354     PackedBit     UCLN:1;                         /* Byte 21 Bits 6 */
355     PackedBit     RRR:1;                          /* Byte 21 Bits 5 */
356     PackedBit     CLND:1;                         /* Byte 21 Bits 4 */
357     PackedBit     CLN:1;                          /* Byte 21 Bits 3 */
358     PackedBit     PEOT:1;                         /* Byte 21 Bits 2 */
359     PackedBit     WSEB:1;                         /* Byte 21 Bits 1 */
360     PackedBit     WSEO:1;                         /* Byte 21 Bits 0 */
361 #endif
362     unsigned char Byte21;                          /* Byte 22         */ 
363     unsigned char RemainingTape[3];                /* Byte 23-25      */ 
364     unsigned char TrackingRetryCounter;            /* Byte 26         */ 
365     unsigned char ReadWriteRetryCounter;           /* Byte 27         */ 
366     unsigned char FaultSymptomCode;                /* Byte 28         */ 
367     
368 } ExtendedRequestSense_T;     
369
370 /* ======================================================= */
371 /*  ReadElementStatus_T */
372 /* ======================================================= */
373 typedef struct 
374 {
375     unsigned char cmd;                           /* Byte 1 */
376 #ifdef LITTLE_ENDIAN_BITFIELDS        
377     PackedBit     type : 4;
378     PackedBit     voltag :1;
379     PackedBit     lun :3;
380 #else
381     PackedBit     lun :3;
382     PackedBit     voltag :1;
383     PackedBit     type : 4;
384 #endif
385     unsigned char start[2];                    /* Byte 3-4 */
386     unsigned char number[2];                   /* Byte 5-6 */
387     unsigned char byte4;                       /* Byte 7 */
388     unsigned char length[4];                   /* Byte 8-11 */
389     unsigned char byte78[2];                   /* Byte 12-13 */
390 } ReadElementStatus_T;
391
392 /* ======================================================= */
393 /* ElementStatusPage_T */
394 /* ======================================================= */
395 typedef struct 
396 {
397     unsigned char type;     /* Byte 1 = Element Type Code*/
398 #ifdef LITTLE_ENDIAN_BITFIELDS        
399     PackedBit     bitres  : 6;
400     PackedBit     avoltag : 1;
401     PackedBit     pvoltag : 1;
402 #else
403     PackedBit     pvoltag : 1;
404     PackedBit     avoltag : 1;
405     PackedBit     bitres  : 6;
406 #endif
407     unsigned char length[2];    /* Byte 2-3  = Element Descriptor Length */
408     unsigned char byte4;        /* Byte 4 */
409     unsigned char count[3];     /* Byte 5-7 = Byte Count of Descriptor Available */
410 } ElementStatusPage_T;
411
412
413 /* ======================================================= */
414 /* ElementStatusData_T */
415 /* ======================================================= */
416 typedef struct 
417 {
418     unsigned char first[2];    /* Byte 1-2 = First Element Adress Reported */
419     unsigned char number[2];   /* Byte 3-4 = Number of Elements Available */
420     unsigned char byte5;      /* Reserved */
421     unsigned char count[3];     /* Byte 6-8 = Byte Count of Report Available */
422 } ElementStatusData_T;
423
424 /* ======================================================= */
425 /* MediumTransportElementDescriptor_T */
426 /* ======================================================= */
427 typedef struct 
428 {
429     unsigned char address[2];   /* Byte 1-2 = Element Address */
430 #ifdef LITTLE_ENDIAN_BITFIELDS        
431     PackedBit     full   : 1;
432     PackedBit     rsvd   : 1;
433     PackedBit     except : 1;
434     PackedBit     res    : 5;
435 #else
436     PackedBit     res    : 5;
437     PackedBit     except : 1;
438     PackedBit     rsvd   : 1;
439     PackedBit     full   : 1;
440 #endif
441     unsigned char byte4;        /* Byte 4      */
442     unsigned char asc;          /* Byte 5 ASC  */
443     unsigned char ascq;         /* Byte 6 ASCQ */
444     unsigned char byte79[3];    /* Byte 7-9    */
445 #ifdef LITTLE_ENDIAN_BITFIELDS        
446     PackedBit     byte10res : 6;
447     PackedBit     invert : 1;
448     PackedBit     svalid : 1;
449 #else
450     PackedBit     svalid : 1;
451     PackedBit     invert : 1;
452     PackedBit     byte10res : 6;
453 #endif
454     unsigned char source[2];
455   unsigned char pvoltag[36];
456   unsigned char res4[4];
457 } MediumTransportElementDescriptor_T;
458
459 /* ======================================================= */
460 /* ImportExportElementDescriptor_T */
461 /* ======================================================= */
462 typedef struct 
463 {
464   unsigned char address[2];   /* Byte 1 = Element Address */
465 #ifdef LITTLE_ENDIAN_BITFIELDS        
466   PackedBit     full   : 1;
467   PackedBit     impexp : 1;
468   PackedBit     except : 1;
469   PackedBit     access : 1;
470   PackedBit     exenab : 1;
471   PackedBit     inenab : 1;
472   PackedBit     res    : 2;
473 #else
474   PackedBit     res    : 2;
475   PackedBit     inenab : 1;
476   PackedBit     exenab : 1;
477   PackedBit     access : 1;
478   PackedBit     except : 1;
479   PackedBit     rsvd   : 1;
480   PackedBit     full   : 1;
481 #endif
482     unsigned char byte4;
483     unsigned char asc;
484     unsigned char ascq;
485     unsigned char byte79[3];
486 #ifdef LITTLE_ENDIAN_BITFIELDS        
487     PackedBit     byte10res : 6;
488     PackedBit     invert : 1;
489     PackedBit     svalid : 1;
490 #else
491     PackedBit     svalid : 1;
492     PackedBit     invert : 1;
493     PackedBit     byte10res : 6;
494 #endif
495     unsigned char source[2];
496   unsigned char pvoltag[36];
497   unsigned char res4[4];
498   unsigned char mediadomain[1];
499   unsigned char mediatype[1];
500   unsigned char res5[2];
501 } ImportExportElementDescriptor_T;
502
503 /* ======================================================= */
504 /* StorageElementDescriptor_T */
505 /* ======================================================= */
506 typedef struct 
507 {
508     unsigned char address[2];
509 #ifdef LITTLE_ENDIAN_BITFIELDS        
510     PackedBit     full   : 1;
511     PackedBit     rsvd   : 1;
512     PackedBit     except : 1;
513     PackedBit     access : 1;
514     PackedBit     res    : 4;
515 #else
516     PackedBit     res    : 4;
517     PackedBit     access : 1;
518     PackedBit     except : 1;
519     PackedBit     rsvd   : 1;
520     PackedBit     full   : 1;
521 #endif
522     unsigned char res1;
523     unsigned char asc;
524     unsigned char ascq;
525     unsigned char res2[3];
526 #ifdef LITTLE_ENDIAN_BITFIELDS        
527     PackedBit     res3   : 6;
528     PackedBit     invert : 1;
529     PackedBit     svalid : 1;
530 #else
531     PackedBit     svalid : 1;
532     PackedBit     invert : 1;
533     PackedBit     res3   : 6;
534 #endif
535     unsigned char source[2];
536   unsigned char pvoltag[36];
537   unsigned char res4[4];
538   unsigned char mediadomain[1];
539   unsigned char mediatype[1];
540   unsigned char res5[2];
541 } StorageElementDescriptor_T;
542
543 /* ======================================================= */
544 /* DataTransferElementDescriptor_T */
545 /* ======================================================= */
546 typedef struct 
547 {
548     unsigned char address[2];
549 #ifdef LITTLE_ENDIAN_BITFIELDS        
550     PackedBit     full    : 1;
551     PackedBit     rsvd    : 1;
552     PackedBit     except  : 1;
553     PackedBit     access  : 1;
554     PackedBit     res     : 4;
555 #else
556     PackedBit     res     : 4;
557     PackedBit     access  : 1;
558     PackedBit     except  : 1;
559     PackedBit     rsvd    : 1;
560     PackedBit     full    : 1;
561 #endif
562     unsigned char res1;
563     unsigned char asc;
564     unsigned char ascq;
565 #ifdef LITTLE_ENDIAN_BITFIELDS        
566     PackedBit     lun     : 3;
567     PackedBit     rsvd1   : 1;
568     PackedBit     luvalid : 1;
569     PackedBit     idvalid : 1;
570     PackedBit     rsvd2   : 1;
571     PackedBit     notbus  : 1;
572 #else
573     PackedBit     notbus  : 1;
574     PackedBit     rsvd2   : 1;
575     PackedBit     idvalid : 1;
576     PackedBit     luvalid : 1;
577     PackedBit     rsvd1   : 1;
578     PackedBit     lun     : 3;
579 #endif
580     unsigned char scsi;
581     unsigned char res2;
582 #ifdef LITTLE_ENDIAN_BITFIELDS        
583     PackedBit     res3    : 6;
584     PackedBit     invert  : 1;
585     PackedBit     svalid  : 1;
586 #else
587     PackedBit     svalid  : 1;
588     PackedBit     invert  : 1;
589     PackedBit     res3    : 6;
590 #endif
591     unsigned char source[2];
592   unsigned char pvoltag[36];
593     unsigned char res4[42];
594 } DataTransferElementDescriptor_T;
595
596 /* ======================================================= */
597 /* SCSIInquiry_T */
598 /* ======================================================= */
599 typedef struct
600 {
601 #ifdef LITTLE_ENDIAN_BITFIELDS
602     PackedBit     type : 5;
603     PackedBit     qualifier : 3;
604
605     PackedBit     type_modifier : 7;
606     PackedBit     removable : 1;
607
608     PackedBit     ansi_version : 3;
609     PackedBit     ecma_version : 3;
610     PackedBit     iso_version : 2;
611
612     PackedBit     data_format : 4;
613     PackedBit     res3_54 : 2;
614     PackedBit     termiop : 1;
615     PackedBit     aenc : 1;
616 #else
617     PackedBit     qualifier : 3;
618     PackedBit     type : 5;
619   
620     PackedBit     removable : 1;
621     PackedBit     type_modifier : 7;
622   
623     PackedBit     iso_version : 2;
624     PackedBit     ecma_version : 3;
625     PackedBit     ansi_version : 3;
626   
627     PackedBit     aenc : 1;
628     PackedBit     termiop : 1;
629     PackedBit     res3_54 : 2;
630     PackedBit     data_format : 4;
631 #endif
632   
633     unsigned char add_len;
634   
635     unsigned char  res2;
636     unsigned char res3;
637   
638 #ifdef LITTLE_ENDIAN_BITFIELDS
639     PackedBit     softreset : 1;
640     PackedBit     cmdque : 1;
641     PackedBit     res7_2 : 1;
642     PackedBit     linked  : 1;
643     PackedBit     sync : 1;
644     PackedBit     wbus16 : 1;
645     PackedBit     wbus32 : 1;
646     PackedBit     reladr : 1;
647 #else
648     PackedBit     reladr : 1;
649     PackedBit     wbus32 : 1;
650     PackedBit     wbus16 : 1;
651     PackedBit     sync : 1;
652     PackedBit     linked  : 1;
653     PackedBit     res7_2 : 1;
654     PackedBit     cmdque : 1;
655     PackedBit     softreset : 1;
656 #endif
657     char vendor_info[8];
658     char prod_ident[16];
659     char prod_version[4];
660     char vendor_specific[20];
661 } SCSIInquiry_T;
662
663 /* ======================================================= */
664 /* ModeSenseHeader_T */
665 /* ======================================================= */
666 typedef struct
667 {
668     unsigned char DataLength;
669     unsigned char MediumType;
670 #ifdef LITTLE_ENDIAN_BITFIELDS
671     PackedBit Speed:4;
672     PackedBit BufferedMode:3;
673     PackedBit WP:1;
674 #else
675     PackedBit WP:1;
676     PackedBit BufferedMode:3;
677     PackedBit Speed:4;
678 #endif
679     unsigned char BlockDescLength;
680 } ModeSenseHeader_T;
681 /* ======================================================= */
682 /* ModeBlockDescriptor_T */
683 /* ======================================================= */
684 typedef struct 
685 {
686     unsigned char DensityCode;
687     unsigned char NumberOfBlocks[3];
688     unsigned char Reserved;
689     unsigned char BlockLength[3];
690 } ModeBlockDescriptor_T;
691 /* ======================================================= */
692 /* LogSenseHeader_T */
693 /* ======================================================= */
694 typedef struct 
695 {
696 #ifdef LITTLE_ENDIAN_BITFIELDS
697     PackedBit PageCode:6;
698     PackedBit Reserved:2;
699 #else
700     PackedBit Reserved:2;
701     PackedBit PageCode:6;
702 #endif
703     unsigned char Reserved1;
704     unsigned char PageLength[2];
705 } LogSenseHeader_T ;
706 /* ======================================================= */
707 /* LogParameters_T */
708 /* ======================================================= */
709 typedef struct
710 {
711     unsigned char ParameterCode[2];
712 #ifdef LITTLE_ENDIAN_BITFIELDS
713     PackedBit LP:1;
714     PackedBit RSCD:1;
715     PackedBit TMC:1;
716     PackedBit ETC:1;
717     PackedBit TSD:1;
718     PackedBit DS:1;
719     PackedBit DU:1;
720 #else
721     PackedBit DU:1;
722     PackedBit DS:1;
723     PackedBit TSD:1;
724     PackedBit ETC:1;
725     PackedBit TMC:1;
726     PackedBit RSCD:1;
727     PackedBit LP:1;
728 #endif
729     char ParameterLength;
730 } LogParameter_T;
731 /*
732  * Pages returned by the MODE_SENSE command
733  */
734 typedef struct {
735     unsigned char SenseDataLength;
736     char res[3];
737 } ParameterListHeader_T;
738 /* ======================================================= */
739 /* ReadWriteErrorRecoveryPage_T */
740 /* ======================================================= */
741 typedef struct 
742 {
743 #ifdef LITTLE_ENDIAN_BITFIELDS
744     PackedBit PageCode : 6;
745     PackedBit res      : 1;
746     PackedBit PS       : 1;
747 #else
748     PackedBit PS       : 1;
749     PackedBit res      : 1;
750     PackedBit PageCode : 6;
751 #endif
752     unsigned char ParameterListLength;
753 #ifdef LITTLE_ENDIAN_BITFIELDS
754     PackedBit dcr  :1;  /* Disable ECC Correction */
755     PackedBit dte  :1;  /* Disable Transfer on Error */
756     PackedBit per  :1;  /* Enable Post  Error reporting */
757     PackedBit eer  :1;  /* Enable early recovery */
758     PackedBit res1 :1;
759     PackedBit tb   :1;  /* Transfer block (when not fully recovered) */
760     PackedBit res2 :1;
761     PackedBit res3 :1;
762 #else
763     PackedBit res3 :1;
764     PackedBit res2 :1;
765     PackedBit tb   :1;
766     PackedBit res1 :1;
767     PackedBit eer  :1;
768     PackedBit per  :1;
769     PackedBit dte  :1;
770     PackedBit dcr  :1;
771 #endif
772     unsigned char ReadRetryCount;
773     unsigned char res4[4];
774     unsigned char WriteRetryCount;
775     unsigned char res5[3];
776 } ReadWriteErrorRecoveryPage_T; 
777 /* ======================================================= */
778 /* EDisconnectReconnectPage_T */
779 /* ======================================================= */
780 typedef struct 
781 {
782 #ifdef LITTLE_ENDIAN_BITFIELDS
783     PackedBit PageCode : 6;
784     PackedBit RSVD     : 1;
785     PackedBit PS       : 1;
786 #else
787     PackedBit PS       : 1;
788     PackedBit RSVD     : 1;
789     PackedBit PageCode : 6;
790 #endif
791
792     unsigned char BufferFullRatio;
793     unsigned char BufferEmptyRatio;
794     unsigned char BusInactivityLimit[2];
795     unsigned char DisconnectTimeLimit[2];
796     unsigned char ConnectTimeLimit[2];
797     unsigned char MaximumBurstSize[2];
798
799 #ifdef LITTLE_ENDIAN_BITFIELDS
800     PackedBit DTDC :2;
801     PackedBit res  :6;
802 #else
803     PackedBit res  :6;
804     PackedBit DTDC :2;
805 #endif
806     unsigned char res1[3];
807 } DisconnectReconnectPage_T;
808
809 /* ======================================================= */
810 /* EAAPage_T */
811 /* ======================================================= */
812 typedef struct 
813 {
814 #ifdef LITTLE_ENDIAN_BITFIELDS
815     PackedBit PageCode : 6;
816     PackedBit RSVD     : 1;
817     PackedBit PS       : 1;
818 #else
819     PackedBit PS       : 1;
820     PackedBit RSVD     : 1;
821     PackedBit PageCode : 6;
822 #endif
823     unsigned char ParameterListLength;
824     unsigned char MediumTransportElementAddress[2];
825     unsigned char NoMediumTransportElements[2];
826     unsigned char FirstStorageElementAddress[2];
827     unsigned char NoStorageElements[2];
828     unsigned char FirstImportExportElementAddress[2];
829     unsigned char NoImportExportElements[2];
830     unsigned char FirstDataTransferElementAddress[2];
831     unsigned char NoDataTransferElements[2];
832     unsigned char res[2];
833 } EAAPage_T;    
834 /* ======================================================= */
835 /* TransPortGeometryDescriptorPage_T */
836 /* ======================================================= */
837 typedef struct {
838 #ifdef LITTLE_ENDIAN_BITFIELDS
839     PackedBit PageCode : 6;
840     PackedBit RSVD     : 1;
841     PackedBit PS       : 1;
842 #else
843     PackedBit PS       : 1;
844     PackedBit RSVD     : 1;
845     PackedBit PageCode : 6;
846 #endif
847     unsigned char ParameterListLength;
848 #ifdef LITTLE_ENDIAN_BITFIELDS
849     PackedBit Rotate    : 1;
850     PackedBit res       : 7;
851 #else
852     PackedBit res       : 7;
853     PackedBit Rotate    : 1;
854 #endif
855     unsigned char MemberNumber;
856 } TransportGeometryDescriptorPage_T;  
857 /* ======================================================= */
858 /* DeviceCapabilitiesPage_T */
859 /* ======================================================= */
860 typedef struct
861 {
862 #ifdef LITTLE_ENDIAN_BITFIELDS
863     PackedBit PageCode : 6;
864     PackedBit RSVD     : 1;
865     PackedBit PS       : 1;
866 #else
867     PackedBit PS       : 1;
868     PackedBit RSVD     : 1;
869     PackedBit PageCode : 6;
870 #endif
871     unsigned char ParameterLength;
872 #ifdef LITTLE_ENDIAN_BITFIELDS
873     PackedBit MT        : 1;
874     PackedBit ST        : 1;
875     PackedBit IE        : 1;
876     PackedBit DT        : 1;
877     PackedBit res1      : 4;
878 #else
879     PackedBit res1      : 4;
880     PackedBit DT        : 1;
881     PackedBit IE        : 1;
882     PackedBit ST        : 1;
883     PackedBit MT        : 1;
884 #endif
885     unsigned char res;
886 #ifdef LITTLE_ENDIAN_BITFIELDS
887     PackedBit MT2MT     : 1;
888     PackedBit MT2ST     : 1;
889     PackedBit MT2IE     : 1;
890     PackedBit MT2DT     : 1;
891     PackedBit res2      : 4;
892 #else
893     PackedBit res2      : 4;
894     PackedBit MT2DT     : 1;
895     PackedBit MT2IE     : 1;
896     PackedBit MT2ST     : 1;
897     PackedBit MT2MT     : 1;
898 #endif
899
900 #ifdef LITTLE_ENDIAN_BITFIELDS
901     PackedBit ST2MT     : 1;
902     PackedBit ST2ST     : 1;
903     PackedBit ST2IE     : 1;
904     PackedBit ST2DT     : 1;
905     PackedBit res3      : 4;
906 #else
907     PackedBit res3      : 4;
908     PackedBit ST2DT     : 1;
909     PackedBit ST2IE     : 1;
910     PackedBit ST2ST     : 1;
911     PackedBit ST2MT     : 1;
912 #endif
913
914 #ifdef LITTLE_ENDIAN_BITFIELDS
915     PackedBit IE2MT     : 1;
916     PackedBit IE2ST     : 1;
917     PackedBit IE2IE     : 1;
918     PackedBit IE2DT     : 1;
919     PackedBit res4      : 4;
920 #else
921     PackedBit res4      : 4;
922     PackedBit IE2DT     : 1;
923     PackedBit IE2IE     : 1;
924     PackedBit IE2ST     : 1;
925     PackedBit IE2MT     : 1;
926 #endif
927
928 #ifdef LITTLE_ENDIAN_BITFIELDS
929     PackedBit DT2MT     : 1;
930     PackedBit DT2ST     : 1;
931     PackedBit DT2IE     : 1;
932     PackedBit DT2DT     : 1;
933     PackedBit res5      : 4;
934 #else
935     PackedBit res5      : 4;
936     PackedBit DT2DT     : 1;
937     PackedBit DT2IE     : 1;
938     PackedBit DT2ST     : 1;
939     PackedBit DT2MT     : 1;
940 #endif
941     unsigned char res0819[12];
942 } DeviceCapabilitiesPage_T;  
943 /* ======================================================= */
944 /* ModePageEXB10hLCD_T */
945 /* ======================================================= */
946 typedef struct ModePageEXB10hLCD
947 {
948   unsigned char PageCode;
949   unsigned char ParameterListLength;
950
951 #ifdef LITTLE_ENDIAN_BITFIELDS
952   PackedBit WriteLine4 : 1;
953   PackedBit WriteLine3 : 1;
954   PackedBit WriteLine2 : 1;
955   PackedBit WriteLine1 : 1;
956   PackedBit res        : 4;
957 #else
958   PackedBit res        : 4;
959   PackedBit WriteLine1 : 1;
960   PackedBit WriteLine2 : 1;
961   PackedBit WriteLine3 : 1;
962   PackedBit WriteLine4 : 1;
963 #endif
964   unsigned char reserved;
965   unsigned char line1[20];
966   unsigned char line2[20];
967   unsigned char line3[20];
968   unsigned char line4[20];
969 } ModePageEXB10hLCD_T;
970 /* ======================================================= */
971 /* ModePageEXBBaudRatePage_T */
972 /* ======================================================= */
973 typedef struct ModePageEXBBaudRatePage
974 {
975   unsigned char PageCode;
976   unsigned char ParameterListLength;
977   unsigned char BaudRate[2];
978 } ModePageEXBBaudRatePage_T;
979 /* ======================================================= */
980 /* ModePageEXB120VendorUnique_T */
981 /* ======================================================= */
982 typedef struct ModePageEXB120VendorUnique
983 {
984 #ifdef  LITTLE_ENDIAN_BITFIELDS
985     PackedBit PageCode : 6;
986     PackedBit RSVD0    : 1;
987     PackedBit PS       : 1;
988 #else
989     PackedBit PS       : 1;
990     PackedBit RSVD0    : 1;
991     PackedBit PageCode : 6;
992 #endif
993     unsigned char ParameterListLength;
994 #ifdef LITTLE_ENDIAN_BITFIELDS
995     PackedBit MDC  : 2;
996     PackedBit NRDC : 1;
997     PackedBit RSVD : 1;
998     PackedBit NBL  : 1;
999     PackedBit PRTY : 1;
1000     PackedBit UINT : 1;
1001     PackedBit AINT : 1;
1002 #else
1003     PackedBit AINT : 1;
1004     PackedBit UINT : 1;
1005     PackedBit PRTY : 1;
1006     PackedBit NBL  : 1;
1007     PackedBit RSVD : 1;
1008     PackedBit NRDC : 1;
1009     PackedBit MDC  : 2;
1010 #endif
1011     unsigned char MaxParityRetries;
1012     unsigned char DisplayMessage[60];
1013 } ModePageEXB120VendorUnique_T;
1014 /* ======================================================= */
1015 /* ModePageTreeFrogVendorUnique_T */
1016 /* ======================================================= */
1017 typedef struct ModePageTreeFrogVendorUnique
1018 {
1019 #ifdef  LITTLE_ENDIAN_BITFIELDS
1020     PackedBit PageCode : 6;
1021     PackedBit res0     : 1;
1022     PackedBit PS       : 1;
1023 #else
1024     PackedBit PS       : 1;
1025     PackedBit res0     : 1;
1026     PackedBit PageCode : 6;
1027 #endif
1028     unsigned char ParameterListLength;
1029 #ifdef LITTLE_ENDIAN_BITFIELDS
1030     PackedBit EBARCO  : 1;
1031     PackedBit CHKSUM  : 1;
1032     PackedBit res2    : 6;
1033 #else
1034     PackedBit res2    : 6;
1035     PackedBit CHKSUM  : 1;
1036     PackedBit EBARCO  : 1;
1037 #endif
1038     unsigned char res3;
1039     unsigned char res4;
1040     unsigned char res5;
1041     unsigned char res6;
1042     unsigned char res7;
1043     unsigned char res8;
1044     unsigned char res9;
1045 } ModePageTreeFrogVendorUnique_T;
1046 /* ======================================================= */
1047 /* ElementInfo_T */
1048 /* ======================================================= */
1049 typedef struct ElementInfo
1050 {
1051     int type;       /* CHANGER - 1, STORAGE - 2, TAPE - 4 */
1052     int address;    /* Adress of this Element */
1053     int from;       /* From where did it come */
1054     char status;    /* F -> Full, E -> Empty */
1055     char VolTag[TAG_SIZE+1]; /* Label Info if Barcode reader exsist */
1056     int ASC;        /* Additional Sense Code from read element status */
1057     int ASCQ;      /* */
1058     unsigned char scsi; /* if DTE, which scsi address */
1059
1060   PackedBit svalid : 1;
1061   PackedBit invert : 1;
1062   PackedBit full   : 1;
1063   PackedBit impexp : 1;
1064   PackedBit except : 1;
1065   PackedBit access : 1;
1066   PackedBit inenab : 1;
1067   PackedBit exenab : 1;
1068
1069 } ElementInfo_T;
1070
1071
1072
1073 typedef struct {
1074     char *ident;                  /* Name of the device from inquiry */
1075     char *type;                   /* Device Type, tape|robot */
1076     int (*function_move)(int, int, int);
1077     int (*function_status)(int, int);
1078     int (*function_reset_status)(int);
1079     int (*function_free)();
1080     int (*function_eject)(char *, int);
1081     int (*function_clean)(char *);
1082     int (*function_rewind)(int);
1083     int (*function_barcode)(int);
1084     int (*function_search)();
1085     int (*function_error)(int, int, unsigned char, unsigned char, unsigned char, char *);
1086 } ChangerCMD_T ;
1087
1088 typedef struct {
1089     unsigned char command;        /* The SCSI command byte */
1090     int length;                   /* How long */
1091     char *name;                   /* Name of the command */
1092 } SC_COM_T;
1093
1094 typedef struct OpenFiles {
1095     int fd;                       /* The filedescriptor */
1096 #ifdef HAVE_CAM_LIKE_SCSI
1097     struct cam_device *curdev;
1098 #endif
1099   unsigned char avail;          /* Is this device available */
1100   unsigned char devopen;        /* Is the device open */
1101   unsigned char inqdone;        /* Did we try to get device infos, was an open sucessfull */
1102   unsigned char SCSI;           /* Can we send SCSI commands */
1103   int flags;                    /* Can be used for some flags ... */
1104   char *dev;                    /* The device which is used */
1105   char *type;                   /* Type of device, tape/changer */
1106   char *ConfigName;             /* The name in the config */
1107   char ident[17];               /* The identifier from the inquiry command */
1108   ChangerCMD_T *functions;      /* Pointer to the function array for this device */
1109   SCSIInquiry_T *inquiry;       /* The result from the Inquiry */
1110 } OpenFiles_T;
1111
1112 typedef struct LogPageDecode {
1113     int LogPage;
1114     char *ident;
1115     void (*decode)(LogParameter_T *, int);
1116 } LogPageDecode_T;
1117
1118 typedef struct {
1119    char *ident;      /* Ident as returned from the inquiry */
1120    char *vendor;     /* Vendor as returned from the inquiry */
1121    int type;         /* removable .... */
1122    int sense;        /* Sense key as returned from the device */
1123    int asc;          /* ASC as set in the sense struct */
1124    int ascq;         /* ASCQ as set in the sense struct */
1125    int  ret;         /* What we think that we should return on this conditon */
1126    char text[80];    /* A short text describing this condition */
1127 } SenseType_T;                                                                                    
1128
1129 /* ======================================================= */
1130 /* Funktion-Declaration */
1131 /* ======================================================= */
1132 int SCSI_OpenDevice(int );
1133 int OpenDevice(int ,char *DeviceName, char *ConfigName, char *ident);
1134
1135 int SCSI_CloseDevice(int DeviceFD); 
1136 int CloseDevice(int ); 
1137 int Tape_Eject(int);
1138 int Tape_Status(int);
1139 void DumpSense();
1140 int Sense2Action(char *ident, unsigned char type, unsigned char ignsense, unsigned char sense, unsigned
1141 char asc, unsigned char ascq, char **text) ;
1142
1143 int SCSI_ExecuteCommand(int DeviceFD,
1144                         Direction_T Direction,
1145                         CDB_T CDB,
1146                         int CDB_Length,
1147                         void *DataBuffer,
1148                         int DataBufferLength,
1149                         char *RequestSense,
1150                         int RequestSenseLength);
1151
1152 int Tape_Ioctl( int DeviceFD, int command);
1153 void ChangerStatus(char * option, char * labelfile, int HasBarCode, char *changer_file, char *changer_dev, char *tape_device);
1154
1155 int SCSI_Inquiry(int, SCSIInquiry_T *, unsigned char);
1156 int PrintInquiry(SCSIInquiry_T *);
1157 int DecodeSCSI(CDB_T CDB, char *string);
1158
1159 int RequestSense P((int fd, ExtendedRequestSense_T *s, int ClearErrorCounters));
1160 int DecodeSense P((RequestSense_T *sense, char *pstring, FILE *out));
1161 int DecodeExtSense P((ExtendedRequestSense_T *sense, char *pstring, FILE *out));
1162
1163 void ChgExit(char *, char *, int);
1164
1165 void ChangerReplay(char *option);
1166 void ChangerStatus(char * option, char * labelfile, int HasBarCode, char *changer_file, char *changer_dev, char *tape_device);
1167 int BarCode(int fd);
1168 int MapBarCode(char *labelfile, MBC_T *);
1169
1170 int Tape_Ready(int fd, int wait_time);
1171
1172 void Inventory(char *labelfile, int drive, int eject, int start, int stop, int clean);
1173 void ChangerDriverVersion();
1174 void PrintConf();
1175 int LogSense(int fd);
1176 int ScanBus(int print);
1177 void DebugPrint(int level, int section, char * fmt, ...);
1178 int DecodeSense(RequestSense_T *sense, char *pstring, FILE *out);
1179 void SCSI_OS_Version();
1180 /*
1181  * Local variables:
1182  * indent-tabs-mode: nil
1183  * c-file-style: gnu
1184  * End:
1185  */