Skip to contentSkip to conversation

scsi-disk.c: Handle inquiry commands of varying length

PATCH New Justin Chevrier 1 participant 1 message Dec 2, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi-disk.c: Handle inquiry commands of varying length

Openserver 5.0.5 sends an Inquiry command to the emulated SCSI disk expecting a response length of 40 bytes. Currently the response to an Inquiry command is hardcoded to 36 bytes. When receiving a response of length 36 instead of 40 Openserver panics.

Modifications to original patch based on feedback from Ryan Harper and Paul Brook. Thanks guys.

Justin

Changelog:

Handle inquiry commands of varying length

scsi-disk.c +8 -3
Index: hw/scsi-disk.c
===================================================================
@@ -38,6 +38,7 @@
 #define STATUS_CHECK_CONDITION 2
 
 #define SCSI_DMA_BUF_SIZE    131072
+#define SCSI_MAX_INQUIRY_LEN 256
 
 typedef struct SCSIRequest {
     SCSIDeviceState *dev;
@@ -492,8 +493,12 @@
                      "is less than 36 (TODO: only 5 required)\n", len);
             }
         }
-	memset(outbuf, 0, 36);
+        
+        if(len > SCSI_MAX_INQUIRY_LEN)
+            len = SCSI_MAX_INQUIRY_LEN;
 
+        memset(outbuf, 0, len);
+
         if (lun || buf[1] >> 5) {
             outbuf[0] = 0x7f;	/* LUN not supported */
 	} else if (bdrv_get_type_hint(s->bdrv) == BDRV_TYPE_CDROM) {
@@ -510,10 +515,10 @@
            Some later commands are also implemented. */
 	outbuf[2] = 3;
 	outbuf[3] = 2; /* Format 2 */
-	outbuf[4] = 31;
+	outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */
         /* Sync data transfer and TCQ.  */
         outbuf[7] = 0x10 | (s->tcq ? 0x02 : 0);
-	r->buf_len = 36;
+	r->buf_len = len;
 	break;
     case 0x16:
         DPRINTF("Reserve(6)\n");