From 70f0c6b34a97f3b179406907ad63187d5328c44b Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 18 Jan 2015 14:56:47 +0200 Subject: [PATCH] Log REQUEST SENSE. Fix LUN checks. --- hardfile.cpp | 13 ++++++++----- scsi.cpp | 23 ++++++++++++----------- scsitape.cpp | 3 ++- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/hardfile.cpp b/hardfile.cpp index cb304e25..ee3b6229 100644 --- a/hardfile.cpp +++ b/hardfile.cpp @@ -1233,6 +1233,10 @@ int scsi_hd_emulate (struct hardfiledata *hfd, struct hd_hardfiledata *hdhfd, ua scsi_cmd_len, scsi_data); } + if (cmdbuf[0] == 0x03) { /* REQUEST SENSE */ + return 0; + } + *reply_len = *sense_len = 0; lun = cmdbuf[1] >> 5; if (cmdbuf[0] != 0x03 && cmdbuf[0] != 0x12 && lun) { @@ -1241,7 +1245,8 @@ int scsi_hd_emulate (struct hardfiledata *hfd, struct hd_hardfiledata *hdhfd, ua s[2] = 5; /* ILLEGAL REQUEST */ s[12] = 0x25; /* INVALID LUN */ ls = 0x12; - goto err; + write_log (_T("UAEHF: CMD=%02X LUN=%d ignored\n"), cmdbuf[0], lun); + goto err_exit; } switch (cmdbuf[0]) { @@ -1300,7 +1305,7 @@ int scsi_hd_emulate (struct hardfiledata *hfd, struct hd_hardfiledata *hdhfd, ua r[2] = 2; /* supports SCSI-2 */ r[3] = 2; /* response data format */ r[4] = 32; /* additional length */ - r[7] = 0x20; /* 16 bit bus */ + r[7] = 0; scsi_len = lr = alen < 36 ? alen : 36; if (hdhfd) { r[2] = hdhfd->ansi_version; @@ -1534,7 +1539,6 @@ nodisk: err: write_log (_T("UAEHF: unsupported scsi command 0x%02X LUN=%d\n"), cmdbuf[0], lun); errreq: - lr = -1; status = 2; /* CHECK CONDITION */ s[0] = 0x70; s[2] = 5; /* ILLEGAL REQUEST */ @@ -1542,7 +1546,6 @@ errreq: ls = 0x12; break; outofbounds: - lr = -1; status = 2; /* CHECK CONDITION */ s[0] = 0x70; s[2] = 5; /* ILLEGAL REQUEST */ @@ -1550,7 +1553,6 @@ outofbounds: ls = 0x12; break; miscompare: - lr = -1; status = 2; /* CHECK CONDITION */ s[0] = 0x70; s[2] = 5; /* ILLEGAL REQUEST */ @@ -1558,6 +1560,7 @@ miscompare: ls = 0x12; break; } +err_exit: if (log_scsiemu && ls) { write_log (_T("-> SENSE STATUS: KEY=%d ASC=%02X ASCQ=%02X\n"), s[2], s[12], s[13]); diff --git a/scsi.cpp b/scsi.cpp index e5cb5021..09699517 100644 --- a/scsi.cpp +++ b/scsi.cpp @@ -18,6 +18,8 @@ #define SCSI_EMU_DEBUG 0 +extern int log_scsiemu; + static const int outcmd[] = { 0x0a, 0x2a, 0xaa, 0x15, 0x55, -1 }; static const int incmd[] = { 0x01, 0x03, 0x05, 0x08, 0x12, 0x1a, 0x5a, 0x25, 0x28, 0x34, 0x37, 0x42, 0x43, 0xa8, 0x51, 0x52, 0xbd, -1 }; static const int nonecmd[] = { 0x00, 0x0b, 0x11, 0x16, 0x17, 0x19, 0x1b, 0x1e, 0x2b, 0x35, -1 }; @@ -137,22 +139,20 @@ void scsi_clear_sense(struct scsi_data *sd) } static void showsense(struct scsi_data *sd) { -#if 0 - write_log (_T("REQUEST SENSE %d, "), sd->data_len); - for (int i = 0; i < sd->data_len; i++) { - if (i > 0) - write_log (_T(".")); - write_log (_T("%02X"), sd->buffer[i]); + if (log_scsiemu) { + for (int i = 0; i < sd->data_len; i++) { + if (i > 0) + write_log (_T(".")); + write_log (_T("%02X"), sd->buffer[i]); + } + write_log (_T("\n")); } - write_log (_T("\n")); -#endif } static void copysense(struct scsi_data *sd) { int len = sd->cmd[4]; -#if SCSI_EMU_DEBUG - write_log (_T("REQUEST SENSE length %d (%d)\n"), len, sd->sense_len); -#endif + if (log_scsiemu) + write_log (_T("REQUEST SENSE length %d (%d)\n"), len, sd->sense_len); memset(sd->buffer, 0, len); memcpy(sd->buffer, sd->sense, sd->sense_len > len ? len : sd->sense_len); if (sd->sense_len == 0) @@ -195,6 +195,7 @@ void scsi_emulate_cmd(struct scsi_data *sd) } } else if (sd->device_type == UAEDEV_HDF && sd->nativescsiunit < 0) { if (sd->cmd[0] == 0x03) { /* REQUEST SENSE */ + scsi_hd_emulate(&sd->hfd->hfd, sd->hfd, sd->cmd, 0, 0, 0, 0, 0, 0, 0); copysense(sd); } else { scsi_clear_sense(sd); diff --git a/scsitape.cpp b/scsitape.cpp index 81a68eaf..d9e7b2cd 100644 --- a/scsitape.cpp +++ b/scsitape.cpp @@ -297,7 +297,7 @@ int scsi_tape_emulate (struct scsi_data_tape *tape, uae_u8 *cmdbuf, int scsi_cmd s[2] = 5; /* ILLEGAL REQUEST */ s[12] = 0x25; /* INVALID LUN */ ls = 0x12; - goto err; + goto end; } switch (cmdbuf[0]) @@ -656,6 +656,7 @@ notape: ls = 0x12; break; } +end: *data_len = scsi_len; *reply_len = lr; *sense_len = ls; -- 2.47.3