2 static char rcsid[] = "$Id: scsi-changer-driver.c,v 1.1.2.27.2.7.2.10 2003/01/26 19:20:56 martinea Exp $";
5 * Interface to control a tape robot/library connected to the SCSI bus
7 * Copyright (c) Thomas Hepper th@ant.han.de
46 #include "scsi-defs.h"
50 extern int TapeEject(int DeviceFD);
52 extern FILE *debug_file;
54 int PrintInquiry(SCSIInquiry_T *);
55 int GenericElementStatus(int DeviceFD, int InitStatus);
56 int SDXElementStatus(int DeviceFD, int InitStatus);
57 int DLT448ElementStatus(int DeviceFD, int InitStatus);
58 ElementInfo_T *LookupElement(int addr);
59 int GenericResetStatus(int DeviceFD);
60 int RequestSense(int, ExtendedRequestSense_T *, int );
61 void dump_hex(char *, int, int, int);
62 void TerminateString(char *string, int length);
63 void ChgExit(char *, char *, int);
66 int SenseHandler(int fd, unsigned char flag, unsigned char SenseKey, unsigned char AdditionalSenseCode, unsigned char AdditionalSenseCodeQualifier, char *buffer);
68 int SCSI_AlignElements(int DeviceFD, int MTE, int DTE, int STE);
71 int GenericMove(int, int, int);
72 int SDXMove(int, int, int);
73 int CheckMove(ElementInfo_T *from, ElementInfo_T *to);
74 int GenericRewind(int);
75 /* int GenericStatus(); */
77 int TapeStatus(); /* Is the tape loaded ? */
78 int DLT4000Eject(char *Device, int type);
79 int GenericEject(char *Device, int type);
80 int GenericClean(char *Device); /* Does the tape need a clean */
81 int GenericBarCode(int DeviceFD); /* Do we have Barcode reader support */
82 int NoBarCode(int DeviceFD);
85 void Inventory(char *labelfile, int drive, int eject, int start, int stop, int clean);
87 int TreeFrogBarCode(int DeviceFD);
88 int EXB_BarCode(int DeviceFD);
89 int GenericSenseHandler(int fd, int flags, unsigned char SenseKey, unsigned char AdditionalSenseCode, unsigned char AdditionalSenseCodeQualifier, char *);
91 ElementInfo_T *LookupElement(int address);
92 int eject_tape(char *tapedev, int type);
93 int unload(int fd, int drive, int slot);
94 int load(int fd, int drive, int slot);
95 int GetElementStatus(int DeviceFD);
100 void WriteErrorCountersPage(LogParameter_T *, int);
101 void ReadErrorCountersPage(LogParameter_T *, int);
102 void C1553APage30(LogParameter_T *, int);
103 void C1553APage37(LogParameter_T *, int);
104 void EXB85058HEPage39(LogParameter_T *, int);
105 void EXB85058HEPage3c(LogParameter_T *, int);
106 int Decode(LogParameter_T *, int *);
107 int DecodeModeSense(char *buffer, int offset, char *pstring, char block, FILE *out);
109 int SCSI_Run(int DeviceFD,
110 Direction_T Direction,
114 int DataBufferLength,
116 int RequestSenseLength);
118 int SCSI_Move(int DeviceFD, unsigned char chm, int from, int to);
119 int SCSI_LoadUnload(int DeviceFD, RequestSense_T *pRequestSense, unsigned char byte1, unsigned char load);
120 int SCSI_TestUnitReady(int, RequestSense_T *);
121 int SCSI_ModeSense(int DeviceFD, char *buffer, u_char size, u_char byte1, u_char byte2);
122 int SCSI_ModeSelect(int DeviceFD,
124 unsigned char length,
129 int SCSI_ReadElementStatus(int DeviceFD,
132 unsigned char VolTag,
140 SC_COM_T SCSICommand[] = {
152 "INITIALIZE ELEMENT STATUS"},
179 "READ ELEMENT STATUS"},
183 ChangerCMD_T ChangerIO[] = {
185 "Generic driver changer [generic_changer]",
187 GenericElementStatus,
195 GenericSenseHandler},
198 "HP Auto Loader [C1553A]",
200 GenericElementStatus,
208 GenericSenseHandler},
209 /* Exabyte Devices */
211 "Exabyte Robot [EXB-10e]",
213 GenericElementStatus,
221 GenericSenseHandler},
223 "Exabyte Robot [EXB-120]",
225 GenericElementStatus,
233 GenericSenseHandler},
235 "Exabyte Robot [EXB-210]",
237 GenericElementStatus,
245 GenericSenseHandler},
247 "Exabyte Tape [EXB-85058HE-0000]",
257 GenericSenseHandler},
258 /* Tandberg Devices */
260 "Tandberg Robot (TDS 1420)",
262 GenericElementStatus,
270 GenericSenseHandler},
273 "ADIC VLS DLT Library [VLS DLT]",
275 GenericElementStatus,
283 GenericSenseHandler},
285 "ADIC VLS DLT Library [VLS SDX]",
295 GenericSenseHandler},
297 "ADIC FastStor DLT Library [FastStor DLT]",
307 GenericSenseHandler},
309 "ADIC DLT 448 [Scalar DLT 448]",
319 GenericSenseHandler},
320 /* Sepctra Logic Devices */
322 "Spectra Logic TreeFrog[215]",
324 GenericElementStatus,
332 GenericSenseHandler},
335 "Breece Hill Quad 7",
337 GenericElementStatus,
345 GenericSenseHandler},
346 /* Quantum Devices */
350 GenericElementStatus,
358 GenericSenseHandler},
360 * And now the tape devices
362 /* The generic handler if nothing matches */
364 "Generic driver tape [generic_tape]",
366 GenericElementStatus,
374 GenericSenseHandler},
376 "DLT Tape [DLT8000]",
386 GenericSenseHandler},
388 "DLT Tape [DLT7000]",
398 GenericSenseHandler},
400 "DLT Tape [DLT4000]",
410 GenericSenseHandler},
411 {NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
415 LogPageDecode_T DecodePages[] = {
418 WriteErrorCountersPage},
421 ReadErrorCountersPage},
430 WriteErrorCountersPage},
433 ReadErrorCountersPage},
444 int ElementStatusValid = 0; /* Set if the READ ELEMENT STATUS was OK, an no error is pending */
445 int LibModeSenseValid = 0; /* Set if we did an scussefull MODE SENSE */
448 /* Pointer to MODE SENSE Pages */
449 char *pModePage = NULL;
450 EAAPage_T *pEAAPage = NULL;
451 DeviceCapabilitiesPage_T *pDeviceCapabilitiesPage = NULL;
452 char *pVendorUnique = NULL;
455 * New way, every element type has its on array
456 * which is dynamic allocated by the ElementStatus function,
458 ElementInfo_T *pMTE = NULL; /*Medium Transport Element */
459 ElementInfo_T *pSTE = NULL; /*Storage Element */
460 ElementInfo_T *pIEE = NULL; /*Import Export Element */
461 ElementInfo_T *pDTE = NULL; /*Data Transfer Element */
462 int MTE = 0; /*Counter for the above element types */
467 char *chgscsi_datestamp = NULL; /* Result pointer for tape_rdlabel */
468 char *chgscsi_label = NULL; /* Result pointer for tape_rdlabel */
469 char *chgscsi_result = NULL; /* Needed for the result string of MapBarCode */
472 * First all functions which are called from extern
477 * Print the scsi-changer-driver version
480 void ChangerDriverVersion()
482 DebugPrint(DEBUG_ERROR, SECTION_INFO, "scsi-changer-driver: %s\n",rcsid);
487 * Try to generate an template which can be used as an example for the config file
492 extern OpenFiles_T *pDev;
496 printf("# Please replace every ??? with the correct parameter. It is not possible\n");
497 printf("# to guess everything :-)\n");
498 printf("# If the option is not needed, cleanmax for example if you have no cleaning\n");
499 printf("# tape remove the line.\n");
501 printf("number_configs 1 # Number of configs, you can have more than 1 config\n");
502 printf(" # if you have for example more than one drive, or you\n");
503 printf(" # to split your lib to use different dump levels\n");
505 printf("emubarcode 1 # If you drive has no barcode reader this will try\n");
506 printf(" # keep an inventory of your tapes to find them faster\n");
508 printf("havebarcode 0 # Set this to 1 if you have an library with an installed\n");
509 printf(" # barcode reader\n");
511 printf("debuglevel 0:0 # For debuging, see the docs /docs/TAPE-CHANGER\n");
513 printf("eject ??? # set this to 1 if your drive needs an eject before move\n");
515 printf("sleep ??? # How long to wait after an eject command before moving\n");
516 printf(" # the tape\n");
519 for (count = 0; count < CHG_MAXDEV ; count++)
523 if (pDev[count].inquiry != NULL && pDev[count].inquiry->type == TYPE_CHANGER)
525 printf("changerdev %s # This is the device to communicate with the robot\n", pDev[count].dev);
532 * Did we reach the end of the list ?
533 * If no we found an changer and now we try to
534 * get the element status for the count of slots
536 if (count < CHG_MAXDEV)
538 pDev[count].functions->function_status(count, 1);
540 printf("changerdev ??? # Ups nothing found. Please check the docs\n");
544 printf(" # Here now comes the config for the first tape\n");
545 printf("config 0 # This value is the one which is used in the amanda\n");
546 printf(" # config file to tell the chg-scsi programm which tape\n");
547 printf(" # and which slots to use\n");
549 printf("cleancart ??? # The slot where the cleaning tape is located\n");
550 printf(" # remove it if you have no cleaning tape\n");
552 printf("drivenum 0 # Which tape drive to use if there are more than one drive\n");
554 printf("dev ??? # Which is the raw device to read/write data from the tape\n");
555 printf(" # It is important to use the non rewinding tape, like\n");
556 printf(" # /dev/nrst0 on linux, /dev/nrsa0 on BSD ....\n");
560 * OK now lets see if we have an direct SCSI channel
562 * If not thats not a problem
564 for (count = 0; count < CHG_MAXDEV; count++)
568 if (pDev[count].inquiry != NULL && pDev[count].inquiry->type == TYPE_TAPE)
570 printf("scsitapedev %s # This is the device to communicate with the tape\n", pDev[count].dev);
571 printf(" # to get some device stats, not so importatn, and\n");
572 printf(" # if you run in problems delete it complete\n");
582 printf("startuse 0 # Which is the first slot to use\n");
584 printf("enduse %d # Which is the last slot to use\n", STE);
586 printf("startuse ??? # Which is the first slot to use\n");
588 printf("enduse ??? # Which is the last slot to use\n");
590 printf(" # decrement this value by 1 if you have an\n");
591 printf(" # cleaning tape in the last slot\n");
594 cwd = getcwd(NULL, 0);
596 printf("statfile %s/tape0-slot #\n",cwd);
597 printf("cleanfile %s/tape0-clean #\n", cwd);
598 printf("usagecount %s/tape0-totaltime #\n", cwd);
599 printf("tapestatus %s/tape0-tapestatus #\n", cwd);
600 printf("labelfile %s/labelfile #\n", cwd);
606 * Try to create a list of tapes and labels which are in the current
607 * magazin. The drive must be empty !!
609 * labelfile -> file name of the db
610 * drive -> which drive should we use
611 * eject -> the tape device needs an eject before move
612 * start -> start at slot start
613 * stop -> stop at slot stop
614 * clean -> if we have an cleaning tape than this is the slot number of it
621 * Check if the tape/changer is ready for the next move
622 * If an tape is loaded unload it and do initialize element status to
623 * get all labels if an bar code reader is installed
625 void Inventory(char *labelfile, int drive, int eject, int start, int stop, int clean)
627 extern OpenFiles_T *pDev;
629 char *datestamp = malloc(1); /* stupid, but tapefd_rdlabel does an free at the begining ... */
630 char *label = malloc(1); /* the same here ..... */
631 char *result; /* Used to store the result of MapBarCode */
632 int barcode; /* cache the result from the BarCode function */
633 static int inv_done = 0; /* Inventory function called ?, marker to disable recursion */
634 MBC_T *pbarcoderes = malloc(sizeof(MBC_T)); /* Here we will pass the parameter to MapBarCode and get the result */
636 DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, "##### START Inventory\n");
637 memset(pbarcoderes, 0 , sizeof(MBC_T));
641 DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, "##### STOP inv_done -> %d Inventory\n",inv_done);
645 barcode = BarCode(INDEX_CHANGER);
647 pbarcoderes->action = RESET_VALID;
649 MapBarCode(labelfile,pbarcoderes);
652 * Check if an tape is loaded, if yes unload it
653 * and do an INIT ELEMENT STATUS
656 if (pDTE[0].status == 'F')
660 eject_tape("", eject);
662 (void)unload(INDEX_TAPE, 0, 0);
665 GenericResetStatus(INDEX_CHANGER);
667 for (x = 0; x < STE; x++)
675 * Load the tape, on error try the next
676 * error could be an empty slot for example
678 if (load(INDEX_CHANGER, drive, x ) != 0)
680 DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE, "Load drive(%d) from(%d) failed\n", drive, x);
685 * Wait until the tape is ready
687 Tape_Ready(INDEX_TAPECTL, 60);
689 SCSI_CloseDevice(INDEX_TAPE);
691 if ((result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &datestamp, &label)) == NULL)
693 pbarcoderes->action = UPDATE_SLOT;
694 strcpy(pbarcoderes->data.voltag, label);
695 pbarcoderes->data.slot = x;
696 pbarcoderes->data.from = 0;
697 pbarcoderes->data.LoadCount = 1;
698 if (BarCode(INDEX_CHANGER) == 1)
700 strcpy(pbarcoderes->data.barcode, pDTE[drive].VolTag);
701 MapBarCode(labelfile, pbarcoderes);
703 MapBarCode(labelfile, pbarcoderes);
706 DebugPrint(DEBUG_ERROR,SECTION_MAP_BARCODE, "Read label failed\n");
711 eject_tape("", eject);
714 (void)unload(INDEX_TAPE, drive, x);
716 DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, "##### STOP Inventory\n");
720 * Check if the slot ist empty
721 * slot -> slot number to check
723 int isempty(int fd, int slot)
725 extern OpenFiles_T *pDev;
726 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### START isempty\n");
728 if (ElementStatusValid == 0)
730 if ( pDev[fd].functions->function_status(fd, 1) != 0)
732 DebugPrint(DEBUG_ERROR,SECTION_TAPE,"##### STOP isempty [-1]\n");
737 if (pSTE[slot].status == 'E')
739 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP isempty [1]\n");
742 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP isempty [0]\n");
746 int get_clean_state(char *tapedev)
748 extern OpenFiles_T *pDev;
749 /* Return 1 if cleaning is needed */
752 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### START get_clean_state\n");
754 if (pDev[INDEX_TAPECTL].SCSI == 0)
756 DebugPrint(DEBUG_ERROR,SECTION_TAPE,"##### STOP get_clean_state [-1]\n");
759 ret=pDev[INDEX_TAPECTL].functions->function_clean(tapedev);
760 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP get_clean_state [%d]\n", ret);
766 * The parameter tapedev is not used.
767 * Type describes if we should force the SCSI eject if available
768 * normal eject is done with the ioctl
770 int eject_tape(char *tapedev, int type)
771 /* This function ejects the tape from the drive */
773 extern OpenFiles_T *pDev;
775 extern changer_t chg; /* Needed for the infos about emubarcode and labelfile */
777 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### START eject_tape\n");
780 * Try to read the label
782 if (pDev[INDEX_TAPE].avail == 1 && (chg.emubarcode == 1 || BarCode(INDEX_CHANGER)))
785 if (pDev[INDEX_TAPECTL].SCSI == 1 && pDev[INDEX_TAPECTL].avail) {
786 pDev[INDEX_TAPECTL].functions->function_rewind(INDEX_TAPECTL);
788 pDev[INDEX_TAPE].functions->function_rewind(INDEX_TAPE);
791 if (pDev[INDEX_TAPE].devopen == 1)
793 SCSI_CloseDevice(INDEX_TAPE);
796 chgscsi_result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &chgscsi_datestamp, &chgscsi_label);
799 if (pDev[INDEX_TAPECTL].SCSI == 1 && pDev[INDEX_TAPECTL].avail == 1 && type == 1)
801 ret=pDev[INDEX_TAPECTL].functions->function_eject(tapedev, type);
802 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP (SCSI)eject_tape [%d]\n", ret);
806 if (pDev[INDEX_TAPE].avail == 1)
808 ret=Tape_Ioctl(INDEX_TAPE, IOCTL_EJECT);
809 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP (ioctl)eject_tape [%d]\n", ret);
813 DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP eject_tape [-1]\n");
818 /* Find an empty slot, starting at start, ending at start+count */
819 int find_empty(int fd, int start, int count)
821 extern OpenFiles_T *pDev;
825 DebugPrint(DEBUG_INFO,SECTION_ELEMENT,"###### START find_empty\n");
827 if (ElementStatusValid == 0)
829 if ( pDev[fd].functions->function_status(fd , 1) != 0)
831 DebugPrint(DEBUG_ERROR,SECTION_ELEMENT,"###### END find_empty [%d]\n", -1);
848 DebugPrint(DEBUG_INFO,SECTION_ELEMENT,"start at %d, end at %d\n", start, end);
850 for (x = start; x < end; x++)
852 if (pSTE[x].status == 'E')
854 DebugPrint(DEBUG_INFO,SECTION_ELEMENT,"###### END find_empty [%d]\n", x);
858 DebugPrint(DEBUG_ERROR,SECTION_ELEMENT,"###### END find_empty [%d]\n", -1);
863 * See if the tape is loaded based on the information we
864 * got back from the ReadElementStatus
866 * -1 -> Error (Fatal)
867 * 0 -> drive is empty
868 * 1 -> drive is loaded
870 int drive_loaded(int fd, int drivenum)
872 extern OpenFiles_T *pDev;
874 DebugPrint(DEBUG_INFO,SECTION_TAPE,"###### START drive_loaded\n");
875 DebugPrint(DEBUG_INFO,SECTION_TAPE,"%-20s : fd %d drivenum %d \n", "drive_loaded", fd, drivenum);
878 if (ElementStatusValid == 0)
880 if (pDev[INDEX_CHANGER].functions->function_status(INDEX_CHANGER, 1) != 0)
882 DebugPrint(DEBUG_ERROR,SECTION_TAPE,"Fatal error\n");
887 if (pDTE[drivenum].status == 'E') {
888 DebugPrint(DEBUG_INFO,SECTION_TAPE,"###### STOP drive_loaded (empty)\n");
891 DebugPrint(DEBUG_INFO,SECTION_TAPE,"###### STOP drive_loaded (not empty)\n");
898 * unload the specified drive into the specified slot
902 * Check if the MTE is empty
904 int unload(int fd, int drive, int slot)
906 extern OpenFiles_T *pDev;
908 extern changer_t chg; /* Needed for the infos about emubarcode and labelfile */
909 extern int do_inventory;
910 MBC_T *pbarcoderes = malloc(sizeof(MBC_T));
912 DebugPrint(DEBUG_INFO, SECTION_TAPE,"###### START unload\n");
913 DebugPrint(DEBUG_INFO, SECTION_TAPE,"%-20s : fd %d, slot %d, drive %d \n", "unload", fd, slot, drive);
914 memset(pbarcoderes, 0, sizeof(MBC_T));
917 * If the Element Status is not valid try to
920 if (ElementStatusValid == 0)
922 if (pDev[INDEX_CHANGER].functions->function_status(INDEX_CHANGER , 1) != 0)
924 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"Element Status not valid, reset failed\n");
925 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP unload (-1)\n");
930 DebugPrint(DEBUG_INFO, SECTION_TAPE,"%-20s : unload drive %d[%d] slot %d[%d]\n", "unload",
937 * Unloading an empty tape unit makes no sense
938 * so return with an error
940 if (pDTE[drive].status == 'E')
942 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"unload : Drive %d address %d is empty\n", drive, pDTE[drive].address);
943 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP unload (-1)\n");
948 * If the destination slot is full
949 * try to find an enpty slot
951 if (pSTE[slot].status == 'F')
953 DebugPrint(DEBUG_INFO, SECTION_TAPE,"unload : Slot %d address %d is full\n", drive, pSTE[slot].address);
954 if ( ElementStatusValid == 0)
956 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "unload: Element Status not valid, can't find an empty slot\n");
960 slot = find_empty(fd, 0, 0);
963 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "unload: No Empty slot found\n");
966 DebugPrint(DEBUG_INFO, SECTION_TAPE,"unload : found empty one, try to unload to slot %d\n", slot);
972 * If eject is not set we must read the label info
977 if (pDev[INDEX_TAPE].avail == 1 && (chg.emubarcode == 1 || BarCode(INDEX_CHANGER)))
980 if (pDev[INDEX_TAPECTL].SCSI == 1 && pDev[INDEX_TAPECTL].avail) {
981 pDev[INDEX_TAPECTL].functions->function_rewind(INDEX_TAPECTL);
983 pDev[INDEX_TAPE].functions->function_rewind(INDEX_TAPE);
986 if (pDev[INDEX_TAPE].devopen == 1)
988 SCSI_CloseDevice(INDEX_TAPE);
991 chgscsi_result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &chgscsi_datestamp, &chgscsi_label);
998 ret = pDev[INDEX_CHANGER].functions->function_move(INDEX_CHANGER , pDTE[drive].address, pSTE[slot].address);
1003 if (pDev[INDEX_CHANGER].functions->function_status(INDEX_CHANGER , 1) != 0)
1005 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP unload (-1 update status failed)\n");
1010 * Did we get an error from tape_rdlabel
1011 * if no update the vol/label mapping
1012 * If chgscsi_label is NULL don't do it
1014 if (chgscsi_result == NULL && chgscsi_label != NULL && chg.labelfile != NULL)
1017 * OK this is only needed if we have emubarcode set
1018 * There we need an exact inventory to get the search function working
1019 * and returning correct results
1021 if (BarCode(INDEX_CHANGER) == 0 && chg.emubarcode == 1)
1024 * We got something, update the db
1025 * but before check if the db has as entry the slot
1026 * to where we placed the tape, if no force an inventory
1028 pbarcoderes->action = FIND_SLOT;
1029 strcpy(pbarcoderes->data.voltag, chgscsi_label);
1030 strcpy(pbarcoderes->data.barcode, pSTE[slot].VolTag );
1031 pbarcoderes->data.slot = 0;
1032 pbarcoderes->data.from = 0;
1033 pbarcoderes->data.LoadCount = 0;
1036 if ( MapBarCode(chg.labelfile, pbarcoderes) == 0) /* Nothing known about this, do an Inventory */
1040 if (slot != pbarcoderes->data.slot)
1042 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"Slot DB out of sync, slot %d != map %d",slot, pbarcoderes->data.slot);
1049 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP unload(0)\n");
1055 * load the media from the specified element (slot) into the
1056 * specified data transfer unit (drive)
1057 * fd -> pointer to the internal device structure pDev
1058 * driver -> which drive in the library
1059 * slot -> the slot number from where to load
1061 * return -> 0 = success
1064 int load(int fd, int drive, int slot)
1066 extern changer_t chg; /* Needed for the infos about emubarcode and labelfile */
1067 char *result = NULL; /* Needed for the result of tape_rdlabel */
1068 char *datestamp = NULL; /* Result pointer for tape_rdlabel */
1069 char *label = NULL; /* Result pointer for tape_rdlabel */
1071 extern OpenFiles_T *pDev;
1072 extern int do_inventory;
1073 MBC_T *pbarcoderes = malloc(sizeof(MBC_T));
1075 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"###### START load\n");
1076 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"%-20s : fd %d, drive %d, slot %d \n", "load", fd, drive, slot);
1077 memset(pbarcoderes, 0 , sizeof(MBC_T));
1079 if (ElementStatusValid == 0)
1081 if (pDev[fd].functions->function_status(fd, 1) != 0)
1083 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1)\n");
1084 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
1090 * Check if the requested slot is in the range of available slots
1091 * The library starts counting at 1, we start at 0, so if the request slot
1092 * is ge than the value we got from the ModeSense fail with an return value
1097 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : slot %d ge STE %d\n",slot, STE);
1098 ChgExit("load", "slot >= STE", FATAL);
1102 * And the same for the tape drives
1106 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : drive %d ge DTE %d\n",drive, DTE);
1107 ChgExit("load", "drive >= DTE", FATAL);
1110 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"load : load drive %d[%d] slot %d[%d]\n",drive,
1111 pDTE[drive].address,
1113 pSTE[slot].address);
1115 if (pDTE[drive].status == 'F')
1117 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : Drive %d address %d is full\n", drive, pDTE[drive].address);
1118 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
1122 if (pSTE[slot].status == 'E')
1124 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : Slot %d address %d is empty\n", drive, pSTE[slot].address);
1125 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
1129 ret = pDev[fd].functions->function_move(fd, pSTE[slot].address, pDTE[drive].address);
1134 if (pDev[fd].functions->function_status(fd, 1) != 0)
1136 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
1141 * Try to read the label
1142 * and update the label/slot database
1144 if (pDev[INDEX_TAPE].avail == 1 && (chg.emubarcode == 1 || BarCode(INDEX_CHANGER)))
1147 if (pDev[INDEX_TAPECTL].SCSI == 1 && pDev[INDEX_TAPECTL].avail) {
1148 pDev[INDEX_TAPECTL].functions->function_rewind(INDEX_TAPECTL);
1150 pDev[INDEX_TAPE].functions->function_rewind(INDEX_TAPE);
1153 if (pDev[INDEX_TAPE].devopen == 1)
1155 SCSI_CloseDevice(INDEX_TAPE);
1158 result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &datestamp, &label);
1162 * Did we get an error from tape_rdlabel
1163 * if no update the vol/label mapping
1165 if (result == NULL && chg.labelfile != NULL && label != NULL )
1168 * We got something, update the db
1169 * but before check if the db has as entry the slot
1170 * to where we placed the tape, if no force an inventory
1172 strcpy(pbarcoderes->data.voltag, label);
1173 pbarcoderes->data.slot = 0;
1174 pbarcoderes->data.from = 0;
1175 pbarcoderes->data.LoadCount = 0;
1179 * If we have an barcode reader we only do an update
1180 * If emubarcode is set we check if the
1181 * info in the DB is up to date, if no we set the do_inventory flag
1184 if (BarCode(INDEX_CHANGER) == 1 && chg.emubarcode == 0)
1186 pbarcoderes->action = UPDATE_SLOT;
1187 strcpy(pbarcoderes->data.barcode, pDTE[drive].VolTag);
1188 pbarcoderes->data.LoadCount = 1;
1189 pbarcoderes->data.slot = slot;
1190 MapBarCode(chg.labelfile, pbarcoderes);
1193 if (BarCode(INDEX_CHANGER) == 0 && chg.emubarcode == 1)
1195 pbarcoderes->action = FIND_SLOT;
1196 if (MapBarCode(chg.labelfile, pbarcoderes) == 0) /* Nothing found, do an inventory */
1199 } else { /* We got something, is it correct ? */
1200 if (slot != pbarcoderes->data.slot && do_inventory == 0)
1202 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"Slot DB out of sync, slot %d != map %d",slot, pbarcoderes->data.slot);
1203 ChgExit("Load", "Label DB out of sync", FATAL);
1204 } else { /* OK, so increment the load count */
1205 pbarcoderes->action = UPDATE_SLOT;
1206 pbarcoderes->data.LoadCount = 1;
1207 pbarcoderes->data.slot = slot;
1208 MapBarCode(chg.labelfile, pbarcoderes);
1213 if (BarCode(INDEX_CHANGER) == 1 && chg.emubarcode == 1)
1215 ChgExit("Load", "BarCode == 1 and emubarcode == 1", FATAL);
1218 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"##### STOP load (%d)\n",ret);
1221 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"##### STOP load (%d)\n",ret);
1226 * Returns the number of Storage Slots which the library has
1227 * fd -> pointer to the internal devie structure pDev
1228 * return -> Number of slots
1230 int get_slot_count(int fd)
1232 extern OpenFiles_T *pDev;
1234 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"###### START get_slot_count\n");
1235 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"%-20s : fd %d\n", "get_slot_count", fd);
1237 if (ElementStatusValid == 0)
1239 pDev[fd].functions->function_status(fd, 1);
1241 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"##### STOP get_slot_count (%d)\n",STE);
1244 * return the number of slots in the robot
1252 * retreive the number of data-transfer devices /Tape drives)
1253 * fd -> pointer to the internal devie structure pDev
1254 * return -> -1 on failure
1256 int get_drive_count(int fd)
1259 extern OpenFiles_T *pDev;
1261 DebugPrint(DEBUG_INFO, SECTION_SCSI,"###### START get_drive_count\n");
1262 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-20s : fd %d\n", "get_drive_count", fd);
1265 if (ElementStatusValid == 0)
1267 if ( pDev[fd].functions->function_status(fd, 1) != 0)
1269 DebugPrint(DEBUG_ERROR, SECTION_SCSI, "Error getting drive count\n");
1270 DebugPrint(DEBUG_ERROR, SECTION_SCSI, "##### STOP get_drive_count (-1)\n");
1274 DebugPrint(DEBUG_INFO, SECTION_SCSI,"###### STOP get_drive_count (%d drives)\n",DTE);
1279 * Now the internal functions
1283 * Open the device and placeit in the list of open files
1284 * The OS has to decide if it is an SCSI Commands capable device
1287 int OpenDevice(int ip , char *DeviceName, char *ConfigName, char *ident)
1289 extern OpenFiles_T *pDev;
1291 ChangerCMD_T *p = (ChangerCMD_T *)&ChangerIO;
1293 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START OpenDevice\n");
1294 DebugPrint(DEBUG_INFO, SECTION_SCSI,"OpenDevice : %s\n", DeviceName);
1296 pDev[ip].ConfigName = stralloc(ConfigName);
1297 pDev[ip].dev = stralloc(DeviceName);
1299 if (SCSI_OpenDevice(ip) != 0 )
1301 if (ident != NULL) /* Override by config */
1303 while(p->ident != NULL)
1305 if (strcmp(ident, p->ident) == 0)
1307 pDev[ip].functions = p;
1308 strncpy(pDev[ip].ident, ident, 17);
1309 DebugPrint(DEBUG_INFO, SECTION_SCSI,"override using ident = %s, type = %s\n",p->ident, p->type);
1310 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP OpenDevice\n");
1315 ChgExit("OpenDevice", "ident not found", FATAL);
1317 while(p->ident != NULL)
1319 if (strcmp(pDev[ip].ident, p->ident) == 0)
1321 pDev[ip].functions = p;
1322 DebugPrint(DEBUG_INFO, SECTION_SCSI,"using ident = %s, type = %s\n",p->ident, p->type);
1323 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP OpenDevice\n");
1329 /* Nothing matching found, try generic */
1330 /* divide generic in generic_type, where type is the */
1331 /* num returned by the inquiry command */
1332 p = (ChangerCMD_T *)&ChangerIO;
1333 sprintf(&tmpstr[0],"%s_%s","generic",pDev[0].type);
1334 while(p->ident != NULL)
1336 if (strcmp(tmpstr, p->ident) == 0)
1338 pDev[ip].functions = p;
1339 DebugPrint(DEBUG_INFO, SECTION_SCSI,"using ident = %s, type = %s\n",p->ident, p->type);
1340 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP OpenDevice\n");
1345 } else { /* Something failed, lets see what */
1346 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"##### STOP OpenDevice failed\n");
1348 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP OpenDevice (nothing found) !!\n");
1354 * This functions checks if the library has an barcode reader.
1355 * fd -> pointer to the internal devie structure pDev
1360 extern OpenFiles_T *pDev;
1362 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### START BarCode\n");
1363 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"%-20s : fd %d\n", "BarCode", fd);
1365 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"Ident = [%s], function = [%s]\n", pDev[fd].ident,
1366 pDev[fd].functions->ident);
1367 ret = pDev[fd].functions->function_barcode(fd);
1368 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### STOP BarCode (%d)\n",ret);
1374 * This functions check if the tape drive is ready
1376 * fd -> pointer to the internal devie structure pDev
1377 * wait -> time to wait for the ready status
1380 int Tape_Ready(int fd, int wait_time)
1382 extern OpenFiles_T *pDev;
1387 RequestSense_T *pRequestSense;
1388 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START Tape_Ready\n");
1391 * Which device should we use to get the
1396 * First the ioctl tapedevice
1398 if (pDev[INDEX_TAPE].avail == 1)
1404 * But if available and can do SCSI
1407 if (pDev[INDEX_TAPECTL].avail == 1 && pDev[INDEX_TAPECTL].SCSI == 1)
1412 if (pDev[fd].avail == 1 && pDev[fd].SCSI == 0)
1414 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : Can't send SCSI commands, try ioctl\n");
1416 * Do we get an non negative result.
1417 * If yes this function is available
1418 * and we can use it to get the status
1421 ret = Tape_Status(fd);
1424 while (cnt < wait_time)
1426 if ( ret & TAPE_ONLINE)
1428 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : Ready after %d seconds\n",cnt);
1429 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
1434 ret = Tape_Status(fd);
1437 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : not ready, stop after %d seconds\n",cnt);
1438 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
1442 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : no ioctl interface, will sleep for %d seconds\n", wait_time);
1444 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
1449 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
1451 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : malloc failed\n");
1452 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
1457 * Ignore errors at this point
1462 * Wait until we get an ready condition
1465 while (true && cnt < wait_time)
1467 ret = SCSI_TestUnitReady(fd, pRequestSense );
1474 switch (SenseHandler(fd, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
1477 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeReady (TestUnitReady) SENSE_NO\n");
1480 case SENSE_TAPE_NOT_ONLINE:
1481 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeReady (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
1484 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeReady (TestUnitReady) SENSE_IGNORE\n");
1488 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeReady (TestUnitReady) SENSE_ABORT\n");
1492 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeReady (TestUnitReady) SENSE_RETRY\n");
1495 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeReady (TestUnitReady) default (SENSE)\n");
1501 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeReady (TestUnitReady) SCSI_ERROR\n");
1505 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeReady (TestUnitReady) SCSI_BUSY\n");
1508 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeReady (TestUnitReady) SCSI_CHECK\n");
1511 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeReady (TestUnitReady) unknown (%d)\n",ret);
1518 free(pRequestSense);
1520 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready after %d sec\n", cnt);
1521 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
1526 int DecodeSCSI(CDB_T CDB, char *string)
1528 SC_COM_T *pSCSICommand;
1531 DebugPrint(DEBUG_INFO, SECTION_SCSI, "##### START DecodeSCSI\n");
1532 pSCSICommand = (SC_COM_T *)&SCSICommand;
1534 while (pSCSICommand->name != NULL)
1536 if (CDB[0] == pSCSICommand->command)
1538 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%s %s", string, pSCSICommand->name);
1539 for (x=0; x < pSCSICommand->length; x++)
1541 DebugPrint(DEBUG_INFO, SECTION_SCSI," %02X", CDB[x]);
1543 DebugPrint(DEBUG_INFO, SECTION_SCSI,"\n");
1544 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP DecodeSCSI\n");
1549 DebugPrint(DEBUG_INFO, SECTION_SCSI,"Not found %X\n", CDB[0]);
1550 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP DecodeSCSI\n");
1554 int DecodeModeSense(char *buffer, int offset, char *pstring, char block, FILE *out)
1556 ReadWriteErrorRecoveryPage_T *prp;
1557 DisconnectReconnectPage_T *pdrp;
1558 int length = (unsigned char)*buffer - 4 - offset;
1560 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START DecodeModeSense\n");
1562 dump_hex(buffer, 255, DEBUG_INFO, SECTION_SCSI);
1564 /* Jump over the Parameter List header and an offset if we have something
1565 * Unknown at the start (ADIC-218) at the moment
1568 buffer = buffer + 4 + offset;
1570 DebugPrint(DEBUG_INFO, SECTION_SCSI,"buffer length = %d\n", length);
1572 if (block) /* Do we have an block descriptor page ?*/
1575 fprintf(out, "DecodeModeSense : Density Code %x\n", buffer[0]);
1579 fprintf(out, "DecodeModeSense : Number of Blocks %d\n", V3(buffer));
1580 buffer = buffer + 4;
1583 fprintf(out, "DecodeModeSense : Block Length %d\n", V3(buffer));
1584 buffer = buffer + 3;
1589 switch (*buffer & 0x3f)
1592 pVendorUnique = buffer;
1596 prp = (ReadWriteErrorRecoveryPage_T *)buffer;
1599 fprintf(out, "DecodeModeSense : Read/Write Error Recovery Page\n");
1600 fprintf(out,"\tTransfer Block %d\n", prp->tb);
1601 fprintf(out,"\tEnable Early Recovery %d\n", prp->eer);
1602 fprintf(out,"\tPost Error %d\n", prp->per);
1603 fprintf(out,"\tDisable Transfer on Error %d\n", prp->dte);
1604 fprintf(out,"\tDisable ECC Correction %d\n", prp->dcr);
1605 fprintf(out,"\tRead Retry Count %d\n", prp->ReadRetryCount);
1606 fprintf(out,"\tWrite Retry Count %d\n", prp->WriteRetryCount);
1611 pdrp = (DisconnectReconnectPage_T *)buffer;
1614 fprintf(out, "DecodeModeSense : Disconnect/Reconnect Page\n");
1615 fprintf(out,"\tBuffer Full Ratio %d\n", pdrp->BufferFullRatio);
1616 fprintf(out,"\tBuffer Empty Ratio %d\n", pdrp->BufferEmptyRatio);
1617 fprintf(out,"\tBus Inactivity Limit %d\n",
1618 V2(pdrp->BusInactivityLimit));
1619 fprintf(out,"\tDisconnect Time Limit %d\n",
1620 V2(pdrp->DisconnectTimeLimit));
1621 fprintf(out,"\tConnect Time Limit %d\n",
1622 V2(pdrp->ConnectTimeLimit));
1623 fprintf(out,"\tMaximum Burst Size %d\n",
1624 V2(pdrp->MaximumBurstSize));
1625 fprintf(out,"\tDTDC %d\n", pdrp->DTDC);
1630 pEAAPage = (EAAPage_T *)buffer;
1633 fprintf(out,"DecodeModeSense : Element Address Assignment Page\n");
1634 fprintf(out,"\tMedium Transport Element Address %d\n",
1635 V2(pEAAPage->MediumTransportElementAddress));
1636 fprintf(out,"\tNumber of Medium Transport Elements %d\n",
1637 V2(pEAAPage->NoMediumTransportElements));
1638 fprintf(out, "\tFirst Storage Element Address %d\n",
1639 V2(pEAAPage->FirstStorageElementAddress));
1640 fprintf(out, "\tNumber of Storage Elements %d\n",
1641 V2(pEAAPage->NoStorageElements));
1642 fprintf(out, "\tFirst Import/Export Element Address %d\n",
1643 V2(pEAAPage->FirstImportExportElementAddress));
1644 fprintf(out, "\tNumber of ImportExport Elements %d\n",
1645 V2(pEAAPage->NoImportExportElements));
1646 fprintf(out, "\tFirst Data Transfer Element Address %d\n",
1647 V2(pEAAPage->FirstDataTransferElementAddress));
1648 fprintf(out, "\tNumber of Data Transfer Elements %d\n",
1649 V2(pEAAPage->NoDataTransferElements));
1654 pDeviceCapabilitiesPage = (DeviceCapabilitiesPage_T *)buffer;
1657 fprintf(out, "DecodeModeSense : MT can store data cartridges %d\n",
1658 pDeviceCapabilitiesPage->MT);
1659 fprintf(out, "DecodeModeSense : ST can store data cartridges %d\n",
1660 pDeviceCapabilitiesPage->ST);
1661 fprintf(out, "DecodeModeSense : IE can store data cartridges %d\n",
1662 pDeviceCapabilitiesPage->IE);
1663 fprintf(out, "DecodeModeSense : DT can store data cartridges %d\n",
1664 pDeviceCapabilitiesPage->DT);
1665 fprintf(out, "DecodeModeSense : MT to MT %d\n",
1666 pDeviceCapabilitiesPage->MT2MT);
1667 fprintf(out, "DecodeModeSense : MT to ST %d\n",
1668 pDeviceCapabilitiesPage->MT2ST);
1669 fprintf(out, "DecodeModeSense : MT to IE %d\n",
1670 pDeviceCapabilitiesPage->MT2IE);
1671 fprintf(out, "DecodeModeSense : MT to DT %d\n",
1672 pDeviceCapabilitiesPage->MT2DT);
1673 fprintf(out, "DecodeModeSense : ST to MT %d\n",
1674 pDeviceCapabilitiesPage->ST2ST);
1675 fprintf(out, "DecodeModeSense : ST to MT %d\n",
1676 pDeviceCapabilitiesPage->ST2ST);
1677 fprintf(out, "DecodeModeSense : ST to DT %d\n",
1678 pDeviceCapabilitiesPage->ST2DT);
1679 fprintf(out, "DecodeModeSense : IE to MT %d\n",
1680 pDeviceCapabilitiesPage->IE2MT);
1681 fprintf(out, "DecodeModeSense : IE to ST %d\n",
1682 pDeviceCapabilitiesPage->IE2IE);
1683 fprintf(out, "DecodeModeSense : IE to ST %d\n",
1684 pDeviceCapabilitiesPage->IE2DT);
1685 fprintf(out, "DecodeModeSense : IE to ST %d\n",
1686 pDeviceCapabilitiesPage->IE2DT);
1687 fprintf(out, "DecodeModeSense : DT to MT %d\n",
1688 pDeviceCapabilitiesPage->DT2MT);
1689 fprintf(out, "DecodeModeSense : DT to ST %d\n",
1690 pDeviceCapabilitiesPage->DT2ST);
1691 fprintf(out, "DecodeModeSense : DT to IE %d\n",
1692 pDeviceCapabilitiesPage->DT2IE);
1693 fprintf(out, "DecodeModeSense : DT to DT %d\n",
1694 pDeviceCapabilitiesPage->DT2DT);
1699 buffer++; /* set pointer to the length information */
1702 /* Error if *buffer (length) is 0 */
1705 /* EAAPage = NULL; */
1706 /* DeviceCapabilitiesPage = NULL; */
1709 length = length - *buffer - 2;
1710 buffer = buffer + *buffer + 1;
1715 int DecodeSense(RequestSense_T *sense, char *pstring, FILE *out)
1721 fprintf(out,"##### START DecodeSense\n");
1722 fprintf(out,"%sSense Keys\n", pstring);
1723 if (sense->ErrorCode == 0x70)
1725 fprintf(out,"\tExtended Sense \n");
1727 fprintf(out,"\tErrorCode %02x\n", sense->ErrorCode);
1728 fprintf(out,"\tValid %d\n", sense->Valid);
1730 fprintf(out,"\tASC %02X\n", sense->AdditionalSenseCode);
1731 fprintf(out,"\tASCQ %02X\n", sense->AdditionalSenseCodeQualifier);
1732 fprintf(out,"\tSense key %02X\n", sense->SenseKey);
1733 switch (sense->SenseKey)
1736 fprintf(out,"\t\tNo Sense\n");
1739 fprintf(out,"\t\tRecoverd Error\n");
1742 fprintf(out,"\t\tNot Ready\n");
1745 fprintf(out,"\t\tMedium Error\n");
1748 fprintf(out,"\t\tHardware Error\n");
1751 fprintf(out,"\t\tIllegal Request\n");
1754 fprintf(out,"\t\tUnit Attention\n");
1757 fprintf(out,"\t\tData Protect\n");
1760 fprintf(out,"\t\tBlank Check\n");
1763 fprintf(out,"\t\tVendor uniq\n");
1766 fprintf(out,"\t\tCopy Aborted\n");
1769 fprintf(out,"\t\tAborted Command\n");
1772 fprintf(out,"\t\tEqual\n");
1775 fprintf(out,"\t\tVolume Overflow\n");
1778 fprintf(out,"\t\tMiscompare\n");
1781 fprintf(out,"\t\tReserved\n");
1787 int DecodeExtSense(ExtendedRequestSense_T *sense, char *pstring, FILE *out)
1789 ExtendedRequestSense_T *p;
1791 fprintf(out,"##### START DecodeExtSense\n");
1794 fprintf(out,"%sExtended Sense\n", pstring);
1795 DecodeSense((RequestSense_T *)p, pstring, out);
1796 fprintf(out,"\tLog Parameter Page Code %02X\n", sense->LogParameterPageCode);
1797 fprintf(out,"\tLog Parameter Code %02X\n", sense->LogParameterCode);
1798 fprintf(out,"\tUnderrun/Overrun Counter %02X\n", sense->UnderrunOverrunCounter);
1799 fprintf(out,"\tRead/Write Error Counter %d\n", V3((char *)sense->ReadWriteDataErrorCounter));
1800 if (sense->AdditionalSenseLength > sizeof(RequestSense_T))
1803 fprintf(out,"\tPower Fail\n");
1805 fprintf(out,"\tSCSI Bus Parity Error\n");
1807 fprintf(out,"\tFormatted Buffer parity Error\n");
1809 fprintf(out,"\tMedia Error\n");
1811 fprintf(out,"\tError Counter Overflow\n");
1813 fprintf(out,"\tTapeMotion Error\n");
1815 fprintf(out,"\tTape Not Present\n");
1817 fprintf(out,"\tLogical Beginning of tape\n");
1819 fprintf(out,"\tTape Mark Detect Error\n");
1821 fprintf(out,"\tWrite Protect\n");
1823 fprintf(out,"\tFilemark Error\n");
1825 fprintf(out,"\tUnder Run Error\n");
1827 fprintf(out,"\tWrite Error 1\n");
1829 fprintf(out,"\tServo System Error\n");
1831 fprintf(out,"\tFormatter Error\n");
1833 fprintf(out,"\tCleaning Cartridge is empty\n");
1835 fprintf(out,"\tReverse Retries Required\n");
1837 fprintf(out,"\tTape Drive has been cleaned\n");
1839 fprintf(out,"\tTape Drive needs to be cleaned\n");
1841 fprintf(out,"\tPhysical End of Tape\n");
1843 fprintf(out,"\tWrite Splice Error\n");
1845 fprintf(out,"\tWrite Splice Error\n");
1846 fprintf(out,"\tRemaing 1024 byte tape blocks %d\n", V3((char *)sense->RemainingTape));
1847 fprintf(out,"\tTracking Retry Counter %02X\n", sense->TrackingRetryCounter);
1848 fprintf(out,"\tRead/Write Retry Counter %02X\n", sense->ReadWriteRetryCounter);
1849 fprintf(out,"\tFault Sympton Code %02X\n", sense->FaultSymptomCode);
1854 int PrintInquiry(SCSIInquiry_T *SCSIInquiry)
1856 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START PrintInquiry\n");
1857 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %x\n", "qualifier", SCSIInquiry->qualifier);
1858 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %x\n", "type", SCSIInquiry->type);
1859 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %x\n", "data_format", SCSIInquiry->data_format);
1860 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %X\n", "ansi_version", SCSIInquiry->ansi_version);
1861 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %X\n", "ecma_version", SCSIInquiry->ecma_version);
1862 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %X\n", "iso_version", SCSIInquiry->iso_version);
1863 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %X\n", "type_modifier", SCSIInquiry->type_modifier);
1864 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %x\n", "removable", SCSIInquiry->removable);
1865 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %.8s\n", "vendor_info", SCSIInquiry->vendor_info);
1866 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %.16s\n", "prod_ident", SCSIInquiry->prod_ident);
1867 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %.4s\n", "prod_version", SCSIInquiry->prod_version);
1868 DebugPrint(DEBUG_INFO, SECTION_SCSI,"%-15s %.19s\n", "vendor_specific", SCSIInquiry->vendor_specific);
1875 dbprintf(("##### START DoNothing\n"));
1881 dbprintf(("##### START GenericFree\n"));
1887 dbprintf(("##### START GenericSearch\n"));
1891 int TreeFrogBarCode(int DeviceFD)
1893 extern OpenFiles_T *pDev;
1895 ModePageTreeFrogVendorUnique_T *pVendor;
1897 dbprintf(("##### START TreeFrogBarCode\n"));
1898 if (pModePage == NULL)
1900 if ((pModePage = malloc(0xff)) == NULL)
1902 dbprintf(("TreeFrogBarCode : malloc failed\n"));
1907 if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x0, 0x3f) == 0)
1909 DecodeModeSense(pModePage, 0, "TreeFrogBarCode :", 0, debug_file);
1911 if (pVendorUnique == NULL)
1913 dbprintf(("TreeFrogBarCode : no pVendorUnique\n"));
1916 pVendor = ( ModePageTreeFrogVendorUnique_T *)pVendorUnique;
1918 dbprintf(("TreeFrogBarCode : EBARCO %d\n", pVendor->EBARCO));
1919 dbprintf(("TreeFrogCheckSum : CHKSUM %d\n", pVendor->CHKSUM));
1921 dump_hex((char *)pDev[INDEX_CHANGER].inquiry, INQUIRY_SIZE, DEBUG_INFO, SECTION_ELEMENT);
1922 return(pVendor->EBARCO);
1927 int EXB_BarCode(int DeviceFD)
1929 extern OpenFiles_T *pDev;
1931 ModePageEXB120VendorUnique_T *pVendor;
1932 ModePageEXB120VendorUnique_T *pVendorWork;
1934 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### START EXB_BarCode\n");
1935 if (pModePage == NULL && LibModeSenseValid == 0)
1937 if ((pModePage = malloc(0xff)) == NULL)
1939 DebugPrint(DEBUG_ERROR, SECTION_BARCODE,"EXB_BarCode : malloc failed\n");
1942 if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x8, 0x3f) == 0)
1944 DecodeModeSense(pModePage, 0, "EXB_BarCode :", 0, debug_file);
1945 LibModeSenseValid = 1;
1947 LibModeSenseValid = -1;
1951 if (LibModeSenseValid == 1)
1953 if (pVendorUnique == NULL)
1955 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : no pVendorUnique\n");
1958 pVendor = ( ModePageEXB120VendorUnique_T *)pVendorUnique;
1960 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : NBL %d\n", pVendor->NBL);
1961 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : PS %d\n", pVendor->PS);
1962 if (pVendor->NBL == 1 && pVendor->PS == 1 )
1964 if ((pVendorWork = ( ModePageEXB120VendorUnique_T *)malloc(pVendor->ParameterListLength + 2)) == NULL)
1966 DebugPrint(DEBUG_ERROR, SECTION_BARCODE,"EXB_BarCode : malloc failed\n");
1969 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : setting NBL to 1\n");
1970 memcpy(pVendorWork, pVendor, pVendor->ParameterListLength + 2);
1971 pVendorWork->NBL = 0;
1972 pVendorWork->PS = 0;
1973 pVendorWork->RSVD0 = 0;
1974 if (SCSI_ModeSelect(DeviceFD, (char *)pVendorWork, pVendorWork->ParameterListLength + 2, 0, 1, 0) == 0)
1976 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : SCSI_ModeSelect OK\n");
1981 /* And now again !!!
1983 GenericResetStatus(DeviceFD);
1985 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : SCSI_ModeSelect failed\n");
1988 dump_hex((char *)pDev[INDEX_CHANGER].inquiry, INQUIRY_SIZE, DEBUG_INFO, SECTION_BARCODE);
1989 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : vendor_specific[19] %x\n",
1990 pDev[INDEX_CHANGER].inquiry->vendor_specific[19]);
1996 int NoBarCode(int DeviceFD)
1998 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### START NoBarCode\n");
1999 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### STOP NoBarCode\n");
2003 int GenericBarCode(int DeviceFD)
2005 extern changer_t chg;
2007 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### START GenericBarCode\n");
2008 if ( chg.havebarcode >= 1)
2010 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### STOP GenericBarCode (havebarcode) => %d\n",chg.havebarcode);
2013 DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### STOP GenericBarCode => 0\n");
2017 int SenseHandler(int DeviceFD, unsigned char flag, unsigned char SenseKey, unsigned char AdditionalSenseCode, unsigned char AdditionalSenseCodeQualifier, char *buffer)
2019 extern OpenFiles_T *pDev;
2021 dbprintf(("##### START SenseHandler\n"));
2022 if (pDev[DeviceFD].inqdone == 1)
2024 dbprintf(("Ident = [%s], function = [%s]\n", pDev[DeviceFD].ident,
2025 pDev[DeviceFD].functions->ident));
2026 ret = pDev[DeviceFD].functions->function_error(DeviceFD, flag, SenseKey, AdditionalSenseCode, AdditionalSenseCodeQualifier, buffer);
2028 dbprintf((" Ups no sense\n"));
2030 dbprintf(("#### STOP SenseHandler\n"));
2035 * Try to get information about the tape,
2036 * Tape loaded ? Online etc
2037 * Use the mtio ioctl to get the information if no SCSI Path
2038 * to the tape drive is available.
2041 * Pass an parameter to identify which unit to use
2042 * if there are more than one
2043 * Implement the SCSI path if available
2047 extern OpenFiles_T *pDev;
2051 RequestSense_T *pRequestSense;
2053 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START TapeStatus\n");
2056 * If it is an device which understand SCSI commands the
2057 * normal ioctl (MTIOCGET for example) may fail
2060 if (pDev[INDEX_TAPECTL].SCSI == 1)
2062 if ((pRequestSense = malloc(sizeof(RequestSense_T))) == NULL)
2064 dbprintf(("%-20s : malloc failed\n","TapeStatus"));
2068 while (true && cnt < 60)
2070 ret = SCSI_TestUnitReady(INDEX_TAPECTL, pRequestSense);
2071 DebugPrint(DEBUG_INFO, SECTION_SCSI, "TapeStatus TestUnitReady ret %d\n",ret);
2076 switch (SenseHandler(INDEX_TAPECTL, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
2080 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeStatus (TestUnitReady) SENSE_NO\n");
2081 pDTE[0].status = 'F';
2082 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### FULL\n");
2085 case SENSE_TAPE_NOT_ONLINE:
2086 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeStatus (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
2087 pDTE[0].status = 'E';
2088 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### EMPTY\n");
2092 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeStatus (TestUnitReady) SENSE_ABORT\n");
2096 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeStatus (TestUnitReady) SENSE_RETRY\n");
2099 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeStatus (TestUnitReady) default (SENSE)\n");
2104 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeStatus (TestUnitReady) SCSI_ERROR\n");
2108 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeStatus (TestUnitReady) SCSI_BUSY\n");
2111 DebugPrint(DEBUG_INFO, SECTION_SCSI,"TapeStatus (TestUnitReady) SCSI_CHECK\n");
2114 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeStatus (TestUnitReady) unknown (%d)\n",ret);
2121 ret = Tape_Status(INDEX_TAPE);
2122 if ( ret & TAPE_ONLINE)
2124 pDTE[0].status ='F';
2125 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### FULL\n");
2127 pDTE[0].status = 'E';
2128 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### EMPTY\n");
2130 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP TapeStatus\n");
2135 int DLT4000Eject(char *Device, int type)
2137 extern OpenFiles_T *pDev;
2139 RequestSense_T *pRequestSense;
2140 ExtendedRequestSense_T *pExtendedRequestSense;
2145 dbprintf(("##### START DLT4000Eject\n"));
2147 if ((pRequestSense = malloc(sizeof(RequestSense_T))) == NULL)
2149 dbprintf(("%-20s : malloc failed\n","DLT4000Eject"));
2153 if ((pExtendedRequestSense = malloc(sizeof(ExtendedRequestSense_T))) == NULL)
2155 dbprintf(("%-20s : malloc failed\n","DLT4000Eject"));
2161 dbprintf(("DLT4000Eject : use mtio ioctl for eject on %s\n", pDev[INDEX_TAPE].dev));
2162 return(Tape_Ioctl(INDEX_TAPE, IOCTL_EJECT));
2167 if (pDev[INDEX_TAPECTL].SCSI == 0)
2169 dbprintf(("DLT4000Eject : Device %s not able to receive SCSI commands\n", pDev[INDEX_TAPE].dev));
2170 return(Tape_Ioctl(INDEX_TAPE, IOCTL_EJECT));
2174 dbprintf(("DLT4000Eject : SCSI eject on %s = %s\n", pDev[INDEX_TAPECTL].dev, pDev[INDEX_TAPECTL].ConfigName));
2176 RequestSense(INDEX_TAPECTL, pExtendedRequestSense, 0);
2177 DecodeExtSense(pExtendedRequestSense, "DLT4000Eject : ", debug_file);
2178 /* Unload the tape, 0 == wait for success
2181 ret = SCSI_LoadUnload(INDEX_TAPECTL, pRequestSense, 0, 0);
2183 RequestSense(INDEX_TAPECTL, pExtendedRequestSense, 0);
2184 DecodeExtSense(pExtendedRequestSense, "DLT4000Eject : ", debug_file);
2197 while (true && cnt < 300)
2199 ret = SCSI_TestUnitReady(INDEX_TAPECTL, pRequestSense);
2200 DebugPrint(DEBUG_INFO, SECTION_SCSI, "DLT4000Eject TestUnitReady ret %d\n",ret);
2207 switch (SenseHandler(INDEX_TAPECTL, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
2210 DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SENSE_NO\n");
2213 case SENSE_TAPE_NOT_ONLINE:
2214 DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
2218 DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SENSE_IGNORE\n");
2222 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SENSE_ABORT\n");
2226 DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SENSE_RETRY\n");
2229 DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) default (SENSE)\n");
2235 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SCSI_ERROR\n");
2239 DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SCSI_BUSY\n");
2242 DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SCSI_CHECK\n");
2245 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"DLT4000Eject (TestUnitReady) unknown (%d)\n",ret);
2254 free(pRequestSense);
2256 dbprintf(("DLT4000Eject : Ready after %d sec, true = %d\n", cnt * 2, true));
2262 * Ejects an tape either with the ioctl interface
2263 * or by using the SCSI interface if available.
2266 * Before unload check if there is an tape in the drive
2269 int GenericEject(char *Device, int type)
2271 extern OpenFiles_T *pDev;
2272 RequestSense_T *pRequestSense;
2277 DebugPrint(DEBUG_INFO, SECTION_TAPE, "##### START GenericEject\n");
2279 if ((pRequestSense = malloc(sizeof(RequestSense_T))) == NULL)
2281 DebugPrint(DEBUG_ERROR, SECTION_TAPE, "%-20s : malloc failed\n","GenericEject");
2285 DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericEject : SCSI eject on %s = %s\n", pDev[INDEX_TAPECTL].dev, pDev[INDEX_TAPECTL].ConfigName);
2288 * Can we use SCSI commands ?
2290 if (pDev[INDEX_TAPECTL].SCSI == 1)
2292 LogSense(INDEX_TAPECTL);
2294 * Unload the tape, 1 == don't wait for success
2297 ret = SCSI_LoadUnload(INDEX_TAPECTL, pRequestSense, 1, 0);
2310 while (true && cnt < 300)
2312 ret = SCSI_TestUnitReady(INDEX_TAPECTL, pRequestSense);
2313 DebugPrint(DEBUG_INFO, SECTION_SCSI, "GenericEject TestUnitReady ret %d\n",ret);
2318 switch (SenseHandler(INDEX_TAPECTL, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
2321 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SENSE_NO\n");
2323 case SENSE_TAPE_NOT_ONLINE:
2324 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
2328 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SENSE_IGNORE\n");
2331 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericEject (TestUnitReady) SENSE_ABORT\n");
2335 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SENSE_RETRY\n");
2338 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) default (SENSE)\n");
2343 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericEject (TestUnitReady) SCSI_ERROR\n");
2347 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SCSI_BUSY\n");
2350 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SCSI_CHECK\n");
2353 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericEject (TestUnitReady) unknown (%d)\n",ret);
2360 free(pRequestSense);
2363 DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericEject : Device can't understand SCSI try ioctl\n");
2364 Tape_Ioctl(INDEX_TAPECTL, IOCTL_EJECT);
2366 DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericEject : Ready after %d sec, true = %d\n", cnt * 2, true);
2374 * Make the retry counter an config option,
2380 int GenericRewind(int DeviceFD)
2383 extern OpenFiles_T *pDev;
2384 RequestSense_T *pRequestSense;
2385 char *errstr; /* Used by tape_rewind */
2390 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START GenericRewind pDEV -> %d\n",DeviceFD);
2394 * If we can use the SCSI device than use it, else use the ioctl
2397 if (pDev[DeviceFD].SCSI == 1)
2399 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
2401 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"GenericRewind : malloc failed\n");
2405 * Before doing the rewind check if the tape is ready to accept commands
2410 ret = SCSI_TestUnitReady(DeviceFD, (RequestSense_T *)pRequestSense );
2411 DebugPrint(DEBUG_INFO, SECTION_TAPE, "GenericRewind (TestUnitReady) ret %d\n",ret);
2418 switch (SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
2421 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_NO\n");
2424 case SENSE_TAPE_NOT_ONLINE:
2425 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
2429 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_IGNORE\n");
2433 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_ABORT\n");
2437 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_RETRY\n");
2440 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) default (SENSE)\n");
2443 } /* switch (SenseHandler(DeviceFD, 0, pRequestSense->SenseKey.... */
2447 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_ERROR\n");
2451 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_BUSY\n");
2454 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_CHECK\n");
2457 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) unknown (%d)\n",ret);
2462 DebugPrint(DEBUG_INFO, SECTION_TAPE," Wait .... (%d)\n",cnt);
2465 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP GenericRewind (-1)\n");
2468 } /* while true == 1 */
2473 CDB[0] = SC_COM_REWIND;
2482 ret = SCSI_Run(DeviceFD, Input, CDB, 6,
2484 (char *) pRequestSense,
2485 sizeof(RequestSense_T));
2487 DecodeSense(pRequestSense, "GenericRewind : ", debug_file);
2491 if (pRequestSense->SenseKey != UNIT_ATTENTION)
2502 DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericRewind : failed %d\n", ret);
2509 while (true && cnt < 300)
2511 ret = SCSI_TestUnitReady(DeviceFD, pRequestSense);
2512 DebugPrint(DEBUG_INFO, SECTION_SCSI, "GenericRewind TestUnitReady ret %d\n",ret);
2519 switch (SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
2522 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_NO\n");
2525 case SENSE_TAPE_NOT_ONLINE:
2526 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
2530 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_IGNORE\n");
2534 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_ABORT\n");
2538 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_RETRY\n");
2541 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) default (SENSE)\n");
2547 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_ERROR\n");
2551 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_BUSY\n");
2554 DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_CHECK\n");
2557 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) unknown (%d)\n",ret);
2565 free(pRequestSense);
2567 DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericRewind : Ready after %d sec, true = %d\n", cnt * 2, true);
2568 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP GenericRewind (0)\n");
2570 DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericRewind : use ioctl rewind\n");
2571 if (pDev[DeviceFD].devopen == 1)
2573 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Close Device\n");
2574 SCSI_CloseDevice(DeviceFD);
2577 * Hmm retry it if it fails ?
2583 if ((errstr = tape_rewind(pDev[DeviceFD].dev)) == NULL)
2586 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Rewind OK, (after %d tries)\n", cnt);
2588 DebugPrint(DEBUG_INFO, SECTION_TAPE,"Rewind failed %s\n",errstr);
2590 * DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP GenericRewind (-1)\n");
2597 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP GenericRewind (-1), retry limit reached\n");
2602 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP GenericRewind (0)\n");
2610 * Check if the tape has the tape clean
2611 * bit set in the return of an request sense
2614 int GenericClean(char * Device)
2616 extern OpenFiles_T *pDev;
2617 ExtendedRequestSense_T ExtRequestSense;
2620 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START GenericClean\n");
2621 if (pDev[INDEX_TAPECTL].SCSI == 0)
2623 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"GenericClean : can't send SCSI commands\n");
2624 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP GenericClean\n");
2629 * Request Sense Data, reset the counter
2631 if ( RequestSense(INDEX_TAPECTL, &ExtRequestSense, 1) == 0)
2634 DecodeExtSense(&ExtRequestSense, "GenericClean : ", debug_file);
2635 if(ExtRequestSense.CLN) {
2641 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"Got error from RequestSense\n");
2643 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP GenericClean (%d)\n",ret);
2647 int GenericResetStatus(int DeviceFD)
2650 RequestSense_T *pRequestSense;
2654 DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "##### START GenericResetStatus\n");
2656 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
2658 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericResetStatus : malloc failed\n");
2664 CDB[0] = SC_COM_IES; /* */
2672 ret = SCSI_Run(DeviceFD, Input, CDB, 6,
2674 (char *) pRequestSense,
2675 sizeof(RequestSense_T));
2679 /* fprintf(stderr, "%s: Request Sense[Inquiry]: %02X", */
2680 /* "chs", ((unsigned char *) &pRequestSense)[0]); */
2681 /* for (i = 1; i < sizeof(RequestSense_T); i++) */
2682 /* fprintf(stderr, " %02X", ((unsigned char *) &pRequestSense)[i]); */
2683 /* fprintf(stderr, "\n"); */
2688 switch (SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
2698 if (retry < MAX_RETRIES )
2700 DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "GenericResetStatus : retry %d\n", retry);
2703 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericResetStatus : return (-1)\n");
2708 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericResetStatus : (default) return (-1)\n");
2716 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "##### STOP GenericResetStatus (%d)\n",ret);
2720 /* GenericSenseHandler
2721 * Handles the conditions/sense wich is returned by an SCSI command
2722 * pwork is an pointer to the structure OpenFiles_T, which is filled with information
2723 * about the device to which we talk. Information are for example
2724 * The vendor, the ident, which fd, etc. This strucure is filled when we open the
2726 * flag tells how to handle the information passed in the buffer,
2727 * 0 -> Sense Key available
2728 * 1 -> No Sense key available
2729 * buffer is a pointer to the data from the request sense result.
2732 * Limit recursion, may run in an infinite loop
2734 int GenericSenseHandler(int ip, int flag, unsigned char SenseKey, unsigned char AdditionalSenseCode, unsigned char AdditionalSenseCodeQualifier, char *buffer)
2736 extern OpenFiles_T *pDev;
2737 RequestSense_T *pRequestSense = (RequestSense_T *)buffer;
2739 unsigned char *info = NULL;
2741 dbprintf(("##### START GenericSenseHandler\n"));
2743 DecodeSense(pRequestSense, "GenericSenseHandler : ", debug_file);
2745 ret = Sense2Action(pDev[ip].ident,
2746 pDev[ip].inquiry->type,
2748 AdditionalSenseCode,
2749 AdditionalSenseCodeQualifier,
2752 dbprintf(("##### STOP GenericSenseHandler\n"));
2757 * Do the move. We don't address the MTE element (the gripper)
2758 * here. We assume that the library use the right MTE.
2759 * The difference to GenericMove is that we do an align element
2764 * != 0 -> error either from the SCSI command or from
2765 * the element handling
2768 int SDXMove(int DeviceFD, int from, int to)
2770 extern OpenFiles_T *pDev;
2771 ElementInfo_T *pfrom;
2776 int SDX_MTE = 0; /* This are parameters passed */
2777 int SDX_STE = -1; /* to */
2778 int SDX_DTE = -1; /* AlignElements */
2780 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### START SDXMove\n");
2782 DebugPrint(DEBUG_INFO, SECTION_MOVE,"%-20s : from = %d, to = %d\n", "SDXMove", from, to);
2785 if ((pfrom = LookupElement(from)) == NULL)
2787 DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : ElementInfo for %d not found\n", from);
2788 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2792 if ((pto = LookupElement(to)) == NULL)
2794 DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : ElementInfo for %d not found\n", to);
2795 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2799 if (pfrom->status == 'E')
2801 DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : from %d is empty\n", from);
2802 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2806 if (pto->status == 'F')
2808 switch (pto->status)
2813 DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : Destination Element %d Type %d is full\n",
2814 pto->address, pto->type);
2815 to = find_empty(DeviceFD, 0, 0);
2818 DebugPrint(DEBUG_ERROR, SECTION_MOVE,"SDXMove : no empty slot found for unload\n");
2821 DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : Unload to %d\n", to);
2822 if ((pto = LookupElement(to)) == NULL)
2824 DebugPrint(DEBUG_INFO, SECTION_MOVE, "SDXMove : ElementInfo for %d not found\n", to);
2825 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2836 moveok = CheckMove(pfrom, pto);
2841 SDX_DTE = pto->address;
2844 SDX_STE = pto->address;
2847 SDX_STE = pto->address;
2851 switch (pfrom->type)
2854 SDX_DTE = pfrom->address;
2857 SDX_STE = pfrom->address;
2860 SDX_STE = pfrom->address;
2864 if (SDX_DTE >= 0 && SDX_STE >= 0)
2866 ret = SCSI_AlignElements(DeviceFD, SDX_MTE, SDX_DTE, SDX_STE);
2867 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### SCSI_AlignElemnts ret = %d\n",ret);
2870 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2874 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### Error setting STE/DTE %d/%d\n", SDX_STE, SDX_DTE);
2875 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2880 * If from is a tape we must check if it is loaded
2881 * and if yes we have to eject it
2883 if (pfrom->type == TAPETYPE)
2885 tapestat = Tape_Status(INDEX_TAPE);
2886 if ( tapestat & TAPE_ONLINE)
2888 if (pDev[INDEX_TAPECTL].SCSI == 1)
2890 ret = eject_tape(pDev[INDEX_TAPECTL].dev,1);
2892 ret = eject_tape(pDev[INDEX_TAPE].dev,2);
2899 ret = SCSI_Move(DeviceFD, 0, from, to);
2901 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2904 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
2909 * Do the move. We don't address the MTE element (the gripper)
2910 * here. We assume that the library use the right MTE
2914 * != 0 -> error either from the SCSI command or from
2915 * the element handling
2918 int GenericMove(int DeviceFD, int from, int to)
2920 ElementInfo_T *pfrom;
2924 DebugPrint(DEBUG_INFO, SECTION_MOVE, "##### START GenericMove\n");
2926 DebugPrint(DEBUG_INFO, SECTION_MOVE, "%-20s : from = %d, to = %d\n", "GenericMove", from, to);
2929 if ((pfrom = LookupElement(from)) == NULL)
2931 DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : ElementInfo for %d not found\n", from);
2932 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
2936 if ((pto = LookupElement(to)) == NULL)
2938 DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : ElementInfo for %d not found\n", to);
2939 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
2943 if (pfrom->status == 'E')
2945 DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : from %d is empty\n", from);
2946 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
2950 if (pto->status == 'F')
2952 DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : Destination Element %d Type %d is full\n",
2953 pto->address, pto->type);
2954 to = find_empty(DeviceFD, 0, 0);
2957 DebugPrint(DEBUG_ERROR, SECTION_MOVE, "GenericMove : no empty slot found\n");
2960 DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : Unload to %d\n", to);
2961 if ((pto = LookupElement(to)) == NULL)
2963 DebugPrint(DEBUG_ERROR, SECTION_MOVE, " Ups should not happen\n");
2964 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
2969 if (CheckMove(pfrom, pto))
2971 ret = SCSI_Move(DeviceFD, 0, from, to);
2974 DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : SCSI_Move return (%d)\n", ret);
2975 DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
2980 * Check if a move based on the information we got from the Mode Sense command
2987 int CheckMove(ElementInfo_T *from, ElementInfo_T *to)
2991 DebugPrint(DEBUG_INFO, SECTION_MOVE, "##### START CheckMove\n");
2992 if (pDeviceCapabilitiesPage != NULL )
2994 DebugPrint(DEBUG_INFO, SECTION_MOVE, "CheckMove : checking if move from %d to %d is legal\n", from->address, to->address);
2998 DebugPrint(DEBUG_INFO, SECTION_MOVE, "CheckMove : MT2");
3002 if (pDeviceCapabilitiesPage->MT2MT == 1)
3004 DebugPrint(DEBUG_INFO, SECTION_MOVE, "MT\n");
3009 if (pDeviceCapabilitiesPage->MT2ST == 1)
3011 DebugPrint(DEBUG_INFO, SECTION_MOVE, "ST\n");
3016 if (pDeviceCapabilitiesPage->MT2IE == 1)
3018 DebugPrint(DEBUG_INFO, SECTION_MOVE, "IE\n");
3023 if (pDeviceCapabilitiesPage->MT2DT == 1)
3025 DebugPrint(DEBUG_INFO, SECTION_MOVE, "DT\n");
3034 DebugPrint(DEBUG_INFO, SECTION_MOVE, "CheckMove : ST2");
3038 if (pDeviceCapabilitiesPage->ST2MT == 1)
3040 DebugPrint(DEBUG_INFO, SECTION_MOVE, "MT\n");
3045 if (pDeviceCapabilitiesPage->ST2ST == 1)
3047 DebugPrint(DEBUG_INFO, SECTION_MOVE, "ST\n");
3052 if (pDeviceCapabilitiesPage->ST2IE == 1)
3054 DebugPrint(DEBUG_INFO, SECTION_MOVE, "IE\n");
3059 if (pDeviceCapabilitiesPage->ST2DT == 1)
3061 DebugPrint(DEBUG_INFO, SECTION_MOVE, "DT\n");
3070 DebugPrint(DEBUG_INFO, SECTION_MOVE, "CheckMove : IE2");
3074 if (pDeviceCapabilitiesPage->IE2MT == 1)
3076 DebugPrint(DEBUG_INFO, SECTION_MOVE, "MT\n");
3081 if (pDeviceCapabilitiesPage->IE2ST == 1)
3083 DebugPrint(DEBUG_INFO, SECTION_MOVE, "ST\n");
3088 if (pDeviceCapabilitiesPage->IE2IE == 1)
3090 DebugPrint(DEBUG_INFO, SECTION_MOVE, "IE\n");
3095 if (pDeviceCapabilitiesPage->IE2DT == 1)
3097 DebugPrint(DEBUG_INFO, SECTION_MOVE, "DT\n");
3106 DebugPrint(DEBUG_INFO, SECTION_MOVE, "CheckMove : DT2");
3110 if (pDeviceCapabilitiesPage->DT2MT == 1)
3112 DebugPrint(DEBUG_INFO, SECTION_MOVE, "MT\n");
3117 if (pDeviceCapabilitiesPage->DT2ST == 1)
3119 DebugPrint(DEBUG_INFO, SECTION_MOVE, "ST\n");
3124 if (pDeviceCapabilitiesPage->DT2IE == 1)
3126 DebugPrint(DEBUG_INFO, SECTION_MOVE, "IE\n");
3131 if (pDeviceCapabilitiesPage->DT2DT == 1)
3133 DebugPrint(DEBUG_INFO, SECTION_MOVE, "DT\n");
3145 DebugPrint(DEBUG_INFO, SECTION_MOVE, "CheckMove : pDeviceCapabilitiesPage == NULL");
3147 ChgExit("CheckMove", "DeviceCapabilitiesPage == NULL", FATAL);
3152 DebugPrint(DEBUG_INFO, SECTION_MOVE, "###### STOP CheckMove\n");
3159 int GetCurrentSlot(int fd, int drive)
3161 extern OpenFiles_T *pDev;
3163 dbprintf(("##### START GetCurrentSlot\n"));
3165 if (pDev[0].SCSI == 0)
3167 dbprintf(("GetCurrentSlot : can't send SCSI commands\n"));
3171 if (ElementStatusValid == 0)
3173 if (pDev[0].functions->function_status(0, 1) != 0)
3179 /* If the from address is the as the same as the tape address skip it */
3180 if (pDTE[drive].from >= 0 && pDTE[drive].from != pDTE[drive].address)
3182 for (x = 0; x < STE;x++)
3184 if (pSTE[x].address == pDTE[drive].from)
3190 for (x = 0; x < STE;x++)
3192 if (pSTE[x].status == 'E')
3196 /* Ups nothing loaded */
3203 * Reworked function to get the ElementStatus
3204 * This function will first call the GetElementStatus
3205 * function to get the Element status,
3206 * and than check if there are abnormal conditions.
3208 * If there are error conditions try to fix them
3211 int GenericElementStatus(int DeviceFD, int InitStatus)
3219 extern OpenFiles_T *pDev;
3221 int error = 0; /* If set do an INIT ELEMENT STATUS */
3222 int x; /* The standard loop counter :-) */
3223 int loop = 2; /* Redo it if an error has been reset */
3225 DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "##### START GenericElementStatus\n");
3227 if (pEAAPage == NULL)
3230 * If this pointer is null
3231 * then try to read the parameter with MODE SENSE
3234 if (pModePage == NULL && LibModeSenseValid == 0)
3236 if ((pModePage = malloc(0xff)) == NULL)
3238 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
3241 if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x8, 0x3f) == 0)
3243 LibModeSenseValid = 1;
3244 DecodeModeSense(pModePage, 0, "GenericElementStatus :", 0, debug_file);
3246 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GetElementStatus : failed SCSI_ModeSense\n");
3247 LibModeSenseValid = -1;
3252 if (GetElementStatus(DeviceFD) == 0 && loop > 0)
3255 for (x = 0; x < MTE; x++)
3257 if (pMTE[x].ASC > 0)
3259 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pMTE[x].ASC, pMTE[x].ASCQ, (char *)&pMTE[x]))
3266 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericElementStatus : Abort on MTE\n");
3273 for (x = 0; x < IEE; x++)
3275 if (pIEE[x].ASC > 0)
3277 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pIEE[x].ASC, pIEE[x].ASCQ, (char *)&pIEE[x]))
3284 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericElementStatus : Abort on IEE\n");
3292 for (x = 0; x < STE; x++)
3295 * Needed for the hack to guess the tape status if an error
3296 * for the tape is pending
3298 if (pSTE[x].status == 'E')
3303 if (pSTE[x].ASC > 0)
3305 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pSTE[x].ASC, pSTE[x].ASCQ, (char *)&pSTE[x]))
3312 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericElementStatus : Abort on IES\n");
3319 for (x = 0; x < DTE; x++)
3321 if (pDTE[x].ASC > 0)
3323 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pDTE[x].ASC, pDTE[x].ASCQ, (char *)&pDTE[x]))
3330 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericElementStatus : Abort on DTE\n");
3338 * OK, we have an error, do an INIT ELMENT
3339 * For the tape if not handled by the robot we have
3340 * to do some extra checks
3344 if (GenericResetStatus(DeviceFD) != 0)
3346 ElementStatusValid = 0;
3347 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericElementStatus : Can't init status STEError(%d) MTEError(%d) DTEError(%d) IEEError(%d)\n", STEError, MTEError, DTEError, IEEError);
3357 * If the status is empty to an move from tape to tape
3358 * This is if the tape is ejected, but not unloaded
3360 if (pDTE[0].status == 'E')
3362 DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "GenericElementStatus : try to move tape to tape drive\n");
3363 pDev[DeviceFD].functions->function_move(DeviceFD, pDTE[0].address, pDTE[0].address);
3366 /* Done GetElementStatus */
3371 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericElementStatus : Can't init status (after loop)\n");
3375 ElementStatusValid = 1;
3376 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "#### STOP GenericElementStatus\n");
3382 * This is for the ADIC changer, it seems that they have an diferent
3383 * offset in the mode sense data before the first mode page (+12)
3385 int DLT448ElementStatus(int DeviceFD, int InitStatus)
3393 extern OpenFiles_T *pDev;
3395 int error = 0; /* If set do an INIT ELEMENT STATUS */
3396 int x; /* The standard loop counter :-) */
3397 int loop = 2; /* Redo it if an error has been reset */
3399 DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "##### START DLT448ElementStatus\n");
3401 if (pEAAPage == NULL)
3404 * If this pointer is null
3405 * then try to read the parameter with MODE SENSE
3408 if (pModePage == NULL && LibModeSenseValid == 0)
3410 if ((pModePage = malloc(0xff)) == NULL)
3412 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"DLT448ElementStatus : malloc failed\n");
3415 if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x8, 0x3f) == 0)
3417 LibModeSenseValid = 1;
3418 DecodeModeSense(pModePage, 12, "DLT448ElementStatus :", 0, debug_file);
3420 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"DLT448ElementStatus : failed SCSI_ModeSense\n");
3421 LibModeSenseValid = -1;
3426 if (GetElementStatus(DeviceFD) == 0 && loop > 0)
3429 for (x = 0; x < MTE; x++)
3431 if (pMTE[x].ASC > 0)
3433 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pMTE[x].ASC, pMTE[x].ASCQ, (char *)&pMTE[x]))
3440 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "DLT448ElementStatus : Abort on MTE\n");
3447 for (x = 0; x < IEE; x++)
3449 if (pIEE[x].ASC > 0)
3451 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pIEE[x].ASC, pIEE[x].ASCQ, (char *)&pIEE[x]))
3458 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "DLT448ElementStatus : Abort on IEE\n");
3466 for (x = 0; x < STE; x++)
3469 * Needed for the hack to guess the tape status if an error
3470 * for the tape is pending
3472 if (pSTE[x].status == 'E')
3477 if (pSTE[x].ASC > 0)
3479 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pSTE[x].ASC, pSTE[x].ASCQ, (char *)&pSTE[x]))
3486 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "DLT448ElementStatus : Abort on IES\n");
3493 for (x = 0; x < DTE; x++)
3495 if (pDTE[x].ASC > 0)
3497 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pDTE[x].ASC, pDTE[x].ASCQ, (char *)&pDTE[x]))
3504 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "DLT448ElementStatus : Abort on DTE\n");
3512 * OK, we have an error, do an INIT ELMENT
3513 * For the tape if not handled by the robot we have
3514 * to do some extra checks
3518 if (GenericResetStatus(DeviceFD) != 0)
3520 ElementStatusValid = 0;
3521 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "DLT448ElementStatus : Can't init status\n");
3531 * If the status is empty to an move from tape to tape
3532 * This is if the tape is ejected, but not unloaded
3534 if (pDTE[0].status == 'E')
3536 DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "DLT448ElementStatus : try to move tape to tape drive\n");
3537 pDev[DeviceFD].functions->function_move(DeviceFD, pDTE[0].address, pDTE[0].address);
3540 /* Done GetElementStatus */
3545 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "DLT448ElementStatus : Can't init status (after loop)\n");
3549 ElementStatusValid = 1;
3550 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "#### STOP DLT448ElementStatus\n");
3556 * Much the same like GenericElementStatus but
3557 * it seemes that for the STE Elements ASC/ASCQ is not set
3558 * on an error, only the except bit is set
3560 int SDXElementStatus(int DeviceFD, int InitStatus)
3567 int error = 0; /* If set do an INIT ELEMENT STATUS */
3568 int x; /* The standard loop counter :-) */
3569 int loop = 2; /* Redo it if an error has been reset */
3571 DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "##### START SDXElementStatus\n");
3573 if (pEAAPage == NULL)
3576 * If this pointer is null
3577 * then try to read the parameter with MODE SENSE
3580 if (pModePage == NULL && LibModeSenseValid == 0)
3582 if ((pModePage = malloc(0xff)) == NULL)
3584 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"SDXElementStatus : malloc failed\n");
3587 if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x8, 0x3f) == 0)
3589 LibModeSenseValid = 1;
3590 DecodeModeSense(pModePage, 0, "SDXElementStatus :", 0, debug_file);
3592 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"SDXElementStatus : failed SCSI_ModeSense\n");
3593 LibModeSenseValid = -1;
3598 if (GetElementStatus(DeviceFD) == 0 && loop)
3602 for (x = 0; x < MTE; x++)
3604 if (pMTE[x].ASC > 0)
3606 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pMTE[x].ASC, pMTE[x].ASCQ, (char *)&pMTE[x]))
3613 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "SDXElementStatus : Abort on MTE\n");
3620 for (x = 0; x < IEE; x++)
3622 if (pIEE[x].ASC > 0)
3624 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pIEE[x].ASC, pIEE[x].ASCQ, (char *)&pIEE[x]))
3631 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "SDXElementStatus : Abort on IEE\n");
3639 for (x = 0; x < STE; x++)
3641 if (pSTE[x].except != 0)
3646 if (pSTE[x].ASC > 0)
3648 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pSTE[x].ASC, pSTE[x].ASCQ, (char *)&pSTE[x]))
3655 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "SDXElementStatus : Abort on IES\n");
3662 for (x = 0; x < DTE; x++)
3664 if (pDTE[x].ASC > 0)
3666 switch(SenseHandler(DeviceFD, 0, SENSE_CHG_ELEMENT_STATUS, pDTE[x].ASC, pDTE[x].ASCQ, (char *)&pDTE[x]))
3675 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "SDXElementStatus : Abort on DTE\n");
3683 * OK, we have an error, do an INIT ELMENT
3684 * For the tape if not handled by the robot we have
3685 * to do some extra checks
3689 if (GenericResetStatus(DeviceFD) != 0)
3691 ElementStatusValid = 0;
3692 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "SDXElementStatus : Can't init status\n");
3697 /* Done GetElementStatus */
3702 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "SDXElementStatus : Can't init status\n");
3706 ElementStatusValid = 1;
3708 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "#### STOP SDXElementStatus\n");
3714 * Reads the element information from the library. There are 2 ways to do this.
3715 * Either check the result from the mode sense page to see which types of elements
3716 * are available (STE/DTE/MTE....), or do an read element status with the option give
3717 * me all and than check what is available.
3719 * Only do the read, error handling is done by the calling function
3727 int GetElementStatus(int DeviceFD)
3729 unsigned char *DataBuffer = NULL;
3730 int DataBufferLength;
3731 ElementStatusData_T *ElementStatusData;
3732 ElementStatusPage_T *ElementStatusPage;
3733 MediumTransportElementDescriptor_T *MediumTransportElementDescriptor;
3734 StorageElementDescriptor_T *StorageElementDescriptor;
3735 DataTransferElementDescriptor_T *DataTransferElementDescriptor;
3736 ImportExportElementDescriptor_T *ImportExportElementDescriptor;
3739 int length = 0; /* Length of an Element */
3740 int barcode = 0; /* To store the result of the BarCode function */
3743 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"##### START GetElementStatus\n");
3745 barcode = BarCode(DeviceFD);
3748 * If the MODE_SENSE was successfull we use this Information to read the Elelement Info
3750 if (pEAAPage != NULL)
3752 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Reading Element Status with the info from mode sense\n");
3753 /* First the Medim Transport*/
3754 if (V2(pEAAPage->NoMediumTransportElements) > 0)
3756 MTE = V2(pEAAPage->NoMediumTransportElements) ;
3759 if ((pMTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * MTE)) == NULL)
3761 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
3765 memset(pMTE, 0, sizeof(ElementInfo_T) * MTE);
3767 if (SCSI_ReadElementStatus(DeviceFD,
3771 V2(pEAAPage->MediumTransportElementAddress),
3773 sizeof(MediumTransportElementDescriptor_T),
3774 (char **)&DataBuffer) != 0)
3776 if (DataBuffer != 0)
3780 ChgExit("genericElementStatus","Can't read MTE status", FATAL);
3782 ElementStatusData = (ElementStatusData_T *)DataBuffer;
3783 offset = sizeof(ElementStatusData_T);
3785 ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
3786 offset = offset + sizeof(ElementStatusPage_T);
3787 length = V2(ElementStatusPage->length);
3788 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"MTE Length %d(%d)\n",length,sizeof(MediumTransportElementDescriptor_T));
3790 for (x = 0; x < MTE; x++)
3792 MediumTransportElementDescriptor = (MediumTransportElementDescriptor_T *)&DataBuffer[offset];
3794 if (ElementStatusPage->pvoltag == 1)
3796 strncpy(pMTE[x].VolTag,
3797 MediumTransportElementDescriptor->pvoltag,
3799 TerminateString(pMTE[x].VolTag, TAG_SIZE+1);
3802 pMTE[x].type = ElementStatusPage->type;
3803 pMTE[x].address = V2(MediumTransportElementDescriptor->address);
3804 pMTE[x].except = MediumTransportElementDescriptor->except;
3805 pMTE[x].status = (MediumTransportElementDescriptor->full > 0) ? 'F':'E';
3806 pMTE[x].full = MediumTransportElementDescriptor->full;
3810 pMTE[x].ASC = MediumTransportElementDescriptor->asc;
3812 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC MTE\n");
3817 pMTE[x].ASCQ = MediumTransportElementDescriptor->ascq;
3819 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ MTE\n");
3824 if (MediumTransportElementDescriptor->svalid == 1)
3826 pMTE[x].from = V2(MediumTransportElementDescriptor->source);
3831 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source MTE\n");
3833 offset = offset + length;
3839 if ( V2(pEAAPage->NoStorageElements) > 0)
3841 STE = V2(pEAAPage->NoStorageElements);
3844 if ((pSTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * STE)) == NULL)
3846 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
3850 memset(pSTE, 0, sizeof(ElementInfo_T) * STE);
3852 if (SCSI_ReadElementStatus(DeviceFD,
3856 V2(pEAAPage->FirstStorageElementAddress),
3858 sizeof(StorageElementDescriptor_T),
3859 (char **)&DataBuffer) != 0)
3861 if (DataBuffer != 0)
3865 ChgExit("GetElementStatus", "Can't read STE status", FATAL);
3868 ElementStatusData = (ElementStatusData_T *)DataBuffer;
3869 offset = sizeof(ElementStatusData_T);
3871 ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
3872 offset = offset + sizeof(ElementStatusPage_T);
3873 length = V2(ElementStatusPage->length);
3874 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"STE Length %d\n",length);
3876 for (x = 0; x < STE; x++)
3878 StorageElementDescriptor = (StorageElementDescriptor_T *)&DataBuffer[offset];
3879 if (ElementStatusPage->pvoltag == 1)
3881 strncpy(pSTE[x].VolTag,
3882 StorageElementDescriptor->pvoltag,
3884 TerminateString(pSTE[x].VolTag, TAG_SIZE+1);
3888 pSTE[x].type = ElementStatusPage->type;
3889 pSTE[x].address = V2(StorageElementDescriptor->address);
3890 pSTE[x].except = StorageElementDescriptor->except;
3891 pSTE[x].status = (StorageElementDescriptor->full > 0) ? 'F':'E';
3892 pSTE[x].full = StorageElementDescriptor->full;
3896 pSTE[x].ASC = StorageElementDescriptor->asc;
3898 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC STE\n");
3903 pSTE[x].ASCQ = StorageElementDescriptor->ascq;
3905 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ STE\n");
3910 if (StorageElementDescriptor->svalid == 1)
3912 pSTE[x].from = V2(StorageElementDescriptor->source);
3917 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
3920 offset = offset + length;
3925 * Import/Export Elements
3927 if ( V2(pEAAPage->NoImportExportElements) > 0)
3929 IEE = V2(pEAAPage->NoImportExportElements);
3932 if ((pIEE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * IEE)) == NULL)
3934 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
3938 memset(pIEE, 0, sizeof(ElementInfo_T) * IEE);
3939 if (SCSI_ReadElementStatus(DeviceFD,
3943 V2(pEAAPage->FirstImportExportElementAddress),
3945 sizeof(ImportExportElementDescriptor_T),
3946 (char **)&DataBuffer) != 0)
3948 if (DataBuffer != 0)
3952 ChgExit("GetElementStatus", "Can't read IEE status", FATAL);
3955 ElementStatusData = (ElementStatusData_T *)DataBuffer;
3956 offset = sizeof(ElementStatusData_T);
3958 ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
3959 offset = offset + sizeof(ElementStatusPage_T);
3960 length = V2(ElementStatusPage->length);
3961 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"IEE Length %d\n",length);
3963 for (x = 0; x < IEE; x++)
3965 ImportExportElementDescriptor = (ImportExportElementDescriptor_T *)&DataBuffer[offset];
3966 if (ElementStatusPage->pvoltag == 1)
3968 strncpy(pIEE[x].VolTag,
3969 ImportExportElementDescriptor->pvoltag,
3971 TerminateString(pIEE[x].VolTag, TAG_SIZE+1);
3973 pIEE[x].type = ElementStatusPage->type;
3974 pIEE[x].address = V2(ImportExportElementDescriptor->address);
3975 pIEE[x].except = ImportExportElementDescriptor->except;
3976 pIEE[x].status = (ImportExportElementDescriptor->full > 0) ? 'F':'E';
3977 pIEE[x].full = ImportExportElementDescriptor->full;
3981 pIEE[x].ASC = ImportExportElementDescriptor->asc;
3983 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC IEE\n");
3988 pIEE[x].ASCQ = ImportExportElementDescriptor->ascq;
3990 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ IEE\n");
3995 if (ImportExportElementDescriptor->svalid == 1)
3997 pIEE[x].from = V2(ImportExportElementDescriptor->source);
4002 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source IEE\n");
4005 offset = offset + length;
4010 * Data Transfer Elements
4012 if (V2(pEAAPage->NoDataTransferElements) >0)
4014 DTE = V2(pEAAPage->NoDataTransferElements) ;
4017 if ((pDTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * DTE)) == NULL)
4019 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
4023 memset(pDTE, 0, sizeof(ElementInfo_T) * DTE);
4024 if (SCSI_ReadElementStatus(DeviceFD,
4028 V2(pEAAPage->FirstDataTransferElementAddress),
4030 sizeof(DataTransferElementDescriptor_T),
4031 (char **)&DataBuffer) != 0)
4033 if (DataBuffer != 0)
4037 ChgExit("GenericElementStatus", "Can't read DTE status", FATAL);
4040 ElementStatusData = (ElementStatusData_T *)DataBuffer;
4041 offset = sizeof(ElementStatusData_T);
4043 ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
4044 offset = offset + sizeof(ElementStatusPage_T);
4045 length = V2(ElementStatusPage->length);
4046 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"DTE Length %d\n",length);
4048 for (x = 0; x < DTE; x++)
4050 DataTransferElementDescriptor = (DataTransferElementDescriptor_T *)&DataBuffer[offset];
4051 if (ElementStatusPage->pvoltag == 1)
4053 strncpy(pDTE[x].VolTag,
4054 DataTransferElementDescriptor->pvoltag,
4056 TerminateString(pDTE[x].VolTag, TAG_SIZE+1);
4058 pDTE[x].type = ElementStatusPage->type;
4059 pDTE[x].address = V2(DataTransferElementDescriptor->address);
4060 pDTE[x].except = DataTransferElementDescriptor->except;
4061 pDTE[x].scsi = DataTransferElementDescriptor->scsi;
4062 pDTE[x].status = (DataTransferElementDescriptor->full > 0) ? 'F':'E';
4063 pDTE[x].full = DataTransferElementDescriptor->full;
4067 pDTE[x].ASC = DataTransferElementDescriptor->asc;
4069 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC DTE\n");
4074 pDTE[x].ASCQ = DataTransferElementDescriptor->ascq;
4076 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ DTE\n");
4081 if (DataTransferElementDescriptor->svalid == 1)
4083 pDTE[x].from = V2(DataTransferElementDescriptor->source);
4088 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
4091 offset = offset + length;
4096 * And now the old way, when we get here the read mode sense page has failed ...
4098 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Reading Element Status the old way .... (max 255 elements)\n");
4099 if (SCSI_ReadElementStatus(DeviceFD,
4106 (char **)&DataBuffer) != 0)
4108 if (DataBuffer != 0)
4112 ChgExit("GenericElementStatus","Can't get ElementStatus", FATAL);
4115 ElementStatusData = (ElementStatusData_T *)DataBuffer;
4116 DataBufferLength = V3(ElementStatusData->count);
4118 offset = sizeof(ElementStatusData_T);
4120 if (DataBufferLength <= 0)
4122 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"DataBufferLength %d\n",DataBufferLength);
4126 while (offset < DataBufferLength)
4128 ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
4129 NoOfElements = V3(ElementStatusPage->count) / V2(ElementStatusPage->length);
4130 offset = offset + sizeof(ElementStatusPage_T);
4131 length = V2(ElementStatusPage->length);
4133 switch (ElementStatusPage->type)
4137 if ((pMTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * MTE)) == NULL)
4139 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
4142 memset(pMTE, 0, sizeof(ElementInfo_T) * MTE);
4143 for (x = 0; x < NoOfElements; x++)
4145 MediumTransportElementDescriptor = (MediumTransportElementDescriptor_T *)&DataBuffer[offset];
4146 if (ElementStatusPage->pvoltag == 1)
4148 strncpy(pMTE[x].VolTag,
4149 MediumTransportElementDescriptor->pvoltag,
4151 TerminateString(pMTE[x].VolTag, TAG_SIZE+1);
4153 pMTE[x].type = ElementStatusPage->type;
4154 pMTE[x].address = V2(MediumTransportElementDescriptor->address);
4155 pMTE[x].except = MediumTransportElementDescriptor->except;
4156 pMTE[x].status = (MediumTransportElementDescriptor->full > 0) ? 'F':'E';
4157 pMTE[x].full = MediumTransportElementDescriptor->full;
4162 pMTE[x].ASC = MediumTransportElementDescriptor->asc;
4164 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC MTE\n");
4169 pMTE[x].ASCQ = MediumTransportElementDescriptor->ascq;
4171 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ MTE\n");
4176 if (MediumTransportElementDescriptor->svalid == 1)
4178 pMTE[x].from = V2(MediumTransportElementDescriptor->source);
4183 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source MTE\n");
4186 offset = offset + length;
4191 if ((pSTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * STE)) == NULL)
4193 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
4196 memset(pSTE, 0, sizeof(ElementInfo_T) * STE);
4197 for (x = 0; x < NoOfElements; x++)
4199 StorageElementDescriptor = (StorageElementDescriptor_T *)&DataBuffer[offset];
4200 if (ElementStatusPage->pvoltag == 1)
4202 strncpy(pSTE[x].VolTag,
4203 StorageElementDescriptor->pvoltag,
4205 TerminateString(pSTE[x].VolTag, TAG_SIZE+1);
4208 pSTE[x].type = ElementStatusPage->type;
4209 pSTE[x].address = V2(StorageElementDescriptor->address);
4210 pSTE[x].except = StorageElementDescriptor->except;
4211 pSTE[x].status = (StorageElementDescriptor->full > 0) ? 'F':'E';
4212 pSTE[x].full = StorageElementDescriptor->full;
4216 pSTE[x].ASC = StorageElementDescriptor->asc;
4218 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC STE\n");
4223 pSTE[x].ASCQ = StorageElementDescriptor->ascq;
4225 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ STE\n");
4230 if (StorageElementDescriptor->svalid == 1)
4232 pSTE[x].from = V2(StorageElementDescriptor->source);
4237 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
4240 offset = offset + length;
4245 if ((pIEE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * IEE)) == NULL)
4247 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
4250 memset(pIEE, 0, sizeof(ElementInfo_T) * IEE);
4252 for (x = 0; x < NoOfElements; x++)
4254 ImportExportElementDescriptor = (ImportExportElementDescriptor_T *)&DataBuffer[offset];
4255 if (ElementStatusPage->pvoltag == 1)
4257 strncpy(pIEE[x].VolTag,
4258 ImportExportElementDescriptor->pvoltag,
4260 TerminateString(pIEE[x].VolTag, TAG_SIZE+1);
4262 ImportExportElementDescriptor = (ImportExportElementDescriptor_T *)&DataBuffer[offset];
4263 pIEE[x].type = ElementStatusPage->type;
4264 pIEE[x].address = V2(ImportExportElementDescriptor->address);
4265 pIEE[x].except = ImportExportElementDescriptor->except;
4266 pIEE[x].status = (ImportExportElementDescriptor->full > 0) ? 'F':'E';
4267 pIEE[x].full = ImportExportElementDescriptor->full;
4271 pIEE[x].ASC = ImportExportElementDescriptor->asc;
4273 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC IEE\n");
4278 pIEE[x].ASCQ = ImportExportElementDescriptor->ascq;
4280 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ IEE\n");
4285 if (ImportExportElementDescriptor->svalid == 1)
4287 pIEE[x].from = V2(ImportExportElementDescriptor->source);
4292 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source IEE\n");
4295 offset = offset + length;
4300 if ((pDTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * DTE)) == NULL)
4302 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
4305 memset(pDTE, 0, sizeof(ElementInfo_T) * DTE);
4307 for (x = 0; x < NoOfElements; x++)
4309 DataTransferElementDescriptor = (DataTransferElementDescriptor_T *)&DataBuffer[offset];
4310 if (ElementStatusPage->pvoltag == 1)
4312 strncpy(pSTE[x].VolTag,
4313 DataTransferElementDescriptor->pvoltag,
4315 TerminateString(pSTE[x].VolTag, TAG_SIZE+1);
4317 pDTE[x].type = ElementStatusPage->type;
4318 pDTE[x].address = V2(DataTransferElementDescriptor->address);
4319 pDTE[x].except = DataTransferElementDescriptor->except;
4320 pDTE[x].scsi = DataTransferElementDescriptor->scsi;
4321 pDTE[x].status = (DataTransferElementDescriptor->full > 0) ? 'F':'E';
4322 pDTE[x].full = DataTransferElementDescriptor->full;
4326 pDTE[x].ASC = DataTransferElementDescriptor->asc;
4328 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC DTE\n");
4333 pDTE[x].ASCQ = DataTransferElementDescriptor->ascq;
4335 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ DTE\n");
4340 if (DataTransferElementDescriptor->svalid == 1)
4342 pDTE[x].from = V2(DataTransferElementDescriptor->source);
4347 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
4350 offset = offset + length;
4354 offset = offset + length;
4355 DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GetElementStatus : UnGknown Type %d\n",ElementStatusPage->type);
4361 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\n\n\tMedia Transport Elements (robot arms) :\n");
4363 for ( x = 0; x < MTE; x++)
4364 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\t\tElement #%04d %c\n\t\t\tEXCEPT = %02x\n\t\t\tASC = %02X ASCQ = %02X\n\t\t\tType %d From = %04d\n\t\t\tTAG = %s\n",
4365 pMTE[x].address, pMTE[x].status, pMTE[x].except, pMTE[x].ASC,
4366 pMTE[x].ASCQ, pMTE[x].type, pMTE[x].from, pMTE[x].VolTag);
4368 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\n\n\tStorage Elements (Media slots) :\n");
4370 for ( x = 0; x < STE; x++)
4371 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\t\tElement #%04d %c\n\t\t\tEXCEPT = %02X\n\t\t\tASC = %02X ASCQ = %02X\n\t\t\tType %d From = %04d\n\t\t\tTAG = %s\n",
4372 pSTE[x].address, pSTE[x].status, pSTE[x].except, pSTE[x].ASC,
4373 pSTE[x].ASCQ, pSTE[x].type, pSTE[x].from, pSTE[x].VolTag);
4375 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\n\n\tData Transfer Elements (tape drives) :\n");
4377 for ( x = 0; x < DTE; x++)
4378 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\t\tElement #%04d %c\n\t\t\tEXCEPT = %02X\n\t\t\tASC = %02X ASCQ = %02X\n\t\t\tType %d From = %04d\n\t\t\tTAG = %s\n\t\t\tSCSI ADDRESS = %d\n",
4379 pDTE[x].address, pDTE[x].status, pDTE[x].except, pDTE[x].ASC,
4380 pDTE[x].ASCQ, pDTE[x].type, pDTE[x].from, pDTE[x].VolTag,pDTE[x].scsi);
4382 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\n\n\tImport/Export Elements :\n");
4384 for ( x = 0; x < IEE; x++)
4385 DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\t\tElement #%04d %c\n\t\t\tEXCEPT = %02X\n\t\t\t\tASC = %02X ASCQ = %02X\n\t\t\tType %d From = %04d\n\t\t\tTAG = %s\n",
4386 pIEE[x].address, pIEE[x].status, pIEE[x].except, pIEE[x].ASC,
4387 pIEE[x].ASCQ, pIEE[x].type, pIEE[x].from, pIEE[x].VolTag);
4397 * If ClearErrorCounters is set the counters will be reset.
4398 * Used by GenericClean for example
4402 int RequestSense(int DeviceFD, ExtendedRequestSense_T *ExtendedRequestSense, int ClearErrorCounters )
4407 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START RequestSense\n");
4409 CDB[0] = SC_COM_REQUEST_SENSE; /* REQUEST SENSE */
4410 CDB[1] = 0; /* Logical Unit Number = 0, Reserved */
4411 CDB[2] = 0; /* Reserved */
4412 CDB[3] = 0; /* Reserved */
4413 CDB[4] = sizeof(ExtendedRequestSense_T); /* Allocation Length */
4414 CDB[5] = (ClearErrorCounters << 7) & 0x80; /* */
4416 memset(ExtendedRequestSense, 0, sizeof(ExtendedRequestSense_T));
4418 ret = SCSI_Run(DeviceFD, Input, CDB, 6,
4419 (char *) ExtendedRequestSense,
4420 sizeof(ExtendedRequestSense_T),
4421 (char *) ExtendedRequestSense, sizeof(ExtendedRequestSense_T));
4426 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP RequestSense (%d)\n",ret);
4432 DecodeExtSense(ExtendedRequestSense, "RequestSense : ",debug_file);
4433 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP RequestSense (%d)\n", ExtendedRequestSense->SenseKey);
4434 return(ExtendedRequestSense->SenseKey);
4437 dump_hex((char *)ExtendedRequestSense , sizeof(ExtendedRequestSense_T) , DEBUG_INFO, SECTION_SCSI);
4438 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP RequestSense (0)\n");
4444 * Lookup function pointer for device ....
4448 ElementInfo_T *LookupElement(int address)
4452 dbprintf(("##### START LookupElement\n"));
4456 for (x = 0; x < DTE; x++)
4458 if (pDTE[x].address == address)
4460 dbprintf(("##### STOP LookupElement (DTE)\n"));
4468 for (x = 0; x < MTE; x++)
4470 if (pMTE[x].address == address)
4472 dbprintf(("##### STOP LookupElement (MTE)\n"));
4480 for (x = 0; x < STE; x++)
4482 if (pSTE[x].address == address)
4484 dbprintf(("##### STOP LookupElement (STE)\n"));
4492 for ( x = 0; x < IEE; x++)
4494 if (pIEE[x].address == address)
4496 dbprintf(("##### STOP LookupElement (IEE)\n"));
4504 * Here comes everything what decode the log Pages
4507 * Fix the result handling from TestUnitReady
4510 int LogSense(DeviceFD)
4512 extern OpenFiles_T *pDev;
4514 RequestSense_T *pRequestSense;
4515 LogSenseHeader_T *LogSenseHeader;
4516 LogParameter_T *LogParameter;
4517 struct LogPageDecode *p;
4519 char *datestamp = NULL;
4521 char *result = NULL;
4522 extern char *tapestatfile;
4533 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START LogSense\n");
4535 if (tapestatfile != NULL &&
4536 (StatFile = fopen(tapestatfile,"a")) != NULL &&
4537 pDev[INDEX_TAPECTL].SCSI == 1)
4539 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
4541 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"LogSense : malloc failed\n");
4545 if (GenericRewind(INDEX_TAPECTL) < 0)
4547 DebugPrint(DEBUG_INFO, SECTION_TAPE,"LogSense : Rewind failed\n");
4548 free(pRequestSense);
4552 * Try to read the tape label
4554 if (pDev[INDEX_TAPE].inqdone == 1)
4556 if (pDev[INDEX_TAPE].devopen == 1)
4558 SCSI_CloseDevice(INDEX_TAPE);
4561 if ((result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &datestamp, &label)) == NULL)
4563 fprintf(StatFile, "==== %s ==== %s ====\n", datestamp, label);
4565 fprintf(StatFile, "%s\n", result);
4569 if ((buffer = (char *)malloc(size)) == NULL)
4571 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"LogSense : malloc failed\n");
4574 memset(buffer, 0, size);
4576 * Get the known log pages
4579 CDB[0] = SC_COM_LOG_SENSE;
4581 CDB[2] = 0x40; /* 0x40 for current values */
4586 MSB2(&CDB[7], size);
4589 if (SCSI_Run(INDEX_TAPECTL, Input, CDB, 10,
4592 (char *)pRequestSense,
4593 sizeof(RequestSense_T)) != 0)
4595 DecodeSense(pRequestSense, "LogSense : ",debug_file);
4597 free(pRequestSense);
4601 LogSenseHeader = (LogSenseHeader_T *)buffer;
4602 nologpages = V2(LogSenseHeader->PageLength);
4603 if ((logpages = (char *)malloc(nologpages)) == NULL)
4605 DebugPrint(DEBUG_ERROR, SECTION_TAPE,"LogSense : malloc failed\n");
4609 memcpy(logpages, buffer + sizeof(LogSenseHeader_T), nologpages);
4611 for (count = 0; count < nologpages; count++) {
4612 if (logpages[count] != 0 ) {
4613 memset(buffer, 0, size);
4616 CDB[0] = SC_COM_LOG_SENSE;
4618 CDB[2] = 0x40 | logpages[count]; /* 0x40 for current values */
4623 MSB2(&CDB[7], size);
4626 if (SCSI_Run(INDEX_TAPECTL, Input, CDB, 10,
4629 (char *)pRequestSense,
4630 sizeof(RequestSense_T)) != 0)
4632 DecodeSense(pRequestSense, "LogSense : ",debug_file);
4634 free(pRequestSense);
4637 LogSenseHeader = (LogSenseHeader_T *)buffer;
4638 length = V2(LogSenseHeader->PageLength);
4639 LogParameter = (LogParameter_T *)(buffer + sizeof(LogSenseHeader_T));
4641 * Decode the log pages
4643 p = (struct LogPageDecode *)&DecodePages;
4646 dump_hex((char *)LogParameter, 64, DEBUG_INFO, SECTION_SCSI);
4648 while(p->ident != NULL) {
4649 if ((strcmp(pDev[INDEX_TAPECTL].ident, p->ident) == 0 ||strcmp("*", p->ident) == 0) && p->LogPage == logpages[count]) {
4650 p->decode(LogParameter, length);
4652 fprintf(StatFile, "\n");
4659 * Hack to disable the printing of unknown pages
4664 fprintf(StatFile, "Logpage No %d = %x\n", count ,logpages[count]);
4666 while ((char *)LogParameter < (buffer + length)) {
4667 i = LogParameter->ParameterLength;
4668 ParameterCode = V2(LogParameter->ParameterCode);
4671 value = V1((char *)LogParameter + sizeof(LogParameter_T));
4672 fprintf(StatFile, "ParameterCode %02X = %u(%d)\n", ParameterCode, value, i);
4675 value = V2((char *)LogParameter + sizeof(LogParameter_T));
4676 fprintf(StatFile, "ParameterCode %02X = %u(%d)\n", ParameterCode, value, i);
4679 value = V3((char *)LogParameter + sizeof(LogParameter_T));
4680 fprintf(StatFile, "ParameterCode %02X = %u(%d)\n", ParameterCode, value, i);
4683 value = V4((char *)LogParameter + sizeof(LogParameter_T));
4684 fprintf(StatFile, "ParameterCode %02X = %u(%d)\n", ParameterCode, value, i);
4687 value = V5((char *)LogParameter + sizeof(LogParameter_T));
4688 fprintf(StatFile, "ParameterCode %02X = %u(%d)\n", ParameterCode, value, i);
4691 fprintf(StatFile, "ParameterCode %02X size %d\n", ParameterCode, i);
4693 LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
4695 fprintf(StatFile, "\n");
4702 * Reset the cumulative counters
4704 CDB[0] = SC_COM_LOG_SELECT;
4715 if (SCSI_Run(INDEX_TAPECTL, Input, CDB, 10,
4718 (char *)pRequestSense,
4719 sizeof(RequestSense_T)) != 0)
4721 DecodeSense(pRequestSense, "LogSense : ",debug_file);
4723 free(pRequestSense);
4727 free(pRequestSense);
4730 DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP LogSense\n");
4735 void WriteErrorCountersPage(LogParameter_T *buffer, int length)
4739 LogParameter_T *LogParameter;
4741 LogParameter = buffer;
4743 fprintf(StatFile, "\tWrite Error Counters Page\n");
4745 while ((char *)LogParameter < ((char *)buffer + length)) {
4746 i = LogParameter->ParameterLength;
4747 ParameterCode = V2(LogParameter->ParameterCode);
4750 if (Decode(LogParameter, &value) == 0) {
4751 switch (ParameterCode) {
4753 fprintf(StatFile, "%-30s = %u\n",
4758 fprintf(StatFile, "%-30s = %u\n",
4759 "Total Errors Corrected",
4763 fprintf(StatFile, "%-30s = %u\n",
4764 "Total Times E. Processed",
4768 fprintf(StatFile, "%-30s = %u\n",
4769 "Total Bytes Processed",
4773 fprintf(StatFile, "%-30s = %u\n",
4774 "Total Unrecoverable Errors",
4778 fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
4784 fprintf(StatFile, "Error decoding Result\n");
4786 LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
4790 void ReadErrorCountersPage(LogParameter_T *buffer, int length)
4794 LogParameter_T *LogParameter;
4796 LogParameter = buffer;
4798 fprintf(StatFile, "\tRead Error Counters Page\n");
4800 while ((char *)LogParameter < ((char *)buffer + length)) {
4801 i = LogParameter->ParameterLength;
4802 ParameterCode = V2(LogParameter->ParameterCode);
4804 if (Decode(LogParameter, &value) == 0) {
4805 switch (ParameterCode) {
4807 fprintf(StatFile, "%-30s = %u\n",
4812 fprintf(StatFile, "%-30s = %u\n",
4813 "Total Errors Corrected",
4817 fprintf(StatFile, "%-30s = %u\n",
4818 "Total Times E. Processed",
4822 fprintf(StatFile, "%-30s = %u\n",
4823 "Total Bytes Processed",
4827 fprintf(StatFile, "%-30s = %u\n",
4828 "Total Unrecoverable Errors",
4832 fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
4838 fprintf(StatFile, "Error decoding Result\n");
4840 LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
4844 void C1553APage30(LogParameter_T *buffer, int length)
4848 LogParameter_T *LogParameter;
4850 LogParameter = buffer;
4852 fprintf(StatFile, "\tData compression transfer Page\n");
4854 while ((char *)LogParameter < ((char *)buffer + length)) {
4855 i = LogParameter->ParameterLength;
4856 ParameterCode = V2(LogParameter->ParameterCode);
4858 if (Decode(LogParameter, &value) == 0) {
4859 switch (ParameterCode) {
4861 fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
4867 LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
4871 void C1553APage37(LogParameter_T *buffer, int length)
4875 LogParameter_T *LogParameter;
4877 LogParameter = buffer;
4879 fprintf(StatFile, "\tDrive Counters Page\n");
4881 while ((char *)LogParameter < ((char *)buffer + length)) {
4882 i = LogParameter->ParameterLength;
4883 ParameterCode = V2(LogParameter->ParameterCode);
4885 if (Decode(LogParameter, &value) == 0) {
4886 switch (ParameterCode) {
4888 fprintf(StatFile, "%-30s = %u\n",
4893 fprintf(StatFile, "%-30s = %u\n",
4894 "Total write drive errors",
4898 fprintf(StatFile, "%-30s = %u\n",
4899 "Total read drive errors",
4903 fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
4909 LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
4913 void EXB85058HEPage39(LogParameter_T *buffer, int length)
4917 LogParameter_T *LogParameter;
4919 LogParameter = buffer;
4921 fprintf(StatFile, "\tData Compression Page\n");
4923 while ((char *)LogParameter < ((char *)buffer + length)) {
4924 i = LogParameter->ParameterLength;
4925 ParameterCode = V2(LogParameter->ParameterCode);
4927 if (Decode(LogParameter, &value) == 0) {
4928 switch (ParameterCode) {
4930 fprintf(StatFile, "%-30s = %u\n",
4935 fprintf(StatFile, "%-30s = %u\n",
4940 fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
4946 LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
4950 void EXB85058HEPage3c(LogParameter_T *buffer, int length)
4954 LogParameter_T *LogParameter;
4956 LogParameter = buffer;
4958 fprintf(StatFile, "\tDrive Usage Information Page\n");
4960 while ((char *)LogParameter < ((char *)buffer + length)) {
4961 i = LogParameter->ParameterLength;
4962 ParameterCode = V2(LogParameter->ParameterCode);
4964 if (Decode(LogParameter, &value) == 0) {
4965 switch (ParameterCode) {
4973 fprintf(StatFile, "%-30s = %u\n",
4978 fprintf(StatFile, "%-30s = %u\n",
4979 "MinutesSince Last Clean",
4986 fprintf(StatFile, "%-30s = %u\n",
4998 fprintf(StatFile, "%-30s = %u\n",
5007 fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
5013 LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
5017 int Decode(LogParameter_T *LogParameter, int *value)
5020 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START Decode\n");
5021 DebugPrint(DEBUG_INFO, SECTION_SCSI,"Decode Parameter with length %d\n", LogParameter->ParameterLength);
5022 switch (LogParameter->ParameterLength) {
5024 *value = V1((char *)LogParameter + sizeof(LogParameter_T));
5027 *value = V2((char *)LogParameter + sizeof(LogParameter_T));
5030 *value = V3((char *)LogParameter + sizeof(LogParameter_T));
5033 *value = V4((char *)LogParameter + sizeof(LogParameter_T));
5036 *value = V5((char *)LogParameter + sizeof(LogParameter_T));
5039 *value = V6((char *)LogParameter + sizeof(LogParameter_T));
5042 fprintf(StatFile, "Can't decode ParameterCode %02X size %d\n",
5043 V2(LogParameter->ParameterCode), LogParameter->ParameterLength);
5044 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP Decode (1)\n");
5047 DebugPrint(DEBUG_INFO, SECTION_SCSI,"Result = %d\n", *value);
5048 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP Decode(0)\n");
5052 void DumpDev(OpenFiles_T *p, char *device)
5056 printf("%s Devicefd %d\n", device, p->fd);
5057 printf("%s Can SCSI %d\n", device, p->SCSI);
5058 printf("%s Device %s\n", device, (p->dev != NULL)? p->dev:"No set");
5059 printf("%s ConfigName %s\n", device, (p->ConfigName != NULL) ? p->ConfigName:"Not ser");
5061 printf("%s Null Pointer ....\n", device);
5066 void ChangerReplay(char *option)
5072 if ((ip=fopen("/tmp/chg-scsi-trace", "r")) == NULL)
5077 while (fscanf(ip, "%2x", &bufferx) != EOF)
5079 buffer[x] = bufferx;
5083 DecodeModeSense(&buffer[0], 12, "DLT448ElementStatus :", 0, debug_file);
5087 * Display all Information we can get about the library....
5089 void ChangerStatus(char *option, char * labelfile, int HasBarCode, char *changer_file, char *changer_dev, char *tape_device)
5091 extern OpenFiles_T *pDev;
5094 ExtendedRequestSense_T ExtRequestSense;
5095 MBC_T *pbarcoderes = malloc(sizeof(MBC_T));
5097 ChangerCMD_T *p = (ChangerCMD_T *)&ChangerIO;
5098 memset(pbarcoderes, 0, sizeof(MBC_T));
5100 if ((pModePage = (char *)malloc(0xff)) == NULL)
5102 printf("malloc failed \n");
5106 if ((out = fdopen(1 , "w")) == NULL)
5108 printf("Error fdopen stdout\n");
5112 if (strcmp("types", option) == 0 || strcmp("all", option) == 0)
5114 while(p->ident != NULL)
5116 printf ("Ident = %s, type = %s\n",p->ident, p->type);
5122 if (strcmp("robot", option) == 0 || strcmp("all", option) == 0)
5124 if (ElementStatusValid == 0)
5126 if (pDev[INDEX_CHANGER].functions->function_status(pDev[INDEX_CHANGER].fd, 1) != 0)
5128 printf("Can not initialize changer status\n");
5132 /* 0123456789012345678901234567890123456789012 */
5135 printf("Address Type Status From Barcode Label\n");
5137 printf("Address Type Status From\n");
5139 printf("-------------------------------------------\n");
5142 for ( x = 0; x < MTE; x++)
5145 printf("%07d MTE %s %04d %s ",pMTE[x].address,
5146 (pMTE[x].full ? "Full " :"Empty"),
5147 pMTE[x].from, pMTE[x].VolTag);
5149 if (pMTE[x].full == 1)
5151 pbarcoderes->action = BARCODE_BARCODE;
5152 strcpy(pbarcoderes->data.barcode, pMTE[x].VolTag);
5154 if (MapBarCode(labelfile, pbarcoderes) == 0 )
5156 printf("No mapping\n");
5158 printf("%s \n",pbarcoderes->data.voltag);
5164 printf("%07d MTE %s %04d \n",pMTE[x].address,
5165 (pMTE[x].full ? "Full " :"Empty"),
5170 for ( x = 0; x < STE; x++)
5173 printf("%07d STE %s %04d %s ",pSTE[x].address,
5174 (pSTE[x].full ? "Full ":"Empty"),
5175 pSTE[x].from, pSTE[x].VolTag);
5177 if (pSTE[x].full == 1)
5179 pbarcoderes->action = BARCODE_BARCODE;
5180 strcpy(pbarcoderes->data.barcode, pSTE[x].VolTag);
5182 if (MapBarCode(labelfile, pbarcoderes) == 0 )
5184 printf("No mapping\n");
5186 printf("%s \n",pbarcoderes->data.voltag);
5192 printf("%07d STE %s %04d %s\n",pSTE[x].address,
5193 (pSTE[x].full ? "Full ":"Empty"),
5194 pSTE[x].from, pSTE[x].VolTag);
5198 for ( x = 0; x < DTE; x++)
5201 printf("%07d DTE %s %04d %s ",pDTE[x].address,
5202 (pDTE[x].full ? "Full " : "Empty"),
5203 pDTE[x].from, pDTE[x].VolTag);
5205 if (pDTE[x].full == 1)
5207 pbarcoderes->action = BARCODE_BARCODE;
5208 strcpy(pbarcoderes->data.barcode, pDTE[x].VolTag);
5210 if (MapBarCode(labelfile, pbarcoderes) == 0 )
5212 printf("No mapping\n");
5214 printf("%s \n",pbarcoderes->data.voltag);
5221 printf("%07d DTE %s %04d %s\n",pDTE[x].address,
5222 (pDTE[x].full ? "Full " : "Empty"),
5223 pDTE[x].from, pDTE[x].VolTag);
5226 for ( x = 0; x < IEE; x++)
5229 printf("%07d IEE %s %04d %s ",pIEE[x].address,
5230 (pIEE[x].full ? "Full " : "Empty"),
5231 pIEE[x].from, pIEE[x].VolTag);
5233 if (pIEE[x].full == 1)
5235 pbarcoderes->action = BARCODE_BARCODE;
5236 strcpy(pbarcoderes->data.barcode, pIEE[x].VolTag);
5238 if (MapBarCode(labelfile, pbarcoderes) == 0 )
5240 printf("No mapping\n");
5242 printf("%s \n",pbarcoderes->data.voltag);
5249 printf("%07d IEE %s %04d %s\n",pIEE[x].address,
5250 (pIEE[x].full ? "Full " : "Empty"),
5251 pIEE[x].from, pIEE[x].VolTag);
5256 if (strcmp("sense", option) == 0 || strcmp("all", option) == 0)
5258 if (pDev[INDEX_CHANGER].SCSI == 1)
5260 printf("\nSense Status from robot:\n");
5261 RequestSense(INDEX_CHANGER , &ExtRequestSense, 0);
5262 DecodeExtSense(&ExtRequestSense, "", out);
5265 if (pDev[INDEX_TAPE].SCSI == 1)
5268 printf("Sense Status from tape (tapectl):\n");
5269 RequestSense(INDEX_TAPE, &ExtRequestSense, 0);
5270 DecodeExtSense(&ExtRequestSense, "", out);
5273 if (pDev[INDEX_TAPECTL].SCSI == 1)
5276 printf("Sense Status from tape (tapectl):\n");
5277 RequestSense(INDEX_TAPECTL, &ExtRequestSense, 0);
5278 DecodeExtSense(&ExtRequestSense, "", out);
5282 if (strcmp("ModeSenseRobot", option) == 0 || strcmp("all", option) == 0)
5285 if (SCSI_ModeSense(INDEX_CHANGER, pModePage, 0xff, 0x08, 0x3f) == 0)
5287 DecodeModeSense(pModePage, 0, "Changer :" , 0, out);
5291 if (strcmp("ModeSenseTape", option) == 0 || strcmp("all", option) == 0)
5293 if (pDev[INDEX_TAPECTL].SCSI == 1)
5296 if (SCSI_ModeSense(INDEX_TAPECTL, pModePage, 0xff, 0x0, 0x3f) == 0)
5298 DecodeModeSense(pModePage, 0, "Tape :" , 1, out);
5303 if (strcmp("fd", option) == 0 || strcmp("all", option) == 0)
5305 printf("changer_dev %s\n",changer_dev);
5306 printf("changer_file %s\n", changer_file);
5307 printf("tape_device %s\n\n", tape_device);
5308 DumpDev(&pDev[INDEX_TAPE], "pTapeDev");
5309 DumpDev(&pDev[INDEX_TAPECTL], "pTapeDevCtl");
5310 DumpDev(&pDev[INDEX_CHANGER], "pChangerDev");
5313 if (GenericClean("") == 1)
5314 printf("Tape needs cleaning\n");
5317 void dump_hex(char *p, int size, int level, int section)
5322 while (row_count < size)
5324 DebugPrint(level, section,"%02X ", (unsigned char)p[row_count]);
5325 if (((row_count + 1) % 16) == 0 )
5328 for (x = 16; x>0;x--)
5330 if (isalnum((unsigned char)p[row_count - x + 1 ]))
5331 DebugPrint(level, section,"%c",(unsigned char)p[row_count - x + 1]);
5333 DebugPrint(level, section,".");
5335 DebugPrint(level, section,"\n");
5339 DebugPrint(level, section,"\n");
5342 void TerminateString(char *string, int length)
5346 for (x = length; x >= 0 && !isalnum((int)string[x]); x--)
5350 void ChgExit(char *where, char *reason, int level)
5352 dbprintf(("ChgExit in %s, reason %s\n", where, reason));
5353 fprintf(stderr,"%s\n",reason);
5357 /* OK here starts a new set of functions.
5358 * Every function is for one SCSI command.
5359 * Prefix is SCSI_ and then the SCSI command name
5363 * SCSI_Run is an wrapper arround SCSI_ExecuteCommand
5364 * It seems to be an good idea to check first if the device
5365 * is ready for accepting commands, and if this is true send
5368 int SCSI_Run(int DeviceFD,
5369 Direction_T Direction,
5373 int DataBufferLength,
5374 char *pRequestSense,
5375 int RequestSenseLength)
5380 RequestSense_T *pRqS;
5382 pRqS = (RequestSense_T *)pRequestSense;
5384 DebugPrint(DEBUG_INFO, SECTION_SCSI, "SCSI_Run TestUnitReady\n");
5385 while (!ok && maxtries < MAXTRIES)
5387 ret = SCSI_TestUnitReady(DeviceFD, (RequestSense_T *)pRequestSense );
5388 DebugPrint(DEBUG_INFO, SECTION_SCSI, "SCSI_Run TestUnitReady ret %d\n",ret);
5395 switch (SenseHandler(DeviceFD, 0, pRqS->SenseKey, pRqS->AdditionalSenseCode, pRqS->AdditionalSenseCodeQualifier, pRequestSense))
5398 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SENSE_NO\n");
5401 case SENSE_TAPE_NOT_ONLINE:
5402 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
5406 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SENSE_IGNORE\n");
5410 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run (TestUnitReady) SENSE_ABORT\n");
5414 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SENSE_RETRY\n");
5417 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) default (SENSE)\n");
5423 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run (TestUnitReady) SCSI_ERROR\n");
5427 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SCSI_BUSY\n");
5430 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SCSI_CHECK\n");
5433 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run (TestUnitReady) unknown (%d)\n",ret);
5443 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run TestUnitReady after %d sec:\n",maxtries);
5447 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run Exit %d\n",ret);
5453 while (!ok && maxtries < MAXTRIES)
5455 ret = SCSI_ExecuteCommand(DeviceFD,
5462 RequestSenseLength);
5464 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run Exit %d\n",ret);
5471 switch (SenseHandler(DeviceFD, 0, pRqS->SenseKey, pRqS->AdditionalSenseCode, pRqS->AdditionalSenseCodeQualifier, pRequestSense))
5474 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run SENSE_NO\n");
5477 case SENSE_TAPE_NOT_ONLINE:
5478 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run SENSE_TAPE_NOT_ONLINE\n");
5482 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run SENSE_IGNORE\n");
5486 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run SENSE_ABORT\n");
5490 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run SENSE_RETRY\n");
5493 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run default (SENSE)\n");
5499 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run SCSI_ERROR\n");
5503 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run SCSI_BUSY\n");
5506 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SCSI_CHECK\n");
5509 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run (TestUnitReady) unknown (%d)\n",ret);
5525 * This a vendor specific command !!!!!!
5526 * First seen at AIT :-)
5528 int SCSI_AlignElements(int DeviceFD, int AE_MTE, int AE_DTE, int AE_STE)
5530 RequestSense_T *pRequestSense;
5536 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_AlignElements\n");
5538 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
5540 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : malloc failed\n");
5544 while (retry > 0 && retry < MAX_RETRIES)
5548 MSB2(&CDB[2],AE_MTE); /* Which MTE to use, default 0 */
5549 MSB2(&CDB[4],AE_DTE); /* Which DTE to use, no range check !! */
5550 MSB2(&CDB[6],AE_STE); /* Which STE to use, no range check !! */
5556 ret = SCSI_Run(DeviceFD, Input, CDB, 12,
5557 NULL, 0, (char *)pRequestSense, sizeof(RequestSense_T));
5559 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : SCSI_Run = %d\n", ret);
5560 DecodeSense(pRequestSense, "SCSI_AlignElements :",debug_file);
5564 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
5565 "chs", ((unsigned char *) &pRequestSense)[0]);
5566 for (i = 1; i < sizeof(RequestSense_T); i++)
5567 DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) &pRequestSense)[i]);
5568 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"\n");
5573 switch(SenseHandler(DeviceFD, 0 , pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
5576 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : SENSE_IGNORE\n");
5580 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : SENSE_RETRY no %d\n", retry);
5583 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_AlignElements : SENSE_ABORT\n");
5586 case SENSE_TAPE_NOT_UNLOADED:
5587 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_AlignElements : Tape still loaded, eject failed\n");
5591 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : end %d\n", pRequestSense->SenseKey);
5592 return(pRequestSense->SenseKey);
5598 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : end %d\n", ret);
5606 int SCSI_Move(int DeviceFD, unsigned char chm, int from, int to)
5608 RequestSense_T *pRequestSense;
5614 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_Move\n");
5616 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
5618 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Move : malloc failed\n");
5622 while (retry > 0 && retry < MAX_RETRIES)
5624 CDB[0] = SC_MOVE_MEDIUM;
5627 CDB[3] = chm; /* Address of CHM */
5635 ret = SCSI_Run(DeviceFD, Input, CDB, 12,
5636 NULL, 0, (char *)pRequestSense, sizeof(RequestSense_T));
5638 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Move : SCSI_Run = %d\n", ret);
5639 DecodeSense(pRequestSense, "SCSI_Move :",debug_file);
5643 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
5644 "chs", ((unsigned char *) &pRequestSense)[0]);
5645 for (i = 1; i < sizeof(RequestSense_T); i++)
5646 DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) &pRequestSense)[i]);
5647 DebugPrint(DEBUG_INFO, SECTION_SCSI,"\n");
5652 switch(SenseHandler(DeviceFD, 0 , pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
5655 dbprintf(("SCSI_Move : SENSE_IGNORE\n"));
5659 dbprintf(("SCSI_Move : SENSE_RETRY no %d\n", retry));
5662 dbprintf(("SCSI_Move : SENSE_ABORT\n"));
5665 case SENSE_TAPE_NOT_UNLOADED:
5666 dbprintf(("SCSI_Move : Tape still loaded, eject failed\n"));
5670 dbprintf(("SCSI_Move : end %d\n", pRequestSense->SenseKey));
5671 return(pRequestSense->SenseKey);
5677 dbprintf(("SCSI_Move : end %d\n", ret));
5684 int SCSI_LoadUnload(int DeviceFD, RequestSense_T *pRequestSense, unsigned char byte1, unsigned char load)
5689 dbprintf(("##### START SCSI_LoadUnload\n"));
5691 CDB[0] = SC_COM_UNLOAD;
5699 ret = SCSI_Run(DeviceFD, Input, CDB, 6,
5701 (char *) pRequestSense,
5702 sizeof(RequestSense_T));
5706 dbprintf(("SCSI_Unload : failed %d\n", ret));
5713 int SCSI_TestUnitReady(int DeviceFD, RequestSense_T *pRequestSense)
5718 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_TestUnitReady\n");
5720 CDB[0] = SC_COM_TEST_UNIT_READY;
5727 ret = SCSI_ExecuteCommand(DeviceFD, Input, CDB, 6,
5729 (char *) pRequestSense,
5730 sizeof(RequestSense_T));
5733 * We got an error, so let the calling function handle this
5737 DebugPrint(DEBUG_INFO, SECTION_SCSI,"###### STOP SCSI_TestUnitReady (1)\n");
5742 * OK, no error condition
5743 * If no sense is set, the Unit is ready
5745 if (pRequestSense->ErrorCode == 0 && pRequestSense->SenseKey == 0)
5747 DebugPrint(DEBUG_INFO, SECTION_SCSI,"###### STOP SCSI_TestUnitReady (1)\n");
5754 DebugPrint(DEBUG_INFO, SECTION_SCSI,"###### STOP SCSI_TestUnitReady (0)\n");
5759 int SCSI_ModeSelect(int DeviceFD, char *buffer, unsigned char length, unsigned char save, unsigned char mode, unsigned char lun)
5762 RequestSense_T *pRequestSense;
5767 dbprintf(("##### START SCSI_ModeSelect\n"));
5769 dbprintf(("SCSI_ModeSelect start length = %d:\n", length));
5770 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
5772 dbprintf(("SCSI_ModeSelect : malloc failed\n"));
5777 if ((sendbuf = (char *)malloc(length + 4)) == NULL)
5779 dbprintf(("SCSI_ModeSelect : malloc failed\n"));
5783 memset(sendbuf, 0 , length + 4);
5785 memcpy(&sendbuf[4], buffer, length);
5786 dump_hex(sendbuf, length+4, DEBUG_INFO, SECTION_SCSI);
5788 while (retry > 0 && retry < MAX_RETRIES)
5790 memset(pRequestSense, 0, sizeof(RequestSense_T));
5792 CDB[0] = SC_COM_MODE_SELECT;
5793 CDB[1] = ((lun << 5) & 0xF0) | ((mode << 4) & 0x10) | (save & 1);
5796 CDB[4] = length + 4;
5798 ret = SCSI_Run(DeviceFD, Output, CDB, 6,
5801 (char *) pRequestSense,
5802 sizeof(RequestSense_T));
5805 dbprintf(("SCSI_ModeSelect : ret %d\n", ret));
5811 switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
5814 dbprintf(("SCSI_ModeSelect : SENSE_IGNORE\n"));
5818 dbprintf(("SCSI_ModeSelect : SENSE_RETRY no %d\n", retry));
5821 dbprintf(("SCSI_ModeSelect : end %d\n", pRequestSense->SenseKey));
5822 return(pRequestSense->SenseKey);
5829 dbprintf(("SCSI_ModeSelect end: %d\n", ret));
5833 dbprintf(("SCSI_ModeSelect end: %d\n", ret));
5839 int SCSI_ModeSense(int DeviceFD, char *buffer, u_char size, u_char byte1, u_char byte2)
5842 RequestSense_T *pRequestSense;
5846 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_ModeSense\n");
5848 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense start length = %d:\n", size);
5849 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
5851 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_ModeSense : malloc failed\n");
5855 while (ret && retry < MAX_RETRIES)
5857 memset(pRequestSense, 0, sizeof(RequestSense_T));
5858 memset(buffer, 0, size);
5860 CDB[0] = SC_COM_MODE_SENSE;
5866 ret = SCSI_Run(DeviceFD, Input, CDB, 6,
5869 (char *) pRequestSense,
5870 sizeof(RequestSense_T));
5878 switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
5881 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : SENSE_IGNORE\n");
5885 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : SENSE_RETRY no %d\n", retry);
5888 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : end %d\n", pRequestSense->SenseKey);
5889 return(pRequestSense->SenseKey);
5896 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense end: %d\n", ret);
5900 int SCSI_Inquiry(int DeviceFD, SCSIInquiry_T *buffer, u_char size)
5903 RequestSense_T *pRequestSense;
5908 DebugPrint(DEBUG_INFO, SECTION_SCSI, "##### START SCSI_Inquiry\n");
5910 DebugPrint(DEBUG_INFO, SECTION_SCSI, "SCSI_Inquiry start length = %d:\n", size);
5912 if ((pRequestSense = (RequestSense_T *)malloc(size)) == NULL)
5914 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Inquiry : malloc failed\n");
5918 while (retry > 0 && retry < MAX_RETRIES)
5920 memset(buffer, 0, size);
5921 CDB[0] = SC_COM_INQUIRY;
5928 ret = SCSI_ExecuteCommand(DeviceFD, Input, CDB, 6,
5931 (char *) pRequestSense,
5932 sizeof(RequestSense_T));
5935 DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
5936 "chs", ((unsigned char *) pRequestSense)[0]);
5937 for (i = 1; i < sizeof(RequestSense_T); i++)
5938 DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) pRequestSense)[i]);
5939 DebugPrint(DEBUG_ERROR, SECTION_SCSI, "\n");
5940 DebugPrint(DEBUG_ERROR, SECTION_SCSI, "Inquiry end: %d\n", ret);
5945 switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
5948 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Inquiry : SENSE_IGNORE\n");
5952 DebugPrint(DEBUG_INFO, SECTION_SCSI, "SCSI_Inquiry : SENSE_RETRY no %d\n", retry);
5955 DebugPrint(DEBUG_ERROR, SECTION_SCSI, "SCSI_Inquiry : end %d\n", pRequestSense->SenseKey);
5956 return(pRequestSense->SenseKey);
5963 dump_hex((char *)buffer, size, DEBUG_INFO, SECTION_SCSI);
5964 DebugPrint(DEBUG_INFO, SECTION_SCSI, "SCSI_Inquiry : end %d\n", ret);
5969 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Inquiry end: %d\n", ret);
5974 * Read the Element Status. If DescriptorSize != 0 then
5975 * allocate DescriptorSize * NoOfElements for the result from the
5976 * Read Element Status command.
5977 * If DescriptorSize == 0 than try to figure out how much space is needed
5979 * 1. do an read with an allocation size of 8
5980 * 2. from the result take the 'Byte Count of Descriptor Available'
5981 * 3. do again an Read Element Status with the result from 2.
5984 int SCSI_ReadElementStatus(int DeviceFD,
5987 unsigned char VolTag,
5994 int DataBufferLength;
5995 ElementStatusData_T *ElementStatusData;
5996 RequestSense_T *pRequestSense;
6000 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_ReadElementStatus\n");
6002 if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
6004 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus : malloc failed\n");
6005 ChgExit("SCSI_ReadElementStatus","malloc failed", FATAL);
6009 * How many elements, if <= 0 than exit with an fatal error
6011 if (NoOfElements <= 0)
6013 ChgExit("SCSI_ReadElementStatus","No of Elements passed are le 0",FATAL);
6016 VolTag = (VolTag << 4) & 0x10;
6018 lun = (lun << 5) & 0xe0;
6021 /* if DescriptorSize == 0
6022 * try to get the allocation length for the second call
6024 if (DescriptorSize == 0)
6028 *data = realloc(*data, 8);
6033 memset(*data, 0, 8);
6037 while (retry > 0 && retry < MAX_RETRIES)
6039 memset(pRequestSense, 0, sizeof(RequestSense_T) );
6041 CDB[0] = SC_COM_RES; /* READ ELEMENT STATUS */
6042 CDB[1] = VolTag | type | lun; /* Element Type Code , VolTag, LUN */
6043 MSB2(&CDB[2], StartAddress); /* Starting Element Address */
6044 MSB2(&CDB[4], NoOfElements); /* Number Of Element */
6045 CDB[6] = 0; /* Reserved */
6046 MSB3(&CDB[7],8); /* Allocation Length */
6047 CDB[10] = 0; /* Reserved */
6048 CDB[11] = 0; /* Control */
6050 ret = SCSI_Run(DeviceFD, Input, CDB, 12,
6052 (char *)pRequestSense, sizeof(RequestSense_T));
6055 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus : (1) SCSI_Run %d\n", ret);
6058 DecodeSense(pRequestSense, "SCSI_ReadElementStatus :",debug_file);
6059 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
6064 switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
6067 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : SENSE_IGNORE\n");
6071 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : SENSE_RETRY no %d\n", retry);
6075 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : end %d\n", pRequestSense->SenseKey);
6076 return(pRequestSense->SenseKey);
6088 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
6092 ElementStatusData = (ElementStatusData_T *)*data;
6093 DataBufferLength = V3(ElementStatusData->count);
6095 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus: DataBufferLength %X, ret %d\n",DataBufferLength, ret);
6097 dump_hex(*data, 8, DEBUG_INFO, SECTION_ELEMENT);
6098 } else { /* DescriptorSize != 0 */
6099 DataBufferLength = NoOfElements * DescriptorSize;
6102 DataBufferLength = DataBufferLength + 8;
6103 *data = realloc(*data, DataBufferLength);
6104 memset(*data, 0, DataBufferLength);
6107 while (retry > 0 && retry < MAX_RETRIES)
6109 memset(pRequestSense, 0, sizeof(RequestSense_T) );
6111 CDB[0] = SC_COM_RES; /* READ ELEMENT STATUS */
6112 CDB[1] = VolTag | type | lun; /* Element Type Code, VolTag, LUN */
6113 MSB2(&CDB[2], StartAddress); /* Starting Element Address */
6114 MSB2(&CDB[4], NoOfElements); /* Number Of Element */
6115 CDB[6] = 0; /* Reserved */
6116 MSB3(&CDB[7],DataBufferLength); /* Allocation Length */
6117 CDB[10] = 0; /* Reserved */
6118 CDB[11] = 0; /* Control */
6120 ret = SCSI_Run(DeviceFD, Input, CDB, 12,
6121 *data, DataBufferLength,
6122 (char *)pRequestSense, sizeof(RequestSense_T));
6125 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus : (2) SCSI_Run %d\n", ret);
6128 DecodeSense(pRequestSense, "SCSI_ReadElementStatus :",debug_file);
6129 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
6134 switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
6137 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : SENSE_IGNORE\n");
6141 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : SENSE_RETRY no %d\n", retry);
6145 DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ModeSense : end %d\n", pRequestSense->SenseKey);
6146 return(pRequestSense->SenseKey);
6159 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
6163 dump_hex(*data, DataBufferLength, DEBUG_INFO, SECTION_SCSI);
6164 DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
6168 printf_arglist_function2(void DebugPrint, int, level, int, section, char *, fmt)
6172 extern changer_t chg;
6173 int dlevel,dsection;
6180 sscanf(chg.debuglevel,"%d:%d", &dlevel, &dsection);
6186 arglist_start(argp, fmt);
6187 vsnprintf(buf, sizeof(buf), fmt, argp);
6188 if (dlevel >= level)
6190 if (section == dsection || dsection == 0)
6192 if (index(buf, '\n') != NULL && strlen(buf) > 1)
6194 dbprintf(("%ld:%s", (long)ti, buf));
6196 dbprintf(("%s", buf));