From 92c44cb89f87e7daa05e1eb049a95d31520103fc Mon Sep 17 00:00:00 2001 From: OBattler Date: Sun, 25 Dec 2016 17:52:17 +0100 Subject: [PATCH] Changed the IOCtl implementation of READ TRACK INFORMATION so that it returns if it succeded or failed, so the ATAPI and SCSI controllers can then act accordingly. --- src/cdrom-ioctl.c | 13 +++++++++++-- src/cdrom-null.c | 5 +++++ src/cdrom.h | 2 +- src/ide.c | 14 +++++++++++--- src/scsi_cdrom.c | 15 ++++++++++++++- 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/cdrom-ioctl.c b/src/cdrom-ioctl.c index 9c26a6d5d..ac06c78b9 100644 --- a/src/cdrom-ioctl.c +++ b/src/cdrom-ioctl.c @@ -537,11 +537,13 @@ static void ioctl_read_header(uint8_t *in_cdb, uint8_t *b) ioctl_close(); } -static void ioctl_read_track_information(uint8_t *in_cdb, uint8_t *b) +static int ioctl_read_track_information(uint8_t *in_cdb, uint8_t *b) { int maxlen = 0; int len = 0; + int ret = 0; + const UCHAR cdb[12]; UCHAR buf[65535]; @@ -552,7 +554,12 @@ static void ioctl_read_track_information(uint8_t *in_cdb, uint8_t *b) ioctl_open(0); memcpy(cdb, in_cdb, 12); - SCSICommand(cdb, buf, 65535); + ret = SCSICommand(cdb, buf, 65535); + + if (!ret) + { + return 0; + } len = buf[0]; len <<= 8; @@ -569,6 +576,8 @@ static void ioctl_read_track_information(uint8_t *in_cdb, uint8_t *b) memcpy(b, buf, len); ioctl_close(); + + return 1; } static void ioctl_read_disc_information(uint8_t *b) diff --git a/src/cdrom-null.c b/src/cdrom-null.c index ab9ef29a4..f8c087835 100644 --- a/src/cdrom-null.c +++ b/src/cdrom-null.c @@ -71,6 +71,11 @@ static void null_readsector_raw(uint8_t *b, int sector, int ismsf) { } +static int null_read_track_information(uint8_t *in_cdb, uint8_t *b) +{ + return 0; +} + static int null_readtoc(unsigned char *b, unsigned char starttrack, int msf, int maxlen, int single) { return 0; diff --git a/src/cdrom.h b/src/cdrom.h index 67513f2f6..7b54fe546 100644 --- a/src/cdrom.h +++ b/src/cdrom.h @@ -13,7 +13,7 @@ typedef struct CDROM void (*read_capacity)(uint8_t *b); void (*read_header)(uint8_t *in_cdb, uint8_t *b); void (*read_disc_information)(uint8_t *b); - void (*read_track_information)(uint8_t *in_cdb, uint8_t *b); + int (*read_track_information)(uint8_t *in_cdb, uint8_t *b); int (*sector_data_type)(int sector, int ismsf); void (*readsector_raw)(uint8_t *b, int sector, int ismsf); void (*playaudio)(uint32_t pos, uint32_t len, int ismsf); diff --git a/src/ide.c b/src/ide.c index 93b2cc64d..6308fde1d 100644 --- a/src/ide.c +++ b/src/ide.c @@ -2563,7 +2563,17 @@ static void atapicommand(int ide_board) if (cdrom->read_track_information) { - cdrom->read_track_information(idebufferb, idebufferb); + ret = cdrom->read_track_information(idebufferb, idebufferb); + + if (!ret) + { + ide->atastat = READY_STAT | ERR_STAT; /*CHECK CONDITION*/ + ide->error = (SENSE_ILLEGAL_REQUEST << 4) | ABRT_ERR; + SCSISense.Asc = ASC_INV_FIELD_IN_CMD_PACKET; + ide->packetstatus = ATAPI_STATUS_ERROR; + idecallback[ide_board]=50*IDE_TIME; + return; + } len = idebufferb[0]; len <<= 8; @@ -2576,8 +2586,6 @@ static void atapicommand(int ide_board) { ide->atastat = READY_STAT | ERR_STAT; /*CHECK CONDITION*/ ide->error = (SENSE_ILLEGAL_REQUEST << 4) | ABRT_ERR; - /* if (SCSISense.SenseKey == SENSE_UNIT_ATTENTION) - ide->error |= MCR_ERR; */ SCSISense.Asc = ASC_INV_FIELD_IN_CMD_PACKET; ide->packetstatus = ATAPI_STATUS_ERROR; idecallback[ide_board]=50*IDE_TIME; diff --git a/src/scsi_cdrom.c b/src/scsi_cdrom.c index 6d7c571c9..9ce15a9b5 100644 --- a/src/scsi_cdrom.c +++ b/src/scsi_cdrom.c @@ -1159,6 +1159,7 @@ void SCSICDROM_ReadData(uint8_t id, uint8_t *cdb, uint8_t *data, int datalen) int read_length = 0; int max_length = 0; int track = 0; + int ret = 0; msf = cdb[1] & 2; @@ -1567,7 +1568,19 @@ SCSIOut: if (cdrom->read_track_information) { - cdrom->read_track_information(SCSIDevices[id].Cdb, SCSIDevices[id].CmdBuffer); + ret = cdrom->read_track_information(SCSIDevices[id].Cdb, SCSIDevices[id].CmdBuffer); + + if (!ret) + { + SCSIStatus = SCSI_STATUS_CHECK_CONDITION; + SCSISenseCodeError(SENSE_ILLEGAL_REQUEST, ASC_INV_FIELD_IN_CMD_PACKET, 0x00); + if (SCSISense.UnitAttention) + { + SCSISenseCodeError(SENSE_UNIT_ATTENTION, ASC_MEDIUM_MAY_HAVE_CHANGED, 0); + } + SCSICallback[id]=50*SCSI_TIME; + return; + } datalen = SCSIDevices[id].CmdBuffer[0]; datalen <<= 8;