[hatari-devel] Patch for logging the full CDB

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

Instead of only logging some fields of the CDB (for some commands the field
names of the current logging is not correct anyway) I suggest to apply the
attached patch, so that all CDB fields are logged.

Sample output:

HDC: REQUEST SENSE (ACSI, t=0, lun=7, cdb=03:e0:00:00:12:00).
HDC: SEEK (ACSI, t=0, lun=0, cdb=0b:00:00:00:00:00), LBA=0 -> OK
HDC: Unsupported command (ACSI, t=0, lun=0, cdb=2b:00:00:00:00:00:00:00:00:00)!
HDC: REQUEST SENSE (ACSI, t=0, lun=0, cdb=03:00:00:00:12:00).
HDC: MODE SENSE (ACSI, t=0, lun=0, cdb=1a:08:3f:00:ff:00).
HDC: INQUIRY (ACSI, t=0, lun=0, cdb=12:00:00:00:0f:00)
HDC: Unsupported command (ACSI, t=0, lun=0, cdb=5a:08:3f:00:00:00:00:10:00:00)!
HDC: REQUEST SENSE (ACSI, t=0, lun=0, cdb=03:00:00:00:12:00).
HDC: Unsupported command (ACSI, t=0, lun=0, cdb=3e:00:00:00:00:00:00:00:00:00)!
HDC: REQUEST SENSE (ACSI, t=0, lun=0, cdb=03:00:00:00:12:00).
HDC: Unsupported command (ACSI, t=0, lun=0, cdb=46:02:00:00:00:00:00:00:fe:00)!
HDC: REQUEST SENSE (ACSI, t=0, lun=0, cdb=03:00:00:00:12:00).
HDC: Unsupported command (ACSI, t=0, lun=0, cdb=a0:00:00:00:00:00:00:00:01:08:00:00).
HDC: REPORT LUNS (ACSI, t=0, lun=0, cdb=a0:00:00:00:00:00:00:00:01:08:00:00).
HDC: INQUIRY (ACSI, t=0, lun=0, cdb=12:00:00:00:0f:00)

Best regards

Uwe
diff --git a/src/hdc.c b/src/hdc.c
index 6a235679..e299c562 100644
--- a/src/hdc.c
+++ b/src/hdc.c
@@ -98,25 +98,34 @@ static unsigned long HDC_GetLBA(SCSI_CTRLR *ctr)
 }
 
 /**
- * Return the count specified in the current ACSI command block.
+ * Return number of bytes for a command block.
  */
-static int HDC_GetCount(SCSI_CTRLR *ctr)
+static int HDC_GetCommandByteCount(SCSI_CTRLR *ctr)
 {
-	if (ctr->opcode < 0x20)
-		return ctr->command[4];			/* Class 0 */
-	else
-		return HDC_ReadInt16(ctr->command, 7);	/* Class 1 */
+	if (ctr->opcode == 0x88 || ctr->opcode == 0x8a || ctr->opcode == 0x8f ||
+		ctr->opcode == 0x91 || ctr->opcode == 0x9e || ctr->opcode == 0x9f) {
+		return 16;
+	}
+	else if (ctr->opcode == 0xa0) {
+		return 12;
+	}
+	else if (ctr->opcode == 0x05 || (ctr->opcode >= 0x20 && ctr->opcode <= 0x7d)) {
+		return 10;
+	} else {
+		return 6;
+	}
 }
 
+
 /**
- * Return the control byte specified in the current ACSI command block.
+ * Return the count specified in the current ACSI command block.
  */
-static inline Uint8 HDC_GetControl(SCSI_CTRLR *ctr)
+static int HDC_GetCount(SCSI_CTRLR *ctr)
 {
 	if (ctr->opcode < 0x20)
-		return ctr->command[5];			/* Class 0 */
+		return ctr->command[4];			/* Class 0 */
 	else
-		return ctr->command[9];			/* Class 1 */
+		return HDC_ReadInt16(ctr->command, 7);	/* Class 1 */
 }
 
 /**
@@ -142,12 +151,18 @@ static Uint8 *HDC_PrepRespBuf(SCSI_CTRLR *ctr, int size)
  */
 static inline char *HDC_CmdInfoStr(SCSI_CTRLR *ctr)
 {
-	static char str[80];
+	char cdb[80] = { 0 };
+
+	for (int i = 0; i < HDC_GetCommandByteCount(ctr); i++) {
+		char tmp[5];
+		snprintf(tmp, sizeof(tmp), "%s%02x", i ? ":" : "", ctr->command[i]);
+		strcat(cdb, tmp);
+	}
+    
+	static char str[160];
 
-	snprintf(str, sizeof(str),
-	         "%s, t=%i, lun=%i, opc=0x%x, cnt=0x%x, ctrl=0x%x",
-	         ctr->typestr, ctr->target, HDC_GetLUN(ctr), ctr->opcode,
-	         HDC_GetCount(ctr), HDC_GetControl(ctr));
+	snprintf(str, sizeof(str), "%s, t=%i, lun=%i, cdb=%s",
+                 ctr->typestr, ctr->target, HDC_GetLUN(ctr), cdb);
 
 	return str;
 }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/