- #ifndef lint
-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 $";
+#ifndef lint
+static char rcsid[] = "$Id: scsi-changer-driver.c,v 1.49 2006/03/16 00:20:53 paddy_s Exp $";
#endif
/*
* Interface to control a tape robot/library connected to the SCSI bus
void C1553APage37(LogParameter_T *, int);
void EXB85058HEPage39(LogParameter_T *, int);
void EXB85058HEPage3c(LogParameter_T *, int);
-int Decode(LogParameter_T *, int *);
+int Decode(LogParameter_T *, int *);
int DecodeModeSense(char *buffer, int offset, char *pstring, char block, FILE *out);
int SCSI_Run(int DeviceFD,
int SCSI_LoadUnload(int DeviceFD, RequestSense_T *pRequestSense, unsigned char byte1, unsigned char load);
int SCSI_TestUnitReady(int, RequestSense_T *);
int SCSI_ModeSense(int DeviceFD, char *buffer, u_char size, u_char byte1, u_char byte2);
-int SCSI_ModeSelect(int DeviceFD,
+int SCSI_ModeSelect(int DeviceFD,
char *buffer,
unsigned char length,
unsigned char save,
unsigned char mode,
unsigned char lun);
-int SCSI_ReadElementStatus(int DeviceFD,
+int SCSI_ReadElementStatus(int DeviceFD,
unsigned char type,
unsigned char lun,
unsigned char VolTag,
"UNLOAD"},
{0x4D,
10,
- "LOG SENSE"},
+ "LOG SENSE"},
{0xA5,
12,
"MOVE MEDIUM"},
GenericRewind,
GenericBarCode,
GenericSearch,
- GenericSenseHandler},
+ GenericSenseHandler},
/* Exabyte Devices */
- {"EXB-10e",
+ {"EXB-10e",
"Exabyte Robot [EXB-10e]",
GenericMove,
GenericElementStatus,
GenericBarCode,
GenericSearch,
GenericSenseHandler},
- {"EXB-120",
+ {"EXB-120",
"Exabyte Robot [EXB-120]",
GenericMove,
GenericElementStatus,
EXB_BarCode,
GenericSearch,
GenericSenseHandler},
- {"EXB-210",
+ {"EXB-210",
"Exabyte Robot [EXB-210]",
GenericMove,
GenericElementStatus,
EXB_BarCode,
GenericSearch,
GenericSenseHandler},
- {"EXB-85058HE-0000",
+ {"EXB-85058HE-0000",
"Exabyte Tape [EXB-85058HE-0000]",
DoNothing,
DoNothing,
GenericSearch,
GenericSenseHandler},
/* Tandberg Devices */
- {"TDS 1420",
+ {"TDS 1420",
"Tandberg Robot (TDS 1420)",
GenericMove,
GenericElementStatus,
GenericSearch,
GenericSenseHandler},
/* ADIC Devices */
- {"VLS DLT",
+ {"VLS DLT",
"ADIC VLS DLT Library [VLS DLT]",
GenericMove,
GenericElementStatus,
GenericBarCode,
GenericSearch,
GenericSenseHandler},
- {"VLS SDX",
+ {"VLS SDX",
"ADIC VLS DLT Library [VLS SDX]",
SDXMove,
SDXElementStatus,
GenericBarCode,
GenericSearch,
GenericSenseHandler},
- {"FastStor DLT",
+ {"FastStor DLT",
"ADIC FastStor DLT Library [FastStor DLT]",
SDXMove,
DLT448ElementStatus,
GenericBarCode,
GenericSearch,
GenericSenseHandler},
- /*
+ /*
* And now the tape devices
*/
/* The generic handler if nothing matches */
GenericBarCode,
GenericSearch,
GenericSenseHandler},
- {"DLT7000",
+ {"DLT7000",
"DLT Tape [DLT7000]",
DoNothing,
DoNothing,
GenericBarCode,
GenericSearch,
GenericSenseHandler},
- {"DLT4000",
+ {"DLT4000",
"DLT Tape [DLT4000]",
DoNothing,
DoNothing,
DLT4000Eject,
GenericClean,
GenericRewind,
- NoBarCode,
+ NoBarCode,
GenericSearch,
GenericSenseHandler},
{NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}
-};
+};
LogPageDecode_T DecodePages[] = {
int MTE = 0; /*Counter for the above element types */
int STE = 0;
int IEE = 0;
-int DTE = 0;
+int DTE = 0;
-char *chgscsi_datestamp = NULL; /* Result pointer for tape_rdlabel */
+char *chgscsi_datestamp = NULL; /* Result pointer for tape_rdlabel */
char *chgscsi_label = NULL; /* Result pointer for tape_rdlabel */
char *chgscsi_result = NULL; /* Needed for the result string of MapBarCode */
printf("sleep ??? # How long to wait after an eject command before moving\n");
printf(" # the tape\n");
printf(" #\n");
-
+
for (count = 0; count < CHG_MAXDEV ; count++)
{
if (pDev[count].dev)
}
}
}
-
+
/*
* Did we reach the end of the list ?
* If no we found an changer and now we try to
*/
if (count < CHG_MAXDEV)
{
- pDev[count].functions->function_status(count, 1);
+ pDev[count].functions->function_status(count, 1);
} else {
printf("changerdev ??? # Ups nothing found. Please check the docs\n");
}
-
+
printf(" #\n");
printf(" # Here now comes the config for the first tape\n");
printf("config 0 # This value is the one which is used in the amanda\n");
printf(" #\n");
cwd = getcwd(NULL, 0);
-
+
printf("statfile %s/tape0-slot #\n",cwd);
printf("cleanfile %s/tape0-clean #\n", cwd);
printf("usagecount %s/tape0-totaltime #\n", cwd);
}
-
+
/*
* Try to create a list of tapes and labels which are in the current
* magazin. The drive must be empty !!
- *
+ *
* labelfile -> file name of the db
* drive -> which drive should we use
* eject -> the tape device needs an eject before move
* stop -> stop at slot stop
* clean -> if we have an cleaning tape than this is the slot number of it
*
- * return
+ * return
* 0 -> fail
* 1 -> successfull
*
{
extern OpenFiles_T *pDev;
int x;
- char *datestamp = malloc(1); /* stupid, but tapefd_rdlabel does an free at the begining ... */
- char *label = malloc(1); /* the same here ..... */
- char *result; /* Used to store the result of MapBarCode */
- int barcode; /* cache the result from the BarCode function */
- static int inv_done = 0; /* Inventory function called ?, marker to disable recursion */
- MBC_T *pbarcoderes = malloc(sizeof(MBC_T)); /* Here we will pass the parameter to MapBarCode and get the result */
-
+ char *result; /* Used to store the result of MapBarCode */
+ int barcode; /* cache the result from the BarCode function */
+ static int inv_done = 0; /* Inventory function called ?, marker to disable recursion */
+ MBC_T *pbarcoderes; /* Here we will pass the parameter to MapBarCode and get the result */
+
DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, "##### START Inventory\n");
+ if ((pbarcoderes = malloc(sizeof(MBC_T))) == NULL)
+ {
+ DebugPrint(DEBUG_ERROR, SECTION_MAP_BARCODE,"##### malloc failed (-1)\n");
+ return;
+ }
memset(pbarcoderes, 0 , sizeof(MBC_T));
if (inv_done != 0)
{
DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, "##### STOP inv_done -> %d Inventory\n",inv_done);
+ free(pbarcoderes);
return;
}
inv_done = 1;
barcode = BarCode(INDEX_CHANGER);
-
+
pbarcoderes->action = RESET_VALID;
MapBarCode(labelfile,pbarcoderes);
-
+
/*
* Check if an tape is loaded, if yes unload it
* and do an INIT ELEMENT STATUS
*/
-
+
if (pDTE[0].status == 'F')
{
if (eject)
}
(void)unload(INDEX_TAPE, 0, 0);
}
-
+
GenericResetStatus(INDEX_CHANGER);
-
+
for (x = 0; x < STE; x++)
{
if (x == clean)
{
continue;
}
-
+
/*
* Load the tape, on error try the next
* error could be an empty slot for example
SCSI_CloseDevice(INDEX_TAPE);
- if ((result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &datestamp, &label)) == NULL)
+ if ((result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &chgscsi_datestamp, &chgscsi_label)) == NULL)
{
pbarcoderes->action = UPDATE_SLOT;
- strcpy(pbarcoderes->data.voltag, label);
+ strcpy(pbarcoderes->data.voltag, chgscsi_label);
pbarcoderes->data.slot = x;
pbarcoderes->data.from = 0;
pbarcoderes->data.LoadCount = 1;
(void)unload(INDEX_TAPE, drive, x);
}
DebugPrint(DEBUG_INFO,SECTION_MAP_BARCODE, "##### STOP Inventory\n");
+ free(pbarcoderes);
}
/*
extern OpenFiles_T *pDev;
/* Return 1 if cleaning is needed */
int ret;
-
+
DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### START get_clean_state\n");
if (pDev[INDEX_TAPECTL].SCSI == 0)
}
ret=pDev[INDEX_TAPECTL].functions->function_clean(tapedev);
DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP get_clean_state [%d]\n", ret);
- return(ret);
+ return(ret);
}
/*
{
SCSI_CloseDevice(INDEX_TAPE);
}
-
+
chgscsi_result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &chgscsi_datestamp, &chgscsi_label);
}
DebugPrint(DEBUG_INFO,SECTION_TAPE,"##### STOP (SCSI)eject_tape [%d]\n", ret);
return(ret);
}
-
+
if (pDev[INDEX_TAPE].avail == 1)
{
ret=Tape_Ioctl(INDEX_TAPE, IOCTL_EJECT);
return(-1);
}
}
-
+
if (count == 0)
{
end = STE;
} else {
end = start + count;
}
-
+
if (end > STE)
{
end = STE;
}
-
+
DebugPrint(DEBUG_INFO,SECTION_ELEMENT,"start at %d, end at %d\n", start, end);
for (x = start; x < end; x++)
{
if (pSTE[x].status == 'E')
{
- DebugPrint(DEBUG_INFO,SECTION_ELEMENT,"###### END find_empty [%d]\n", x);
+ DebugPrint(DEBUG_INFO,SECTION_ELEMENT,"###### END find_empty [%d]\n", x);
return(x);
}
}
DebugPrint(DEBUG_INFO,SECTION_TAPE,"###### START drive_loaded\n");
DebugPrint(DEBUG_INFO,SECTION_TAPE,"%-20s : fd %d drivenum %d \n", "drive_loaded", fd, drivenum);
-
-
+
+
if (ElementStatusValid == 0)
{
if (pDev[INDEX_CHANGER].functions->function_status(INDEX_CHANGER, 1) != 0)
return(-1);
}
}
-
+
if (pDTE[drivenum].status == 'E') {
DebugPrint(DEBUG_INFO,SECTION_TAPE,"###### STOP drive_loaded (empty)\n");
return(0);
* TODO:
* Check if the MTE is empty
*/
-int unload(int fd, int drive, int slot)
+int unload(int fd, int drive, int slot)
{
extern OpenFiles_T *pDev;
int ret;
extern changer_t chg; /* Needed for the infos about emubarcode and labelfile */
extern int do_inventory;
- MBC_T *pbarcoderes = malloc(sizeof(MBC_T));
+ MBC_T *pbarcoderes;
DebugPrint(DEBUG_INFO, SECTION_TAPE,"###### START unload\n");
DebugPrint(DEBUG_INFO, SECTION_TAPE,"%-20s : fd %d, slot %d, drive %d \n", "unload", fd, slot, drive);
+ if ((pbarcoderes = malloc(sizeof(MBC_T))) == NULL)
+ {
+ DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### malloc failed (-1)\n");
+ return(-1);
+ }
memset(pbarcoderes, 0, sizeof(MBC_T));
-
+
/*
* If the Element Status is not valid try to
* init it
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"Element Status not valid, reset failed\n");
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP unload (-1)\n");
+ free(pbarcoderes);
return(-1);
}
}
-
- DebugPrint(DEBUG_INFO, SECTION_TAPE,"%-20s : unload drive %d[%d] slot %d[%d]\n", "unload",
- drive,
- pDTE[drive].address,
- slot,
+
+ DebugPrint(DEBUG_INFO, SECTION_TAPE,"%-20s : unload drive %d[%d] slot %d[%d]\n", "unload",
+ drive,
+ pDTE[drive].address,
+ slot,
pSTE[slot].address);
-
+
/*
* Unloading an empty tape unit makes no sense
* so return with an error
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"unload : Drive %d address %d is empty\n", drive, pDTE[drive].address);
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP unload (-1)\n");
+ free(pbarcoderes);
return(-1);
}
-
+
/*
* If the destination slot is full
* try to find an enpty slot
*/
- if (pSTE[slot].status == 'F')
+ if (pSTE[slot].status == 'F')
{
DebugPrint(DEBUG_INFO, SECTION_TAPE,"unload : Slot %d address %d is full\n", drive, pSTE[slot].address);
if ( ElementStatusValid == 0)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "unload: Element Status not valid, can't find an empty slot\n");
+ free(pbarcoderes);
return(-1);
}
-
+
slot = find_empty(fd, 0, 0);
if (slot == -1 )
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "unload: No Empty slot found\n");
+ free(pbarcoderes);
return(-1);
}
DebugPrint(DEBUG_INFO, SECTION_TAPE,"unload : found empty one, try to unload to slot %d\n", slot);
}
-
+
/*
* If eject is not set we must read the label info
} else {
pDev[INDEX_TAPE].functions->function_rewind(INDEX_TAPE);
}
-
+
if (pDev[INDEX_TAPE].devopen == 1)
{
SCSI_CloseDevice(INDEX_TAPE);
}
-
+
chgscsi_result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &chgscsi_datestamp, &chgscsi_label);
- }
+ }
}
/*
if (pDev[INDEX_CHANGER].functions->function_status(INDEX_CHANGER , 1) != 0)
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP unload (-1 update status failed)\n");
+ free(pbarcoderes);
return(-1);
}
-
+
/*
* Did we get an error from tape_rdlabel
* if no update the vol/label mapping
*/
if (BarCode(INDEX_CHANGER) == 0 && chg.emubarcode == 1)
{
- /*
+ /*
* We got something, update the db
* but before check if the db has as entry the slot
* to where we placed the tape, if no force an inventory
pbarcoderes->data.slot = 0;
pbarcoderes->data.from = 0;
pbarcoderes->data.LoadCount = 0;
-
-
+
+
if ( MapBarCode(chg.labelfile, pbarcoderes) == 0) /* Nothing known about this, do an Inventory */
{
do_inventory = 1;
}
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP unload(0)\n");
+ free(pbarcoderes);
return(0);
}
{
extern changer_t chg; /* Needed for the infos about emubarcode and labelfile */
char *result = NULL; /* Needed for the result of tape_rdlabel */
- char *datestamp = NULL; /* Result pointer for tape_rdlabel */
- char *label = NULL; /* Result pointer for tape_rdlabel */
int ret;
extern OpenFiles_T *pDev;
extern int do_inventory;
- MBC_T *pbarcoderes = malloc(sizeof(MBC_T));
+ MBC_T *pbarcoderes;
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"###### START load\n");
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"%-20s : fd %d, drive %d, slot %d \n", "load", fd, drive, slot);
+ if ((pbarcoderes = malloc(sizeof(MBC_T))) == NULL)
+ {
+ DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### malloc failed (-1)\n");
+ return(-1);
+ }
memset(pbarcoderes, 0 , sizeof(MBC_T));
if (ElementStatusValid == 0)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1)\n");
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
+ free(pbarcoderes);
return(-1);
}
}
*/
if (slot >= STE)
{
- DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : slot %d ge STE %d\n",slot, STE);
+ DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : slot %d ge STE %d\n",slot, STE);
ChgExit("load", "slot >= STE", FATAL);
}
-
- /*
+
+ /*
* And the same for the tape drives
*/
if (drive >= DTE)
{
- DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : drive %d ge DTE %d\n",drive, DTE);
+ DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : drive %d ge DTE %d\n",drive, DTE);
ChgExit("load", "drive >= DTE", FATAL);
}
pDTE[drive].address,
slot,
pSTE[slot].address);
-
+
if (pDTE[drive].status == 'F')
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : Drive %d address %d is full\n", drive, pDTE[drive].address);
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
+ free(pbarcoderes);
return(-1);
}
-
+
if (pSTE[slot].status == 'E')
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"load : Slot %d address %d is empty\n", drive, pSTE[slot].address);
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
+ free(pbarcoderes);
return(-1);
}
-
+
ret = pDev[fd].functions->function_move(fd, pSTE[slot].address, pDTE[drive].address);
/*
if (pDev[fd].functions->function_status(fd, 1) != 0)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### STOP load (-1 update status failed)\n");
+ free(pbarcoderes);
return(-1);
}
} else {
pDev[INDEX_TAPE].functions->function_rewind(INDEX_TAPE);
}
-
+
if (pDev[INDEX_TAPE].devopen == 1)
{
SCSI_CloseDevice(INDEX_TAPE);
}
-
- result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &datestamp, &label);
+
+ result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &chgscsi_datestamp, &chgscsi_label);
}
-
+
/*
* Did we get an error from tape_rdlabel
* if no update the vol/label mapping
*/
- if (result == NULL && chg.labelfile != NULL && label != NULL )
+ if (result == NULL && chg.labelfile != NULL && chgscsi_label != NULL )
{
- /*
+ /*
* We got something, update the db
* but before check if the db has as entry the slot
* to where we placed the tape, if no force an inventory
*/
- strcpy(pbarcoderes->data.voltag, label);
+ strcpy(pbarcoderes->data.voltag, chgscsi_label);
pbarcoderes->data.slot = 0;
pbarcoderes->data.from = 0;
pbarcoderes->data.LoadCount = 0;
-
-
+
+
/*
* If we have an barcode reader we only do an update
* If emubarcode is set we check if the
* info in the DB is up to date, if no we set the do_inventory flag
*/
-
+
if (BarCode(INDEX_CHANGER) == 1 && chg.emubarcode == 0)
{
pbarcoderes->action = UPDATE_SLOT;
pbarcoderes->data.slot = slot;
MapBarCode(chg.labelfile, pbarcoderes);
}
-
+
if (BarCode(INDEX_CHANGER) == 0 && chg.emubarcode == 1)
{
pbarcoderes->action = FIND_SLOT;
}
}
}
-
+
if (BarCode(INDEX_CHANGER) == 1 && chg.emubarcode == 1)
{
ChgExit("Load", "BarCode == 1 and emubarcode == 1", FATAL);
}
-
+
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"##### STOP load (%d)\n",ret);
+ free(pbarcoderes);
return(ret);
}
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"##### STOP load (%d)\n",ret);
+ free(pbarcoderes);
return(ret);
}
* Returns the number of Storage Slots which the library has
* fd -> pointer to the internal devie structure pDev
* return -> Number of slots
- */
+ */
int get_slot_count(int fd)
{
extern OpenFiles_T *pDev;
* return the number of slots in the robot
* to the caller
*/
-
+
}
* retreive the number of data-transfer devices /Tape drives)
* fd -> pointer to the internal devie structure pDev
* return -> -1 on failure
- */
+ */
int get_drive_count(int fd)
{
extern OpenFiles_T *pDev;
char tmpstr[15];
ChangerCMD_T *p = (ChangerCMD_T *)&ChangerIO;
-
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START OpenDevice\n");
DebugPrint(DEBUG_INFO, SECTION_SCSI,"OpenDevice : %s\n", DeviceName);
-
- pDev[ip].ConfigName = stralloc(ConfigName);
- pDev[ip].dev = stralloc(DeviceName);
+
+ pDev[ip].ConfigName = strdup(ConfigName);
+ pDev[ip].dev = strdup(DeviceName);
if (SCSI_OpenDevice(ip) != 0 )
{
return(1);
}
p++;
- }
+ }
} else { /* Something failed, lets see what */
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"##### STOP OpenDevice failed\n");
}
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP OpenDevice (nothing found) !!\n");
- return(0);
+ return(0);
}
int true = 1;
int ret;
int cnt = 0;
-
+
RequestSense_T *pRequestSense;
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START Tape_Ready\n");
-
+
/*
- * Which device should we use to get the
+ * Which device should we use to get the
* tape status
*/
{
fd = INDEX_TAPE;
}
-
+
/*
* But if available and can do SCSI
* the scsitapedev
{
fd = INDEX_TAPECTL;
}
-
+
if (pDev[fd].avail == 1 && pDev[fd].SCSI == 0)
{
DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : Can't send SCSI commands, try ioctl\n");
/*
* Do we get an non negative result.
* If yes this function is available
- * and we can use it to get the status
+ * and we can use it to get the status
* of the tape
*/
ret = Tape_Status(fd);
DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : not ready, stop after %d seconds\n",cnt);
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
return(0);
-
+
} else {
DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : no ioctl interface, will sleep for %d seconds\n", wait_time);
sleep(wait_time);
return(0);
}
}
-
+
if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
{
DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready : malloc failed\n");
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
return(-1);
}
-
+
/*
* Ignore errors at this point
*/
GenericRewind(fd);
-
+
/*
* Wait until we get an ready condition
*/
-
+
while (true && cnt < wait_time)
{
ret = SCSI_TestUnitReady(fd, pRequestSense );
break;
case SENSE_ABORT:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeReady (TestUnitReady) SENSE_ABORT\n");
+ free(pRequestSense);
return(-1);
break;
case SENSE_RETRY:
break;
case SCSI_ERROR:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"TapeReady (TestUnitReady) SCSI_ERROR\n");
+ free(pRequestSense);
return(-1);
break;
case SCSI_BUSY:
cnt++;
}
- free(pRequestSense);
-
DebugPrint(DEBUG_INFO, SECTION_TAPE,"Tape_Ready after %d sec\n", cnt);
- DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
+ DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP Tape_Ready\n");
+ free(pRequestSense);
return(0);
}
/* Jump over the Parameter List header and an offset if we have something
* Unknown at the start (ADIC-218) at the moment
- *
+ *
*/
buffer = buffer + 4 + offset;
fprintf(out, "DecodeModeSense : Block Length %d\n", V3(buffer));
buffer = buffer + 3;
}
-
+
while (length > 0)
{
switch (*buffer & 0x3f)
case 0x1:
prp = (ReadWriteErrorRecoveryPage_T *)buffer;
if (out != NULL)
- {
+ {
fprintf(out, "DecodeModeSense : Read/Write Error Recovery Page\n");
fprintf(out,"\tTransfer Block %d\n", prp->tb);
fprintf(out,"\tEnable Early Recovery %d\n", prp->eer);
fprintf(out, "DecodeModeSense : Disconnect/Reconnect Page\n");
fprintf(out,"\tBuffer Full Ratio %d\n", pdrp->BufferFullRatio);
fprintf(out,"\tBuffer Empty Ratio %d\n", pdrp->BufferEmptyRatio);
- fprintf(out,"\tBus Inactivity Limit %d\n",
+ fprintf(out,"\tBus Inactivity Limit %d\n",
V2(pdrp->BusInactivityLimit));
- fprintf(out,"\tDisconnect Time Limit %d\n",
+ fprintf(out,"\tDisconnect Time Limit %d\n",
V2(pdrp->DisconnectTimeLimit));
fprintf(out,"\tConnect Time Limit %d\n",
V2(pdrp->ConnectTimeLimit));
if (out != NULL)
{
fprintf(out,"DecodeModeSense : Element Address Assignment Page\n");
- fprintf(out,"\tMedium Transport Element Address %d\n",
+ fprintf(out,"\tMedium Transport Element Address %d\n",
V2(pEAAPage->MediumTransportElementAddress));
- fprintf(out,"\tNumber of Medium Transport Elements %d\n",
+ fprintf(out,"\tNumber of Medium Transport Elements %d\n",
V2(pEAAPage->NoMediumTransportElements));
- fprintf(out, "\tFirst Storage Element Address %d\n",
+ fprintf(out, "\tFirst Storage Element Address %d\n",
V2(pEAAPage->FirstStorageElementAddress));
- fprintf(out, "\tNumber of Storage Elements %d\n",
+ fprintf(out, "\tNumber of Storage Elements %d\n",
V2(pEAAPage->NoStorageElements));
- fprintf(out, "\tFirst Import/Export Element Address %d\n",
+ fprintf(out, "\tFirst Import/Export Element Address %d\n",
V2(pEAAPage->FirstImportExportElementAddress));
- fprintf(out, "\tNumber of ImportExport Elements %d\n",
+ fprintf(out, "\tNumber of ImportExport Elements %d\n",
V2(pEAAPage->NoImportExportElements));
- fprintf(out, "\tFirst Data Transfer Element Address %d\n",
+ fprintf(out, "\tFirst Data Transfer Element Address %d\n",
V2(pEAAPage->FirstDataTransferElementAddress));
- fprintf(out, "\tNumber of Data Transfer Elements %d\n",
+ fprintf(out, "\tNumber of Data Transfer Elements %d\n",
V2(pEAAPage->NoDataTransferElements));
}
buffer++;
return(-1);
}
length = length - *buffer - 2;
- buffer = buffer + *buffer + 1;
+ buffer = buffer + *buffer + 1;
}
return(0);
}
fprintf(out,"\t\tReserved\n");
break;
}
- return(0);
+ return(0);
}
int DecodeExtSense(ExtendedRequestSense_T *sense, char *pstring, FILE *out)
fprintf(out,"\tLog Parameter Page Code %02X\n", sense->LogParameterPageCode);
fprintf(out,"\tLog Parameter Code %02X\n", sense->LogParameterCode);
fprintf(out,"\tUnderrun/Overrun Counter %02X\n", sense->UnderrunOverrunCounter);
- fprintf(out,"\tRead/Write Error Counter %d\n", V3((char *)sense->ReadWriteDataErrorCounter));
+ fprintf(out,"\tRead/Write Error Counter %d\n", V3((char *)sense->ReadWriteDataErrorCounter));
if (sense->AdditionalSenseLength > sizeof(RequestSense_T))
{
if (sense->PF)
return(-1);
}
}
-
+
if (SCSI_ModeSense(DeviceFD, pModePage, 0xff, 0x0, 0x3f) == 0)
{
DecodeModeSense(pModePage, 0, "TreeFrogBarCode :", 0, debug_file);
-
+
if (pVendorUnique == NULL)
{
dbprintf(("TreeFrogBarCode : no pVendorUnique\n"));
return(0);
}
pVendor = ( ModePageTreeFrogVendorUnique_T *)pVendorUnique;
-
+
dbprintf(("TreeFrogBarCode : EBARCO %d\n", pVendor->EBARCO));
dbprintf(("TreeFrogCheckSum : CHKSUM %d\n", pVendor->CHKSUM));
extern OpenFiles_T *pDev;
ModePageEXB120VendorUnique_T *pVendor;
- ModePageEXB120VendorUnique_T *pVendorWork;
+ ModePageEXB120VendorUnique_T *pVendorWork = NULL;
DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### START EXB_BarCode\n");
if (pModePage == NULL && LibModeSenseValid == 0)
LibModeSenseValid = -1;
}
}
-
+
if (LibModeSenseValid == 1)
{
if (pVendorUnique == NULL)
return(0);
}
pVendor = ( ModePageEXB120VendorUnique_T *)pVendorUnique;
-
+
DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : NBL %d\n", pVendor->NBL);
DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : PS %d\n", pVendor->PS);
if (pVendor->NBL == 1 && pVendor->PS == 1 )
/* Hack !!!!!!
*/
pVendor->NBL = 0;
-
+
/* And now again !!!
*/
GenericResetStatus(DeviceFD);
} else {
DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : SCSI_ModeSelect failed\n");
}
+ amfree(pVendorWork);
}
dump_hex((char *)pDev[INDEX_CHANGER].inquiry, INQUIRY_SIZE, DEBUG_INFO, SECTION_BARCODE);
DebugPrint(DEBUG_INFO, SECTION_BARCODE,"EXB_BarCode : vendor_specific[19] %x\n",
pDev[INDEX_CHANGER].inquiry->vendor_specific[19]);
}
-
+
return(1);
}
int GenericBarCode(int DeviceFD)
{
extern changer_t chg;
-
+
DebugPrint(DEBUG_INFO, SECTION_BARCODE,"##### START GenericBarCode\n");
if ( chg.havebarcode >= 1)
{
int ret;
int true = 1;
int cnt = 0;
- RequestSense_T *pRequestSense;
+ RequestSense_T *pRequestSense = NULL;
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START TapeStatus\n");
dbprintf(("%-20s : malloc failed\n","TapeStatus"));
return(-1);
}
-
+
while (true && cnt < 60)
{
ret = SCSI_TestUnitReady(INDEX_TAPECTL, pRequestSense);
sleep(2);
cnt++;
}
+ amfree(pRequestSense);
} else {
ret = Tape_Status(INDEX_TAPE);
if ( ret & TAPE_ONLINE)
{
- pDTE[0].status ='F';
+ pDTE[0].status ='F';
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### FULL\n");
} else {
pDTE[0].status = 'E';
if ((pExtendedRequestSense = malloc(sizeof(ExtendedRequestSense_T))) == NULL)
{
dbprintf(("%-20s : malloc failed\n","DLT4000Eject"));
+ free(pRequestSense);
return(-1);
}
-
+
if ( type > 1)
{
dbprintf(("DLT4000Eject : use mtio ioctl for eject on %s\n", pDev[INDEX_TAPE].dev));
+ free(pExtendedRequestSense);
+ free(pRequestSense);
return(Tape_Ioctl(INDEX_TAPE, IOCTL_EJECT));
}
-
-
-
+
+
+
if (pDev[INDEX_TAPECTL].SCSI == 0)
{
dbprintf(("DLT4000Eject : Device %s not able to receive SCSI commands\n", pDev[INDEX_TAPE].dev));
+ free(pExtendedRequestSense);
+ free(pRequestSense);
return(Tape_Ioctl(INDEX_TAPE, IOCTL_EJECT));
}
-
-
+
+
dbprintf(("DLT4000Eject : SCSI eject on %s = %s\n", pDev[INDEX_TAPECTL].dev, pDev[INDEX_TAPECTL].ConfigName));
-
- RequestSense(INDEX_TAPECTL, pExtendedRequestSense, 0);
+
+ RequestSense(INDEX_TAPECTL, pExtendedRequestSense, 0);
DecodeExtSense(pExtendedRequestSense, "DLT4000Eject : ", debug_file);
/* Unload the tape, 0 == wait for success
- * 0 == unload
+ * 0 == unload
*/
ret = SCSI_LoadUnload(INDEX_TAPECTL, pRequestSense, 0, 0);
- RequestSense(INDEX_TAPECTL, pExtendedRequestSense, 0);
+ RequestSense(INDEX_TAPECTL, pExtendedRequestSense, 0);
DecodeExtSense(pExtendedRequestSense, "DLT4000Eject : ", debug_file);
-
+
/* < 0 == fatal */
- if (ret < 0)
- return(-1);
-
- if ( ret > 0)
- {
+ if (ret >= 0) {
+ free(pExtendedRequestSense);
+ free(pRequestSense);
+ return(-1);
}
-
+
true = 1;
-
-
while (true && cnt < 300)
{
ret = SCSI_TestUnitReady(INDEX_TAPECTL, pRequestSense);
break;
case SENSE_ABORT:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SENSE_ABORT\n");
+ free(pExtendedRequestSense);
+ free(pRequestSense);
return(-1);
- break;
case SENSE_RETRY:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SENSE_RETRY\n");
break;
break;
case SCSI_ERROR:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SCSI_ERROR\n");
+ free(pExtendedRequestSense);
+ free(pRequestSense);
return(-1);
- break;
case SCSI_BUSY:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"DLT4000Eject (TestUnitReady) SCSI_BUSY\n");
break;
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"DLT4000Eject (TestUnitReady) unknown (%d)\n",ret);
break;
}
-
+
cnt++;
sleep(2);
}
-
-
- free(pRequestSense);
-
+
dbprintf(("DLT4000Eject : Ready after %d sec, true = %d\n", cnt * 2, true));
+
+ free(pExtendedRequestSense);
+ free(pRequestSense);
+
return(0);
-
}
/*
int ret;
int cnt = 0;
int true = 1;
-
+
DebugPrint(DEBUG_INFO, SECTION_TAPE, "##### START GenericEject\n");
-
+
if ((pRequestSense = malloc(sizeof(RequestSense_T))) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE, "%-20s : malloc failed\n","GenericEject");
return(-1);
}
-
- DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericEject : SCSI eject on %s = %s\n", pDev[INDEX_TAPECTL].dev, pDev[INDEX_TAPECTL].ConfigName);
-
+
+ DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericEject : SCSI eject on %s = %s\n",
+ pDev[INDEX_TAPECTL].dev, pDev[INDEX_TAPECTL].ConfigName);
+
/*
* Can we use SCSI commands ?
*/
if (pDev[INDEX_TAPECTL].SCSI == 1)
{
LogSense(INDEX_TAPECTL);
- /*
+ /*
* Unload the tape, 1 == don't wait for success
- * 0 == unload
+ * 0 == unload
*/
ret = SCSI_LoadUnload(INDEX_TAPECTL, pRequestSense, 1, 0);
-
+
/* < 0 == fatal */
- if (ret < 0)
+ if (ret < 0) {
+ free(pRequestSense);
return(-1);
-
- if ( ret > 0)
- {
- }
-
+ }
+
true = 1;
-
-
while (true && cnt < 300)
{
ret = SCSI_TestUnitReady(INDEX_TAPECTL, pRequestSense);
break;
case SENSE_ABORT:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericEject (TestUnitReady) SENSE_ABORT\n");
+ free(pRequestSense);
return(-1);
- break;
case SENSE_RETRY:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SENSE_RETRY\n");
break;
break;
case SCSI_ERROR:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericEject (TestUnitReady) SCSI_ERROR\n");
+ free(pRequestSense);
return(-1);
- break;
case SCSI_BUSY:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericEject (TestUnitReady) SCSI_BUSY\n");
break;
default:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericEject (TestUnitReady) unknown (%d)\n",ret);
break;
- }
+ }
cnt++;
sleep(2);
}
-
- free(pRequestSense);
-
} else {
DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericEject : Device can't understand SCSI try ioctl\n");
Tape_Ioctl(INDEX_TAPECTL, IOCTL_EJECT);
}
DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericEject : Ready after %d sec, true = %d\n", cnt * 2, true);
+ free(pRequestSense);
return(0);
}
/*
- * Rewind the tape
+ * Rewind the tape
*
* TODO:
* Make the retry counter an config option,
int GenericRewind(int DeviceFD)
{
CDB_T CDB;
- extern OpenFiles_T *pDev;
- RequestSense_T *pRequestSense;
+ extern OpenFiles_T *pDev;
+ RequestSense_T *pRequestSense = NULL;
char *errstr; /* Used by tape_rewind */
int ret;
int cnt = 0;
/*
* Before doing the rewind check if the tape is ready to accept commands
*/
-
+
while (true == 1)
{
ret = SCSI_TestUnitReady(DeviceFD, (RequestSense_T *)pRequestSense );
break;
case SENSE_TAPE_NOT_ONLINE:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
+ free(pRequestSense);
return(-1);
break;
case SENSE_IGNORE:
break;
case SENSE_ABORT:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_ABORT\n");
+ free(pRequestSense);
return(-1);
break;
case SENSE_RETRY:
case SCSI_ERROR:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_ERROR\n");
+ free(pRequestSense);
return(-1);
break;
case SCSI_BUSY:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) unknown (%d)\n",ret);
break;
}
-
+
sleep(1);
DebugPrint(DEBUG_INFO, SECTION_TAPE," Wait .... (%d)\n",cnt);
if (cnt > 180)
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP GenericRewind (-1)\n");
+ free(pRequestSense);
return(-1);
}
} /* while true == 1 */
-
+
cnt = 0;
true = 1;
-
+
CDB[0] = SC_COM_REWIND;
- CDB[1] = 1;
+ CDB[1] = 1;
CDB[2] = 0;
CDB[3] = 0;
CDB[4] = 0;
CDB[5] = 0;
-
+
while (true)
{
ret = SCSI_Run(DeviceFD, Input, CDB, 6,
- NULL, 0,
+ NULL, 0,
(char *) pRequestSense,
sizeof(RequestSense_T));
-
+
DecodeSense(pRequestSense, "GenericRewind : ", debug_file);
-
- if (ret > 0)
+
+ if (ret > 0)
{
if (pRequestSense->SenseKey != UNIT_ATTENTION)
{
true = 0;
}
}
-
+
true = 1;
-
+
while (true && cnt < 300)
{
ret = SCSI_TestUnitReady(DeviceFD, pRequestSense);
break;
case SENSE_TAPE_NOT_ONLINE:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_TAPE_NOT_ONLINE\n");
+ free(pRequestSense);
return(-1);
break;
case SENSE_IGNORE:
break;
case SENSE_ABORT:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SENSE_ABORT\n");
+ free(pRequestSense);
return(-1);
break;
case SENSE_RETRY:
break;
case SCSI_ERROR:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_ERROR\n");
+ free(pRequestSense);
return(-1);
- break;
+ break;
case SCSI_BUSY:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"GenericRewind (TestUnitReady) SCSI_BUSY\n");
break;
cnt++;
sleep(2);
}
-
- free(pRequestSense);
-
+
+ amfree(pRequestSense);
+
DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericRewind : Ready after %d sec, true = %d\n", cnt * 2, true);
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP GenericRewind (0)\n");
} else {
DebugPrint(DEBUG_INFO, SECTION_TAPE,"GenericRewind : use ioctl rewind\n");
- if (pDev[DeviceFD].devopen == 1)
+ if (pDev[DeviceFD].devopen == 1)
{
DebugPrint(DEBUG_INFO, SECTION_TAPE,"Close Device\n");
SCSI_CloseDevice(DeviceFD);
}
- /*
- * Hmm retry it if it fails ?
- */
- cnt = 0;
- true = 1;
- while (true)
- {
- if ((errstr = tape_rewind(pDev[DeviceFD].dev)) == NULL)
- {
- true = 0;
- DebugPrint(DEBUG_INFO, SECTION_TAPE,"Rewind OK, (after %d tries)\n", cnt);
- } else {
- DebugPrint(DEBUG_INFO, SECTION_TAPE,"Rewind failed %s\n",errstr);
- /*
- * DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP GenericRewind (-1)\n");
- * return(-1);
- */
- cnt++;
- sleep(1);
- if (cnt > 60)
- {
- DebugPrint(DEBUG_ERROR, SECTION_TAPE,"##### STOP GenericRewind (-1), retry limit reached\n");
- return(-1);
- }
- }
- }
+ /* We don't retry if it fails; that is left to the vtape driver. */
+ if ((errstr = tape_rewind(pDev[DeviceFD].dev)) == NULL) {
+ true = 0;
+ DebugPrint(DEBUG_INFO, SECTION_TAPE,"Rewind OK,\n", cnt);
+ } else {
+ DebugPrint(DEBUG_ERROR, SECTION_TAPE,"Rewind failed %s\n",errstr);
+ DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP GenericRewind (-1)\n");
+ amfree(pRequestSense);
+ return(-1);
+ }
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP GenericRewind (0)\n");
}
+ amfree(pRequestSense);
return(0);
}
*/
if ( RequestSense(INDEX_TAPECTL, &ExtRequestSense, 1) == 0)
{
-
+
DecodeExtSense(&ExtRequestSense, "GenericClean : ", debug_file);
if(ExtRequestSense.CLN) {
ret = 1;
RequestSense_T *pRequestSense;
int ret = 0;
int retry = 1;
-
+
DebugPrint(DEBUG_INFO, SECTION_ELEMENT, "##### START GenericResetStatus\n");
-
+
if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericResetStatus : malloc failed\n");
/* for (i = 1; i < sizeof(RequestSense_T); i++) */
/* fprintf(stderr, " %02X", ((unsigned char *) &pRequestSense)[i]); */
/* fprintf(stderr, "\n"); */
+ free(pRequestSense);
return(ret);
}
if ( ret > 0 )
switch (SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
{
case SENSE_IGNORE:
+ free(pRequestSense);
return(0);
break;
case SENSE_ABORT:
+ free(pRequestSense);
return(-1);
break;
case SENSE_RETRY:
sleep(2);
} else {
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericResetStatus : return (-1)\n");
+ free(pRequestSense);
return(-1);
}
break;
default:
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "GenericResetStatus : (default) return (-1)\n");
+ free(pRequestSense);
return(-1);
break;
}
retry = 0;
}
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT, "##### STOP GenericResetStatus (%d)\n",ret);
+ free(pRequestSense);
return(ret);
}
* pwork is an pointer to the structure OpenFiles_T, which is filled with information
* about the device to which we talk. Information are for example
* The vendor, the ident, which fd, etc. This strucure is filled when we open the
- * device
+ * device
* flag tells how to handle the information passed in the buffer,
* 0 -> Sense Key available
* 1 -> No Sense key available
* Limit recursion, may run in an infinite loop
*/
int GenericSenseHandler(int ip, int flag, unsigned char SenseKey, unsigned char AdditionalSenseCode, unsigned char AdditionalSenseCodeQualifier, char *buffer)
-{
+{
extern OpenFiles_T *pDev;
RequestSense_T *pRequestSense = (RequestSense_T *)buffer;
int ret = 0;
unsigned char *info = NULL;
-
+
dbprintf(("##### START GenericSenseHandler\n"));
-
+
DecodeSense(pRequestSense, "GenericSenseHandler : ", debug_file);
-
+
ret = Sense2Action(pDev[ip].ident,
pDev[ip].inquiry->type,
flag, SenseKey,
AdditionalSenseCode,
AdditionalSenseCodeQualifier,
(char **)&info);
-
+
dbprintf(("##### STOP GenericSenseHandler\n"));
return(ret);
}
* Return:
* == 0 -> success
* != 0 -> error either from the SCSI command or from
- * the element handling
+ * the element handling
* TODO:
*/
int SDXMove(int DeviceFD, int from, int to)
int SDX_DTE = -1; /* AlignElements */
DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### START SDXMove\n");
-
+
DebugPrint(DEBUG_INFO, SECTION_MOVE,"%-20s : from = %d, to = %d\n", "SDXMove", from, to);
-
+
if ((pfrom = LookupElement(from)) == NULL)
{
DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : ElementInfo for %d not found\n", from);
DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
return(-1);
}
-
+
if ((pto = LookupElement(to)) == NULL)
{
DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : ElementInfo for %d not found\n", to);
DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
return(-1);
}
-
- if (pfrom->status == 'E')
+
+ if (pfrom->status == 'E')
{
DebugPrint(DEBUG_INFO, SECTION_MOVE,"SDXMove : from %d is empty\n", from);
DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP SDXMove\n");
return(-1);
}
- if (pto->status == 'F')
+ if (pto->status == 'F')
{
switch (pto->status)
{
return(-1);
}
- /*
- * If from is a tape we must check if it is loaded
- * and if yes we have to eject it
+ /*
+ * If from is a tape we must check if it is loaded
+ * and if yes we have to eject it
*/
if (pfrom->type == TAPETYPE)
{
if ( tapestat & TAPE_ONLINE)
{
if (pDev[INDEX_TAPECTL].SCSI == 1)
- {
+ {
ret = eject_tape(pDev[INDEX_TAPECTL].dev,1);
} else {
ret = eject_tape(pDev[INDEX_TAPE].dev,2);
* Return:
* == 0 -> success
* != 0 -> error either from the SCSI command or from
- * the element handling
+ * the element handling
* TODO:
*/
int GenericMove(int DeviceFD, int from, int to)
ElementInfo_T *pfrom;
ElementInfo_T *pto;
int ret = 0;
-
+
DebugPrint(DEBUG_INFO, SECTION_MOVE, "##### START GenericMove\n");
-
+
DebugPrint(DEBUG_INFO, SECTION_MOVE, "%-20s : from = %d, to = %d\n", "GenericMove", from, to);
-
-
+
+
if ((pfrom = LookupElement(from)) == NULL)
{
DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : ElementInfo for %d not found\n", from);
DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
return(-1);
}
-
+
if ((pto = LookupElement(to)) == NULL)
{
DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : ElementInfo for %d not found\n", to);
DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
return(-1);
}
-
- if (pfrom->status == 'E')
+
+ if (pfrom->status == 'E')
{
DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : from %d is empty\n", from);
DebugPrint(DEBUG_INFO, SECTION_MOVE,"##### STOP GenericMove\n");
return(-1);
}
-
- if (pto->status == 'F')
+
+ if (pto->status == 'F')
{
DebugPrint(DEBUG_INFO, SECTION_MOVE, "GenericMove : Destination Element %d Type %d is full\n",
pto->address, pto->type);
return(-1);
}
}
-
+
if (CheckMove(pfrom, pto))
{
ret = SCSI_Move(DeviceFD, 0, from, to);
*/
moveok=1;
}
-
+
DebugPrint(DEBUG_INFO, SECTION_MOVE, "###### STOP CheckMove\n");
return(moveok);
}
/*
*/
-
+
int GetCurrentSlot(int fd, int drive)
{
extern OpenFiles_T *pDev;
{
return(-1);
}
- }
+ }
/* If the from address is the as the same as the tape address skip it */
if (pDTE[drive].from >= 0 && pDTE[drive].from != pDTE[drive].address)
}
}
}
-
+
if (GetElementStatus(DeviceFD) == 0 && loop > 0)
{
loop--;
}
}
}
-
+
if (GetElementStatus(DeviceFD) == 0 && loop > 0)
{
loop--;
}
-/*
+/*
* Much the same like GenericElementStatus but
* it seemes that for the STE Elements ASC/ASCQ is not set
* on an error, only the except bit is set
* Only do the read, error handling is done by the calling function
*
* Return Values:
- * < 0 -> Error
+ * < 0 -> Error
* == 0 -> OK
*
* TODO:
int length = 0; /* Length of an Element */
int barcode = 0; /* To store the result of the BarCode function */
int NoOfElements;
-
+
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"##### START GetElementStatus\n");
-
+
barcode = BarCode(DeviceFD);
- /*
- * If the MODE_SENSE was successfull we use this Information to read the Elelement Info
+ /*
+ * If the MODE_SENSE was successfull we use this Information to read the Elelement Info
*/
if (pEAAPage != NULL)
{
/* First the Medim Transport*/
if (V2(pEAAPage->NoMediumTransportElements) > 0)
{
+ free(pMTE);
MTE = V2(pEAAPage->NoMediumTransportElements) ;
- if (pMTE == NULL)
+ if ((pMTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * MTE)) == NULL)
{
- if ((pMTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * MTE)) == NULL)
- {
- DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
- return(-1);
- }
+ DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ return(-1);
}
memset(pMTE, 0, sizeof(ElementInfo_T) * MTE);
-
- if (SCSI_ReadElementStatus(DeviceFD,
- CHANGER,
+
+ if (SCSI_ReadElementStatus(DeviceFD,
+ CHANGER,
0,
barcode,
V2(pEAAPage->MediumTransportElementAddress),
sizeof(MediumTransportElementDescriptor_T),
(char **)&DataBuffer) != 0)
{
- if (DataBuffer != 0)
- {
- free(DataBuffer);
- }
+ free(pMTE);
+ free(DataBuffer);
ChgExit("genericElementStatus","Can't read MTE status", FATAL);
}
ElementStatusData = (ElementStatusData_T *)DataBuffer;
offset = sizeof(ElementStatusData_T);
-
+
ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
offset = offset + sizeof(ElementStatusPage_T);
length = V2(ElementStatusPage->length);
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"MTE Length %d(%d)\n",length,sizeof(MediumTransportElementDescriptor_T));
-
+
for (x = 0; x < MTE; x++)
{
MediumTransportElementDescriptor = (MediumTransportElementDescriptor_T *)&DataBuffer[offset];
-
+
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pMTE[x].VolTag,
- MediumTransportElementDescriptor->pvoltag,
+ strncpy((char *)pMTE[x].VolTag,
+ (char *)MediumTransportElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pMTE[x].VolTag, TAG_SIZE+1);
}
-
+
pMTE[x].type = ElementStatusPage->type;
pMTE[x].address = V2(MediumTransportElementDescriptor->address);
pMTE[x].except = MediumTransportElementDescriptor->except;
pMTE[x].status = (MediumTransportElementDescriptor->full > 0) ? 'F':'E';
pMTE[x].full = MediumTransportElementDescriptor->full;
-
+
if (length >= 5)
{
pMTE[x].ASC = MediumTransportElementDescriptor->asc;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC MTE\n");
}
-
+
if (length >= 6)
{
pMTE[x].ASCQ = MediumTransportElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ MTE\n");
}
-
+
if (length >= 0xa)
{
if (MediumTransportElementDescriptor->svalid == 1)
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source MTE\n");
}
- offset = offset + length;
+ offset = offset + length;
}
}
- /*
- * Storage Elements
+ /*
+ * Storage Elements
*/
if ( V2(pEAAPage->NoStorageElements) > 0)
{
+ free(pSTE);
STE = V2(pEAAPage->NoStorageElements);
- if (pSTE == NULL)
+ if ((pSTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * STE)) == NULL)
{
- if ((pSTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * STE)) == NULL)
- {
- DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
- return(-1);
- }
+ DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ free(pMTE);
+ return(-1);
}
memset(pSTE, 0, sizeof(ElementInfo_T) * STE);
-
- if (SCSI_ReadElementStatus(DeviceFD,
- STORAGE,
+
+ if (SCSI_ReadElementStatus(DeviceFD,
+ STORAGE,
0,
barcode,
V2(pEAAPage->FirstStorageElementAddress),
sizeof(StorageElementDescriptor_T),
(char **)&DataBuffer) != 0)
{
- if (DataBuffer != 0)
- {
- free(DataBuffer);
- }
+ free(DataBuffer);
ChgExit("GetElementStatus", "Can't read STE status", FATAL);
}
-
+
ElementStatusData = (ElementStatusData_T *)DataBuffer;
offset = sizeof(ElementStatusData_T);
-
+
ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
offset = offset + sizeof(ElementStatusPage_T);
length = V2(ElementStatusPage->length);
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"STE Length %d\n",length);
-
+
for (x = 0; x < STE; x++)
{
StorageElementDescriptor = (StorageElementDescriptor_T *)&DataBuffer[offset];
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pSTE[x].VolTag,
- StorageElementDescriptor->pvoltag,
+ strncpy(pSTE[x].VolTag,
+ (char *)StorageElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pSTE[x].VolTag, TAG_SIZE+1);
}
-
-
+
+
pSTE[x].type = ElementStatusPage->type;
pSTE[x].address = V2(StorageElementDescriptor->address);
pSTE[x].except = StorageElementDescriptor->except;
pSTE[x].status = (StorageElementDescriptor->full > 0) ? 'F':'E';
pSTE[x].full = StorageElementDescriptor->full;
-
+
if (length >= 5)
{
pSTE[x].ASC = StorageElementDescriptor->asc;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC STE\n");
}
-
+
if (length >= 6)
{
pSTE[x].ASCQ = StorageElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ STE\n");
}
-
+
if (length >= 0xa)
{
if (StorageElementDescriptor->svalid == 1)
pSTE[x].from = V2(StorageElementDescriptor->source);
} else {
pSTE[x].from = -1;
- }
+ }
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
}
-
- offset = offset + length;
+
+ offset = offset + length;
}
-
+
}
- /*
+ /*
* Import/Export Elements
*/
if ( V2(pEAAPage->NoImportExportElements) > 0)
{
+ free(pIEE);
IEE = V2(pEAAPage->NoImportExportElements);
- if (pIEE == NULL)
+ if ((pIEE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * IEE)) == NULL)
{
- if ((pIEE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * IEE)) == NULL)
- {
- DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
- return(-1);
- }
+ DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ free(DataBuffer);
+ return(-1);
}
memset(pIEE, 0, sizeof(ElementInfo_T) * IEE);
- if (SCSI_ReadElementStatus(DeviceFD,
- IMPORT,
+
+ if (SCSI_ReadElementStatus(DeviceFD,
+ IMPORT,
0,
barcode,
V2(pEAAPage->FirstImportExportElementAddress),
}
ChgExit("GetElementStatus", "Can't read IEE status", FATAL);
}
-
+
ElementStatusData = (ElementStatusData_T *)DataBuffer;
offset = sizeof(ElementStatusData_T);
-
+
ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
offset = offset + sizeof(ElementStatusPage_T);
length = V2(ElementStatusPage->length);
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"IEE Length %d\n",length);
-
+
for (x = 0; x < IEE; x++)
{
ImportExportElementDescriptor = (ImportExportElementDescriptor_T *)&DataBuffer[offset];
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pIEE[x].VolTag,
- ImportExportElementDescriptor->pvoltag,
+ strncpy(pIEE[x].VolTag,
+ (char *)ImportExportElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pIEE[x].VolTag, TAG_SIZE+1);
}
pIEE[x].except = ImportExportElementDescriptor->except;
pIEE[x].status = (ImportExportElementDescriptor->full > 0) ? 'F':'E';
pIEE[x].full = ImportExportElementDescriptor->full;
-
+
if (length >= 5)
{
pIEE[x].ASC = ImportExportElementDescriptor->asc;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC IEE\n");
}
-
+
if (length >= 6)
{
pIEE[x].ASCQ = ImportExportElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ IEE\n");
}
-
+
if (length >= 0xa)
{
if (ImportExportElementDescriptor->svalid == 1)
pIEE[x].from = V2(ImportExportElementDescriptor->source);
} else {
pIEE[x].from = -1;
- }
+ }
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source IEE\n");
}
-
- offset = offset + length;
+
+ offset = offset + length;
}
-
+
}
- /*
+ /*
* Data Transfer Elements
*/
if (V2(pEAAPage->NoDataTransferElements) >0)
{
+ free(pDTE);
DTE = V2(pEAAPage->NoDataTransferElements) ;
- if (pDTE == NULL)
+ if ((pDTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * DTE)) == NULL)
{
- if ((pDTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * DTE)) == NULL)
- {
- DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
- return(-1);
- }
+ DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ free(DataBuffer);
+ return(-1);
}
memset(pDTE, 0, sizeof(ElementInfo_T) * DTE);
- if (SCSI_ReadElementStatus(DeviceFD,
- TAPETYPE,
+
+ if (SCSI_ReadElementStatus(DeviceFD,
+ TAPETYPE,
0,
barcode,
V2(pEAAPage->FirstDataTransferElementAddress),
sizeof(DataTransferElementDescriptor_T),
(char **)&DataBuffer) != 0)
{
- if (DataBuffer != 0)
- {
- free(DataBuffer);
- }
+ free(DataBuffer);
ChgExit("GenericElementStatus", "Can't read DTE status", FATAL);
}
-
+
ElementStatusData = (ElementStatusData_T *)DataBuffer;
offset = sizeof(ElementStatusData_T);
-
+
ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
offset = offset + sizeof(ElementStatusPage_T);
length = V2(ElementStatusPage->length);
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"DTE Length %d\n",length);
-
+
for (x = 0; x < DTE; x++)
{
DataTransferElementDescriptor = (DataTransferElementDescriptor_T *)&DataBuffer[offset];
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pDTE[x].VolTag,
- DataTransferElementDescriptor->pvoltag,
+ strncpy(pDTE[x].VolTag,
+ (char *)DataTransferElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pDTE[x].VolTag, TAG_SIZE+1);
}
pDTE[x].scsi = DataTransferElementDescriptor->scsi;
pDTE[x].status = (DataTransferElementDescriptor->full > 0) ? 'F':'E';
pDTE[x].full = DataTransferElementDescriptor->full;
-
+
if (length >= 5)
{
pDTE[x].ASC = DataTransferElementDescriptor->asc;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC DTE\n");
}
-
+
if (length >= 6)
{
pDTE[x].ASCQ = DataTransferElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ DTE\n");
}
-
+
if (length >= 0xa)
{
if (DataTransferElementDescriptor->svalid == 1)
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
}
-
- offset = offset + length;
+
+ offset = offset + length;
}
}
} else {
* And now the old way, when we get here the read mode sense page has failed ...
*/
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Reading Element Status the old way .... (max 255 elements)\n");
- if (SCSI_ReadElementStatus(DeviceFD,
- 0,
+ if (SCSI_ReadElementStatus(DeviceFD,
+ 0,
0,
barcode,
0,
}
ChgExit("GenericElementStatus","Can't get ElementStatus", FATAL);
}
-
+
ElementStatusData = (ElementStatusData_T *)DataBuffer;
DataBufferLength = V3(ElementStatusData->count);
-
+
offset = sizeof(ElementStatusData_T);
-
- if (DataBufferLength <= 0)
+
+ if (DataBufferLength <= 0)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"DataBufferLength %d\n",DataBufferLength);
+ free(DataBuffer);
return(1);
}
-
- while (offset < DataBufferLength)
+
+ while (offset < DataBufferLength)
{
ElementStatusPage = (ElementStatusPage_T *)&DataBuffer[offset];
NoOfElements = V3(ElementStatusPage->count) / V2(ElementStatusPage->length);
offset = offset + sizeof(ElementStatusPage_T);
length = V2(ElementStatusPage->length);
-
+
switch (ElementStatusPage->type)
{
case CHANGER:
+ free(pMTE);
MTE = NoOfElements;
if ((pMTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * MTE)) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ free(DataBuffer);
return(-1);
}
memset(pMTE, 0, sizeof(ElementInfo_T) * MTE);
+
for (x = 0; x < NoOfElements; x++)
- {
+ {
MediumTransportElementDescriptor = (MediumTransportElementDescriptor_T *)&DataBuffer[offset];
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pMTE[x].VolTag,
- MediumTransportElementDescriptor->pvoltag,
+ strncpy(pMTE[x].VolTag,
+ (char *)MediumTransportElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pMTE[x].VolTag, TAG_SIZE+1);
}
pMTE[x].except = MediumTransportElementDescriptor->except;
pMTE[x].status = (MediumTransportElementDescriptor->full > 0) ? 'F':'E';
pMTE[x].full = MediumTransportElementDescriptor->full;
-
-
+
+
if (length >= 5)
{
pMTE[x].ASC = MediumTransportElementDescriptor->asc;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC MTE\n");
}
-
+
if (length >= 6)
{
pMTE[x].ASCQ = MediumTransportElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ MTE\n");
}
-
+
if (length >= 0xa)
{
if (MediumTransportElementDescriptor->svalid == 1)
pMTE[x].from = V2(MediumTransportElementDescriptor->source);
} else {
pMTE[x].from = -1;
- }
+ }
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source MTE\n");
}
- offset = offset + length;
+ offset = offset + length;
}
break;
case STORAGE:
+ free(pSTE);
STE = NoOfElements;
if ((pSTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * STE)) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ free(DataBuffer);
return(-1);
}
memset(pSTE, 0, sizeof(ElementInfo_T) * STE);
+
for (x = 0; x < NoOfElements; x++)
{
StorageElementDescriptor = (StorageElementDescriptor_T *)&DataBuffer[offset];
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pSTE[x].VolTag,
- StorageElementDescriptor->pvoltag,
+ strncpy(pSTE[x].VolTag,
+ (char *)StorageElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pSTE[x].VolTag, TAG_SIZE+1);
}
-
+
pSTE[x].type = ElementStatusPage->type;
pSTE[x].address = V2(StorageElementDescriptor->address);
pSTE[x].except = StorageElementDescriptor->except;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC STE\n");
}
-
+
if (length >= 6)
{
pSTE[x].ASCQ = StorageElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ STE\n");
}
-
+
if (length >= 0xa)
{
if (StorageElementDescriptor->svalid == 1)
pSTE[x].from = V2(StorageElementDescriptor->source);
} else {
pSTE[x].from = -1;
- }
+ }
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
}
-
- offset = offset + length;
+
+ offset = offset + length;
}
break;
case IMPORT:
+ free(pIEE);
IEE = NoOfElements;
if ((pIEE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * IEE)) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ free(DataBuffer);
return(-1);
}
memset(pIEE, 0, sizeof(ElementInfo_T) * IEE);
-
+
for (x = 0; x < NoOfElements; x++)
{
ImportExportElementDescriptor = (ImportExportElementDescriptor_T *)&DataBuffer[offset];
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pIEE[x].VolTag,
- ImportExportElementDescriptor->pvoltag,
+ strncpy(pIEE[x].VolTag,
+ (char *)ImportExportElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pIEE[x].VolTag, TAG_SIZE+1);
}
pIEE[x].except = ImportExportElementDescriptor->except;
pIEE[x].status = (ImportExportElementDescriptor->full > 0) ? 'F':'E';
pIEE[x].full = ImportExportElementDescriptor->full;
-
+
if (length >= 5)
{
pIEE[x].ASC = ImportExportElementDescriptor->asc;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC IEE\n");
}
-
+
if (length >= 6)
{
pIEE[x].ASCQ = ImportExportElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ IEE\n");
}
-
+
if (length >= 0xa)
{
if (ImportExportElementDescriptor->svalid == 1)
pIEE[x].from = V2(ImportExportElementDescriptor->source);
} else {
pIEE[x].from = -1;
- }
+ }
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source IEE\n");
}
-
- offset = offset + length;
+
+ offset = offset + length;
}
break;
case TAPETYPE:
+ free(pDTE);
DTE = NoOfElements;
if ((pDTE = (ElementInfo_T *)malloc(sizeof(ElementInfo_T) * DTE)) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GenericElementStatus : malloc failed\n");
+ free(DataBuffer);
return(-1);
}
memset(pDTE, 0, sizeof(ElementInfo_T) * DTE);
-
+
for (x = 0; x < NoOfElements; x++)
{
DataTransferElementDescriptor = (DataTransferElementDescriptor_T *)&DataBuffer[offset];
if (ElementStatusPage->pvoltag == 1)
{
- strncpy(pSTE[x].VolTag,
- DataTransferElementDescriptor->pvoltag,
+ strncpy(pSTE[x].VolTag,
+ (char *)DataTransferElementDescriptor->pvoltag,
TAG_SIZE);
TerminateString(pSTE[x].VolTag, TAG_SIZE+1);
}
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASC DTE\n");
}
-
+
if (length >= 6)
{
pDTE[x].ASCQ = DataTransferElementDescriptor->ascq;
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip ASCQ DTE\n");
}
-
+
if (length >= 0xa)
{
if (DataTransferElementDescriptor->svalid == 1)
} else {
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"Skip source STE\n");
}
-
- offset = offset + length;
+
+ offset = offset + length;
}
break;
default:
- offset = offset + length;
+ offset = offset + length;
DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"GetElementStatus : UnGknown Type %d\n",ElementStatusPage->type);
break;
}
pSTE[x].ASCQ, pSTE[x].type, pSTE[x].from, pSTE[x].VolTag);
DebugPrint(DEBUG_INFO, SECTION_ELEMENT,"\n\n\tData Transfer Elements (tape drives) :\n");
-
+
for ( x = 0; x < DTE; x++)
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",
pDTE[x].address, pDTE[x].status, pDTE[x].except, pDTE[x].ASC,
{
CDB_T CDB;
int ret;
-
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START RequestSense\n");
-
- CDB[0] = SC_COM_REQUEST_SENSE; /* REQUEST SENSE */
- CDB[1] = 0; /* Logical Unit Number = 0, Reserved */
- CDB[2] = 0; /* Reserved */
+
+ CDB[0] = SC_COM_REQUEST_SENSE; /* REQUEST SENSE */
+ CDB[1] = 0; /* Logical Unit Number = 0, Reserved */
+ CDB[2] = 0; /* Reserved */
CDB[3] = 0; /* Reserved */
- CDB[4] = sizeof(ExtendedRequestSense_T); /* Allocation Length */
+ CDB[4] = sizeof(ExtendedRequestSense_T); /* Allocation Length */
CDB[5] = (ClearErrorCounters << 7) & 0x80; /* */
-
+
memset(ExtendedRequestSense, 0, sizeof(ExtendedRequestSense_T));
-
- ret = SCSI_Run(DeviceFD, Input, CDB, 6,
+
+ ret = SCSI_Run(DeviceFD, Input, CDB, 6,
(char *) ExtendedRequestSense,
- sizeof(ExtendedRequestSense_T),
+ sizeof(ExtendedRequestSense_T),
(char *) ExtendedRequestSense, sizeof(ExtendedRequestSense_T));
-
-
+
+
if (ret < 0)
{
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP RequestSense (%d)\n",ret);
return(ret);
}
-
+
if ( ret > 0)
{
DecodeExtSense(ExtendedRequestSense, "RequestSense : ",debug_file);
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP RequestSense (%d)\n", ExtendedRequestSense->SenseKey);
return(ExtendedRequestSense->SenseKey);
}
-
+
dump_hex((char *)ExtendedRequestSense , sizeof(ExtendedRequestSense_T) , DEBUG_INFO, SECTION_SCSI);
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP RequestSense (0)\n");
return(0);
LogParameter_T *LogParameter;
struct LogPageDecode *p;
int found;
- char *datestamp = NULL;
- char *label = NULL;
- char *result = NULL;
extern char *tapestatfile;
int i;
int ParameterCode;
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### START LogSense\n");
- if (tapestatfile != NULL &&
- (StatFile = fopen(tapestatfile,"a")) != NULL &&
- pDev[INDEX_TAPECTL].SCSI == 1)
+ if ((tapestatfile != NULL) && (pDev[INDEX_TAPECTL].SCSI == 1) &&
+ ((StatFile = fopen(tapestatfile,"a")) != NULL))
{
- if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
+ if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"LogSense : malloc failed\n");
+ fclose(StatFile);
return(-1);
}
-
- if (GenericRewind(INDEX_TAPECTL) < 0)
- {
+
+ if (GenericRewind(INDEX_TAPECTL) < 0)
+ {
DebugPrint(DEBUG_INFO, SECTION_TAPE,"LogSense : Rewind failed\n");
free(pRequestSense);
- return(0);
- }
+ fclose(StatFile);
+ return(0);
+ }
/*
* Try to read the tape label
*/
{
SCSI_CloseDevice(INDEX_TAPE);
}
-
- if ((result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &datestamp, &label)) == NULL)
+
+ if ((chgscsi_result = (char *)tape_rdlabel(pDev[INDEX_TAPE].dev, &chgscsi_datestamp, &chgscsi_label)) == NULL)
{
- fprintf(StatFile, "==== %s ==== %s ====\n", datestamp, label);
+ fprintf(StatFile, "==== %s ==== %s ====\n", chgscsi_datestamp, chgscsi_label);
} else {
- fprintf(StatFile, "%s\n", result);
+ fprintf(StatFile, "%s\n", chgscsi_result);
}
}
if ((buffer = (char *)malloc(size)) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"LogSense : malloc failed\n");
+ free(pRequestSense);
+ fclose(StatFile);
return(-1);
}
memset(buffer, 0, size);
/*
- * Get the known log pages
+ * Get the known log pages
*/
-
+
CDB[0] = SC_COM_LOG_SENSE;
CDB[1] = 0;
CDB[2] = 0x40; /* 0x40 for current values */
CDB[6] = 00;
MSB2(&CDB[7], size);
CDB[9] = 0;
-
+
if (SCSI_Run(INDEX_TAPECTL, Input, CDB, 10,
buffer,
- size,
+ size,
(char *)pRequestSense,
sizeof(RequestSense_T)) != 0)
{
DecodeSense(pRequestSense, "LogSense : ",debug_file);
- free(buffer);
free(pRequestSense);
+ free(buffer);
+ fclose(StatFile);
return(0);
}
-
+
LogSenseHeader = (LogSenseHeader_T *)buffer;
nologpages = V2(LogSenseHeader->PageLength);
if ((logpages = (char *)malloc(nologpages)) == NULL)
{
DebugPrint(DEBUG_ERROR, SECTION_TAPE,"LogSense : malloc failed\n");
+ free(pRequestSense);
+ free(buffer);
+ fclose(StatFile);
return(-1);
}
-
+
memcpy(logpages, buffer + sizeof(LogSenseHeader_T), nologpages);
-
+
for (count = 0; count < nologpages; count++) {
if (logpages[count] != 0 ) {
memset(buffer, 0, size);
-
-
CDB[0] = SC_COM_LOG_SENSE;
CDB[1] = 0;
CDB[2] = 0x40 | logpages[count]; /* 0x40 for current values */
CDB[6] = 00;
MSB2(&CDB[7], size);
CDB[9] = 0;
-
+
if (SCSI_Run(INDEX_TAPECTL, Input, CDB, 10,
buffer,
- size,
+ size,
(char *)pRequestSense,
sizeof(RequestSense_T)) != 0)
- {
+ {
DecodeSense(pRequestSense, "LogSense : ",debug_file);
- free(buffer);
free(pRequestSense);
+ free(logpages);
+ free(buffer);
+ fclose(StatFile);
return(0);
}
LogSenseHeader = (LogSenseHeader_T *)buffer;
p++;
}
- /*
- * Hack to disable the printing of unknown pages
- */
- found = 1;
-
if (!found) {
fprintf(StatFile, "Logpage No %d = %x\n", count ,logpages[count]);
-
+
while ((char *)LogParameter < (buffer + length)) {
i = LogParameter->ParameterLength;
ParameterCode = V2(LogParameter->ParameterCode);
/*
* Test only !!!!
- * Reset the cumulative counters
+ * Reset the cumulative counters
*/
CDB[0] = SC_COM_LOG_SELECT;
CDB[1] = 2;
- CDB[2] = 0xc0;
+ CDB[2] = 0xc0;
CDB[3] = 0;
CDB[4] = 0;
CDB[5] = 0;
CDB[7] = 0;
CDB[8] = 0;
CDB[9] = 0;
-
+
if (SCSI_Run(INDEX_TAPECTL, Input, CDB, 10,
buffer,
- size,
+ size,
(char *)pRequestSense,
sizeof(RequestSense_T)) != 0)
{
DecodeSense(pRequestSense, "LogSense : ",debug_file);
- free(buffer);
free(pRequestSense);
+ free(logpages);
+ free(buffer);
+ fclose(StatFile);
return(0);
}
free(pRequestSense);
+ free(logpages);
free(buffer);
+ fclose(StatFile);
}
DebugPrint(DEBUG_INFO, SECTION_TAPE,"##### STOP LogSense\n");
-
return(0);
}
value);
break;
default:
- fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
+ fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
ParameterCode,
value, i);
break;
value);
break;
default:
- fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
+ fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
ParameterCode,
value, i);
break;
if (Decode(LogParameter, &value) == 0) {
switch (ParameterCode) {
default:
- fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
+ fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
ParameterCode,
value, i);
break;
value);
break;
default:
- fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
+ fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
ParameterCode,
value, i);
break;
value);
break;
default:
- fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
+ fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
ParameterCode,
value, i);
break;
}
}
- LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
+ LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
}
}
case 0x14:
break;
default:
- fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
+ fprintf(StatFile, "Unknown ParameterCode %02X = %u(%d)\n",
ParameterCode,
value, i);
break;
}
}
- LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
+ LogParameter = (LogParameter_T *)((char *)LogParameter + sizeof(LogParameter_T) + i);
}
}
char buffer[1024];
FILE *ip;
int x = 0, bufferx;
-
+
if ((ip=fopen("/tmp/chg-scsi-trace", "r")) == NULL)
{
exit(1);
}
-
+
while (fscanf(ip, "%2x", &bufferx) != EOF)
{
buffer[x] = bufferx;
}
DecodeModeSense(&buffer[0], 12, "DLT448ElementStatus :", 0, debug_file);
+ fclose(ip);
}
/*
int x;
FILE *out;
ExtendedRequestSense_T ExtRequestSense;
- MBC_T *pbarcoderes = malloc(sizeof(MBC_T));
-
+ MBC_T *pbarcoderes;
+
ChangerCMD_T *p = (ChangerCMD_T *)&ChangerIO;
+ if ((pbarcoderes = malloc(sizeof(MBC_T))) == NULL)
+ {
+ printf("malloc failed \n");
+ return;
+ }
memset(pbarcoderes, 0, sizeof(MBC_T));
- if ((pModePage = (char *)malloc(0xff)) == NULL)
+ if ((pModePage == NULL) && ((pModePage = (char *)malloc(0xff)) == NULL))
{
+ DebugPrint(DEBUG_ERROR, SECTION_ELEMENT,"##### malloc failed (-1)\n");
printf("malloc failed \n");
+ free(pbarcoderes);
return;
}
if ((out = fdopen(1 , "w")) == NULL)
{
printf("Error fdopen stdout\n");
+ free(pbarcoderes);
return;
}
-
+
if (strcmp("types", option) == 0 || strcmp("all", option) == 0)
{
while(p->ident != NULL)
if (pDev[INDEX_CHANGER].functions->function_status(pDev[INDEX_CHANGER].fd, 1) != 0)
{
printf("Can not initialize changer status\n");
+ free(pbarcoderes);
+ fclose(out);
return;
}
}
printf("Address Type Status From\n");
}
printf("-------------------------------------------\n");
-
-
+
+
for ( x = 0; x < MTE; x++)
if (HasBarCode)
{
{
pbarcoderes->action = BARCODE_BARCODE;
strcpy(pbarcoderes->data.barcode, pMTE[x].VolTag);
-
+
if (MapBarCode(labelfile, pbarcoderes) == 0 )
- {
+ {
printf("No mapping\n");
} else {
printf("%s \n",pbarcoderes->data.voltag);
(pMTE[x].full ? "Full " :"Empty"),
pMTE[x].from);
}
-
-
+
+
for ( x = 0; x < STE; x++)
if (HasBarCode)
{
- printf("%07d STE %s %04d %s ",pSTE[x].address,
+ printf("%07d STE %s %04d %s ",pSTE[x].address,
(pSTE[x].full ? "Full ":"Empty"),
pSTE[x].from, pSTE[x].VolTag);
{
pbarcoderes->action = BARCODE_BARCODE;
strcpy(pbarcoderes->data.barcode, pSTE[x].VolTag);
-
+
if (MapBarCode(labelfile, pbarcoderes) == 0 )
{
printf("No mapping\n");
printf("\n");
}
} else {
- printf("%07d STE %s %04d %s\n",pSTE[x].address,
+ printf("%07d STE %s %04d %s\n",pSTE[x].address,
(pSTE[x].full ? "Full ":"Empty"),
pSTE[x].from, pSTE[x].VolTag);
}
-
-
+
+
for ( x = 0; x < DTE; x++)
if (HasBarCode)
{
- printf("%07d DTE %s %04d %s ",pDTE[x].address,
+ printf("%07d DTE %s %04d %s ",pDTE[x].address,
(pDTE[x].full ? "Full " : "Empty"),
pDTE[x].from, pDTE[x].VolTag);
{
pbarcoderes->action = BARCODE_BARCODE;
strcpy(pbarcoderes->data.barcode, pDTE[x].VolTag);
-
+
if (MapBarCode(labelfile, pbarcoderes) == 0 )
{
printf("No mapping\n");
}
} else {
- printf("%07d DTE %s %04d %s\n",pDTE[x].address,
+ printf("%07d DTE %s %04d %s\n",pDTE[x].address,
(pDTE[x].full ? "Full " : "Empty"),
pDTE[x].from, pDTE[x].VolTag);
}
-
+
for ( x = 0; x < IEE; x++)
if (HasBarCode)
- {
- printf("%07d IEE %s %04d %s ",pIEE[x].address,
+ {
+ printf("%07d IEE %s %04d %s ",pIEE[x].address,
(pIEE[x].full ? "Full " : "Empty"),
pIEE[x].from, pIEE[x].VolTag);
{
pbarcoderes->action = BARCODE_BARCODE;
strcpy(pbarcoderes->data.barcode, pIEE[x].VolTag);
-
+
if (MapBarCode(labelfile, pbarcoderes) == 0 )
{
printf("No mapping\n");
}
} else {
- printf("%07d IEE %s %04d %s\n",pIEE[x].address,
+ printf("%07d IEE %s %04d %s\n",pIEE[x].address,
(pIEE[x].full ? "Full " : "Empty"),
pIEE[x].from, pIEE[x].VolTag);
}
-
+
}
if (strcmp("sense", option) == 0 || strcmp("all", option) == 0)
RequestSense(INDEX_CHANGER , &ExtRequestSense, 0);
DecodeExtSense(&ExtRequestSense, "", out);
}
-
+
if (pDev[INDEX_TAPE].SCSI == 1)
{
printf("\n");
printf("Sense Status from tape (tapectl):\n");
- RequestSense(INDEX_TAPE, &ExtRequestSense, 0);
+ RequestSense(INDEX_TAPE, &ExtRequestSense, 0);
DecodeExtSense(&ExtRequestSense, "", out);
}
{
printf("\n");
printf("Sense Status from tape (tapectl):\n");
- RequestSense(INDEX_TAPECTL, &ExtRequestSense, 0);
+ RequestSense(INDEX_TAPECTL, &ExtRequestSense, 0);
DecodeExtSense(&ExtRequestSense, "", out);
}
}
printf("\n");
if (SCSI_ModeSense(INDEX_CHANGER, pModePage, 0xff, 0x08, 0x3f) == 0)
{
- DecodeModeSense(pModePage, 0, "Changer :" , 0, out);
+ DecodeModeSense(pModePage, 0, "Changer :" , 0, out);
}
}
-
+
if (strcmp("ModeSenseTape", option) == 0 || strcmp("all", option) == 0)
{
if (pDev[INDEX_TAPECTL].SCSI == 1)
printf("\n");
if (SCSI_ModeSense(INDEX_TAPECTL, pModePage, 0xff, 0x0, 0x3f) == 0)
{
- DecodeModeSense(pModePage, 0, "Tape :" , 1, out);
+ DecodeModeSense(pModePage, 0, "Tape :" , 1, out);
}
}
}
}
if (GenericClean("") == 1)
- printf("Tape needs cleaning\n");
+ printf("Tape needs cleaning\n");
+
+ free(pbarcoderes);
+ fclose(out);
}
void dump_hex(char *p, int size, int level, int section)
void TerminateString(char *string, int length)
{
int x;
-
+
for (x = length; x >= 0 && !isalnum((int)string[x]); x--)
string[x] = '\0';
}
{
dbprintf(("ChgExit in %s, reason %s\n", where, reason));
fprintf(stderr,"%s\n",reason);
- exit(2);
+ exit(2);
}
/* OK here starts a new set of functions.
case SCSI_ERROR:
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run (TestUnitReady) SCSI_ERROR\n");
return(-1);
- break;
+ break;
case SCSI_BUSY:
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run (TestUnitReady) SCSI_BUSY\n");
break;
maxtries++;
}
}
-
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run TestUnitReady after %d sec:\n",maxtries);
-
+
if (ok != 1)
{
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_Run Exit %d\n",ret);
DataBufferLength,
pRequestSense,
RequestSenseLength);
-
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Run Exit %d\n",ret);
switch (ret)
{
maxtries++;
sleep(1);
}
-
+
if (ok == 1)
{
return(0);
}
}
-/*
- * This a vendor specific command !!!!!!
- * First seen at AIT :-)
- */
+/*
+ * This a vendor specific command !!!!!!
+ * First seen at AIT :-)
+ */
int SCSI_AlignElements(int DeviceFD, int AE_MTE, int AE_DTE, int AE_STE)
{
RequestSense_T *pRequestSense;
- int retry = 1;
+ int retry;
CDB_T CDB;
- int ret;
+ int ret = -1;
int i;
-
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_AlignElements\n");
-
+
if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
{
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : malloc failed\n");
return(-1);
}
-
- while (retry > 0 && retry < MAX_RETRIES)
+
+ for (retry = 0; retry < MAX_RETRIES; retry++)
{
CDB[0] = 0xE5;
CDB[1] = 0;
CDB[9] = 0;
CDB[10] = 0;
CDB[11] = 0;
-
+
ret = SCSI_Run(DeviceFD, Input, CDB, 12,
- NULL, 0, (char *)pRequestSense, sizeof(RequestSense_T));
+ NULL, 0, (char *)pRequestSense, sizeof(RequestSense_T));
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : SCSI_Run = %d\n", ret);
DecodeSense(pRequestSense, "SCSI_AlignElements :",debug_file);
if (ret < 0)
{
- DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
- "chs", ((unsigned char *) &pRequestSense)[0]);
- for (i = 1; i < sizeof(RequestSense_T); i++)
- DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) &pRequestSense)[i]);
- DebugPrint(DEBUG_ERROR, SECTION_SCSI,"\n");
+ DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
+ "chs", ((unsigned char *) &pRequestSense)[0]);
+ for (i = 1; i < sizeof(RequestSense_T); i++)
+ DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) &pRequestSense)[i]);
+ DebugPrint(DEBUG_ERROR, SECTION_SCSI,"\n");
return(ret);
}
if ( ret > 0)
{
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_AlignElements : end %d\n", ret);
return(ret);
- }
+ }
}
- return(ret);
+ DebugPrint(DEBUG_ERROR, SECTION_SCSI,"SCSI_AlignElements :"
+ "Retries exceeded = %d\n", retry);
+ return(-1);
}
int SCSI_Move(int DeviceFD, unsigned char chm, int from, int to)
{
RequestSense_T *pRequestSense;
- int retry = 1;
+ int retry;
CDB_T CDB;
- int ret;
+ int ret = -1;
int i;
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_Move\n");
return(-1);
}
- while (retry > 0 && retry < MAX_RETRIES)
+ for (retry = 0; (ret != 0) && (retry < MAX_RETRIES); retry++)
{
CDB[0] = SC_MOVE_MEDIUM;
CDB[1] = 0;
CDB[9] = 0;
CDB[10] = 0;
CDB[11] = 0;
-
+
ret = SCSI_Run(DeviceFD, Input, CDB, 12,
- NULL, 0, (char *)pRequestSense, sizeof(RequestSense_T));
+ NULL, 0, (char *)pRequestSense, sizeof(RequestSense_T));
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Move : SCSI_Run = %d\n", ret);
DecodeSense(pRequestSense, "SCSI_Move :",debug_file);
if (ret < 0)
{
- DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
- "chs", ((unsigned char *) &pRequestSense)[0]);
- for (i = 1; i < sizeof(RequestSense_T); i++)
- DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) &pRequestSense)[i]);
- DebugPrint(DEBUG_INFO, SECTION_SCSI,"\n");
+ DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
+ "chs", ((unsigned char *) &pRequestSense)[0]);
+ for (i = 1; i < sizeof(RequestSense_T); i++)
+ DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) &pRequestSense)[i]);
+ DebugPrint(DEBUG_INFO, SECTION_SCSI,"\n");
return(ret);
}
if ( ret > 0)
break;
}
}
- if (ret == 0)
- {
- dbprintf(("SCSI_Move : end %d\n", ret));
- return(ret);
- }
}
+ dbprintf(("SCSI_Move : end %d\n", ret));
return(ret);
}
int ret;
dbprintf(("##### START SCSI_LoadUnload\n"));
-
+
CDB[0] = SC_COM_UNLOAD;
- CDB[1] = byte1;
+ CDB[1] = byte1;
CDB[2] = 0;
CDB[3] = 0;
CDB[4] = load;
CDB[5] = 0;
-
-
+
+
ret = SCSI_Run(DeviceFD, Input, CDB, 6,
- NULL, 0,
+ NULL, 0,
(char *) pRequestSense,
sizeof(RequestSense_T));
-
+
if (ret < 0)
{
dbprintf(("SCSI_Unload : failed %d\n", ret));
return(-1);
- }
+ }
return(ret);
}
CDB[5] = 0;
ret = SCSI_ExecuteCommand(DeviceFD, Input, CDB, 6,
- NULL, 0,
+ NULL, 0,
(char *) pRequestSense,
sizeof(RequestSense_T));
/*
- * We got an error, so let the calling function handle this
+ * We got an error, so let the calling function handle this
*/
if (ret > 0)
{
{
CDB_T CDB;
RequestSense_T *pRequestSense;
- int ret;
+ int ret = -1;
int retry = 1;
char *sendbuf;
-
+
dbprintf(("##### START SCSI_ModeSelect\n"));
dbprintf(("SCSI_ModeSelect start length = %d:\n", length));
return(-1);
}
-
+
if ((sendbuf = (char *)malloc(length + 4)) == NULL)
{
dbprintf(("SCSI_ModeSelect : malloc failed\n"));
+ free(pRequestSense);
return(-1);
}
memcpy(&sendbuf[4], buffer, length);
dump_hex(sendbuf, length+4, DEBUG_INFO, SECTION_SCSI);
- while (retry > 0 && retry < MAX_RETRIES)
+ for (retry = 0; (ret != 0) && (retry < MAX_RETRIES); retry++)
{
memset(pRequestSense, 0, sizeof(RequestSense_T));
-
+
CDB[0] = SC_COM_MODE_SELECT;
CDB[1] = ((lun << 5) & 0xF0) | ((mode << 4) & 0x10) | (save & 1);
CDB[2] = 0;
CDB[3] = 0;
CDB[4] = length + 4;
CDB[5] = 0;
- ret = SCSI_Run(DeviceFD, Output, CDB, 6,
+ ret = SCSI_Run(DeviceFD, Output, CDB, 6,
sendbuf,
- length + 4,
+ length + 4,
(char *) pRequestSense,
sizeof(RequestSense_T));
if (ret < 0)
{
dbprintf(("SCSI_ModeSelect : ret %d\n", ret));
+ free(pRequestSense);
+ free(sendbuf);
return(ret);
}
-
+
if ( ret > 0)
{
- switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
+ switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey,
+ pRequestSense->AdditionalSenseCode,
+ pRequestSense->AdditionalSenseCodeQualifier,
+ (char *)pRequestSense))
{
case SENSE_IGNORE:
dbprintf(("SCSI_ModeSelect : SENSE_IGNORE\n"));
+ free(pRequestSense);
+ free(sendbuf);
return(0);
break;
case SENSE_RETRY:
break;
default:
dbprintf(("SCSI_ModeSelect : end %d\n", pRequestSense->SenseKey));
+ free(pRequestSense);
+ free(sendbuf);
return(pRequestSense->SenseKey);
break;
}
}
- retry++;
- if (ret == 0)
- {
- dbprintf(("SCSI_ModeSelect end: %d\n", ret));
- return(ret);
- }
}
dbprintf(("SCSI_ModeSelect end: %d\n", ret));
+ free(pRequestSense);
+ free(sendbuf);
return(ret);
}
{
memset(pRequestSense, 0, sizeof(RequestSense_T));
memset(buffer, 0, size);
-
+
CDB[0] = SC_COM_MODE_SENSE;
CDB[1] = byte1;
CDB[2] = byte2;
CDB[3] = 0;
CDB[4] = size;
CDB[5] = 0;
- ret = SCSI_Run(DeviceFD, Input, CDB, 6,
+ ret = SCSI_Run(DeviceFD, Input, CDB, 6,
buffer,
- size,
+ size,
(char *) pRequestSense,
sizeof(RequestSense_T));
if (ret < 0)
{
return(ret);
}
-
+
if ( ret > 0)
{
switch(SenseHandler(DeviceFD, 0, pRequestSense->SenseKey, pRequestSense->AdditionalSenseCode, pRequestSense->AdditionalSenseCodeQualifier, (char *)pRequestSense))
CDB[3] = 0;
CDB[4] = size;
CDB[5] = 0;
-
- ret = SCSI_ExecuteCommand(DeviceFD, Input, CDB, 6,
+
+ ret = SCSI_ExecuteCommand(DeviceFD, Input, CDB, 6,
buffer,
- size,
+ size,
(char *) pRequestSense,
sizeof(RequestSense_T));
if (ret < 0)
{
DebugPrint(DEBUG_ERROR, SECTION_SCSI,"%s: Request Sense[Inquiry]: %02X",
"chs", ((unsigned char *) pRequestSense)[0]);
- for (i = 1; i < sizeof(RequestSense_T); i++)
+ for (i = 1; i < sizeof(RequestSense_T); i++)
DebugPrint(DEBUG_ERROR, SECTION_SCSI," %02X", ((unsigned char *) pRequestSense)[i]);
- DebugPrint(DEBUG_ERROR, SECTION_SCSI, "\n");
+ DebugPrint(DEBUG_ERROR, SECTION_SCSI, "\n");
DebugPrint(DEBUG_ERROR, SECTION_SCSI, "Inquiry end: %d\n", ret);
return(ret);
}
return(ret);
}
}
-
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_Inquiry end: %d\n", ret);
return(ret);
}
/*
- * Read the Element Status. If DescriptorSize != 0 then
+ * Read the Element Status. If DescriptorSize != 0 then
* allocate DescriptorSize * NoOfElements for the result from the
- * Read Element Status command.
+ * Read Element Status command.
* If DescriptorSize == 0 than try to figure out how much space is needed
- * by
+ * by
* 1. do an read with an allocation size of 8
* 2. from the result take the 'Byte Count of Descriptor Available'
* 3. do again an Read Element Status with the result from 2.
*
*/
-int SCSI_ReadElementStatus(int DeviceFD,
- unsigned char type,
+int SCSI_ReadElementStatus(int DeviceFD,
+ unsigned char type,
unsigned char lun,
unsigned char VolTag,
int StartAddress,
ElementStatusData_T *ElementStatusData;
RequestSense_T *pRequestSense;
int retry = 1;
- int ret = -1;
-
+ int ret = -1;
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### START SCSI_ReadElementStatus\n");
if ((pRequestSense = (RequestSense_T *)malloc(sizeof(RequestSense_T))) == NULL)
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus : malloc failed\n");
ChgExit("SCSI_ReadElementStatus","malloc failed", FATAL);
}
-
+
/*
* How many elements, if <= 0 than exit with an fatal error
*/
} else {
*data = malloc(8);
}
-
+
memset(*data, 0, 8);
-
-
-
+
+
+
while (retry > 0 && retry < MAX_RETRIES)
{
memset(pRequestSense, 0, sizeof(RequestSense_T) );
-
+
CDB[0] = SC_COM_RES; /* READ ELEMENT STATUS */
CDB[1] = VolTag | type | lun; /* Element Type Code , VolTag, LUN */
MSB2(&CDB[2], StartAddress); /* Starting Element Address */
MSB2(&CDB[4], NoOfElements); /* Number Of Element */
- CDB[6] = 0; /* Reserved */
- MSB3(&CDB[7],8); /* Allocation Length */
- CDB[10] = 0; /* Reserved */
- CDB[11] = 0; /* Control */
-
- ret = SCSI_Run(DeviceFD, Input, CDB, 12,
- *data, 8,
+ CDB[6] = 0; /* Reserved */
+ MSB3(&CDB[7],8); /* Allocation Length */
+ CDB[10] = 0; /* Reserved */
+ CDB[11] = 0; /* Control */
+
+ ret = SCSI_Run(DeviceFD, Input, CDB, 12,
+ *data, 8,
(char *)pRequestSense, sizeof(RequestSense_T));
-
-
+
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus : (1) SCSI_Run %d\n", ret);
if (ret < 0)
{
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
return(ret);
}
-
+
ElementStatusData = (ElementStatusData_T *)*data;
DataBufferLength = V3(ElementStatusData->count);
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus: DataBufferLength %X, ret %d\n",DataBufferLength, ret);
-
+
dump_hex(*data, 8, DEBUG_INFO, SECTION_ELEMENT);
} else { /* DescriptorSize != 0 */
DataBufferLength = NoOfElements * DescriptorSize;
while (retry > 0 && retry < MAX_RETRIES)
{
memset(pRequestSense, 0, sizeof(RequestSense_T) );
-
+
CDB[0] = SC_COM_RES; /* READ ELEMENT STATUS */
CDB[1] = VolTag | type | lun; /* Element Type Code, VolTag, LUN */
MSB2(&CDB[2], StartAddress); /* Starting Element Address */
MSB2(&CDB[4], NoOfElements); /* Number Of Element */
- CDB[6] = 0; /* Reserved */
- MSB3(&CDB[7],DataBufferLength); /* Allocation Length */
- CDB[10] = 0; /* Reserved */
- CDB[11] = 0; /* Control */
-
- ret = SCSI_Run(DeviceFD, Input, CDB, 12,
- *data, DataBufferLength,
+ CDB[6] = 0; /* Reserved */
+ MSB3(&CDB[7],DataBufferLength); /* Allocation Length */
+ CDB[10] = 0; /* Reserved */
+ CDB[11] = 0; /* Control */
+
+ ret = SCSI_Run(DeviceFD, Input, CDB, 12,
+ *data, DataBufferLength,
(char *)pRequestSense, sizeof(RequestSense_T));
-
-
+
+
DebugPrint(DEBUG_INFO, SECTION_SCSI,"SCSI_ReadElementStatus : (2) SCSI_Run %d\n", ret);
if (ret < 0)
{
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
return(ret);
}
-
+
dump_hex(*data, DataBufferLength, DEBUG_INFO, SECTION_SCSI);
DebugPrint(DEBUG_INFO, SECTION_SCSI,"##### STOP SCSI_ReadElementStatus (%d)\n",ret);
return(ret);
}
}
}
- arglist_end(argp);
-
+ arglist_end(argp);
}