Blame SOURCES/emc-fix-fail-with-too-high-slot-count_cleanupver.patch

45ab98
diff --git a/mtxl.c b/mtxl.c
45ab98
index 3ae77a6..12ea157 100644
45ab98
--- a/mtxl.c
45ab98
+++ b/mtxl.c
45ab98
@@ -39,6 +39,9 @@
45ab98
 /* zap the following define when we finally add real import/export support */
45ab98
 #define IMPORT_EXPORT_HACK 1 /* for the moment, import/export == storage */
45ab98
 
45ab98
+/* only so many element per SCSI Read Element Status */
45ab98
+#define SCSI_RES_ELEMENTS 5000
45ab98
+
45ab98
 /* First, do some SCSI routines: */
45ab98
 
45ab98
 /* the camlib is used on FreeBSD. */
45ab98
@@ -1055,7 +1058,7 @@ static void ParseElementStatus(	int *EmptyStorageElementAddress,
45ab98
 				ElementStatus->DataTransferElementSourceStorageElementNumber[ElementStatus->DataTransferElementCount] =
45ab98
 					BigEndian16(TransportElementDescriptor->SourceStorageElementAddress);
45ab98
 
45ab98
-#if DEBUG
45ab98
+#ifdef DEBUG
45ab98
 				fprintf(stderr, "%d: ElementAddress = %d, Full = %d, SourceElement = %d\n", 
45ab98
 						ElementStatus->DataTransferElementCount,
45ab98
 						ElementStatus->DataTransferElementAddress[ElementStatus->DataTransferElementCount],
45ab98
@@ -1141,6 +1144,7 @@ ElementStatus_T *ReadElementStatus(DEVICE_TYPE MediumChangerFD, RequestSense_T *
45ab98
 	int empty_idx = 0;
45ab98
 	boolean is_attached = false;
45ab98
 	int i,j;
45ab98
+	int FirstElem, NumElements, NumThisRES;
45ab98
 
45ab98
 	ElementModeSense_T *mode_sense = NULL;
45ab98
 
45ab98
@@ -1205,35 +1209,46 @@ ElementStatus_T *ReadElementStatus(DEVICE_TYPE MediumChangerFD, RequestSense_T *
45ab98
 	{
45ab98
 #ifdef DEBUG
45ab98
 		fprintf(stderr,"Using original element status polling method (storage, import/export, drivers etc independantly)\n");
45ab98
+		fprintf(stderr,"Storage start %d, Num %d, max %d\n", mode_sense->StorageStart, mode_sense->NumStorage - mode_sense->NumImportExport, mode_sense->MaxReadElementStatusData);
45ab98
 #endif
45ab98
 		flags->elementtype = StorageElement; /* sigh! */
45ab98
-		DataBuffer = SendElementStatusRequest(	MediumChangerFD, RequestSense,
45ab98
+
45ab98
+		NumElements = mode_sense->NumStorage - mode_sense->NumImportExport;
45ab98
+		FirstElem = mode_sense->StorageStart;
45ab98
+
45ab98
+		do
45ab98
+		{
45ab98
+			NumThisRES = (NumElements > SCSI_RES_ELEMENTS ? SCSI_RES_ELEMENTS : NumElements);
45ab98
+			DataBuffer = SendElementStatusRequest(	MediumChangerFD, RequestSense,
45ab98
 												inquiry_info, flags,
45ab98
-												mode_sense->StorageStart,
45ab98
+												FirstElem,
45ab98
 												/* adjust for import/export. */
45ab98
-												mode_sense->NumStorage - mode_sense->NumImportExport,
45ab98
-												mode_sense->MaxReadElementStatusData);
45ab98
+												NumThisRES,
45ab98
+												SCSI_RES_ELEMENTS * 52 +120);
45ab98
 
45ab98
-		if (!DataBuffer)
45ab98
-		{
45ab98
+			if (!DataBuffer)
45ab98
+			{
45ab98
 #ifdef DEBUG
45ab98
-			fprintf(stderr,"Had no elements!\n");
45ab98
+				fprintf(stderr,"Had no elements!\n");
45ab98
 #endif
45ab98
-			/* darn. Free up stuff and return. */
45ab98
+				/* darn. Free up stuff and return. */
45ab98
 #ifdef DEBUG_MODE_SENSE
45ab98
-			PrintRequestSense(RequestSense);
45ab98
+				PrintRequestSense(RequestSense);
45ab98
 #endif
45ab98
-			FreeElementData(ElementStatus);
45ab98
-			return NULL; 
45ab98
-		}
45ab98
+				FreeElementData(ElementStatus);
45ab98
+				return NULL;
45ab98
+			}
45ab98
 
45ab98
 #ifdef DEBUG
45ab98
-		fprintf(stderr, "Parsing storage elements\n");
45ab98
+			fprintf(stderr, "Parsing storage elements\n");
45ab98
 #endif
45ab98
-		ParseElementStatus(EmptyStorageElementAddress, &EmptyStorageElementCount,
45ab98
-			DataBuffer,ElementStatus,mode_sense,NULL);
45ab98
+			ParseElementStatus(EmptyStorageElementAddress, &EmptyStorageElementCount,
45ab98
+					   DataBuffer,ElementStatus,mode_sense,NULL);
45ab98
 
45ab98
-		free(DataBuffer); /* sigh! */
45ab98
+			free(DataBuffer); /* sigh! */
45ab98
+			FirstElem += SCSI_RES_ELEMENTS;
45ab98
+			NumElements -= SCSI_RES_ELEMENTS;
45ab98
+		} while ( NumElements > 0 );
45ab98
 
45ab98
 		/* --------------IMPORT/EXPORT--------------- */
45ab98
 		/* Next let's see if we need to do Import/Export: */
45ab98
@@ -1247,8 +1262,7 @@ ElementStatus_T *ReadElementStatus(DEVICE_TYPE MediumChangerFD, RequestSense_T *
45ab98
 													inquiry_info, flags,
45ab98
 													mode_sense->ImportExportStart,
45ab98
 													mode_sense->NumImportExport,
45ab98
-													mode_sense->MaxReadElementStatusData);
45ab98
-
45ab98
+												        SCSI_RES_ELEMENTS * 52 +120);
45ab98
 			if (!DataBuffer)
45ab98
 			{
45ab98
 #ifdef DEBUG
45ab98
@@ -1283,7 +1297,7 @@ ElementStatus_T *ReadElementStatus(DEVICE_TYPE MediumChangerFD, RequestSense_T *
45ab98
 												inquiry_info, flags,
45ab98
 												mode_sense->DataTransferStart,
45ab98
 												mode_sense->NumDataTransfer,
45ab98
-												mode_sense->MaxReadElementStatusData);
45ab98
+												SCSI_RES_ELEMENTS * 52 +120);
45ab98
 		if (!DataBuffer)
45ab98
 		{
45ab98
 #ifdef DEBUG
45ab98
@@ -1322,7 +1336,7 @@ ElementStatus_T *ReadElementStatus(DEVICE_TYPE MediumChangerFD, RequestSense_T *
45ab98
 													inquiry_info, flags,
45ab98
 													mode_sense->MediumTransportStart,
45ab98
 													1, /* only get 1, sigh. */
45ab98
-													mode_sense->MaxReadElementStatusData);
45ab98
+													SCSI_RES_ELEMENTS * 52 +120);
45ab98
 			if (!DataBuffer)
45ab98
 			{
45ab98
 #ifdef DEBUG
45ab98